pyshred.objects package#

Submodules#

pyshred.objects.dataset module#

class pyshred.objects.dataset.TimeSeriesDataset(X, Y)[source]#

Bases: Dataset

PyTorch Dataset for time series sensor data and corresponding full-state measurements.

Parameters:
  • X (torch.Tensor) – Input sensor sequences of shape (batch_size, lags, num_sensors).

  • Y (torch.Tensor) – Target full-state measurements of shape (batch_size, state_dim).

Variables:
  • X (torch.Tensor) – Sensor measurement sequences.

  • Y (torch.Tensor) – Full-state target measurements.

  • len (int) – Number of samples in the dataset.

pyshred.objects.sindy module#

class pyshred.objects.sindy.E_SINDy(num_replicates, latent_dim, library_dim, poly_order, include_sine)[source]#

Bases: Module

Ensemble Sparse Identification of Nonlinear Dynamics (E-SINDy) module.

An ensemble version of SINDy that uses multiple replicate models to improve robustness and handle noise in the data.

Parameters:
  • num_replicates (int) – Number of SINDy models in the ensemble.

  • latent_dim (int) – Dimension of the latent space.

  • library_dim (int) – Dimension of the feature library.

  • poly_order (int) – Order of polynomial terms in the library.

  • include_sine (bool) – Whether to include sine functions in the library.

Variables:
  • coefficients (torch.nn.Parameter) – Learnable coefficients for all ensemble members.

  • coefficient_mask (torch.Tensor) – Binary masks for enforcing sparsity in each ensemble member.

add_noise(noise=0.1)[source]#

Add noise to coefficients and reset masks.

Parameters:

noise (float, optional) – Standard deviation of noise to add. Defaults to 0.1.

forward(h_replicates, dt)[source]#

Forward pass through the E-SINDy ensemble dynamics.

Parameters:
  • h_replicates (torch.Tensor) – Current latent states for all replicates, shape (num_data, num_replicates, latent_dim).

  • dt (float) – Time step size.

Returns:

Updated latent states for all replicates after one time step.

Return type:

torch.Tensor

recenter()[source]#

Reset all coefficients to zero and masks to ones.

thresholding(threshold, base_threshold=0)[source]#

Apply varying thresholds to different ensemble members for sparsity.

Parameters:
  • threshold (float) – Base threshold value.

  • base_threshold (float, optional) – Minimum threshold to add to scaled threshold. Defaults to 0.

class pyshred.objects.sindy.SINDy(latent_dim, library_dim, poly_order, include_sine)[source]#

Bases: Module

Sparse Identification of Nonlinear Dynamics (SINDy) module.

A PyTorch implementation of SINDy for discovering sparse dynamical systems from data. Uses polynomial and optional sine libraries to represent the dynamics with sparse coefficients.

Parameters:
  • latent_dim (int) – Dimension of the latent space.

  • library_dim (int) – Dimension of the feature library.

  • poly_order (int) – Order of polynomial terms in the library.

  • include_sine (bool) – Whether to include sine functions in the library.

Variables:
  • coefficients (torch.nn.Parameter) – Learnable coefficients of the SINDy model.

  • coefficient_mask (torch.Tensor) – Binary mask for enforcing sparsity.

add_noise(noise=0.1)[source]#

Add noise to coefficients and reset mask.

Parameters:

noise (float, optional) – Standard deviation of noise to add. Defaults to 0.1.

forward(h, dt)[source]#

Forward pass through the SINDy dynamics.

Parameters:
  • h (torch.Tensor) – Current latent state.

  • dt (float) – Time step size.

Returns:

Updated latent state after one time step.

Return type:

torch.Tensor

recenter()[source]#

Reset coefficients to zero and mask to ones.

thresholding(threshold)[source]#

Apply thresholding to enforce sparsity in coefficients.

Parameters:

threshold (float) – Threshold value below which coefficients are set to zero.

Module contents#