pyforce.online package
Submodules
pyforce.online.eim module
- class pyforce.online.eim.EIM(grid: pyvista.UnstructuredGrid, gdim: int = 3, varname: str = 'u')[source]
Bases:
OnlineDDROMA class to estimate the state using the EIM.
This class implements the empirical interpolation method (EIM) to estimate the state using measurements.
- Parameters:
grid (pyvista.UnstructuredGrid) – The grid on which the POD is performed. It is used to define the spatial domain of the snapshots.
gdim (int, optional (Default = 3)) – The geometric dimension of the grid. It can be either 2 or 3.
varname (str, optional) – The name of the variable to be used for the POD. Default is ‘u’.
- compute_B_matrix()[source]
Compute the matrix B used in the EIM: this matrix is the evluation of the magic functions at the magic points.
\[B_{ij} = q_j(x_i) \qquad i,j = 1, \ldots, M\]where \(\{q_j\}_{j=1}^M\) are the magic functions and \(\{x_i\}_{i=1}^M\) are the magic points.
- compute_errors(snaps: FunctionsList | ndarray, Mmax: int | None = None, noise_std: float = 0.0, regularization_params: dict | None = None, verbose: bool = False)[source]
Computes the errors between the original snapshots and the reconstructed ones.
- Parameters:
snaps (FunctionsList or np.ndarray) – Original snapshots to compare with.
Mmax (int, optional) – Maximum number of sensors and magic functions to use for the reconstruction. If None, all reduced basis is used.
noise_std (float, optional (Default = 0.0)) – Standard deviation of the Gaussian noise to be added to the measurements. Default is 0.
regularization_params (dict, optional (Default = None)) – Dictionary containing the regularization parameters. If None, no regularization is applied. At the moment, the only supported regularization is Tikhonov from Introini et al. (2023).
verbose (bool, optional) – If True, print progress messages. Default is False.
- Returns:
mean_abs_err (np.ndarray) – Average absolute error measured in \(L^2\).
mean_rel_err (np.ndarray) – Average relative error measured in \(L^2\).
computational_time (dict) – Dictionary with the CPU time of the most relevant operations during the online phase.
- estimate(measures: ndarray, M: int | None = None, regularization_params: dict | None = None)[source]
Estimate the state using the EIM given the measures at the magic points locations.
- Parameters:
measures (np.ndarray) – Measures \(\{y_m\}_{m=1}^{M_{max}}\), shaped \((M_{max},N_s)\).
M (int, optional (Default = None)) – Number of magic points to use for the extraction. If None, all available magic points are used.
regularization_params (dict, optional (Default = None)) –
Dictionary containing the regularization parameters. If None, no regularization is applied. At the moment, the only supported regularization is Tikhonov from Introini et al. (2023).
- Returns:
estimation – An instance of FunctionsList containing the estimated state.
- Return type:
- get_measurements(snaps: FunctionsList | ndarray, M: int | None = None, noise_std: float = 0.0)[source]
This method extracts the measures from the input functions at the magic points locations.
- Parameters:
snaps (FunctionsList or np.ndarray) – Function object to extract the measures from.
M (int, optional (Default = None)) – Number of magic points to use for the extraction. If None, all available magic points are used.
noise_std (float, optional (Default = 0.0)) – Standard deviation of the Gaussian noise to be added to the measurements. Default is 0.
- Returns:
measures – Measures \(\{y_m\}_{m=1}^M\), shaped \((M,N_s)\).
- Return type:
np.ndarray
- set_basis(basis=None, path_folder: str | None = None, **kwargs)[source]
Assign the magic functions to the EIM model either from a FunctionsList object or by loading from a folder.
- Parameters:
basis (FunctionsList, optional) – An instance of FunctionsList containing the basis functions.
path_folder (str, optional) – The path to the folder containing the basis functions.
**kwargs (dict) – Additional keyword arguments to pass to the loading function.
- Return type:
None
- set_magic_points(magic_points: dict | None = None, path_folder: str | None = None)[source]
Set the magic points for the EIM.
- Parameters:
magic_points (list of int) – A list containing the indices of the magic points.
- set_tikhonov_matrices(beta_coeffs: ndarray | None = None, train_snaps: FunctionsList | ndarray | None = None)[source]
This method is used to compute the matrices and vectors needed for the Tikhonov regularization, following Introini et al. (2023), from the training reduced coefficients. Given the training reduced coefficients \(\{\beta_m(\boldsymbol{\mu}_i)\}_{m=1}^{M}, i=1,\ldots,N_{train}\) it computes the following:
\[\langle \boldsymbol{\beta} \rangle = \sum_{i=1}^{N_{train}} \boldsymbol{\beta}(\boldsymbol{\mu}_i) \in\mathbb{R}^{M}\]\[\sigma_{\beta_j}^2 = \frac{1}{N_{train}-1}\sum_{i=1}^{N_{train}} (\beta_j(\boldsymbol{\mu}_i) - \langle \beta_j \rangle)^2 \qquad j=1,\ldots,M\]from which the Tikhonov matrix is defined:
\[\mathbb{T} = \mathrm{diag}\left(\frac{1}{|\sigma_{\beta_1}|}, \ldots, \frac{1}{|\sigma_{\beta_M}|}\right) \in\mathbb{R}^{M\times M}\]The training coefficients can be provided as input or they can be computed from the training snapshots using the _reduce method.
- Parameters:
beta_coeffs (np.ndarray, optional) – The training reduced coefficients, shaped \((M, N_{train})\). If not provided, they will be computed from the training snapshots.
train_snaps (FunctionsList or np.ndarray, optional) – The training snapshots to compute the reduced coefficients from. Required if beta_coeffs is not provided.
pyforce.online.failure_sens module
- class pyforce.online.failure_sens.FailingGEIM(grid: pyvista.UnstructuredGrid, gdim: int = 3, varname: str = 'u')[source]
Bases:
GEIMClass for the online phase of GEIM with failing sensors. Inherits from GEIM class.
- Parameters:
grid (pv.UnstructuredGrid) – The computational grid.
gdim (int, optional) – Geometrical dimension of the problem (default is 3).
varname (str, optional) – Name of the variable in the grid (default is ‘u’).
- estimate(measures: ndarray, regularization_params: dict | None = None, hard_failure_dict: dict | None = None)[source]
Estimate the state using the GEIM given the measures at the sensor locations.
- Parameters:
measures (np.ndarray) – Measures \(\{y_m\}_{m=1}^{M_{max}}\), shaped \((M_{max},N_s)\).
regularization_params (dict, optional (Default = None)) –
Dictionary containing the regularization parameters. If None, no regularization is applied. At the moment, the only supported regularization is Tikhonov from Introini et al. (2023).
hard_failure_dict (dict, optional (Default = None)) – Dictionary containing the parameters for the hard failure simulation. If provided, the method will handle hard failures by removing the corresponding sensors from the estimation process.
- Returns:
estimation – An instance of FunctionsList containing the estimated state.
- Return type:
- get_measurements(snaps: FunctionsList | ndarray, M: int | None = None, noise_std: float = 0.0, drift_dict: dict | None = None) ndarray[source]
This method extracts the measures from the input functions at the magic sensors locations. It allows also to add Gaussian noise to the measurements.
Moreover, the drift failure of the sensor can be simulated by providing a drift_dict with the following keys:
- ‘kappa’float
Shift from the average value of the sensor.
- ‘rho’float, optional
High frequency oscillation amplitude.
- ‘idx_failed’list of int, optional
List of indices of the failed sensors.
- ‘mu_failure’int, optional (Default = 0)
Starting index of the failure in the snapshots.
- Parameters:
snaps (FunctionsList or np.ndarray) – Function object to extract the measures from.
M (int, optional (Default = None)) – Number of sensors to use for the extraction. If None, all available magic sensors are used.
noise_std (float, optional (Default = 0.0)) – Standard deviation of the Gaussian noise to be added to the measurements. Default is 0.
drift_dict (dict, optional (Default = None)) – Dictionary containing the parameters for the drift failure simulation.
- Returns:
measures – Measures \(\{y_m\}_{m=1}^M\), shaped \((M,N_s)\).
- Return type:
np.ndarray
- class pyforce.online.failure_sens.FailingPBDW(grid: pyvista.UnstructuredGrid, gdim: int = 3, varname: str = 'u')[source]
Bases:
PBDWClass for the online phase of PBDW with failing sensors. Inherits from PBDW class.
- Parameters:
grid (pv.UnstructuredGrid) – The computational grid.
gdim (int, optional) – Geometrical dimension of the problem (default is 3).
varname (str, optional) – Name of the variable in the grid (default is ‘u’).
- estimate(measures: ndarray, xi: float = 0.0, hard_failure_dict: dict | None = None)[source]
Estimate the state using the PBDW given the measures at the sensor locations.
- Parameters:
measures (np.ndarray) – Measures \(\{y_m\}_{m=1}^{M}\), shaped \((M, N_s)\).
xi (float, optional (Default = 0.0)) – Regularization parameter for the regularization. Default is 0.0
hard_failure_dict (dict, optional (Default = None)) – Dictionary containing the parameters for the hard failure simulation. If provided, the method will handle hard failures by removing the corresponding sensors from the estimation process.-
- Returns:
estimation – An instance of FunctionsList containing the estimated state.
- Return type:
- get_measurements(snaps: FunctionsList | ndarray, M: int | None = None, noise_std: float = 0.0, drift_dict: dict | None = None)[source]
This method extracts the measures from the input functions at the magic sensors locations. It allows also to add Gaussian noise to the measurements.
Moreover, the drift failure of the sensor can be simulated by providing a drift_dict with the following keys:
- ‘kappa’float
Shift from the average value of the sensor.
- ‘rho’float, optional
High frequency oscillation amplitude.
- ‘idx_failed’list of int, optional
List of indices of the failed sensors.
- ‘mu_failure’int, optional (Default = 0)
Starting index of the failure in the snapshots.
- Parameters:
snaps (FunctionsList or np.ndarray) – Function object to extract the measures from.
M (int, optional (Default = None)) – Number of sensors to use for the extraction. If None, all available magic sensors are used.
noise_std (float, optional (Default = 0.0)) – Standard deviation of the Gaussian noise to be added to the measurements. Default is 0.
drift_dict (dict, optional (Default = None)) – Dictionary containing the parameters for the drift failure simulation.
- Returns:
measures – Measures \(\{y_m\}_{m=1}^M\), shaped \((M,N_s)\).
- Return type:
np.ndarray
pyforce.online.geim module
- class pyforce.online.geim.GEIM(grid: pyvista.UnstructuredGrid, gdim: int = 3, varname: str = 'u')[source]
Bases:
OnlineDDROMA class to estimate the state using the GEIM.
This class implements the generalized empirical interpolation method (GEIM) to estimate the state using measurements.
- Parameters:
grid (pyvista.UnstructuredGrid) – The computational grid. It is used to define the spatial domain of the snapshots.
gdim (int, optional (Default = 3)) – The geometric dimension of the grid. It can be either 2 or 3.
varname (str, optional) – The name of the variable to be used. Default is ‘u’.
- compute_B_matrix()[source]
Compute the matrix B used in the GEIM: this matrix is the evaluation of the magic functions at the magic sensors.
\[B_{ij} = v_i(q_j) \qquad i,j = 1, \ldots, M\]where \(\{q_j\}_{j=1}^M\) are the magic functions and \(\{v_i\}_{i=1}^M\) are the magic sensors.
- compute_errors(snaps: FunctionsList | ndarray, Mmax: int | None = None, noise_std: float = 0.0, regularization_params: dict | None = None, verbose: bool = False)[source]
Computes the errors between the original snapshots and the reconstructed ones.
- Parameters:
snaps (FunctionsList or np.ndarray) – Original snapshots to compare with.
Mmax (int, optional) – Maximum number of sensors and magic functions to use for the reconstruction. If None, all reduced basis is used.
noise_std (float, optional (Default = 0.0)) – Standard deviation of the Gaussian noise to be added to the measurements. Default is 0.
regularization_params (dict, optional (Default = None)) –
Dictionary containing the regularization parameters. If None, no regularization is applied. At the moment, the only supported regularization is Tikhonov from Introini et al. (2023).
verbose (bool, optional) – If True, print progress messages. Default is False.
- Returns:
mean_abs_err (np.ndarray) – Average absolute error measured in \(L^2\).
mean_rel_err (np.ndarray) – Average relative error measured in \(L^2\).
computational_time (dict) – Dictionary with the CPU time of the most relevant operations during the online phase.
- estimate(measures: ndarray, regularization_params: dict | None = None)[source]
Estimate the state using the GEIM given the measures at the sensor locations.
- Parameters:
measures (np.ndarray) – Measures \(\{y_m\}_{m=1}^{M_{max}}\), shaped \((M_{max},N_s)\).
regularization_params (dict, optional (Default = None)) –
Dictionary containing the regularization parameters. If None, no regularization is applied. At the moment, the only supported regularization is Tikhonov from Introini et al. (2023).
- Returns:
estimation – An instance of FunctionsList containing the estimated state.
- Return type:
- get_measurements(snaps: FunctionsList | ndarray, M: int | None = None, noise_std: float = 0.0)[source]
This method extracts the measures from the input functions at the magic sensors locations.
- Parameters:
snaps (FunctionsList or np.ndarray) – Function object to extract the measures from.
M (int, optional (Default = None)) – Number of sensors to use for the extraction. If None, all available magic sensors are used.
noise_std (float, optional (Default = 0.0)) – Standard deviation of the Gaussian noise to be added to the measurements. Default is 0.
- Returns:
measures – Measures \(\{y_m\}_{m=1}^M\), shaped \((M,N_s)\).
- Return type:
np.ndarray
- set_basis(basis: FunctionsList | None = None, path_folder: str | None = None, **kwargs)[source]
Assign the magic functions to the GEIM model either from a FunctionsList object or by loading from a folder.
- Parameters:
basis (FunctionsList, optional) – An instance of FunctionsList containing the basis functions.
path_folder (str, optional) – The path to the folder containing the basis functions.
**kwargs (dict) – Additional keyword arguments to pass to the loading function.
- Return type:
None
- set_magic_sensors(sensors: FunctionsList | None = None, path_folder: str | None = None, **kwargs)[source]
Assign the magic sensors to the GEIM model either from a FunctionsList object or by loading from a folder.
- Parameters:
sensors (FunctionsList, optional) – An instance of FunctionsList containing the sensor functions.
path_folder (str, optional) – The path to the folder containing the sensor functions.
**kwargs (dict) – Additional keyword arguments to pass to the loading function.
- Return type:
None
- set_tikhonov_matrices(beta_coeffs: ndarray | None = None, train_snaps: FunctionsList | ndarray | None = None)[source]
This method is used to compute the matrices and vectors needed for the Tikhonov regularization, following Introini et al. (2023), from the training reduced coefficients. Given the training reduced coefficients \(\{\beta_m(\boldsymbol{\mu}_i)\}_{m=1}^{M}, i=1,\ldots,N_{train}\) it computes the following:
\[\langle \boldsymbol{\beta} \rangle = \sum_{i=1}^{N_{train}} \boldsymbol{\beta}(\boldsymbol{\mu}_i) \in\mathbb{R}^{M}\]\[\sigma_{\beta_j}^2 = \frac{1}{N_{train}-1}\sum_{i=1}^{N_{train}} (\beta_j(\boldsymbol{\mu}_i) - \langle \beta_j \rangle)^2 \qquad j=1,\ldots,M\]from which the Tikhonov matrix is defined:
\[\mathbb{T} = \mathrm{diag}\left(\frac{1}{|\sigma_{\beta_1}|}, \ldots, \frac{1}{|\sigma_{\beta_M}|}\right) \in\mathbb{R}^{M\times M}\]The training coefficients can be provided as input or they can be computed from the training snapshots using the _reduce method.
- Parameters:
beta_coeffs (np.ndarray, optional) – The training reduced coefficients, shaped \((M, N_{train})\). If not provided, they will be computed from the training snapshots.
train_snaps (FunctionsList or np.ndarray, optional) – The training snapshots to compute the reduced coefficients from. Required if beta_coeffs is not provided.
pyforce.online.indirect_reconstruction module
- class pyforce.online.indirect_reconstruction.ParameterEstimation(grid: pyvista.UnstructuredGrid, maps: SurrogateModelWrapper, bnds: list, gdim: int = 3)[source]
Bases:
object- compute_B_matrix()[source]
Compute the matrix B used in the GEIM: this matrix is the evaluation of the magic functions at the magic sensors.
\[B_{ij} = v_i(q_j) \qquad i,j = 1, \ldots, M\]where \(\{q_j\}_{j=1}^M\) are the magic functions and \(\{v_i\}_{i=1}^M\) are the magic sensors.
- compute_errors(test_param: ndarray, test_snaps: FunctionsList | ndarray, M: int, noise_std=0.0, use_brute=True, grid_elem=10, verbose=False)[source]
The absolute and relative error of the PE phase, using different measurements coming from the test set, are computed.
- Parameters:
test_param (np.ndarray) – The test parameter set \(\{\boldsymbol{\mu}^{(n)}\}_{n=1}^{N_{test}}\), shaped \((N_{test}, p)\).
test_snaps (FunctionsList or np.ndarray) – The test snapshots set \(\{u^{(n)}\}_{n=1}^{N_{test}}\).
M (int) – Number of sensors to use for the generation of the measures.
noise_std (float, optional (Default = 0.0)) – Standard deviation of the Gaussian noise to be added to the measurements.
use_brute (bool, optional (Default = True)) – If True, the brute force method is used for the initial guess in the optimisation. If False, differential evolution is used.
grid_elem (int, optional (Default = 10)) – Number of elements in the grid for the brute force method.
verbose (bool, optional (Default = False)) – If True, progress information is printed to the console.
- Returns:
mean_abs_err (np.ndarray) – Average absolute error of the parameter estimation
mean_rel_err (np.ndarray) – Average relative error of the parameter estimation
computational_time (dict) – Dictionary with the CPU time of the most relevant operations during the online phase.
mu_PE (list) – List containing the estimated parameters after least squares at varying number of measurements
mu_PE_guess (list) – List containing the estimated parameters before least squares at varying number of measurements
- get_measurements(snaps: FunctionsList | ndarray, M: int | None = None, noise_std: float = 0.0)[source]
This method extracts the measures from the input functions at the magic sensors locations.
- Parameters:
snaps (FunctionsList or np.ndarray) – Function object to extract the measures from.
M (int, optional (Default = None)) – Number of sensors to use for the extraction. If None, all available magic sensors are used.
noise_std (float, optional (Default = 0.0)) – Standard deviation of the Gaussian noise to be added to the measurements. Default is 0.
- Returns:
measures – Measures \(\{y_m\}_{m=1}^M\), shaped \((M,N_s)\).
- Return type:
np.ndarray
- optimise(measure: ndarray, use_brute=True, grid_elem=10)[source]
This auxiliary function performs the optimisation process given an input collection of measurements.
Two options are available:
brute force method for finding the first guess of the parameter estimation + Least squares
differential evolution method for finding the first guess of the parameter estimation + Least squares
- Parameters:
measure (np.ndarray) – Measurement vector of M elements, array-like.
use_brute (bool, optional (Default = True)) – brute force method for finding the first guess of the parameter estimation
grid_elem (int, optional (Default = 10)) – Number of elements in the grid for the brute force method
- Returns:
solution (np.ndarray) – Solution of the optimisation (after least squares)
guess (np.ndarray) – Solution of the optimisation (before least squares)
- set_magic_functions(basis: FunctionsList | None = None, path_folder: str | None = None, **kwargs)[source]
Assign the magic functions to the GEIM model either from a FunctionsList object or by loading from a folder.
- Parameters:
basis (FunctionsList, optional) – An instance of FunctionsList containing the basis functions.
path_folder (str, optional) – The path to the folder containing the basis functions.
**kwargs (dict) – Additional keyword arguments to pass to the loading function.
- Return type:
None
- set_magic_sensors(sensors: FunctionsList | None = None, path_folder: str | None = None, **kwargs)[source]
Assign the magic sensors to the GEIM model either from a FunctionsList object or by loading from a folder.
- Parameters:
sensors (FunctionsList, optional) – An instance of FunctionsList containing the sensor functions.
path_folder (str, optional) – The path to the folder containing the sensor functions.
**kwargs (dict) – Additional keyword arguments to pass to the loading function.
- Return type:
None
- pyforce.online.indirect_reconstruction.objective(mu: ndarray, matrix_B: ndarray, target_measure: ndarray, maps: SurrogateModelWrapper)[source]
This function evaluates the standard loss function \(\mathcal{L}_{PE}\) to be minimized during the Parameter Estimation phase
\[\mathcal{L}_{PE}(\boldsymbol{\mu}) = \|B\boldsymbol{\beta}(\boldsymbol{\mu}) - \mathbf{y}\|_2^2 \qquad\qquad \text{ given }\mathcal{F}_m(\boldsymbol{\mu}) = \beta_m(\boldsymbol{\mu})\]given the maps \(\mathcal{F}_m:\boldsymbol{\mu} \rightarrow \beta_m\) (\(m = 1, \dots, M\)).
- Parameters:
mu (np.ndarray) – The input parameter vector \(\boldsymbol{\mu} \in \mathbb{R}^{p}\).
matrix_B (np.ndarray) – The (G)EIM matrix \(B \in \mathbb{R}^{M \times M}\).
target_measure (np.ndarray) – The target measurement vector \(\mathbf{y} \in \mathbb{R}^{M}\).
maps (SurrogateModelWrapper) – The surrogate model wrapper containing the maps \(\mathcal{F}_m\) from parameters to (G)EIM coefficients.
pyforce.online.online_base module
Module for offline base class of offline phase in pyforce library. This module provides the base class for the offline phase of the pyforce library.
- class pyforce.online.online_base.OnlineDDROM(grid, gdim=3, varname='u', **kwargs)[source]
Bases:
ABCAbstract base class for the online phase of the pyforce library.
This class defines the interface for the online phase, which is responsible for making predictions and (if possible) updating the model in real-time.
- property basis
Property to access the basis used in the online phase. This property returns a FunctionsList containing the basis functions used for the online phase of the model.
- Returns:
The basis functions used in the online phase.
- Return type:
- abstract set_basis(basis: FunctionsList | None = None, path_folder: str | None = None, **kwargs)[source]
Abstract method to load or assign the basis functions.
- class pyforce.online.online_base.OnlineSensors(grid: pyvista.UnstructuredGrid, library: FunctionsList, gdim: int = 3)[source]
Bases:
objectBase class for online sensors. This class provides the basic functionality for online sensors, focusing on the action of the sensor on a given function to obtain measurements.
- Parameters:
grid (pv.UnstructuredGrid) – The computational grid.
library (FunctionsList) – The library of sensors to be used.
gdim (int, optional (default=3)) – The geometric dimension of the problem.
- action(func: FunctionsList | ndarray, M: int | None = None)[source]
Compute the action of the sensor library on a given function (both single or matrix) or a list of functions.
- Parameters:
func (FunctionsList | np.ndarray) – The function or list of functions to be sensed.
M (int, optional (default=None)) – If provided, only the first M sensors in the library are used.
- Returns:
actions – The actions of the sensor library on the function(s). Shape (Nsensors, Ns).
- Return type:
np.ndarray
- class pyforce.online.online_base.SurrogateModelWrapper[source]
Bases:
ABCA wrapper class for surrogate models to predict coefficients based on input vector (it can be either test parameters or measurements).
- abstract predict(input_vector: ndarray, **kwargs) ndarray[source]
Predict coefficients based on the provided input vector of size \((N_s, N_p)\), where \(N_s\) is the number of samples and \(N_p\) is the degrees of freedom of the input vector (for instance, either the number of parameters or the number of sensors).
- Parameters:
input_vector (np.ndarray) – The input vector for which to predict the coefficients, shaped \((N_s, N_p)\).
- Returns:
The predicted coefficients shaped \((r, N_s)\).
- Return type:
np.ndarray
pyforce.online.pbdw module
- class pyforce.online.pbdw.PBDW(grid: pyvista.UnstructuredGrid, gdim: int = 3, varname: str = 'u')[source]
Bases:
OnlineDDROMA class to estimate the state using the PBDW.
This class implements the parameterized background data-weak (PBDW) method to estimate the state using measurements.
- Parameters:
grid (pyvista.UnstructuredGrid) – The computational grid. It is used to define the spatial domain of the snapshots.
gdim (int, optional (Default = 3)) – The geometric dimension of the grid. It can be either 2 or 3.
varname (str, optional) – The name of the variable to be used for the POD. Default is ‘u’.
- compute_errors(snaps: FunctionsList | ndarray, Mmax: int | None = None, noise_std: float = 0.0, xi: float = 0.0, verbose: bool = False)[source]
Computes the errors between the original snapshots and the reconstructed ones.
- Parameters:
snaps (FunctionsList or np.ndarray) – Original snapshots to compare with.
Mmax (int, optional) – Maximum number of sensors and magic functions to use for the reconstruction. If None, all reduced basis is used.
noise_std (float, optional (Default = 0.0)) – Standard deviation of the Gaussian noise to be added to the measurements. Default is 0.
xi (float, optional (Default = 0.0)) – Regularization parameter for the regularization. Default is 0.0
verbose (bool, optional) – If True, print progress messages. Default is False.
- Returns:
mean_abs_err (np.ndarray) – Average absolute error measured in \(L^2\).
mean_rel_err (np.ndarray) – Average relative error measured in \(L^2\).
computational_time (dict) – Dictionary with the CPU time of the most relevant operations during the online phase.
- compute_matrices()[source]
Compute the matrices K, A and Z used in the PBDW: given \(\{g_j\}_{j=1}^M\) the basis sensors and \(\{\zeta_i\}_{i=1}^N\) the basis functions
\[\mathbb{A}_{ij} = (g_i, g_j)_{L^2} \in\mathbb{R}^{M\times M}\]\[\mathbb{K}_{ji} = (\zeta_i, g_j)_{L^2} \in\mathbb{R}^{M\times N}\]\[\mathbb{Z}_{ij} = (\zeta_i, \zeta_j)_{L^2} \in\mathbb{R}^{N\times N}\]where \((\cdot, \cdot)_{L^2}\) is the \(L^2\) inner product.
- estimate(measures: ndarray, xi: float = 0.0)[source]
Estimate the state using the PBDW given the measures at the sensor locations.
- Parameters:
measures (np.ndarray) – Measures \(\{y_m\}_{m=1}^{M}\), shaped \((M, N_s)\).
xi (float, optional (Default = 0.0)) – Regularization parameter for the regularization. Default is 0.0
- Returns:
estimation – An instance of FunctionsList containing the estimated state.
- Return type:
- get_measurements(snaps: FunctionsList | ndarray, M: int | None = None, noise_std: float = 0.0)[source]
This method extracts the measures from the input functions at the sensor locations.
- Parameters:
snaps (FunctionsList or np.ndarray) – Function object to extract the measures from.
M (int, optional (Default = None)) – Number of sensors to use for the extraction. If None, all available sensors are used.
noise_std (float, optional (Default = 0.0)) – Standard deviation of the Gaussian noise to be added to the measurements. Default is 0.
- Returns:
measures – Measures \(\{y_m\}_{m=1}^M\), shaped \((M,N_s)\).
- Return type:
np.ndarray
- set_basis(basis: FunctionsList | None = None, path_folder: str | None = None, **kwargs)[source]
Assign the basis functions of the reduced space \(Z_N\) either from a FunctionsList object or by loading from a folder.
- Parameters:
basis (FunctionsList, optional) – An instance of FunctionsList containing the basis functions.
path_folder (str, optional) – The path to the folder containing the basis functions.
**kwargs (dict) – Additional keyword arguments to pass to the loading function.
- Return type:
None
- set_basis_sensors(sensors: FunctionsList | None = None, path_folder: str | None = None, **kwargs)[source]
Assign the basis sensors to the PBDW model either from a FunctionsList object or by loading from a folder. At the moment, they are the Riesz representation in \(L^2\) of the functionals.
- Parameters:
sensors (FunctionsList, optional) – An instance of FunctionsList containing the sensor functions.
path_folder (str, optional) – The path to the folder containing the sensor functions.
**kwargs (dict) – Additional keyword arguments to pass to the loading function.
- Return type:
None
pyforce.online.pod module
- class pyforce.online.pod.POD(grid, gdim=3, varname='u', **kwargs)[source]
Bases:
OnlineDDROMA class to estimate the state using the POD modes.
This class implements the pure projection method to estimate the state using the POD modes and allows for the integration with surrogate models for the reduced dynamics (e.g., interpolation, machine learning, etc.), adopting the scheme of the POD with Interpolation (Demo et al, 2019 - https://doi.org/10.48550/arXiv.1905.05982).
- Parameters:
grid (pyvista.UnstructuredGrid) – The grid on which the POD is performed. It is used to define the spatial domain of the snapshots.
gdim (int, optional (Default = 3)) – The geometric dimension of the grid. It can be either 2 or 3.
varname (str, optional) – The name of the variable to be used for the POD. Default is ‘u’.
- compute_errors(snaps: FunctionsList | ndarray, coeff_model: SurrogateModelWrapper, input_vector: ndarray, verbose: bool = False)[source]
Computes the errors between the original snapshots and the reconstructed ones.
- Parameters:
snaps (FunctionsList or np.ndarray) – Original snapshots to compare with.
coeff_model (SurrogateModelWrapper) – The surrogate model to use for estimating the coefficients.
input_vector (np.ndarray) – The input vector for which to estimate the state.
verbose (bool, optional) – If True, print progress messages. Default is False.
- Returns:
mean_abs_err (np.ndarray) – Average absolute error measured in \(L^2\).
mean_rel_err (np.ndarray) – Average relative error measured in \(L^2\).
computational_time (dict) – Dictionary with the CPU time of the most relevant operations during the online phase.
- estimate(coeff_model: SurrogateModelWrapper, input_vector: ndarray)[source]
This method can be adopted to estimate the state using a surrogate model \(\{\mathcal{F}_k\}_{k=1}^N\) (i.e., coeff_model) for the reduced coefficients \(\{\alpha_k\}_{k=1}^N\), given the input vector \(\mathbf{z}\), such that
\[\alpha_k(\mathbf{z}) = \mathcal{F}_k(\mathbf{z})\]- Parameters:
coeff_model (SurrogateModelWrapper) – The surrogate model to use for estimating the coefficients.
input_vector (np.ndarray) – The input vector for which to estimate the state.
- Returns:
estimation – An instance of FunctionsList containing the estimated state.
- Return type:
- set_basis(basis: FunctionsList | None = None, path_folder: str | None = None, **kwargs)[source]
Assign the basis functions to the POD model either from a FunctionsList object or by loading from a folder.
- Parameters:
basis (FunctionsList, optional) – An instance of FunctionsList containing the basis functions.
path_folder (str, optional) – The path to the folder containing the basis functions.
**kwargs (dict) – Additional keyword arguments to pass to the loading function.
- Return type:
None
Module contents
pyforce/online.
Online phase of the pyforce library.