A deep learning approach to modeling chaotic systems by enforcing Lagrangian mechanics within a Gated Recurrent Unit (GRU) architecture.
This project implements a Physics-Informed Neural Network (PINN) to predict the trajectory of a double pendulum based on video tracking data. By integrating the Euler-Lagrange equations directly into the loss function, the model learns to respect physical constraints such as energy conservation and rigid-body dynamics, significantly reducing the "drift" common in standard sequence models.
- Core: Python, PyTorch (Modeling & Autograd)
- Numerical: NumPy (Data Processing), SciPy (Signal Analysis)
- Visualization: Matplotlib (Real-time Animation & Phase Space plots)
- Architecture: Custom Gated Recurrent Unit (GRU)
- Physics Engine: Lagrangian Mechanics (Second-order ODE residuals)
-
Physics-Informed Loss: Combines standard Mean Squared Error (MSE) with a physical penalty term based on the system's Lagrangian:
$Loss = MSE + \lambda \cdot L_{physics}$ . - Custom GRU Architecture: Hand-implemented GRU cells for granular control over hidden state dynamics and gradient flow.
-
Modular MSE: Implemented circular topology logic to correctly interpret the
$0 = 2\pi$ angular relationship, preventing prediction "snapping" and spinning artifacts. - Chaos Management: Optimized for high-sensitivity dynamical systems, maintaining trajectory integrity through chaotic transitions.
- Efficient Data Pipeline: Implemented data striding and downsampling to balance computational speed with high-fidelity physical modeling.
-
Exploding Gradients: Managed the numerical instability caused by dividing by
$dt^2$ in the acceleration terms through adaptive loss annealing and gradient norm clipping. - Coordinate Misalignment: Synchronized the mathematical Lagrangian reference frame with the real-world video tracking coordinate system.
- Local Minima: Utilized a multi-stage training strategy (Warm-up -> Physics Refinement) to ensure the model captures the motion profile before enforcing strict physical laws.
git clone https://github.com/Emwook/double_pendulum.git
cd double-pendulumpip install -r requirements.txtLoad the pre-trained 18KB model and visualize the side-by-side comparison between actual tracking and AI prediction.
python scripts/demo.pyTo retrain the model or experiment with different physics weights:
python scripts/training_loop.pyThe training data for this project consists of high-frequency video tracking coordinates from Myers, Audun; Khasawneh, Firas; Tempelman, Josh; Petrushenko, David (2020), “Low-cost double pendulum for high-quality data collection with open-source video tracking and analysis”. The raw trajectories were processed and converted from pixel-space to angular coordinates (radians) to fit the Lagrangian reference frame. Link to the source:
https://data.mendeley.com/datasets/7yd2ntbh3w/1