Source code for our paper on approximating Hamiltonian with sampled neural networks
Available models are:
- MLP: ODE-Net, directly approximates
q_dotandp_dot. paper - HNN: Hamiltonian neural network approximates
H, thenq_dotandp_dotare 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:
This project depends on the submodule swimnetworks:
git submodule init
git submodule updateto clone the submodule.
Create the conda environment:
conda env create --file=environments.ymlThen activate it with conda activate s-hnn.
After setting up the conda environment, you can use the bash script main located at the root of the
project.
- Run
./main --helpfor 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-HNNFirst-order error correction example:
python src/main_limited_data.py --target single_pendulum --model S-HNNFor details you can refer to our paper paper.
- All the experiment results listed in our paper, including all the trained models, are stored under
/experimentsas 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*.share used to conduct the experiments listed in our paper in a cluster environment. - The notebook
error_correction_demonstration.ipynbcontains error correction experiments.
If you use Sampled-HNNs in your research, please cite our paper.
