Computing Library › Scientific Ml
Scientific Ml

Hamiltonian Neural Networks

Hamiltonian neural networks learn a scalar energy function whose derivatives generate the dynamics, conserving energy by construction.

Learning the energy, not the flow

Classical mechanics can be written in Hamiltonian form: a single scalar function, the Hamiltonian, encodes the total energy, and the equations of motion follow from its partial derivatives. A Hamiltonian neural network learns this scalar function from data rather than learning the velocity field directly. The dynamics are then obtained by differentiating the learned Hamiltonian.

How conservation emerges

Kronos motion — energy for everyone

Hamilton's equations state that position derivatives equal the gradient of the Hamiltonian with respect to momentum, and momentum derivatives equal the negative gradient with respect to position. Because the network's outputs are built from these gradients, the resulting flow conserves the learned Hamiltonian exactly along trajectories. Energy conservation is not enforced by a penalty; it is a mathematical consequence of the structure.

Training

The network takes the phase-space state, position and momentum, and outputs a single scalar. Automatic differentiation computes the required gradients, and the predicted time derivatives are compared to observed ones. The loss is an ordinary regression on the derivatives, but the architecture guarantees the physics of the resulting motion.

Benefits

Limits

The clean guarantees assume the system is conservative. Real systems with friction, driving, or dissipation are not purely Hamiltonian and need extensions that add damping or forcing terms. Where energy is genuinely conserved, however, Hamiltonian networks capture the dynamics with fewer data and far greater long-horizon reliability than unstructured models.