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, wheredis the system dimension.A (
array-like,shape (d,d)) – State transition matrix defining the linear dynamics.n_steps (
int, default100) – Number of time steps to simulate.noise (
float, default0.0) – Standard deviation of the zero-mean Gaussian noise \(\sigma\).dt (
float, default1.0) – Time step size. For discrete-time systems, this is typically 1.0.random_state (
int,RandomState instanceorNone, defaultNone) – Controls the random number generation for the noise. Pass anintfor reproducible output across multiple function calls.
- Returns:
df – Trajectory of the linear system with columns
['x0', 'x1', ..., 'x{d-1}']andn_steps + 1samples. Has a MultiIndex with levels['step', 'time']. Metadata stored indf.attrsincludes:'generator':'make_linear_system';'X0': initial conditions;'A': state transition matrix;'params': dict of all parameters.
- Return type:
pandas.DataFrame
Examples
>>> import numpy as npStable 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']).TNotes
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.