Double Pendulum

notion image
notion image
Double pendulum is defined by the following equations:
 
 
Solving the Euler-Lagrange equation for the system we get the following set of equations.
Assuming for
Insight
As long as we can put the equation like this, we don’t have to worry about the data of derivative. We can obtain it by solving RHS through diff equation solvers. And further do calculations using this as well.
The following code returns the derivative with respect to the time.

Dynamics from the Lagrangian

In order to obtain the trajectory back from the learned Lagrangian Neural Network, is expressed as equations of gradients of our LNN, and integrated twice using odeint — a built in function in script to integrate.
 
 

Dynamics from the LNN Equation

 
Normalize
 
Runga-Kutta Method

Generate training data

 
jax.vmap
partial from functools
Returns a function with partial arguments filled up https://docs.python.org/3/library/functools.html
Initial value and time
Data generation
x_train is generated by using the function solve_analytical : (Initial state, times) → Integration of dynamics equation (f_analytical).
xt_train is generated by applying f_analytical to x_train
Question
Note that xt is generated by the applying the RHS function on the solution which was generated by numerically integrating that same function.
 

Network

Replace the Lagrangian with a parametric model. Here the function learned_lagrangian is a function of learnable params and returns the Lagrangian function defined inside it as a neural network.
 

Loss function

 
badge