pykoop
Koopman operator identification library in Python, compatible with `scikit-learn`
Science Score: 95.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
✓DOI references
Found 5 DOI reference(s) in README and JOSS metadata -
✓Academic publication links
Links to: arxiv.org, zenodo.org -
✓Committers with academic emails
2 of 2 committers (100.0%) from academic institutions -
○Institutional organization owner
-
✓JOSS paper metadata
Published in Journal of Open Source Software
Keywords
control
dynamical-systems
koopman
machine-learning
scikit-learn
Last synced: 6 months ago
·
JSON representation
Repository
Koopman operator identification library in Python, compatible with `scikit-learn`
Basic Info
- Host: GitHub
- Owner: decargroup
- License: mit
- Language: Python
- Default Branch: main
- Homepage: https://pykoop.readthedocs.io/en/stable/
- Size: 53.3 MB
Statistics
- Stars: 81
- Watchers: 3
- Forks: 7
- Open Issues: 8
- Releases: 15
Topics
control
dynamical-systems
koopman
machine-learning
scikit-learn
Created over 4 years ago
· Last pushed 7 months ago
Metadata Files
Readme
Contributing
License
Code of conduct
Citation
Codeowners
README.rst
.. role:: class(code)
pykoop
======
.. image:: https://github.com/decargroup/pykoop/actions/workflows/test-package.yml/badge.svg
:target: https://github.com/decargroup/pykoop/actions/workflows/test-package.yml
:alt: Test package
.. image:: https://readthedocs.org/projects/pykoop/badge/?version=stable
:target: https://pykoop.readthedocs.io/en/stable/?badge=stable
:alt: Documentation status
.. image:: https://zenodo.org/badge/DOI/10.5281/zenodo.5576490.svg
:target: https://doi.org/10.5281/zenodo.5576490
:alt: DOI
.. image:: https://mybinder.org/badge_logo.svg
:target: https://mybinder.org/v2/gh/decargroup/pykoop/main?labpath=notebooks%2F1_example_pipeline_simple.ipynb
:alt: Examples on binder
``pykoop`` is a Koopman operator identification library written in Python. It
allows the user to specify Koopman lifting functions and regressors in order to
learn a linear model of a given system in the lifted space.
.. image:: https://raw.githubusercontent.com/decargroup/pykoop/main/doc/_static/pykoop_diagram.png
:alt: Koopman pipeline diagram
To learn more about Koopman operator theory, check out
`this talk `_
or
`this review article `_.
``pykoop`` places heavy emphasis on modular lifting function construction and
``scikit-learn`` compatibility. The library aims to make it easy to
automatically find good lifting functions and regressor hyperparameters by
leveraging ``scikit-learn``'s existing cross-validation infrastructure.
``pykoop`` also gracefully handles control inputs and multi-episode datasets
at every stage of the pipeline.
``pykoop`` also includes several experimental regressors that use linear matrix
inequalities to constraint the asymptotic stability of the Koopman system, or
regularize the regression using its H-infinity norm. Check out
`arXiv:2110.09658 [eess.SY] `_ and
`arXiv:2102.03613 [eess.SY] `_ for details.
Example
=======
Consider Tikhonov-regularized EDMD with polynomial lifting functions applied to
mass-spring-damper data. Using ``pykoop``, this can be implemented as:
.. code-block:: python
import pykoop
from sklearn.preprocessing import MaxAbsScaler, StandardScaler
# Get example mass-spring-damper data
eg = pykoop.example_data_msd()
# Create pipeline
kp = pykoop.KoopmanPipeline(
lifting_functions=[
('ma', pykoop.SkLearnLiftingFn(MaxAbsScaler())),
('pl', pykoop.PolynomialLiftingFn(order=2)),
('ss', pykoop.SkLearnLiftingFn(StandardScaler())),
],
regressor=pykoop.Edmd(alpha=1),
)
# Fit the pipeline
kp.fit(
eg['X_train'],
n_inputs=eg['n_inputs'],
episode_feature=eg['episode_feature'],
)
# Predict using the pipeline
X_pred = kp.predict_trajectory(eg['x0_valid'], eg['u_valid'])
# Score using the pipeline
score = kp.score(eg['X_valid'])
# Plot results
kp.plot_predicted_trajectory(eg['X_valid'], plot_input=True)
More examples are available in ``examples/``, in ``notebooks/``, or on
`binder `_.
Library layout
==============
Most of the required classes and functions have been imported into the
``pykoop`` namespace. The most important object is the
:class:`pykoop.KoopmanPipeline`, which requires a list of lifting functions and
a regressor.
Some example lifting functions are
- :class:`pykoop.PolynomialLiftingFn`,
- :class:`pykoop.RbfLiftingFn`,
- :class:`pykoop.DelayLiftingFn`, and
- :class:`pykoop.BilinearInputLiftingFn`.
``scikit-learn`` preprocessors can be wrapped into lifting functions using
:class:`pykoop.SkLearnLiftingFn`. States and inputs can be lifted independently
using :class:`pykoop.SplitPipeline`. This is useful to avoid lifting inputs.
Some basic regressors included are
- :class:`pykoop.Edmd` (includes Tikhonov regularization),
- :class:`pykoop.Dmdc`, and
- :class:`pykoop.Dmd`.
More advanced (and experimental) LMI-based regressors are included in the
``pykoop.lmi_regressors`` namespace. They allow for different kinds of
regularization as well as hard constraints on the Koopman operator.
You can roll your own lifting functions and regressors by inheriting from
:class:`pykoop.KoopmanLiftingFn`, :class:`pykoop.EpisodeIndependentLiftingFn`,
:class:`pykoop.EpisodeDependentLiftingFn`, and
:class:`pykoop.KoopmanRegressor`.
Some sample dynamic models are also included in the ``pykoop.dynamic_models``
namespace.
Installation and testing
========================
``pykoop`` can be installed from PyPI using
.. code-block:: sh
$ pip install pykoop
Additional LMI solvers can be installed using
.. code-block:: sh
$ pip install mosek
$ pip install cvxopt
$ pip install smcp
Mosek is recommended, but is nonfree and requires a license.
The library can be tested using
.. code-block:: sh
$ pip install -r requirements-dev.txt
$ pytest
Note that ``pytest`` must be run from the repository's root directory.
To skip unit tests that require a MOSEK license, including all doctests and
examples, run
.. code-block:: sh
$ pytest ./tests -k "not mosek"
The documentation can be compiled using
.. code-block:: sh
$ cd doc
$ make html
If you want a hook to check source code formatting before allowing a commit,
you can use
.. code-block:: sh
$ cd .git/hooks/
$ ln -s ../../.githooks/pre-commit .
$ chmod +x ./pre-commit
You will need ``yapf`` installed for this.
Related packages
================
Other excellent Python packages for learning dynamical systems exist,
summarized in the table below:
============ ==================================================================
Library Unique features
============ ==================================================================
`pykoop`_ - Modular lifting functions
- Full ``scikit-learn`` compatibility
- Built-in regularization
- Multi-episode datasets
`pykoopman`_ - Continuous-time Koopman operator identification
- Built-in numerical differentiation
- Detailed DMD outputs
- DMDc with known control matrix
`PyDMD`_ - Extensive library containing pretty much every variant of DMD
`PySINDy`_ - Python implementation of the famous SINDy method
- Related to, but not the same as, Koopman operator approximation
============ ==================================================================
.. _pykoop: https://github.com/decargroup/pykoop
.. _pykoopman: https://github.com/dynamicslab/pykoopman
.. _PyDMD: https://github.com/mathLab/PyDMD
.. _PySINDy: https://github.com/dynamicslab/pysindy
Citation
========
If you use this software in your research, please cite it as below or see
``CITATION.cff``.
.. code-block:: bibtex
@software{dahdah_pykoop_2024,
title={{decargroup/pykoop}},
doi={10.5281/zenodo.5576490},
url={https://github.com/decargroup/pykoop},
publisher={Zenodo},
author={Steven Dahdah and James Richard Forbes},
version = {{v2.0.2}},
year={2024},
}
License
=======
This project is distributed under the MIT License, except the contents of
``pykoop/_sklearn_metaestimators/``, which are from the `scikit-learn`_
project, and are distributed under the BSD-3-Clause License.
.. _scikit-learn: https://github.com/scikit-learn/scikit-learn
Owner
- Name: DECAR
- Login: decargroup
- Kind: organization
- Location: Canada
- Website: decar.ca
- Twitter: decargroup
- Repositories: 7
- Profile: https://github.com/decargroup
Dynamics, Estimation, and Control in Aerospace and Robotics (DECAR)
JOSS Publication
pykoop: a Python Library for Koopman Operator Approximation
Published
October 03, 2025
Volume 10, Issue 114, Page 7947
Authors
Tags
Koopman operator system identification differential equations machine learning dynamical systemsGitHub Events
Total
- Issues event: 9
- Watch event: 15
- Delete event: 6
- Issue comment event: 16
- Push event: 16
- Pull request event: 13
- Pull request review event: 1
- Fork event: 1
- Create event: 7
Last Year
- Issues event: 9
- Watch event: 15
- Delete event: 6
- Issue comment event: 16
- Push event: 16
- Pull request event: 13
- Pull request review event: 1
- Fork event: 1
- Create event: 7
Committers
Last synced: 9 months ago
Top Committers
| Name | Commits | |
|---|---|---|
| Steven Dahdah | s****h@m****a | 631 |
| James Forbes | j****s@m****a | 1 |
Committer Domains (Top 20 + Academic)
mcgill.ca: 1
mail.mcgill.ca: 1
Issues and Pull Requests
Last synced: 6 months ago
All Time
- Total issues: 74
- Total pull requests: 79
- Average time to close issues: about 2 months
- Average time to close pull requests: 1 day
- Total issue authors: 4
- Total pull request authors: 2
- Average comments per issue: 0.24
- Average comments per pull request: 0.04
- Merged pull requests: 78
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 8
- Pull requests: 12
- Average time to close issues: 16 days
- Average time to close pull requests: about 4 hours
- Issue authors: 3
- Pull request authors: 2
- Average comments per issue: 1.13
- Average comments per pull request: 0.0
- Merged pull requests: 12
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- sdahdah (69)
- JDRanpariya (3)
- matt-graham (2)
- LouisLortie (1)
Pull Request Authors
- sdahdah (91)
- jrforbes (2)
Top Labels
Issue Labels
bug (35)
enhancement (25)
documentation (13)
wontfix (4)
question (2)
Pull Request Labels
bug (39)
documentation (20)
enhancement (18)
Packages
- Total packages: 1
-
Total downloads:
- pypi 57 last-month
- Total dependent packages: 0
- Total dependent repositories: 2
- Total versions: 16
- Total maintainers: 2
pypi.org: pykoop
Koopman operator identification library in Python, compatible with `scikit-learn`
- Homepage: https://github.com/decargroup/pykoop
- Documentation: https://pykoop.readthedocs.io/en/stable
- License: MIT License
-
Latest release: 2.0.1
published over 1 year ago
Rankings
Stargazers count: 9.7%
Dependent packages count: 10.1%
Dependent repos count: 11.6%
Average: 12.9%
Forks count: 15.3%
Downloads: 18.0%
Last synced:
6 months ago
Dependencies
requirements.txt
pypi
- Deprecated *
- PICOS *
- matplotlib *
- numpy *
- optht *
- pandas *
- pytest *
- scikit-learn *
- scipy *
- sphinx *
- sphinx-rtd-theme *
setup.py
pypi
- Deprecated >=1.2.13
- numpy >=1.2.1
- optht >=0.2.0
- pandas >=1.3.1
- picos >=2.2.52
- scikit-learn >=0.24.1
- scipy >=1.7.0
.github/workflows/check-formatting.yml
actions
- AlexanderMelde/yapf-action master composite
- actions/checkout v2 composite
.github/workflows/check-version.yml
actions
- Bruce17/ghaction-package-latest-version v1 composite
- actions/checkout v2 composite
.github/workflows/release-package.yml
actions
- actions/checkout v2 composite
- actions/setup-python v2 composite
- pypa/gh-action-pypi-publish 27b31702a0e7fc50959f5ad993c78deac1bdfc29 composite
.github/workflows/test-package.yml
actions
- actions/checkout v2 composite
- actions/setup-python v2 composite
requirements-dev.txt
pypi
- mosek >=9.2.49 development
- pytest * development
- pytest-regressions * development
- sphinx * development
- sphinx-rtd-theme * development
.github/workflows/test-package-no-mosek.yml
actions
- actions/checkout v2 composite
- actions/setup-python v2 composite
