Skip to main content

A general-purpose Python package for Koopman theory using deep learning.

Project description

DLKoopman: A general-purpose Python package for Koopman theory using deep learning.

Koopman theory is a technique to encode sampled data (aka states) of a nonlinear dynamical system into a linear domain. This is very powerful as a linear model can:

  • Give insight into the dynamics via eigenvalues and eigenvectors.
  • Leverage linear algebra techniques to easily analyze the system and predict its behavior under unknown conditions.

Why DLKoopman?

DLKoopman uses deep learning to learn an encoding of a nonlinear dynamical system into a linear domain, while simultaneously learning the dynamics of the linear model. DLKoopman bridges the gap between:

  • Software packages that restrict the learning of a good encoding (e.g. pykoopman), and
  • Efforts that learn encodings for specific applications instead of being a general-purpose tool (e.g. DeepKoopman).

Key DLKoopman features

  • State prediction (StatePred) - Train on individual states of a system, then predict unknown states.
    • E.g: What is the pressure vector on this aircraft for $23.5^{\circ}$ angle of attack?
  • Trajectory prediction (TrajPred) - Train on generated trajectories of a system, then predict unknown trajectories for new initial states.
    • E.g: What is the behavior of this pendulum if I start from the point $[1,-1]$?
  • General-purpose and reusable - supports data from any dynamical system.
  • Novel error function Average Normalized Absolute Error (ANAE) for visualizing performance.
  • Extensive options and a ready-to-use hyperparameter search module to improve performance.
  • Built using Pytorch, supports both CPU and GPU platforms.

Read more about DLKoopman in this blog article.

Installation

With pip (for regular users)

pip install dlkoopman

From source (for development)

git clone https://github.com/GaloisInc/dlkoopman.git
cd dlkoopman
pip install .

Running as a Docker container

DLKoopman can also be run as a docker container by pulling the image from galoisinc/dlkoopman:<version>, e.g. docker pull galoisinc/dlkoopman:v1.2.1.

Tutorials and examples

Available in the examples folder.

Documentation and API Reference

Available at https://galoisinc.github.io/dlkoopman/.

Changelog

See Releases and their notes.

Description

Koopman theory

Assume a dynamical system $x_{i+1} = F(x_i)$, where $x$ is the (generally multi-dimensional) state of the system at index $i$, and $F$ is the (generally nonlinear) evolution rule describing the dynamics of the system. Koopman theory attempts to encode $x$ into a different space $y = g(x)$ where the dynamics are linear, i.e. $y_{i+1} = Ky_i$, where $K$ is the Koopman matrix. This is incredibly powerful since the state $y_i$ at any index $i$ can be predicted from the initial state $y_0$ as $y_i = K^iy_0$. This is then decoded back into the original space as $x = g^{-1}(y)$.

For a thorough mathematical treatment, see this technical report.

dlkoopman training

This is a small example with three input states $\left[x_0, x_1, x_2\right]$. These are passed through an encoder neural network to get encoded states $\left[y_0, y_1, y_2\right]$. These are used to learn $K$, and also passed through a decoder neural network to get decoded states $\left[\hat{x}_0, \hat{x}_1, \hat{x}_2\right]$. The Koopman matrix $K$ is used to derive predicted encoded states $\left[\textsf{y}_1, \textsf{y}_2\right]$, which are then passed through the same decoder to get predicted decoded states $\left[\hat{\textsf{x}}_1, \hat{\textsf{x}}_2\right]$ as approximations to the original input states.

Errors mimimized during training:

  • Train the autoencoder - Reconstruction recon between input states $x$ and decoded states $\hat{x}$.
  • Train the Koopman matrix - Linearity lin between encoded states $y$ and predicted encoded states $\textsf{y}$.
  • Combine the above - Prediction pred between input states $x$ and predicted decoded states $\hat{\textsf{x}}$.

dlkoopman prediction

Prediction happens after training.

(a) State prediction - Compute predicted states for new indexes such as $i'$. This uses the eigendecomposition of $K$, so $i'$ can be any real number - positive (forward extapolation), negative (backward extrapolation), or fractional (interpolation).

(b) Trajectory prediction - Generate predicted trajectories $j'$ for new starting states such as $x^{j'}_0$. This uses a linear neural net layer to evolve the initial state.

Known issues

Some common issues and ways to overcome them are described in the known issues.

How to cite

Please cite the accompanying paper:

@inproceedings{Dey2023_L4DC,
    author = {Sourya Dey and Eric William Davis},
    title = {{DLKoopman: A deep learning software package for Koopman theory}},
    booktitle = {Proceedings of The 5th Annual Learning for Dynamics and Control Conference},
    pages = {1467--1479},
    volume = {211},
    series = {Proceedings of Machine Learning Research},
    publisher = {PMLR},
    year = {2023},
    month = {Jun}
}

References

  • B. O. Koopman - Hamiltonian systems and transformation in Hilbert space
  • J. Nathan Kutz, Steven L. Brunton, Bingni Brunton, Joshua L. Proctor - Dynamic Mode Decomposition
  • Bethany Lusch, J. Nathan Kutz & Steven L. Brunton - Deep learning for universal linear embeddings of nonlinear dynamics

Distribution Statement

This material is based upon work supported by the United States Air Force and DARPA under Contract No. FA8750-20-C-0534. Any opinions, findings and conclusions or recommendations expressed in this material are those of the author(s) and do not necessarily reflect the views of the United States Air Force and DARPA. Distribution Statement A, "Approved for Public Release, Distribution Unlimited."

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dlkoopman-1.2.1.tar.gz (27.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dlkoopman-1.2.1-py3-none-any.whl (33.1 kB view details)

Uploaded Python 3

File details

Details for the file dlkoopman-1.2.1.tar.gz.

File metadata

  • Download URL: dlkoopman-1.2.1.tar.gz
  • Upload date:
  • Size: 27.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.13.7 Darwin/23.4.0

File hashes

Hashes for dlkoopman-1.2.1.tar.gz
Algorithm Hash digest
SHA256 4431a86499bd1c3855326bd6a318c3a3cc4908cc8e98ea844a538e503587b97d
MD5 be71d4b5aa9fc5fa85e4d4862cbd602b
BLAKE2b-256 d0891dfd89a21923d56789f1673b32d4f61c92bf15ecb0301712f7532022308c

See more details on using hashes here.

File details

Details for the file dlkoopman-1.2.1-py3-none-any.whl.

File metadata

  • Download URL: dlkoopman-1.2.1-py3-none-any.whl
  • Upload date:
  • Size: 33.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.13.7 Darwin/23.4.0

File hashes

Hashes for dlkoopman-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9165e1134399425965eb9d3635b69da711ba77d009ae89579bb1f6b9054fd3a8
MD5 ac202e73d161bba3bb13bb7993404431
BLAKE2b-256 0c59fb58185909c1e1e4000f9604da9e90aeb57eb7dea1c55d7a17c61b43f16e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page