PyDMD: an easy tool for dynamical systems forecasting

Nicola Demo
SISSA mathLab
Published in
4 min readDec 11, 2020

The study of dynamical systems is the focus of dynamical systems theory, which has applications to a wide variety of fields such as mathematics, physics, biology, chemistry, engineering, economics, history, and medicine. [Wikipedia]

Nowadays, dynamical systems are studied in several fields in order to understand and predict the behaviour of such systems. For sake of simplicity, we define dynamical systems as all the phenomena that depend from the time. As examples, the reader can look at the below images, where a Lorenz system, a climate simulation and a time-dependent problem in fluid dynamics are shown.

From left to right: visualisation of a Lorenz system, climate simulation and fluid dynamics simulation (source: wikipedia.com)

All these systems (and many others) have in common that the quantities we are interested in depend from the time. For the complexity of such problems, the analysis often is not trivial and, especially in a simulation context, it requires many computational resources.

Dynamic Mode Decomposition is a powerful and relatively new tool that is gaining popularity thanks to its easy applicability to many different problems. Proposed by Schmid in 2010 for the analysis of fluid dynamics simulations, it is now diffused in many fields where the analysis of dynamical systems plays a crucial role, also thanks to the model-free nature of the method. The idea of the method is to approximate the Koopman operator using a least-square procedure and a model order reduction technique. An algorithmic discussion is out of the scope of this story: if the reader is interested, we refer to the state-of-the-art literature (that we will summarise at the end) for all the details.
Long short story, with the approximation of such operator (which contains the principal physical phenomenon) it is easy to predict the future behaviour of our system, or simply analyse its dynamic.

PyDMD is a Python library that implements the dynamic mode decomposition technique and many of its variants. Completely open source, it is released on Github and it proposes many features that aim to enhance the robustness, usability and the reliability of such software. In particular:

  • a complete and updated online documentation is available at mathlab.github.io/PyDMD;
  • the package can be installed using the Python package manager: pip install pydmd;
  • PyDMD contains many different tests that helps to keep bugs under control, already embedded in a continuous integration system;
  • several tutorials proposing applications to different problems, in order to make the software easy to learn.

Ok, everything looks cool. But let see a concrete example to show how to use the software.

We suppose to have some snapshots, some frames of our system, at different times. For example, if the studied dynamical system is a Gaussian wave (in a two-dimensional domain) oscillating with less and less intensity, the resulting snapshots would look something like:

We have just 16 frames of the system. Now we can extract the value of the function in all these snapshots and arrange them into a matrix (a numpy.ndarray): we unroll them and put as column. This is all we need to apply dynamic mode decomposition. No equations, no formulas, nothing else!

Now, move into Python world: we need just few lines of code to apply the method to the data we have, assuming we have already implemented a custom function to read the snapshots and put them in the snapshots_matrix.

Very simple, isn’t? Of course there are a lot of different (hyper)parameters we can touch, to improve the results, but the structure is anyway maintained very simple and intuitive.

But, as written in the introduction, the dynamic mode decomposition allows for a system forecasting, so how we can compute it? In PyDMD the user can manipulate the temporal window where the approximated system is reconstructed, so extending it we can make a future prediction! By adding a simple instruction in the Python script dmd.dmd_time['tend'] *= 2 we can see the evolution until twice the time computed in the original system! And more precisely, such approximation should result like this:

Yes, I know, pretty amazing. We can also note that the most of the noise (voluntarily added to original snapshots) is vanished thanks to the model reduction adopted in the method.

Of course things are not always so easy: for many complex problems it is really difficult to find an approximation that returns an accurate response, but for all these cases we hope that at least working with PyDMD may ease your work!

References

  1. Schmid. Dynamic mode decomposition of numerical and experimental data. Journal of Fluid Mechanics, 2010
  2. Kutz, Brunton, Brunton, Proctor. Dynamic Mode Decomposition: Data-Driven Modeling of Complex Systems. SIAM Other Titles in Applied Mathematics, 2016
  3. Demo, Tezzele, Rozza. PyDMD: Python Dynamic Mode Decomposition. Journal of Open Source Software, https://doi.org/10.21105/joss.00530, 2018

--

--