fn
hessian
→Callablehessian(func: Callable[..., Tensor], argnums: int | tuple[int, ...] = 0)Build a function returning the Hessian of a scalar-valued func.
Computes the matrix of second partial derivatives by composing
forward-mode over reverse-mode differentiation
(jacfwd(jacrev(func))). The result captures the local curvature
used by Newton-style optimisers, natural-gradient methods, and
second-order analyses such as eigenvalue spectra of the loss.
Parameters
funcCallableFunction returning a scalar Tensor.
argnumsint or tuple of int= 0Argument(s) to differentiate twice. Default
0.Returns
CallableFunction returning the Hessian tensor with shape
arg.shape + arg.shape.
Notes
For ,
Cost is dominated by JVPs over the reverse-mode gradient
graph, retained via create_graph=True.
Examples
>>> import lucid
>>> from lucid.func import hessian
>>> f = lambda x: (x ** 3).sum() # H = diag(6 * x)
>>> hessian(f)(lucid.tensor([1.0, 2.0, 3.0]))