Parametric DMD¶
Module for the parametric Dynamic Mode Decomposition.
References: - A Dynamic Mode Decomposition Extension for the Forecasting of Parametric Dynamical Systems, F. Andreuzzi, N. Demo, G. Rozza, 2023, SIAM Journal on Applied Dynamical Systems
-
class
ParametricDMD
(dmd, spatial_pod, approximation, light=False, dmd_fit_args=None, dmd_fit_kwargs=None)[source] Bases:
object
Implementation of the parametric Dynamic Mode Decomposition proposed in arXiv:2110.09155v1. Both the monolithic and partitioned methods are available, see the documentation of the parameter dmd for more details.
- Parameters
dmd (DMDBase or list) – Instance(s) of
dmdbase.DMDBase
, used by the paramtric DMD for the prediction of future spatial modal coefficients. If dmd is a list the partitioned approach is selected, in this case the number of parameters in the training set should be equal to the number of DMD instances provided. If dmd is not a list, we employ the monolithic approach.spatial_pod – Instance of an object usable for the generation of a ROM of the dataset (see for instance the class POD from the Python library EZyRB).
approximation –
An interpolator following the standard learning-prediction pattern (fit() -> predict()). For some convenient wrappers see those implemented in EZyRB).
light (bool) – Whether this instance should be light or not. A light instance uses less memory since it caches a smaller number of resources. Setting light=True might invalidate several properties (see also
training_modal_coefficients()
).dmd_fit_args – Positional arguments to be passed to the fit method of the given DMD instance.
dmd_fit_kwargs – Keyword arguments to be passed to the fit method of the given DMD instance.
-
property
dmd_time
The time dictionary used by the reference DMD instance (see also
_reference_dmd()
). Note that when you set this attribute the value is set only for the reference DMD (see_reference_dmd()
), however when_predict_modal_coefficients()
is called the values of all DMDs become consistent.- Getter
Return the time dictionary used by the reference DMD instance.
- Setter
Set the given time dictionary in the field dmd_time for all DMD instances.
- Type
pydmd.dmdbase.DMDTimeDict
-
property
dmd_timesteps
The timesteps in the output of this instance, which coincides with the timesteps in the output of the reference of this instance (see
_reference_dmd()
).- Returns
The timesteps in the output of this instance.
- Return type
list
-
fit
(X, training_parameters)[source] Compute the parametric Dynamic Modes Decomposition from the input data stored in the array X. The shape of the parameter X must be used as follows:
0: Training parameters;
1: Space;
2: Training time instants.
The parameter training_parameters contains the list of training parameters corresponding to the training datasets in X. For instance, training_parameters[0] is the parameter which generated the dataset in X[0]. For this reason len(training_parameters) should be equal to X.shape[0].
- Parameters
X (numpy.ndarray) – Training snapshots of the parametric system, observed for two or more parameters and in multiple time instants.
training_parameters (numpy.ndarray) – Training parameters corresponding to the snapshots in X.
-
property
forecasted_modal_coefficients
Modal coefficients forecasted for the input parameters.
The tensor returned has the following shape:
0: Training parameters;
1: Dimensionality of the POD sub-space;
2: Time.
-
property
interpolated_modal_coefficients
Modal coefficients forecasted and then interpolated for the untested parameters.
The tensor returned has the following shape:
0: Parameters;
1: Dimensionality of the POD sub-space;
2: Time.
-
property
is_partitioned
Return True if this instance is partitioned, False if it is monolithic.
- Type
-
static
load
(fname)[source] Load the object from fname using the pickle module.
- Returns
The ReducedOrderModel loaded
Example:
>>> from pydmd import ParametricDMD >>> pdmd = ParametricDMD.load('pydmd.pdmd') >>> print(pdmd.reconstructed_data)
-
property
original_time
The original time dictionary used by this instance, which coincides with the original dictionary used by the reference of this instance (see
_reference_dmd()
).- Returns
The original time dictionary used by this instance.
- Return type
-
property
original_timesteps
The original timesteps in the input fed to this instance, which coincides with the original timesteps in the input fed to the reference of this instance (see
_reference_dmd()
).- Returns
The original timesteps in the input fed to this instance.
- Return type
list
-
property
parameters
The new parameters to be used in reconstructed_data, represented as a 2D array (the index of the parameter vary along the first dimension). For, instance, the following feeds a set of four 3D parameters to ParametricDMD:
>>> from pydmd import ParametricDMD >>> pdmd = ParametricDMD(...) >>> pdmd.fit(...) >>> p0 = [0.1, 0.2, 0.1] >>> p1 = [0.1, 0.2, 0.3], >>> p2 = [0.2, 0.2, 0.2], >>> p3 = [0.1, 0.2, 0.2] >>> pdmd.parameters = np.array([p0,p1,p2,p3])
Therefore, when we collect the results from reconstructed_data:
>>> result = pdmd.reconstructed_data >>> # reconstruction corresponding to p0 >>> rec_p0 = result[0] >>> # reconstruction corresponding to p1 >>> rec_p1 = result[1] >>> ...
- Getter
Return the current parameters.
- Setter
Change the current parameters.
- Type
-
property
reconstructed_data
Get the reconstructed data, for the time instants specified in dmd_time, and the parameters stored in parameters.
The shape of the returned data is distributed as follows:
0: Parameters;
1: Space;
2: Time.
- Returns
Snapshots predicted/interpolated using parametric DMD and the given method for ROM.
- Return type
-
save
(fname)[source] Save the object to fname using the pickle module.
- Parameters
fname (str) – the name of file where the reduced order model will be saved.
Example:
>>> from pydmd import ParametricDMD >>> pdmd = ParametricDMD(...) # Construct here the rom >>> pdmd.fit(...) >>> pdmd.save('pydmd.pdmd')
-
property
training_modal_coefficients
Modal coefficients of the input dataset. Since this is cached after calls to
fit()
this property needs to be called afterfit()
, and light should be set to False in the constructor of the class.The tensor returned has the following shape:
0: Training parameters;
1: Dimensionality of the POD sub-space;
2: Time.
-
property
training_parameters
The original parameters passed when self.fit was called, represented as a 2D array (the index of the parameter vary along the first dimension).
- Type