ReducedOrderModel

Module for the Reduced Order Modeling.

ReducedOrderModel

Reduced Order Model class.

ReducedOrderModel.fit

Calculate reduced space

ReducedOrderModel.predict

Calculate predicted solution for given parameters.

ReducedOrderModel.test_error

Compute the mean norm of the relative error vectors of predicted test snapshots.

ReducedOrderModel.kfold_cv_error

Split the database into k consecutive folds (no shuffling by default).

ReducedOrderModel.loo_error

Estimate the approximation error using leave-one-out strategy.

ReducedOrderModel.optimal_mu

Return the parametric points where new high-fidelity solutions have to be computed in order to globally reduce the estimated error.

ReducedOrderModel._simplex_volume

Method implementing the computation of the volume of a N dimensional simplex.

class ReducedOrderModel(database, reduction, approximation, plugins=None)[source]

Bases: ReducedOrderModelInterface

Reduced Order Model class.

This class performs the actual reduced order model using the selected methods for approximation and reduction.

Parameters:
  • database (ezyrb.Database) – the database to use for training the reduced order model.

  • reduction (ezyrb.Reduction) – the reduction method to use in reduced order model.

  • approximation (ezyrb.Approximation) – the approximation method to use in reduced order model.

  • plugins (list) – list of plugins to use in the reduced order model.

Variables:
  • database (ezyrb.Database) – the database used for training the reduced order model.

  • reduction (ezyrb.Reduction) – the reduction method used in reduced order model.

  • approximation (ezyrb.Approximation) – the approximation method used in reduced order model.

  • plugins (list) – list of plugins used in the reduced order model.

Example:
>>> from ezyrb import ReducedOrderModel as ROM
>>> from ezyrb import POD, RBF, Database
>>> pod = POD()
>>> rbf = RBF()
>>> # param, snapshots and new_param are assumed to be declared
>>> db = Database(param, snapshots)
>>> rom = ROM(db, pod, rbf).fit()
>>> rom.predict(new_param)
_abc_impl = <_abc._abc_data object>
_reduce_database(db)[source]
_simplex_volume(vertices)[source]

Method implementing the computation of the volume of a N dimensional simplex. Source from: wikipedia.org/wiki/Simplex.

Parameters:

simplex_vertices (numpy.ndarray) – Nx3 array containing the parameter values representing the vertices of a simplex. N is the dimensionality of the parameters.

Returns:

N dimensional volume of the simplex.

Return type:

float

property approximation
clean()[source]
property database
fit()[source]

Calculate reduced space

fit_approximation()[source]
fit_reduction()[source]
kfold_cv_error(n_splits, *args, norm=<function norm>, **kwargs)[source]

Split the database into k consecutive folds (no shuffling by default). Each fold is used once as a validation while the k - 1 remaining folds form the training set. If n_splits is equal to the number of snapshots this function is the same as loo_error but the error here is relative and not absolute.

Parameters:
  • n_splits (int) – number of folds. Must be at least 2.

  • norm (function) – function to apply to compute the relative error between the true snapshot and the predicted one. Default value is the L2 norm.

  • *args – additional parameters to pass to the fit method.

  • **kwargs – additional parameters to pass to the fit method.

Returns:

the vector containing the errors corresponding to each fold.

Return type:

numpy.ndarray

static load(fname)[source]

Load the object from fname using the pickle module.

Returns:

The ReducedOrderModel loaded

Example:

>>> from ezyrb import ReducedOrderModel as ROM
>>> rom = ROM.load('ezyrb.rom')
>>> rom.predict(new_param)
loo_error(*args, norm=<function norm>, **kwargs)[source]

Estimate the approximation error using leave-one-out strategy. The main idea is to create several reduced spaces by combining all the snapshots except one. The error vector is computed as the difference between the removed snapshot and the projection onto the properly reduced space. The procedure repeats for each snapshot in the database. The norm is applied on each vector of error to obtained a float number.

Parameters:
  • norm (function) – the function used to assign at each vector of error a float number. It has to take as input a ‘numpy.ndarray` and returns a float. Default value is the L2 norm.

  • *args – additional parameters to pass to the fit method.

  • **kwargs – additional parameters to pass to the fit method.

Returns:

the vector that contains the errors estimated for all parametric points.

Return type:

numpy.ndarray

property n_approximation
property n_database
property n_reduction
optimal_mu(error=None, k=1)[source]

Return the parametric points where new high-fidelity solutions have to be computed in order to globally reduce the estimated error. These points are the barycentric center of the region (simplex) with higher error.

Parameters:
  • error (numpy.ndarray) – the estimated error evaluated for each snapshot; if error array is not passed, it is computed using loo_error() with the default function. Default value is None.

  • k (int) – the number of optimal points to return. Default value is 1.

Returns:

the optimal points

Return type:

numpy.ndarray

predict(parameters)[source]

Calculate predicted solution for given parameters. If parameters is a 2D array, the function returns a 2D array of predicted solutions. If parameters is a Database, the function returns the database of predicted solutions.

Returns:

the database containing all the predicted solution (with corresponding parameters).

Return type:

Database

property reduction
save(fname, save_db=True, save_reduction=True, save_approx=True)[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.

  • save_db (bool) – Flag to select if the Database will be saved.

  • save_reduction (bool) – Flag to select if the Reduction will be saved.

  • save_approx (bool) – Flag to select if the Approximation will be saved.

Example:

>>> from ezyrb import ReducedOrderModel as ROM
>>> rom = ROM(...) #  Construct here the rom
>>> rom.fit()
>>> rom.save('ezyrb.rom')
test_error(test, norm=<function norm>)[source]

Compute the mean norm of the relative error vectors of predicted test snapshots.

Parameters:
  • test (database.Database) – the input test database.

  • norm (function) – the function used to assign at the vector of errors a float number. It has to take as input a ‘numpy.ndarray’ and returns a float. Default value is the L2 norm.

Returns:

the mean L2 norm of the relative errors of the estimated test snapshots.

Return type:

numpy.ndarray