Skip to main content

koopman-dmd

PyPI Python versions License: MIT

Dynamic Mode Decomposition (DMD) with Koopman operator theory extensions, with a Rust core.

DMD extracts spatiotemporal coherent structures from time-series data, giving a linear operator that approximates the dynamics of a possibly nonlinear system. This package wraps the koopman-dmd Rust crate via PyO3, so the numerics run at native speed with no BLAS/LAPACK installation required.

Installation

pip install koopman-dmd

The distribution is named koopman-dmd; the import name is koopman_dmd:

import koopman_dmd

Prebuilt wheels are published for Linux (x86_64, aarch64), macOS (x86_64, arm64), and Windows (x86_64) on Python 3.9+. Installing from source requires a Rust toolchain.

Quick start

Data is passed as a NumPy array with one row per variable and one column per time step.

import numpy as np
import koopman_dmd

# A 2-variable oscillating signal, shape (2, 100)
t = np.linspace(0, 10, 100)
x = np.vstack([np.sin(t), np.cos(t)])

d = koopman_dmd.DMD(x, rank=2, dt=t[1] - t[0])

print(d.eigenvalues)      # (r, 2) array of [real, imag]
print(d.modes)            # DMD modes
print(d.singular_values)

# Forecast 10 steps beyond the input
future = d.predict(10)

# Per-mode frequency, growth rate, amplitude, and stability
for mode in d.spectrum():
    print(mode)

Note that the data is passed to the constructor — there is no separate fit() step.

DMD

koopman_dmd.DMD(x, rank=None, center=False, dt=1.0, lifting=None, lifting_param=None)

rank=None selects a truncation rank automatically (99% of variance). lifting enables Extended DMD and accepts "polynomial", "polynomial_cross", "trigonometric", or "delay", with the degree / harmonic count / delay count given by lifting_param.

Properties: rank, data_dim, center, dt, eigenvalues, modes, amplitudes, singular_values

Methods:

Method Returns
predict(n_ahead, x0=None, method="modes") forecast array; method is "modes" or "matrix"
reconstruct(n_steps, modes_subset=None) reconstruction from all or selected modes
spectrum() per-mode frequency, growth rate, amplitude, stability — uses the dt given at construction
stability() (is_stable, is_unstable, is_marginal, spectral_radius)
error() (rmse, mae, mape, rel_err)
dominant_modes(n, criterion="amplitude") indices of the n most significant modes
residual() (absolute, relative)

Extended DMD with lifting

d = koopman_dmd.DMD(x, lifting="polynomial", lifting_param=2)

HankelDMD

Time-delay embedding, for scalar signals or systems with few measured variables.

koopman_dmd.HankelDMD(y, delays=None, rank=None, dt=1.0)

Properties: rank, delays, n_obs, residual, eigenvalues Methods: predict(n_ahead), reconstruct(n_steps)

y = np.sin(np.linspace(0, 4 * np.pi, 200)).reshape(1, -1)
h = koopman_dmd.HankelDMD(y, delays=20)
print(h.rank)          # 2 — chosen automatically
print(h.predict(10))

Leaving rank=None is usually right. Requesting a rank higher than the signal actually supports (a pure sinusoid is rank 2) leaves the reduced operator near-singular, and the eigendecomposition can fail with NoConvergence.

GLA

Generalized Laplace Analysis — computes Koopman eigenfunctions directly via weighted time averages.

koopman_dmd.GLA(y, eigenvalues=None, n_eigenvalues=5, tol=1e-6, max_iter=None)

Properties: n_obs, n_time, eigenvalues, convergence, residuals Methods: predict(n_ahead), reconstruct(modes_to_use=None)

Phase space analysis

For area-preserving and chaotic maps.

Maps and their params keys — params is a dict, and omitting it uses defaults:

map_name State dim Parameters
"standard" (Chirikov) 2 epsilon
"froeschle" 4 epsilon, eta
"extended_standard" 3 epsilon, delta
"henon" 2 a, b
"logistic" 1 r

Observables: "identity", "sin_pi", "cos_pi", "sin_pi_xy", "cos_pi_xy", "sin_2pi", "cos_2pi", "trig_product"

Initial conditions are NumPy arrays, not lists.

ic = np.array([0.5, 0.3])

# Iterate a map from an initial condition
traj = koopman_dmd.generate_trajectory("standard", ic, 1000, {"epsilon": 0.12})

# Harmonic time average at a single initial condition
mag, phase, hta_re, hta_im = koopman_dmd.harmonic_time_average(
    "standard", ic, "sin_pi", 0.5, 10000, {"epsilon": 0.12}
)

# Mesochronic plot over a grid (parallelized in Rust).
# Returns (hta_magnitude, phase, x_coords, y_coords).
hta, phase, x_coords, y_coords = koopman_dmd.mesochronic_compute(
    "standard", (0.0, 1.0), (0.0, 1.0), 100, "sin_pi", 0.5, 10000, {"epsilon": 0.12}
)

# Classify orbits as regular, resonating, or chaotic from HTA magnitudes
labels = koopman_dmd.classify_phase_space(hta.ravel())

# Convergence history of the time average
conv = koopman_dmd.hta_convergence("standard", ic, "sin_pi", 0.5, 10000, {"epsilon": 0.12})

Other languages

Development

pip install maturin pytest numpy
maturin develop --release
pytest tests/

