ARotting's picture
Publish Conservative pendulum state-derivative field
01e81ce verified
|
Raw
History Blame Contribute Delete
1.51 kB
---
license: apache-2.0
tags:
- scientific-machine-learning
- hamiltonian-neural-network
- differentiable-physics
- neural-ode
- gradio
---
# Hamiltonian Pocket
Hamiltonian Pocket learns pendulum dynamics from state/derivative observations.
The structured model predicts one scalar Hamiltonian and obtains time derivatives
through the symplectic gradient. A parameter-matched MLP directly predicts the two
derivatives. Both train on the same samples and use the same RK4 solver at test time.
The benchmark measures local derivative error, long-horizon state error, and drift
in the true physical energy. It tests whether encoding conservative mechanics in the
model helps trajectories remain physically plausible.
## Verified results
Both models trained for 3,000 steps on 20,000 states. Long-horizon evaluation used
128 new initial conditions, 400 RK4 steps, and `dt=0.05`.
| Metric | Hamiltonian network | Black-box vector field |
| --- | ---: | ---: |
| Parameters | 4,417 | 4,482 |
| Held-out derivative MSE | 4.84e-6 | 1.13e-5 |
| Full-trajectory MSE | 49.00 | 119.89 |
| Final-state MSE | 201.84 | 439.03 |
| Final absolute true-energy drift | 2.95 | 343.11 |
The Hamiltonian inductive bias reduced final energy drift by about 116 times. It
did not eliminate drift in the true physical energy: the learned scalar Hamiltonian
is an approximation, and small derivative errors accumulate over 20 simulated
seconds.
## Reproduce
```powershell
uv run python projects/hamiltonian-pocket/train.py
```