Skip to main content

5. Koopman analysis

Patterns that oscillate with a single frequency

The Koopman block of the NLSA Python toolkit: the Galerkin basis, the diffusion-regularized generator, compactified Laplace and Gauss transforms (resolvent methods), Dirichlet energies, eigenfrequencies, and how Koopman eigenfunctions are evaluated, exported and forecast.

The Koopman operator moves functions of the state forward along the dynamics. Its eigenfunctions \(\zeta_k\) evolve in the simplest possible way, \(\zeta_k(t) = e^{i\omega_k t}\,\zeta_k(0)\): their real and imaginary parts oscillate with a single frequency \(\omega_k\). In climate data they pick out the annual cycle, ENSO, the MJO and their combinations, and serve as indices of these phenomena. The theory is on the Koopman operator theory page.

The toolkit approximates the Koopman generator (the rate of change of functions along the dynamics) in the basis of kernel eigenfunctions, with one of two schemes:

Here koop is nlsa.jax.koopman.

The Galerkin basis

Both schemes work in a finite basis of kernel eigenfunctions, the Galerkin space, chosen with which_eigs_galerkin. The constant eigenfunction \(\varphi_0\) is always an exact Koopman eigenfunction (with frequency 0) and is handled separately, so the convention differs from the other options that select eigenfunctions:

which_eigs_galerkin Basis Example
integer L \(\varphi_1, \dots, \varphi_L\) 256 gives \(\varphi_1, \dots, \varphi_{256}\)
tuple (a, b) \(\varphi_a, \dots, \varphi_b\) (1, 64)
list the listed eigenfunctions [1, 2, 5, 6]

The properties dim_galerkin (the number of basis functions) and which_kernel_eigs (the basis together with \(\varphi_0\)) of the parameter object give the sizes used elsewhere, for example vec.l2_vector_algebra(shape=(koopman_pars.dim_galerkin + 1,), dtype=jax_env.complex_dtype) for the space of Koopman expansion coefficients. The Galerkin space must not be larger than the number of kernel eigenfunctions computed (num_eigs of the kernel parameters).

Diffusion-regularized generator

