shredx.modules.sindy_layer.SINDyLayer#
- class shredx.modules.sindy_layer.SINDyLayer(hidden_size: int, forecast_length: int, device: str = 'cpu', strict_symmetry: bool = True, std_init: float = 0.1, **kwargs)#
Bases:
ModuleDifferentiable SINDy layer for ODE-based forecasting.
Learns sparse polynomial dynamics from data and uses ODE integration for arbitrary-length forecasting. Supports both strict symmetry (parameterized via lower triangle) and general coefficient matrices.
- Parameters:
- hidden_sizeint
Input/output dimension of the layer.
- forecast_lengthint
Number of future timesteps to predict.
- devicestr, optional
Device to place the model on. Default is
"cpu".- strict_symmetrybool, optional
If True, enforces symmetric coefficient matrix via lower triangle parameterization. Default is
True.- std_initfloat, optional
Standard deviation for initial coefficients. Default is
0.1.- **kwargs
Additional keyword arguments (ignored).
Methods
dense_matrix_from_symmetric_params(params)Build symmetric dense matrix from lower-triangle parameters.
forward(x)Integrate learned ODE dynamics to produce multi-step forecasts.
get_dense_sindy_coefficients()Return dense SINDy coefficient matrix.
get_eigenvalues()Return eigenvalues of the SINDy coefficient matrix (1j * matrix).
get_raw_sindy_coefficients()Return raw SINDy coefficients (1D or full matrix).
set_raw_sindy_coefficients(coefficients)Set raw SINDy coefficients from a tensor.
Notes
Class Methods:
get_dense_sindy_coefficients():
Converts symmetric parameters (1D) to a dense matrix when
strict_symmetryis True; otherwise returns the stored full matrix.- Returns:
Float[torch.Tensor, "hidden_size hidden_size"]. Dense SINDy coefficient matrix.
get_raw_sindy_coefficients():
Returns raw SINDy coefficients (1D lower triangle or full matrix).
- Returns:
Float[torch.Tensor, "library_dim library_dim"]whenstrict_symmetryis False, elseFloat[torch.Tensor, "num_params"](lower triangle 1D).
set_raw_sindy_coefficients(coefficients):
Updates the layer parameters in-place from raw SINDy coefficients.
- Parameters:
coefficients :
Float[torch.Tensor, "library_dim library_dim"]|Float[torch.Tensor, "num_params"]. Raw SINDy coefficients (same shape asget_raw_sindy_coefficients).
- Returns:
None.
dense_matrix_from_symmetric_params(params):
Builds a symmetric matrix by filling the lower triangle and reflecting.
- Parameters:
params :
Float[torch.Tensor, "num_params"]. 1D lower-triangle coefficients.
- Returns:
Float[torch.Tensor, "library_dim library_dim"]. Dense symmetric matrix.
get_eigenvalues():
Returns eigenvalues of the SINDy coefficient matrix (1j * matrix).
- Returns:
Float[torch.Tensor, "hidden_size"]. Eigenvalues.
forward(x):
Integrates the learned ODE (dopri5) over
forecast_lengthsteps to produce multi-step forecasts.- Parameters:
x :
Float[torch.Tensor, "batch_size hidden_size"]. Input state.
- Returns:
Float[torch.Tensor, "batch_size forecast_length hidden_size"]. Rollout of predicted states.