Skip to main content

A Laplacian without a full Hessian

When your residual needs the sum of diagonal second derivatives, request that contraction directly. deep_field_laplacian propagates the value, gradient information, and Laplacian through supported layers without materializing a dense spatial Hessian.

Run and validate​

Install omnibias-torch==0.5.0rc1. This deliberately small example checks the contraction against an independent dense-Hessian trace, then verifies parameter gradients.

deep_laplacian.py
"""A direct deep Laplacian, independently checked against a dense Hessian."""
import torch
from omnibias.torch.laplacian import deep_field_laplacian

weight = torch.tensor([[0.2, -0.3], [0.5, 0.1]], dtype=torch.float64,
requires_grad=True)
bias = torch.tensor([0.1, -0.1], dtype=torch.float64)
readout = torch.tensor([[0.7, -0.4]], dtype=torch.float64)
layers = [(weight, bias, "tanh"), (readout, None, None)]
point = torch.tensor([[0.3, -0.2]], dtype=torch.float64)
laplacian = deep_field_laplacian(point, layers)

def field(x):
return (readout @ torch.tanh(weight @ x + bias)).squeeze()

reference = torch.func.hessian(field)(point[0]).trace()
assert laplacian.shape == (1, 1)
torch.testing.assert_close(laplacian.squeeze(), reference, rtol=1e-10, atol=1e-12)
laplacian.square().mean().backward()
assert weight.grad is not None and torch.isfinite(weight.grad).all()
print("Laplacian agrees with Hessian trace; parameter gradients retained.")

Download the complete script.

Save the script and run:

python -m pip install --pre "omnibias-torch==0.5.0rc1"
python deep_laplacian.py

Expected output: Laplacian agrees with Hessian trace; parameter gradients retained. The assertion compares the direct operator with an independently assembled scalar field; it also checks the (batch, 1) result shape and finite weight gradients.

Is a Laplacian the same as a Hessian?​

For a scalar field, the Laplacian is the sum of the Hessian's diagonal entries. It does not contain the off-diagonal mixed partials or reconstruct the full Hessian. Choose the direct contraction when the trace is the quantity your residual needs; use a supported Hessian or mixed-jet representation when the individual entries matter.

Shapes and scaling​

The input batch has shape (1, 2) and the output has shape (1, 1). Weights are (out_features, in_features). The direct deep path has no fixed input-dimension ceiling; for fixed widths and depth, its work and memory still grow with input dimension.

For large dimensions, do not run the dense-Hessian reference from this tiny validation example. The purpose of the contraction is to avoid that allocation.

Repeated Laplacians​

A one-hidden-layer field supports direct neural_field_polylaplacian contractions. Deep repeated Laplacians have a different budget: deep_field_polylaplacian_with_report distinguishes exact support enumeration from a directional estimator. Inspect that report rather than interpreting every mode as exact.

The Torch module and JAX module document input contracts and failure cases. A standalone JAX comparison is also available.

Solve a complete problem​

Continue with the executed notebook, including full initialization, training or optimization, numerical assertions, plots, and recorded results.