Table of Contents
Fetching ...

Hamiltonian Neural Networks

Sam Greydanus, Misko Dzamba, Jason Yosinski

TL;DR

The paper proposes Hamiltonian Neural Networks (HNNs) that learn a neural Hamiltonian H_theta(q,p) to enforce exact energy conservation in dynamics, addressing the lack of physics priors in standard neural nets. By using in-graph gradients of H_theta to match time derivatives, HNNs yield energy-preserving, reversible dynamics that generalize across tasks. Across ideal mass-spring, pendulum, real pendulum, two-body, and pixel-based pendulum scenarios, HNNs match baseline performance on pointwise losses but dramatically outperform on energy conservation, demonstrating scalability and robustness to high-dimensional observations. The work offers a general, unsupervised framework for embedding conservative physics into neural models and enables energy-based counterfactuals and precise reversible simulations.

Abstract

Even though neural networks enjoy widespread use, they still struggle to learn the basic laws of physics. How might we endow them with better inductive biases? In this paper, we draw inspiration from Hamiltonian mechanics to train models that learn and respect exact conservation laws in an unsupervised manner. We evaluate our models on problems where conservation of energy is important, including the two-body problem and pixel observations of a pendulum. Our model trains faster and generalizes better than a regular neural network. An interesting side effect is that our model is perfectly reversible in time.

Hamiltonian Neural Networks

TL;DR

The paper proposes Hamiltonian Neural Networks (HNNs) that learn a neural Hamiltonian H_theta(q,p) to enforce exact energy conservation in dynamics, addressing the lack of physics priors in standard neural nets. By using in-graph gradients of H_theta to match time derivatives, HNNs yield energy-preserving, reversible dynamics that generalize across tasks. Across ideal mass-spring, pendulum, real pendulum, two-body, and pixel-based pendulum scenarios, HNNs match baseline performance on pointwise losses but dramatically outperform on energy conservation, demonstrating scalability and robustness to high-dimensional observations. The work offers a general, unsupervised framework for embedding conservative physics into neural models and enables energy-based counterfactuals and precise reversible simulations.

Abstract

Even though neural networks enjoy widespread use, they still struggle to learn the basic laws of physics. How might we endow them with better inductive biases? In this paper, we draw inspiration from Hamiltonian mechanics to train models that learn and respect exact conservation laws in an unsupervised manner. We evaluate our models on problems where conservation of energy is important, including the two-body problem and pixel observations of a pendulum. Our model trains faster and generalizes better than a regular neural network. An interesting side effect is that our model is perfectly reversible in time.

Paper Structure

This paper contains 18 sections, 7 equations, 11 figures, 2 tables.

Figures (11)

  • Figure 1: Learning the Hamiltonian of a mass-spring system. The variables $q$ and $p$ correspond to position and momentum coordinates. As there is no friction, the baseline's inner spiral is due to model errors. By comparison, the Hamiltonian Neural Network learns to exactly conserve a quantity that is analogous to total energy.
  • Figure 2: Analysis of models trained on three simple physics tasks. In the first column, we observe that the baseline model's dynamics gradually drift away from the ground truth. The HNN retains a high degree of accuracy, even obscuring the black baseline in the first two plots. In the second column, the baseline's coordinate MSE error rapidly diverges whereas the HNN's does not. In the third column, we plot the quantity conserved by the HNN. Notice that it closely resembles the total energy of the system, which we plot in the fourth column. In consequence, the HNN roughly conserves total energy whereas the baseline does not.
  • Figure 3: Analysis of an example 2-body trajectory. The dynamics of the baseline model do not conserve total energy and quickly diverge from ground truth. The HNN, meanwhile, approximately conserves total energy and accrues a small amount of error after one full orbit.
  • Figure 4: Predicting the dynamics of the pixel pendulum. We train an HNN and its baseline to predict dynamics in the latent space of an autoencoder. Then we project to pixel space for visualization. The baseline model rapidly decays to lower energy states whereas the HNN remains close to ground truth even after hundreds of frames. It mostly obscures the ground truth line in the bottom plot.
  • Figure 5: Visualizing integration in the latent space of the Pixel Pendulum model. We alternately integrate $\mathbf{S_{\mathcal{H}}}$ at low energy (blue circle), $\mathbf{R_{\mathcal{H}}}$ (purple line), and then $\mathbf{S_{\mathcal{H}}}$ at higher energy (red circle).
  • ...and 6 more figures