Skip to content

sofiakloukianova/Sampling-HNNs

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

52 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Random Feature Hamiltonian Networks for N-Body Problems

Bachelor's Thesis: RF-HNNs-Thesis.pdf
Bachelor's Thesis Presentation: RF-HNNs-Presentation.pdf


Original Work

This repository is based on the implementation from: Training Hamiltonian Neural Networks without Backpropagation


Models

The following models are available:

  • MLP: ODE-Net, directly approximates q_dot and p_dot. paper

  • HNN: Hamiltonian neural network approximates H, then recovers q_dot and p_dot using automatic differentiation and Hamilton’s equations. paper

All models are available in sampled form (S-MLP, S-HNN). In sampled models, hidden-layer parameters are randomly sampled and the final layer is computed using a least-squares solution.
Different sampling strategies are available through the SWIM method. paper


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 the original paper.


This Project

This repository extends the original Sampled-HNN framework to gravitational N-body systems.

Main additions:

  • 2-body orbit generation : src/data/two_body_orbit_generator.py
  • 3-body orbit generation : src/data/three_body_orbit_generator.py
  • Hamiltonian formulation of the 2-body system : src/hamiltonian/two_body.py
  • Hamiltonian formulation of the 3-body system : src/hamiltonian/three_body.py
  • Symplectic integrators : src/integrators/
  • Training and evaluation notebooks for 2-body and 3-body systems : analyze_two_body.ipynb & analyze_three_body.ipynb
  • Generated plots for the thesis plots/

About

Random Feature Hamiltonian Neural Networks for N-body Problems (Bachelor's Thesis)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Jupyter Notebook 93.5%
  • Python 6.3%
  • Shell 0.2%