pyLOM.GPOD#

Module contents#

class pyLOM.GPOD.GappyPOD(centered=False, apply_truncation=False, truncation_param=-0.99, reconstruction_method='standard', ridge_lambda=0.01)[source]#

Bases: object

This class implements the Gappy POD algorithm. Gappy POD model for reconstructing incomplete data using POD basis modes.

Variables:
  • centered (bool) – If True, subtract the mean from inputs.

  • truncate (bool) – If True, apply modal truncation based on a threshold.

  • truncation_param (float or int) – Parameter controlling truncation.

  • reconstruction_type (callable) – Function to compute POD coefficients.

  • ridge_lambda (float) – Regularization weight for ridge reconstruction.

  • mean (np.ndarray or cp.ndarray) – Mean vector computed during fitting.

  • U_truncated (np.ndarray or cp.ndarray) – Truncated POD modes.

  • S_truncated (np.ndarray or cp.ndarray) – Corresponding singular values.

  • U_truncated_scaled (np.ndarray or cp.ndarray or cp.ndarray) – Modes scaled by singular values.

__init__(centered=False, apply_truncation=False, truncation_param=-0.99, reconstruction_method='standard', ridge_lambda=0.01)[source]#

Initialize a Gappy POD instance.

Parameters:
  • centered (bool) – Whether to subtract the mean from data.

  • apply_truncation (bool) – Whether to truncate POD modes.

  • truncation_param (float or int) – Parameter controlling truncation (r): If r >= 1, it is treated as the number of modes. If r < 1 and r > 0 it is treated as the residual target. If r < 1 and r < 0 it is treated as the fraction of cumulative energy to retain. Note: must be in (0,-1] and r = -1 is valid

  • reconstruction_method (str) – “standard” for least squares. “ridge” for ridge regression.

  • ridge_lambda (float) – Regularization parameter for ridge solver.

Raises:

ValueError – If reconstruction_method is not “standard” or “ridge”.

fit(snapshot_matrix: ndarray, **kwargs) None[source]#

Fit the Gappy POD model using a complete snapshot matrix.

Computes the POD basis (via SVD) of the input data, optionally centers the data and truncates modes.

Parameters:
  • snapshot_matrix (np.ndarray or cp.ndarray) – Array of shape (n_features, n_samples) containing training snapshots.

  • **kwargs – Additional keyword arguments forwarded to the POD run function.

Returns:

None

predict(gappy_vector: ndarray) ndarray[source]#

Reconstruct a single vector with missing entries.

Uses the fitted POD basis to estimate missing values in the input vector.

Parameters:

gappy_vector (np.ndarray or cp.ndarray) – Input vector of length n_features where missing entries are zeroed.

Returns:

Full reconstructed vector of length n_features.

Return type:

np.ndarray or cp.ndarray

Raises:

RuntimeError – If the model has not been fitted prior to prediction.

reconstruct_full_set(incomplete_snapshot: ndarray, iter_num: int) tuple[ndarray, ndarray, ndarray][source]#

Iteratively reconstruct an entire snapshot matrix with missing data.

Applies the Gappy POD algorithm for a specified number of iterations, updating missing entries based on previous reconstructions.

Parameters:
  • incomplete_snapshot (np.ndarray or cp.ndarray) – Array of shape (n_features, n_samples) with zeros indicating missing values.

  • iter_num (int) – Number of iterations to perform.

Returns:

  • reconstructed (np.ndarray or cp.ndarray):

    Reconstructed snapshot matrix of same shape as input.

  • eig_spec_iter (np.ndarray or cp.ndarray):

    Eigenvalue spectrum (normalized squared singular values) at each iteration, shape (n_samples, iter_num).

  • cumulative_energy (np.ndarray or cp.ndarray):

    Cumulative energy content of modes per iteration, shape (n_modes, iter_num).

Return type:

tuple

pyLOM.GPOD.set_random_elements_to_zero(vector, percentage)[source]#

Randomly zero out a specified percentage of elements in a vector.

Parameters:
  • vector (np.ndarray or cp.ndarray) – 1D input array whose elements will be modified.

  • percentage (float) – Percentage (0 to 100) of elements to set to zero.

Returns:

Copy of the input vector with the specified fraction of elements set to zero.

Return type:

np.ndarray or cp.ndarray

pyLOM.GPOD.delete_snapshot(X, snap, axis=1)[source]#

Remove one or more snapshots from a snapshot matrix.

Parameters:
  • X (np.ndarray or cp.ndarray) – Input snapshot matrix of shape (n_features, n_samples).

  • snap (int or sequence of int) – Index or indices of snapshot columns to remove.

  • axis (int, optional) – Axis along which to delete snapshots (default is 1).

Returns:

Snapshot matrix with specified columns removed.

Return type:

np.ndarray or cp.ndarray