romtools.vector_space.utils.truncater#
Constructing a basis via POD typically entails computing the SVD of a snapshot matrix,
and then selecting the first \(K\) left singular vectors (i.e., the first \(K\) columns of \(\mathbf{U}\)). Typically, \(K\) is determined through the decay of the singular values.
The truncater class is designed to truncate a basis. We provide concrete implementations that truncate based on a specified number of basis vectors and the decay of the singular values
Classes
|
Truncates to a specified number of singular vectors, as specified in the constructor |
|
Truncates based on the decay of singular values, i.e., will define \(K\) to be the number of singular values such that the cumulative energy retained meets or exceeds a threshold. |
|
Interface for the Truncater class. |
No op implementation |
- class romtools.vector_space.utils.truncater.BasisSizeTruncater(basis_dimension)[source]#
Bases:
objectTruncates to a specified number of singular vectors, as specified in the constructor
This class conforms to the
LeftSingularVectorTruncaterprotocol.- Parameters:
basis_dimension (int)
- get_energy()[source]#
- Returns:
The energy criteria corresponding to the truncated basis
- Return type:
float
- truncate(basis, singular_values, total_energy=None)[source]#
Truncate the basis based on the specified dimension.
- Parameters:
basis (np.ndarray) – The original basis matrix.
singular_values (np.ndarray) – The array of singular values associated with the basis matrix.
total_energy (float) – Optional squared Frobenius norm of the full snapshot matrix.
- Returns:
The truncated basis matrix with the specified dimension.
- Return type:
np.ndarray
- class romtools.vector_space.utils.truncater.EnergyBasedTruncater(threshold)[source]#
Bases:
objectTruncates based on the decay of singular values, i.e., will define \(K\) to be the number of singular values such that the cumulative energy retained meets or exceeds a threshold.
This class conforms to the
LeftSingularVectorTruncaterprotocol.- Parameters:
threshold (float)
- get_energy()[source]#
- Returns:
The energy criteria corresponding to the truncated basis
- Return type:
float
- truncate(basis, singular_values, total_energy=None)[source]#
Truncate the basis based on the energy threshold.
- Parameters:
basis (np.ndarray) – The original basis matrix.
singular_values (np.ndarray) – The array of singular values associated with the basis matrix.
total_energy (float) – Optional squared Frobenius norm of the full snapshot matrix. If omitted, the supplied singular values are treated as the complete spectrum.
- Returns:
The truncated basis matrix based on the energy threshold.
- Return type:
np.ndarray
- class romtools.vector_space.utils.truncater.LeftSingularVectorTruncater(*args, **kwargs)[source]#
Bases:
ProtocolInterface for the Truncater class.
- truncate(basis, singular_values, total_energy=None)[source]#
Truncate left singular vectors.
total_energyis the squared Frobenius norm of the full snapshot matrix when it is available. This permits energy-based truncation whensingular_valuescontains only a leading portion of the spectrum.- Parameters:
basis (ndarray)
singular_values (ndarray)
total_energy (float | None)
- Return type:
ndarray
- class romtools.vector_space.utils.truncater.NoOpTruncater[source]#
Bases:
objectNo op implementation
This class conforms to the
LeftSingularVectorTruncaterprotocol.