Skip to content

About

Learning pendulum dynamics from 40 observations with FNN, SympNet, and PINN in PyTorch — comparing rollout accuracy, energy conservation, and physical parameter recovery.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

11 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Learning Dynamical Systems from Data

Can a neural network learn physics from 40 data points? This project compares three PyTorch models on one task: learning the dynamics of a frictionless pendulum and predicting its future motion.

Model Idea Built-in physical structure
FNN (feedforward network) Learns the one-step map $x_i \mapsto x_{i+1}$ directly from data None
SympNet (symplectic network) Stacks alternating symplectic shear layers, so the learned map preserves phase-space area Symplectic geometry
PINN (physics-informed network) Fits the trajectory while penalizing violations of Hamilton's equations, learning the physical parameters $m$ and $l$ along the way The governing equations

The main finding is that the evaluation metrics disagree with each other. The model with the best short-term accuracy is not the one that best conserves energy, and physical structure only helps when it matches the task. Every model is scored on four diagnostics so these trade-offs are visible.

Problem setup

The pendulum is a Hamiltonian system with state $x = (p_\theta, \theta)$:

$$ \frac{dp_\theta}{dt} = -mgl\sin\theta, \qquad \frac{d\theta}{dt} = \frac{p_\theta}{ml^2}, \qquad H = \frac{p_\theta^2}{2ml^2} + mgl(1 - \cos\theta) $$

  • Data: 140 states sampled at step size $h = 0.1$ from a Störmer–Verlet simulation with $m = l = g = 1$ and $(p_\theta, \theta)_0 = (0, 1)$
  • Train: the first 40 states (data/train.txt)
  • Test: the next 100 states (data/test.txt), used only for evaluation

Results

Metric FNN SympNet PINN + Störmer–Verlet
One-step (teacher-forcing) MSE 1.66e-5 5.29e-6 —
Mean rollout MSE 2.83e-4 4.34e-3 1.45e-6
Rollout energy range (true data: 1.7e-14) 4.82e-2 1.47e-2 1.17e-3
Recovered parameters — — $m$ = 0.99940, $l$ = 1.00032

FNN and SympNet roll out 100 steps from the last training state. The PINN's learned $m$ and $l$ go into a Störmer–Verlet integrator that simulates the full 140-step trajectory from $t = 0$.

Key takeaways

  • Low one-step error doesn't guarantee good long-horizon predictions. Both learned maps are accurate one step ahead, but when a model is fed its own predictions, small errors pile up and the trajectory drifts off the true orbit.
  • Better energy conservation doesn't mean better phase accuracy. SympNet's energy range is about 3× smaller than the FNN's, so it stays near the correct orbit. Its rollout MSE is still higher because it moves along that orbit at slightly the wrong speed, and the phase error builds up over time.
  • Correct physics gives the most accurate predictions. The PINN recovers $m$ and $l$ to within 0.1% of their true values, and simulating with those values gives the lowest rollout error of any model.
  • Some parameters matter far more than others. A 1% error in $l$ raises rollout MSE by about 450–550×, while a 1% error in $m$ raises it by only about 10–20×. That's because $l$ appears squared in $\dot\theta = p_\theta / (ml^2)$ and sets the oscillation period.

Phase portrait: true vs FNN vs SympNet rollout Energy over rollout: true vs FNN vs SympNet

PINN learned m and l converging to 1 Trajectory error under ±1% parameter perturbations

Repository structure

├── data/
│   ├── train.txt                  # 40 training states [p_theta, theta]
│   └── test.txt                   # 100 held-out states
├── notebooks/
│   └── pendulum_dynamics.ipynb    # Full analysis: sanity checks, FNN, SympNet, PINN, comparison
├── figures/                       # Key plots used in this README
├── docs/
│   └── slides.pdf                 # Project presentation
└── requirements.txt

Running it

git clone https://github.com/axlezhao/Learning-Dynamical-Systems-From-Data.git
cd Learning-Dynamical-Systems-From-Data
python -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt
jupyter lab notebooks/pendulum_dynamics.ipynb

The notebook runs on the CPU or on an Apple Silicon GPU (MPS) and takes a few minutes. The saved outputs match the results above. The FNN and PINN results reproduce closely on a fresh run. SympNet training is less stable (its loss spikes during training), so its numbers can change noticeably between runs.

Notebook contents

  1. Physics sanity checks: confirms the data trace a closed phase-space orbit and conserve energy to floating-point precision
  2. FNN: trains the one-step map, then compares one-step and rollout error, phase portraits and energy drift
  3. SympNet: covers the symplectic shear architecture, a proposed Jacobian-based test for symplecticity, and an energy vs. phase-accuracy analysis
  4. PINN: combines data and physics residuals in the loss, learns $m$ and $l$, analyzes whether they can be identified, and tests sensitivity to ±1% parameter changes
  5. Comparative analysis: ranks the models by inductive bias and discusses robustness to noisy data

Background

This was a course project for APMA 2070 (Deep Learning for Scientific Computing), Brown University. The problem statement and dataset were provided by the course. The models, experiments and analysis are my own.

References

  • Jin et al., SympNets: Intrinsic structure-preserving symplectic networks for identifying Hamiltonian systems, Neural Networks, 2020.
  • Raissi, Perdikaris & Karniadakis, Physics-informed neural networks, Journal of Computational Physics, 2019.

Author

Axle Zhao · GitHub

About

Learning pendulum dynamics from 40 observations with FNN, SympNet, and PINN in PyTorch — comparing rollout accuracy, energy conservation, and physical parameter recovery.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages