Giter Club home page Giter Club logo

decon-hnn's Introduction

Deconstructing The Inductive Biases of Hamiltonian Neural Networks

This repo contains the implementation and the experiments for the paper

Deconstructing The Inductive Biases of Hamiltonian Neural Networks by Nate Gruver, Marc Finzi, Sam Stanton, and Andrew Gordon Wilson.

Code

Our repo was constructed from https://github.com/mfinzi/constrained-hamiltonian-neural-networks.git

Installation instructions

Pip

git clone https://github.com/ngruver/decon-hnn.git
cd decon-hnn
pip install -r requirements.txt

Conda

git clone https://github.com/ngruver/decon-hnn.git
cd decon-hnn
conda env create -f decon-hnn.yml

View experimental runs and recreate paper figures

All figures from the paper can be recreated by running the notebooks

energy_plots.ipynb

bar_plots.ipynb

These notebooks process data from the following wandb sweeps

https://wandb.ai/ngruver/physics-uncertainty-exps/sweeps

https://wandb.ai/samuelstanton/physics-uncertainty-exps/sweeps

All experimental data, and the associated configurations, are contained in these sweeps.

Train pendulum models

You can train the models NN (NODE), MechanicsNN (NODE + SO), and HNN using the model_type option as shown below.

python toy_systems.py --system_type "ChainPendulum" --model_type "NN"
python toy_systems.py --system_type "ChainPendulum" --model_type "MechanicsNN"
python toy_systems.py --system_type "ChainPendulum" --model_type "HNN"

The other systems, with and without friction, can be specified as SpringPendulum, FrictionChainPendulum, and FrictionSpringPendulum.

Train Mujoco models

To train models on mujoco, you must first download our saved mujoco trajectories with full state and velocity.

Mac

brew install gdrive
gdrive download 1Vdf8rjPXabfMaCouNfqUYf0ifDW3qAU2 --recursive
mv full_state_mujoco_trajs data

Linux

pip install gshell
gshell init
gshell download --with-id '1Vdf8rjPXabfMaCouNfqUYf0ifDW3qAU2' --recursive
mv full_state_mujoco_trajs data

Once the data has been downloaded, NODE, CoupledNODE(NODE + SO), and MixtureHNN (SymODEN) models can be trained as shown below.

python mujoco.py --model_type "NODE" --task "HopperFull-v0"
python mujoco.py --model_type "CoupledNODE" --task "HopperFull-v0"
python mujoco.py --model_type "MixtureHNN" --task "HopperFull-v0"

The other mujoco tasks included in the paper can be specified as SwimmerFull-v0 and HalfCheetahFull-v0

Citation

If you find our work helpful, please cite it with

@inproceedings{
  gruver2022deconstructing,
  title={Deconstructing the Inductive Biases of Hamiltonian Neural Networks},
  author={Nate Gruver and Marc Anton Finzi and Samuel Don Stanton and Andrew Gordon Wilson},
  booktitle={International Conference on Learning Representations},
  year={2022},
  url={https://openreview.net/forum?id=EDeVYpT42oS}
}

decon-hnn's People

Contributors

ngruver avatar mfinzi avatar

Stargazers

MuhammadAnwar avatar yin huang avatar Asem avatar Ilze Amanda Auzina avatar  avatar Fei_Ni avatar Magnus Ross avatar Farrukh Nauman avatar Moritz Schneider avatar Vaibhav Bansal avatar

Watchers

James Cloos avatar Andrew Gordon Wilson avatar  avatar  avatar  avatar

Forkers

joe-nano

decon-hnn's Issues

Some problem with mujoco data downloading

Hello!
It's really an exciting work and we really appreciate your released codes ! But we found some errors when we tried to download the mujoco training data you provided. Maybe something wrong with the authentication and vertification codes of gdrive api but we still cannot solve it after a few days' trying. If it is convenient for you, could you provide the direct link for us please to download the data via google drive instead of gdrive which occurs some bugs for us?
We really appreciate your time and help! Best wishes!

Code can't run

Running the command line python toy_systems.py --system_type "ChainPendulum" --model_type "MechanicsNN" returns the following error, could you please check?

NN
{'C': 5,
 'bs': 200,
 'data_seed': 0,
 'device': 'cuda:0',
 'loss': 'l2',
 'lr': 0.005,
 'n_systems': 1000,
 'net_cfg': {'hidden_size': 128},
 'net_seed': 0,
 'num_epochs': 2000,
 'regen': False,
 'tau': 10.0,
 'weight_decay': 0.0001}
Traceback (most recent call last):
  File "/home/ubuntu/decon-hnn/toy_systems.py", line 68, in <module>
    Fire(main)
  File "/home/ubuntu/anaconda3/envs/check/lib/python3.9/site-packages/fire/core.py", line 141, in Fire
    component_trace = _Fire(component, args, parsed_flag_args, context, name)
  File "/home/ubuntu/anaconda3/envs/check/lib/python3.9/site-packages/fire/core.py", line 466, in _Fire
    component, remaining_args = _CallAndUpdateTrace(
  File "/home/ubuntu/anaconda3/envs/check/lib/python3.9/site-packages/fire/core.py", line 681, in _CallAndUpdateTrace
    component = fn(*varargs, **kwargs)
  File "/home/ubuntu/decon-hnn/toy_systems.py", line 60, in main
    trainer = make_trainer(**cfg, network=net, body=body,
TypeError: make_trainer() got an unexpected keyword argument 'loss'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.