Skip to content

AlphaGergedan/Sampling-HNNs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Training Hamiltonian neural networks without backpropagation

Source code for our paper on approximating Hamiltonian with sampled neural networks

Models

Available models are:

  • MLP: ODE-Net, directly approximates q_dot and p_dot. paper
  • HNN: Hamiltonian neural network approximates H, then q_dot and p_dot are recovered using automatic differentiation and Hamilton's equations. paper

All the models are available in sampled form. Sampled models have the S- prefix, which stands for Sampled. In this case, the model's hidden layer parameters are sampled, and the network's last layer is set using the least-squares solution. Different sampling options and resampling using approximate values are available for the SWIM method. paper

Here are the sampled ODE-Net (S-MLP) and HNN (S-MLP) models with their architecture illustrations for comparison:


Setup

Submodule

This project depends on the submodule swimnetworks:

git submodule init
git submodule update

to clone the submodule.

Environment

Create the conda environment:

conda env create --file=environments.yml

Then activate it with conda activate s-hnn.

Examples

After setting up the conda environment, you can use the bash script main located at the root of the project.

  • Run ./main --help for usage.
  • Training a traditional network: ./main --target single_pendulum --model {MLP,HNN}
  • Sampling a network: ./main --target single_pendulum --model {S-MLP,S-HNN}

Here is an example to quickly train a Sampled-HNN for single pendulum:

python src/main.py --target single_pendulum --model S-HNN

First-order error correction example:

python src/main_limited_data.py --target single_pendulum --model S-HNN

For details you can refer to our paper paper.


Paper experiments

  • All the experiment results listed in our paper, including all the trained models, are stored under /experiments as pickle files and categorized.
  • In order to reproduce the experiments, refer to the scripts /src/*experiment.py.
  • In order to analyze the results we prepared notebooks located at the root of the project /analyze-*.ipynb.
  • The scripts /batch*.sh are used to conduct the experiments listed in our paper in a cluster environment.
  • The notebook error_correction_demonstration.ipynb contains error correction experiments.

Citation

If you use Sampled-HNNs in your research, please cite our paper.

About

Quickly train accurate Hamiltonian Neural Networks with data-driven random features on CPUs.

Resources

License

Stars

Watchers

Forks

Contributors