References

  • Schmid, P.J. (2010). Dynamic mode decomposition of numerical and experimental data. Journal of Fluid Mechanics, 656, 5–28.
  • Kutz, J.N., Brunton, S.L., Brunton, B.W., & Proctor, J.L. (2016). Dynamic Mode Decomposition: Data-Driven Modeling of Complex Systems. SIAM.
  • Mezić, I. (2020). Spectrum of the Koopman operator, spectral expansions in functional spaces, and state-space geometry. arXiv:2009.05883
  • Levnajić, Z. & Mezić, I. (2014). Ergodic theory and visualization. arXiv:0808.2182v2

License

MIT — see LICENSE.

Download files

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

Source Distribution

koopman_dmd-0.1.0.tar.gz (70.5 kB view details)

Uploaded Source

Built Distributions

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

koopman_dmd-0.1.0-cp39-abi3-win_amd64.whl (980.1 kB view details)

Uploaded CPython 3.9+Windows x86-64

koopman_dmd-0.1.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ x86-64

koopman_dmd-0.1.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (866.1 kB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ ARM64

koopman_dmd-0.1.0-cp39-abi3-macosx_11_0_arm64.whl (741.2 kB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

koopman_dmd-0.1.0-cp39-abi3-macosx_10_12_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.9+macOS 10.12+ x86-64

File details

Details for the file koopman_dmd-0.1.0.tar.gz.

File metadata

  • Download URL: koopman_dmd-0.1.0.tar.gz
  • Upload date:
  • Size: 70.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for koopman_dmd-0.1.0.tar.gz
Algorithm Hash digest
SHA256 106b2d3f83b0b11d76bf035db18a8bd1b1238de250e617053509bf69d8f967d1
MD5 3837a64279524852b1459602c9442b50
BLAKE2b-256 b332cb298101cd69e6edf18f55b665f197311800af2aec137339a45ca2ea9fe4

See more details on using hashes here.

Provenance

The following attestation bundles were made for koopman_dmd-0.1.0.tar.gz:

Publisher: release-python.yml on jimeharrisjr/rust-dmd

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file koopman_dmd-0.1.0-cp39-abi3-win_amd64.whl.

File metadata

  • Download URL: koopman_dmd-0.1.0-cp39-abi3-win_amd64.whl
  • Upload date:
  • Size: 980.1 kB
  • Tags: CPython 3.9+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for koopman_dmd-0.1.0-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 76671f76c098f207a8be1c0cace8fd86ad061a2c1f7f29f0946f55fef23a8354
MD5 cfec4fa47c69339f4d797d22240c99a5
BLAKE2b-256 ac46a45cfe2fb0825e0d0f9dcfdcb8e13e0fa7c64277f2a81f30cab3a9b9979f

See more details on using hashes here.

Provenance

The following attestation bundles were made for koopman_dmd-0.1.0-cp39-abi3-win_amd64.whl:

Publisher: release-python.yml on jimeharrisjr/rust-dmd

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file koopman_dmd-0.1.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for koopman_dmd-0.1.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 32727c1d8fc94b3025d89b496b1f73f19e1c1044590d857db909b57f6381f674
MD5 e39acb9bac989c8261fd63acc3406746
BLAKE2b-256 4605ad04aa6c5cef330cfbd5f58cf6ed47c7e6cf15dfdf3311cfb86677f0a16e

See more details on using hashes here.

Provenance

The following attestation bundles were made for koopman_dmd-0.1.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release-python.yml on jimeharrisjr/rust-dmd

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file koopman_dmd-0.1.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for koopman_dmd-0.1.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 f1b30cdcb93ad0e2c0e8d7d459465868b90fa763dafc4d2698f47a71e2f28a3e
MD5 e5ebbadcf6ff51e7a9be1964ce689b0d
BLAKE2b-256 c4c209c07bb8fc8c4c1330328d00821896fa168a1dbed7356d295d9b25321136

See more details on using hashes here.

Provenance

The following attestation bundles were made for koopman_dmd-0.1.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release-python.yml on jimeharrisjr/rust-dmd

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file koopman_dmd-0.1.0-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for koopman_dmd-0.1.0-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e7924c4516a2a04c1a68580e3f0720dfc1dac2461a5f026633ba69d01e185f27
MD5 43bd6800d3bb1598ac4c3451b44b2761
BLAKE2b-256 fda669ba175df1a8acb946a48f4fb2c42db7b7d49cfcfd3ddf8c682758e77534

See more details on using hashes here.

Provenance

The following attestation bundles were made for koopman_dmd-0.1.0-cp39-abi3-macosx_11_0_arm64.whl:

Publisher: release-python.yml on jimeharrisjr/rust-dmd

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file koopman_dmd-0.1.0-cp39-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for koopman_dmd-0.1.0-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 d16efd12fa7ca005da43bf3255aa09c0844d73c94eacf04f56b8f11f6aaca416
MD5 d16a80b81e7f4cd66a0eac232f2ec299
BLAKE2b-256 f492b8a061c22f7ed7e137840ce72d307864030dee28307a3043afd48fdfb087

See more details on using hashes here.

Provenance

The following attestation bundles were made for koopman_dmd-0.1.0-cp39-abi3-macosx_10_12_x86_64.whl:

Publisher: release-python.yml on jimeharrisjr/rust-dmd

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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