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 |
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 |
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.
The pendulum is a Hamiltonian system with state
-
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
| 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 | — | — |
|
FNN and SympNet roll out 100 steps from the last training state. The PINN's learned
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.
├── 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
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.ipynbThe 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.
- Physics sanity checks: confirms the data trace a closed phase-space orbit and conserve energy to floating-point precision
- FNN: trains the one-step map, then compares one-step and rollout error, phase portraits and energy drift
- SympNet: covers the symplectic shear architecture, a proposed Jacobian-based test for symplecticity, and an energy vs. phase-accuracy analysis
-
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 - Comparative analysis: ranks the models by inductive bias and discusses robustness to noisy data
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.
Axle Zhao · GitHub



