Home

Awesome

Hamiltonian Neural Networks

Sam Greydanus, Misko Dzamba, Jason Yosinski | 2019

overall-idea.png

Basic usage

To train a Hamiltonian Neural Network (HNN):

To analyze results

Summary

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.

The HNN recipe

  1. Make a dataset of pixel-space observations of a physical system where energy is conserved. Here we're working with a pendulum.

pendulum-dataset.gif.png

  1. Train an autoencoder on the dataset. The autoencoder is a bit unusual: its latent representation gets fed to the HNN, which tries to model the system's dynamics in latent space.

autoencoder-hnn.png

  1. Since the HNN uses the latent representation to model dynamics, we can think of the latent factors as being analogous to canonical coordinates (e.g. position and velocity).

latents-hnn.png

  1. Phase space plots are a common way to visualize Hamiltonians. We can make a phase space plot in the autoencoder's latent space. We can also integrate along the energy contours of phase space to predict the dynamics of the system (in the figure below, we intentionally "add energy" halfway through).

integrate-latent-hnn.png

  1. After integrating in latent space, we can project back into pixel space to simulate the dynamics of the system.

pendulum-compare-labeled.gif

Here's what it looks like when we add energy halfway through the simulation:

pendulum-compare-labeled.gif

Modeling larger systems

We can also model larger systems -- systems with more than one pair of canonical coordinates. The two-body problem, for example, has four coordinate pairs.

orbits-compare.gif

Numbers

Train loss

Baseline NNHamiltonian NN
Ideal mass-spring3.7134e-02 +/- 1.9143e-033.6933e-02 +/- 1.9128e-03
Ideal pendulum3.2606e-02 +/- 1.7434e-033.2787e-02 +/- 1.7567e-03
Real pendulum2.7455e-03 +/- 2.0735e-049.2376e-03 +/- 5.0263e-04
2 body problem3.2682e-05 +/- 1.2022e-062.9959e-06 +/- 6.5500e-08
3 body problem9.5573e-02 +/- 6.5610e-028.0346e-02 +/- 2.1470e-02
Pixel pendulum1.7731e-04 +/- 2.4202e-061.8683e-04 +/- 2.4238e-06

Test loss

Do the same thing with test data

Baseline NNHamiltonian NN
Ideal mass-spring3.6656e-02 +/- 1.8652e-033.5928e-02 +/- 1.8328e-03
Ideal pendulum3.5273e-02 +/- 1.7970e-033.5586e-02 +/- 1.8178e-03
Real pendulum2.1864e-03 +/- 3.3296e-045.9584e-03 +/- 6.1798e-04
2 body problem2.9575e-05 +/- 8.8900e-072.8218e-06 +/- 4.2020e-08
3 body problem3.8000e-01 +/- 4.1612e-014.8809e-01 +/- 4.7745e-01
Pixel pendulum1.7306e-04 +/- 3.2413e-061.8451e-04 +/- 3.3422e-06

Energy MSE

Baseline NNHamiltonian NN
Ideal mass-spring1.7077e-01 +/- 2.06e-023.8416e-04 +/- 6.53e-05
Ideal pendulum4.1519e-02 +/- 9.62e-032.4852e-02 +/- 5.42e-03
Real pendulum3.8564e-01 +/- 6.92e-021.4477e-02 +/- 4.65e-03
2 body problem6.3276e-02 +/- 3.36e-023.8751e-05 +/- 5.04e-06
3 body problem1.0906e+02 +/- 7.74e+014.1926e-02 +/- 3.39e-02
Pixel pendulum9.2748e-03 +/- 1.14e-031.5315e-04 +/- 8.42e-06

Dependencies

This project is written in Python 3.