Skip to main content

Python package for data-driven approximations to the Koopman operator.

Project description

Build Documentation Status PyPI Codecov DOI

PyKoopman is a Python package for computing data-driven approximations to the Koopman operator.

Data-driven approximation of Koopman operator

docs/JOSS/Fig1.png

Given a nonlinear dynamical system,

\begin{equation*} x'(t) = f(x(t)), \end{equation*}

the Koopman operator governs the temporal evolution of the measurement function. Unfortunately, it is an infinite-dimensional linear operator. Most of the time, one has to project the Koopman operator onto a finite-dimensional subspace that is spanned by user-defined/data-adaptive functions.

\begin{equation*} z = \Phi(x). \end{equation*}

If the system state is also contained in such subspace, then effectively, the nonlinear dynamical system is (approximately) linearized in a global sense.

The goal of data-driven approximation of Koopman operator is to find such a set of functions that span such lifted space and the transition matrix associated with the lifted system.

Structure of PyKoopman

docs/JOSS/Fig2.png

PyKoopman package is centered around the Koopman class and KoopmanContinuous class. It consists of two key components

  • observables: a set of observables functions, which spans the subspace for projection.

  • regressor: the optimization algorithm to find the best fit for the projection of Koopman operator.

After Koopman/KoopmanContinuous object has been created, it must be fit to data, similar to a scikit-learn model. We design PyKoopman such that it is compatible to scikit-learn objects and methods as much as possible.

Features implemented

  • Observable library for lifting the state into the observable space

    • Identity (for DMD/DMDc or in case users want to compute observables themselves): Identity

    • Multivariate polynomials: Polynomial

    • Time delay coordinates: TimeDelay

    • Radial basis functions: RadialBasisFunctions

    • Random Fourier features: RandomFourierFeatures

    • Custom library (defined by user-supplied functions): CustomObservables

    • Concatenation of observables: ConcatObservables

  • System identification method for performing regression

    • Dynamic mode decomposition: PyDMDRegressor

    • Dynamic mode decomposition with control: DMDc

    • Extended dynamic mode decomposition: EDMD

    • Extended dynamic mode decomposition with control: EDMDc

    • Kernel dynamic mode decomposition: KDMD

    • Hankel Alternative View of Koopman Analysis: HAVOK

    • Neural Network DMD: NNDMD

  • Sparse construction of Koopman invariant subspace

    • Multi-task learning based on linearity consistency

Examples

1. Learning how to create observables

2. Learning how to compute time derivatives

3. Dynamic mode decomposition on two mixed spatial signals

4. Dynamic mode decomposition with control on a 2D linear system

5. Dynamic mode decomposition with control (DMDc) for a 128D system

6. Dynamic mode decomposition with control on a high-dimensional linear system

7. Successful examples of using Dynamic mode decomposition on PDE system

8. Unsuccessful examples of using Dynamic mode decomposition on PDE system

9. Extended DMD for Van Der Pol System

10. Learning Koopman eigenfunctions on Slow manifold

11. Comparing DMD and KDMD for Slow manifold dynamics

12. Extended DMD with control for chaotic duffing oscillator

13. Extended DMD with control for Van der Pol oscillator

14. Hankel Alternative View of Koopman Operator for Lorenz System

15. Hankel DMD with control for Van der Pol Oscillator

16. Neural Network DMD on Slow Manifold

17. EDMD and NNDMD for a simple linear system

18. Sparisfying a minimal Koopman invariant subspace from EDMD for a simple linear system

Installation

Language

  • Python == 3.10

Installing with pip

If you are using Linux or macOS you can install PyKoopman with pip:

pip install pykoopman

Installing from source

First clone this repository:

git clone https://github.com/dynamicslab/pykoopman

Second, it is highly recommended to use venv to get a local python environment

python -m venv venv
source ./venv/bin/activate

In windows, you activate virtual environment in a different way

.\venv\Scripts\activate.ps1

Then, to install the package, run

python -m pip install -e .

If you do not have root access, you should add the --user option to the above lines.

Installing with GPU support

After you download the Github package, go to the directory, type

python -m pip install -r requirements-dev.txt

Documentation

The documentation for PyKoopman is hosted on Read the Docs.

Community guidelines

Contributing code

We welcome contributions to PyKoopman. To contribute a new feature please submit a pull request. To get started we recommend installing the packages in “developer mode” via

python -m pip install -e .[dev]

This will allow you to run unit tests and automatically format your code. To be accepted your code should conform to PEP8 and pass all unit tests. Code can be tested by invoking

pytest

We recommed using pre-commit to format your code. Once you have staged changes to commit

git add path/to/changed/file.py

you can run the following to automatically reformat your staged code

pre-commit -a -v

Note that you will then need to re-stage any changes pre-commit made to your code.

Reporting issues or bugs

If you find a bug in the code or want to request a new feature, please open an issue.

Known issues:

  • Python 3.12 might cause unexpected problems.

Citing PyKoopman

@misc{pan2023pykoopman,
      title={PyKoopman: A Python Package for Data-Driven Approximation of the Koopman Operator},
      author={Shaowu Pan and Eurika Kaiser and Brian M. de Silva and J. Nathan Kutz and Steven L. Brunton},
      year={2023},
      eprint={2306.12962},
      archivePrefix={arXiv},
      primaryClass={eess.SY}
}

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

pykoopman-1.1.0.tar.gz (83.7 kB view details)

Uploaded Source

Built Distribution

pykoopman-1.1.0-py3-none-any.whl (95.7 kB view details)

Uploaded Python 3

File details

Details for the file pykoopman-1.1.0.tar.gz.

File metadata

  • Download URL: pykoopman-1.1.0.tar.gz
  • Upload date:
  • Size: 83.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.11

File hashes

Hashes for pykoopman-1.1.0.tar.gz
Algorithm Hash digest
SHA256 6ae2fbe68d36a29bed6160f80026aee1fa4780f3f8067b36aa8469749f57d2e1
MD5 27a5033adbb2810ce9ff5d419f8b55d5
BLAKE2b-256 c352dd14ea52bb8746a301de178f6b1cd5a997bea124d8f03846e064702b9d92

See more details on using hashes here.

File details

Details for the file pykoopman-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: pykoopman-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 95.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.11

File hashes

Hashes for pykoopman-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c63a7dc4d19882882b3fa4b7e368bcfe45dd9231078b7c7c1370636330b8a771
MD5 dcdd51dc2aa24106595b49fd74f88a35
BLAKE2b-256 c98f641404778d7b8819ce293acc9675f6a1038038d2558b7c89dd9f945db949

See more details on using hashes here.

Supported by

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