make_linear_system

kooplearn.datasets.make_linear_system(X0, A, n_steps=100, noise=0.0, dt=1.0, random_state=None)[source]

Generate a trajectory from a discrete-time linear dynamical system.

The linear dynamical system is governed by:

\[x_{t+1} = A x_t + \xi_t\]

where \(\xi_t \sim \mathcal{N}(0, \sigma^2 I)\) is zero-mean Gaussian noise with standard deviation \(\sigma\).

For this linear system, the Koopman operator is simply the transpose of \(A\).

Parameters:
  • X0 (array-like, shape (d,)) – Initial conditions, where d is the system dimension.

  • A (array-like, shape (d, d)) – State transition matrix defining the linear dynamics.

  • n_steps (int, default 100) – Number of time steps to simulate.

  • noise (float, default 0.0) – Standard deviation of the zero-mean Gaussian noise \(\sigma\).

  • dt (float, default 1.0) – Time step size. For discrete-time systems, this is typically 1.0.

  • random_state (int, RandomState instance or None, default None) – Controls the random number generation for the noise. Pass an int for reproducible output across multiple function calls.

Returns:

df – Trajectory of the linear system with columns ['x0', 'x1', ..., 'x{d-1}'] and n_steps + 1 samples. Has a MultiIndex with levels ['step', 'time']. Metadata stored in df.attrs includes:

  • 'generator': 'make_linear_system';

  • 'X0': initial conditions;

  • 'A': state transition matrix;

  • 'params': dict of all parameters.

Return type:

pandas.DataFrame

Examples

>>> import numpy as np

Stable 2D linear system:

>>> A = np.array([[0.9, 0.1], [-0.1, 0.9]])
>>> X0 = np.array([1.0, 0.0])
>>> df = make_linear_system(X0, A, n_steps=100)
>>> df.shape
(101, 2)
>>> df.columns.tolist()
['x0', 'x1']

With Gaussian noise:

>>> df_noisy = make_linear_system(
...     X0=[1.0, 0.0],
...     A=A,
...     n_steps=100,
...     noise=0.1,
...     random_state=42
... )

Unstable system (eigenvalues > 1):

>>> A_unstable = np.array([[1.1, 0.0], [0.0, 1.1]])
>>> df_unstable = make_linear_system(
...     X0=[0.1, 0.1],
...     A=A_unstable,
...     n_steps=50
... )

Rotation matrix (periodic dynamics):

>>> theta = np.pi / 4
>>> A_rotation = np.array([
...     [np.cos(theta), -np.sin(theta)],
...     [np.sin(theta), np.cos(theta)]
... ])
>>> df_rotation = make_linear_system(
...     X0=[1.0, 0.0],
...     A=A_rotation,
...     n_steps=100
... )

Access the Koopman operator (transpose of A):

>>> K = np.array(df.attrs['A']).T

Notes

The Koopman operator for this linear system is the transpose of the state transition matrix \(A\). This makes linear systems ideal test cases for Koopman operator learning algorithms.