The scheme of the ENSO example, in five steps:

  1. Velocities along the trajectory. For each training sample, the rate of change of its delay window is estimated with a central finite difference of order fd_order along the time series (clim.make_data_driven_tangent_evaluation_functional_fd).
  2. Directional derivatives. The derivative of each basis function along that velocity, \(v\cdot\nabla\varphi_j(x_n)\), is computed by automatic differentiation of the Nyström extension of \(\varphi_j\).
  3. Generator matrix. \(V_{ij} = \langle \varphi'_i, v\cdot\nabla\varphi_j\rangle\) for the L basis functions (koop.compute_generator_matrix, saved as gen_mat.npy).
  4. Regularization. Diffusion is subtracted to damp rough, poorly resolved functions: \[ L_\tau = \tfrac12 \big(V - V^\top\big) - \tau\, \mathrm{diag}(\eta_1, \dots, \eta_L) \] with antisym=True, or \(V - \tau\,\mathrm{diag}(\eta)\) without antisymmetrization, where \(\eta_j = -4\ln\lambda_j/\varepsilon^2\) are the Laplace eigenvalues of the basis functions.
  5. Eigendecomposition. \(L_\tau c_k = \gamma_k c_k\) gives the Koopman eigenfunctions \(\zeta_k = \sum_j c_{jk}\varphi_j\), with generator eigenvalues \(\gamma_k\) whose imaginary part is the angular frequency \(\omega_k\) and whose real part is a damping rate due to the regularization. Each eigenfunction gets a Dirichlet energy \[ E_k = \sum_j |c_{jk}|^2 \Big(\frac{1}{\lambda_j} - 1\Big), \] which measures its roughness (0 for the constant function). The eigenfunctions are sorted by energy or by frequency, the constant function \(\zeta_0\) (eigenvalue 0) is placed first, and num_eigs of them are kept (koop.compute_diffusion_regularized_generator_eigen).

Eigenvalues come in complex-conjugate pairs \(\pm\omega_k\), with eigenfunctions that are complex conjugates of each other. Sorting by energy puts the smooth, physically meaningful eigenfunctions first.

KoopmanParsDiff (nlsa.jax.koopman, defined in src/nlsa/koopman.py)
Option Type or values Default Description
fd_order 2 or 4 or 6 or 8 required Order (2, 4, 6 or 8) of the central finite differences used for time derivatives along the trajectory. Reserve fd_order // 2 samples before and after with num_before and num_after.
dt float required Time step. Recorded in the output folder name only: the finite differences use the sampling interval of the data (one sample in the climate pipeline, DataPars.dt for Lorenz 63). The ENSO example sets it to 1.
tau float required Strength τ of the diffusion regularization: the generator is replaced by V − τΔ, which damps rough eigenfunctions. The examples use 0.002 to 0.01.
antisym bool required Keep only the antisymmetric part (V − Vᵀ)/2 of the generator matrix, the structure the generator has for measure-preserving dynamics.
which_eigs_galerkin int or tuple[int, int] or list[int] required Kernel eigenfunctions spanning the Galerkin space (the constant one is added separately): an integer L means φ₁ … φ_L; a tuple (a, b) means φ_a … φ_b; a list gives the indices.
num_eigs int or None None Number of Koopman eigenpairs kept after sorting, including the constant eigenfunction. None keeps nearly all of them.
laplacian_method "log" or "lin" or "inv" "log" Formula for converting kernel eigenvalues λ into Laplace eigenvalues η: "log" η = −4 ln λ / ε², "lin" η = 4(1 − λ)/ε², "inv" η = (1/λ − 1) rescaled by a reference eigenvalue. In the current code the value only enters the output folder name: the regularization always uses "log".
sort_by "energy" or "frequency" "frequency" Order of the results: "energy" (smallest Dirichlet energy, i.e. smoothest, first) or "frequency" (smallest |frequency| first).
eval_tx_batch_size int or None None Batch size for evaluating the time derivatives on the samples (used by the Lorenz 63 scripts).
grad_batch_size int or None None Batch size for the directional derivatives of the basis functions.
gram_batch_size int or None None Batch size for the inner products that form the generator matrix.

Compactified integral transforms

The second scheme approximates an integral transform of the Koopman operator instead of the generator itself, which avoids differentiating the eigenfunctions:

  1. Transform. For each basis function, \((T\varphi_j)(x_n) = \sum_{m=0}^{M} w_m\, \varphi_j(x_{n+m})\) with \(M\) = num_quad, approximates \(\int_0^{M\Delta t} w(t)\, \varphi_j(x(t_n + t))\, dt\), where \(w(t) = e^{-zt}\) (Laplace transform, the resolvent) or \(e^{-(zt)^2}\) (Gauss transform), \(z\) = bandwidth, and \(w_m\) includes the trapezoidal or Simpson quadrature weights.
  2. Matrix. \(A_{ij} = \langle\varphi'_i, T\varphi_j\rangle\), antisymmetrized.
  3. Compactification. \(\tilde A = \Lambda A \Lambda\) with \(\Lambda = \mathrm{diag}(\lambda_j^\tau)\) (smoothing_kernel="exponential") or \(\mathrm{diag}\big((1 - \sqrt{\eta_j/\eta_{\max}})^\tau\big)\) ("fejer").
  4. Eigendecomposition, with a Hermitian solver when antisym=True.
  5. Generator eigenvalues from those of the transform, by inverting the transform’s formula (koop.invert_qz for the Laplace transform, koop.invert_dawson for the Gauss transform).

The quadrature uses the num_quad samples after each training sample, so the training data need num_after ≥ num_quad. The Lorenz 63 script builds the quadrature samples with nlsa_models.lorenz63.make_data_driven_quadrature_evaluation_functional; the climate pipeline has no dedicated function yet (clim.make_data_driven_evaluation_functional with num_after=num_quad evaluates functions on the same samples, but has not been tried for this purpose).

KoopmanParsTransf (nlsa.jax.koopman, defined in src/nlsa/koopman.py)
Option Type or values Default Description
transform "laplace" or "gauss" required Integral transform of the Koopman evolution: "laplace" (weights \(e^{-zt}\), the resolvent) or "gauss" (weights \(e^{-(zt)^2}\)).
quadrature "trapezoidal" or "simpson" required Rule for the time integral: "trapezoidal" or "simpson" (Simpson needs an even num_quad).
num_quad int required Number of quadrature intervals. The transform uses the next num_quad samples after each training sample, so reserve them with num_after.
bandwidth float required Transform parameter z. Larger values weight short times more heavily.
dt float required Time step of the quadrature (the sampling interval of the data).
tau float required Exponent τ of the smoothing weights that make the operator compact.
which_eigs_galerkin int or tuple[int, int] or list[int] required As for KoopmanParsDiff.
antisym bool True Use the antisymmetric part of the transform matrix and a Hermitian eigensolver.
num_eigs int or None None As for KoopmanParsDiff.
laplacian_method "log" or "lin" or "inv" "log" As for KoopmanParsDiff: recorded in the folder name; the Laplace eigenvalues used by the "fejer" smoothing are always computed with "log".
smoothing_kernel "exponential" or "fejer" "exponential" Smoothing weights: "exponential" λ_j^τ (kernel eigenvalues to the power τ) or "fejer" (1 − √(η_j / η_max))^τ.
sort_by "energy" or "frequency" "frequency" As for KoopmanParsDiff.
eval_quad_batch_size int or None None Batch size for evaluating the basis functions at the quadrature samples.
quad_batch_size int or None None Batch size for the quadrature over basis functions.
gram_batch_size int or None None Batch size for the inner products that form the transform matrix.

The classes KoopmanParsLapl and KoopmanParsGauss in nlsa.koopman are earlier versions of KoopmanParsTransf and are no longer used.

Results

Both schemes return a KoopmanEigen:

KoopmanEigen (nlsa.jax.koopman, defined in src/nlsa/jax/koopman/_koopman.py)
Field Type Description
evals array Eigenvalues of the operator that was diagonalized (the regularized generator, or the transform for resolvent schemes).
gen_evals array Generator eigenvalues; the imaginary part is the angular frequency, the real part a growth or decay rate.
engys array Dirichlet energy of each eigenfunction, a measure of roughness (smaller is smoother).
efreqs array Eigenfrequencies ω, in radians per unit time (per sample in the climate pipeline).
eperiods array Eigenperiods 2π/ω, in the same time units.
evec_coeffs array Expansion coefficients of the Koopman eigenfunctions in the kernel basis.
dual_evec_coeffs array Expansion coefficients of the dual eigenfunctions (used to project data onto the eigenfunctions).

Its methods evecs(kernel_eigen, which_kernel_eigs) and dual_evecs(kernel_eigen, which_kernel_eigs) return the eigenfunctions and their duals on the training samples. Times are counted in samples, so in the climate pipeline the frequencies are in radians per month (or per day). The ENSO script converts them when it prints the eigenvalue table:

The Koopman eigenvalue table printed by the ENSO script
Column Conversion for monthly data
Growth rate (1/year) \(12\, \mathrm{Re}\,\gamma_k\)
Dirichlet energy \(E_k\)
Eigenfrequency (cycles/year) \(12\, \omega_k / 2\pi\)
Eigenperiod (years) \(2\pi / (12\, \omega_k)\)

The annual cycle appears at 1 cycle per year, the semiannual cycle at 2, and ENSO as a pair with a period of 3–5 years (0.2–0.33 cycles per year). Its index in the sorted list depends on the settings, so check the table before choosing which eigenfunction to forecast or plot.

Using the eigenfunctions

Functions that use Koopman eigenfunctions
Task Function
Values of eigenfunction k on training or test samples (Nyström extension), for example as a climate index koop.evaluate_eigenfunction
Spatial patterns (Koopman modes) clim.compute_eigenfunction_projections, with koopman_eigen.dual_evecs(...); see Skill and outputs
Forecast of an eigenfunction, or Koopman forecast of a target See Forecasting
Table of eigenfunction values with dates, for use as predictors elsewhere clim.koopman_efuncs_to_data_frame
Plots koop.plot_operator_matrix ("generator_mat")
koop.plot_generator_spectrum ("generator_spec")
clim.make_koopman_evecs_plotter ("koopman_eigen")

A complex eigenfunction is an index with an amplitude \(|\zeta_k|\) (how strong the phenomenon is) and a phase \(\arg\zeta_k\) (where it is in its cycle), as in the phase diagrams on the Experiments page.

How to choose τ, the Galerkin space and the other settings is discussed in Choosing hyperparameters.

References

Das, S., D. Giannakis, and J. Slawinska. 2021. “Reproducing Kernel Hilbert Space Compactification of Unitary Evolution Groups.” Applied and Computational Harmonic Analysis 54: 75–136. https://doi.org/10.1016/j.acha.2021.02.004.
Giannakis, D. 2019. “Data-Driven Spectral Decomposition and Forecasting of Ergodic Dynamical Systems.” Applied and Computational Harmonic Analysis 47 (2): 338–96. https://doi.org/10.1016/j.acha.2017.09.001.
Valva, C., and D. Giannakis. 2024. “Consistent Spectral Approximation of Koopman Operators Using Resolvent Compactification.” Nonlinearity, ahead of print. https://doi.org/10.1088/1361-6544/ad4ade.