The double pendulum is a physical system that due to its high sensitivity to initial conditions has a chaotic behavior. This behavior makes it ideal to study the prediction and modeling capabilities of complex physical systems using neural networks (NN).
In this work, we show a simple framework to generate datasets from simulations of the double pendulum and, of its more complex variant, the double pendulum on a cart, in order to afterwards train NNs. The equations used are based on the Matplotlib double pendulum animation.
This project has been realized with Python 3.6.8 and the following libraries:
- NumPy == 1.19.5
- Matplotlib == 3.0.3
Here is a list of the main files and directories included in the project, along with a brief description of what each one does:
double_pendulum_nn.py
: Main script to generate animations and datasets of random configurations of the double pendulum and the double pendulum on a cart.dataset/
: Directory that contains datasets for each model.double_pendulum/
: Directory for the double pendulum dataset. It has a small dataset of 500 simulations.double_pendulum_on_cart/
: Directory for the double pendulum on a cart dataset. It has a small dataset of 500 simulations.
models/
: Directory that contains a class for each model.double_pendulum.py
: Class that models the motion of a double pendulum system, providing functionality to simulate, animate, and save its dynamic behavior based on customizable physical parameters and initial conditions.double_pendulum_on_cart.py
: Class that models the motion of a double pendulum on cart system, providing functionality to simulate, animate, and save its dynamic behavior based on customizable physical parameters and initial conditions.
requirements.txt
: List of Python dependencies required to run the project.README.md
: The readme file you are currently reading.LICENSE
: The license file for the project.
Using double_pendulum_nn.py to generate animations and datasets of random configurations of the double pendulum and the double pendulum on cart is very simple. Use the following command:
python double_pendulum_nn.py <pendulum|pendulum_cart> <dataset|animation> <simulations>
The script requires three command line arguments:
<pendulum|pendulum_cart>
: Model to be used.<dataset|animation>
: Specifies if it is generated a dataset of an animation.<simulations>
: Number of simulations.
Here are two examples demonstrating how to use the command:
To create a dataset of 100 simulations of a double pendulum on a cart:
python double_pendulum_nn.py pendulum_cart dataset 100
To generate an animation of the double pendulum:
python double_pendulum_nn.py pendulum animation 1
The project has two datasets of 2000 simulations, one for each model. Each simulation corresponds to 5 seconds, where we save the information every 0.01 seconds (
Each row in each simulation of the Double Pendulum Dataset corresponds to one time step and includes the following data:
Parameter | Description |
---|---|
th1 (rad) | Angle of the first pendulum |
w1 (rad/s) | Angular velocity of the first pendulum |
th2 (rad) | Angle of the second pendulum |
w2 (rad/s) | Angular velocity of the second pendulum |
a1 (rad/s²) | Angular acceleration of the first pendulum |
a2 (rad/s²) | Angular acceleration of the second pendulum |
Each row in each simulation of the Double Pendulum on Cart Dataset corresponds to one time step and includes the following data:
Parameter | Description |
---|---|
f (N) | Control force applied to the cart at each time step |
th1 (rad) | Angle of the first pendulum |
w1 (rad/s) | Angular velocity of the first pendulum |
th2 (rad) | Angle of the second pendulum |
w2 (rad/s) | Angular velocity of the second pendulum |
x (m) | Horizontal position of the cart |
vx (m/s) | Horizontal velocity of the cart |
a1 (rad/s²) | Angular acceleration of the first pendulum |
a2 (rad/s²) | Angular acceleration of the second pendulum |
ax (m/s²) | Horizontal acceleration of the cart |
Here is a list of our proposed NN architectures. These NNs are suitable for training dynamical systems such as the double pendulum proposed in this project.
- MA-LSTM-MLP: Dynamical System Simulation with Attention and Recurrent Neural Networks.
- AR-Transformer: Robot Modeling with Autoregressive Transformers.
This project is licensed under the GNU General Public License v3.0. You can find the full text of the license in the LICENSE file or visit the GNU website for more details.
Feel free to contact Javier Fañanás Anaya for any questions or issues found with the code.