pymor.reductors.data_driven¶
Module Contents¶
- class pymor.reductors.data_driven.AdaptiveDataDrivenReductor(dd_reductor_parameters, retrain_interval=1, fom=None)[source]¶
Bases:
pymor.core.base.BasicObjectAdaptive data-driven reductor for use in a
ModelHierarchy.Manages one or more
DataDrivenReductorsurrogates that approximate the reduced coefficients of the model above it in the hierarchy (typically a reduced basis model). Whenever the reduced basis of that model is extended, a new data-driven surrogate is added for the additional basis coefficients. The training data is split accordingly and passed to the respective surrogates before (re-)training. For prediction, all surrogates are evaluated for the given parameter and their outputs are combined into a singleModelOfDataDrivenModels.- Parameters:
dd_reductor_parameters – Attributes used to generate the
DataDrivenReductorsurrogates. A'regressor'entry, if present, must be a factory (a callable returning a fresh regressor) rather than a single regressor object, since each surrogate is trained independently and therefore needs its own regressor.retrain_interval – Number of new training data points to collect before retraining a surrogate.
fom – Reference model whose reduced coefficients the surrogates approximate (the model above this one in the hierarchy). It is
Noneuntil the first adaptation provides it and supplies the error estimator and output functional of the resulting model.
Methods
- class pymor.reductors.data_driven.DataDrivenPODReductor(training_parameters, training_snapshots, regressor=None, T=None, time_vectorized=False, output_functional=None, input_scaler=None, output_scaler=None, input_scaler_fitted=False, output_scaler_fitted=False, product=None, pod_params=None)[source]¶
Bases:
DataDrivenReductorReductor building a reduced basis and relying on a machine learning surrogate.
In addition to the
DataDrivenReductor, this reductor uses snapshot data in order to construct a reduced basis via POD and projects the snapshots onto the reduced basis to generate data for the machine learning training. The approach is described in [HU18]. SeeDataDrivenReductorfor more details.- Parameters:
training_parameters –
Parameter valuesto use for training of the regressor.training_snapshots –
VectorArrayto use for the training of the regressor. Contains the solutions or outputs associated to the parameters intraining_parameters. In the case of a time-dependent problem, the snapshots are assumed to be equidistant in time.regressor – See
DataDrivenReductor.T – See
DataDrivenReductor.time_vectorized – See
DataDrivenReductor.output_functional –
Operatormapping a given solution to the model output. In many applications, this will be aFunctional, i.e. anOperatormapping to scalars. This is not required, however. The output functional will be projected automatically onto the reduced space.input_scaler – See
DataDrivenReductor.output_scaler – See
DataDrivenReductor.input_scaler_fitted – See
DataDrivenReductor.output_scaler_fitted – See
DataDrivenReductor.product – Inner product
Operatorsdefined on the discrete space the problem is posed on. Used for reduced basis computation via POD and orthogonal projection onto the reduced basis.pod_params – Dict of additional parameters for the POD-method.
Methods
Add sequences of parameters and corresponding snapshots to the training data.
Reconstruct high-dimensional vector from reduced vector
u.Reduce by training a machine learning surrogate.
- extend_training_data(parameters, snapshots)[source]¶
Add sequences of parameters and corresponding snapshots to the training data.
- reduce(**kwargs)[source]¶
Reduce by training a machine learning surrogate.
If the regressor supports incremental extension via an
extendmethod and has already been fitted, only the new training data (added viaextend_training_data) is passed toextend. Otherwise, the regressor is fully retrained on all training data.Incremental extension requires that all scalers are either pre-fitted (via the
input_scaler_fitted/output_scaler_fittedflags) or not used, since unfitted scalers need to be refitted on the full dataset.- Parameters:
kwargs – Additional arguments that will be passed to the
fitmethod of the regressor.- Returns:
The data-driven reduced model.
- class pymor.reductors.data_driven.DataDrivenReductor(training_parameters, training_snapshots, regressor=None, target_quantity='solution', T=None, time_vectorized=False, output_functional=None, input_scaler=None, output_scaler=None, input_scaler_fitted=False, output_scaler_fitted=False)[source]¶
Bases:
pymor.core.base.BasicObjectReductor relying on a machine learning surrogate.
The reductor works for stationary as well as for instationary problems and returns a suitable model for the respective case.
Depending on the argument
target_quantity, this reductor either approximates the solution or the output as a parametric quantity by training a machine learning surrogate.In case of an approximation of the solution, the reductor trains a machine learning regressor that approximates the mapping from parameter space to a
NumPy array. Typically, the array contains coefficients of the solution with respect to a reduced basis.For
target_quantity='output', the machine learning regressor directly approximates the output depending on the parameter. The outputs for the training parameters are either computed using the full-order model or can be provided as thetraining_snapshotsargument.- Parameters:
training_parameters –
Parameter valuesto use for training of the regressor.training_snapshots – Iterable containing the training snapshots of the regressor. Contains the solutions (reduced coefficients w.r.t. the reduced basis or outputs) associated to the parameters in
training_parameters. In the case of a time-dependent problem, the snapshots are assumed to be equidistant in time.regressor – Regressor object with
fitandpredictmethods similar to scikit-learn regressors that is trained in thereduce-method. IfNone, aVKOGARegressorwith default settings is used.target_quantity – Either
'solution'or'output', determines which quantity to learn.T – In the instationary case, determines the final time until which to solve.
time_vectorized – In the instationary case, determines whether to predict the whole time trajectory at once (time-vectorized version; output of the regressor is typically very high-dimensional in this case) or if the result for a single point in time is approximated (time serves as an additional input to the regressor).
output_functional –
Operatormapping a given solution to the model output. In many applications, this will be aFunctional, i.e. anOperatormapping to scalars. This is not required, however.input_scaler – If not
None, a scaler object withfit,transformandinverse_transformmethods similar to the scikit-learn interface can be used to scale the parameters before passing them to the regressor.output_scaler – If not
None, a scaler object withfit,transformandinverse_transformmethods similar to the scikit-learn interface can be used to scale the outputs (reduced coeffcients or output quantities) before passing them to the regressor.input_scaler_fitted – If
True, theinput_scaleris assumed to be already fitted and will not be refitted duringreduce. This enables the incrementalextendpath for regressors that support it. Useful when the scaler has been pre-fitted based on domain knowledge (e.g., the parameter space bounds).output_scaler_fitted – If
True, theoutput_scaleris assumed to be already fitted and will not be refitted duringreduce.
Methods
Add sequences of parameters and corresponding snapshots to the training data.
Reduce by training a machine learning surrogate.
- extend_training_data(parameters, snapshots)[source]¶
Add sequences of parameters and corresponding snapshots to the training data.
- reduce(**kwargs)[source]¶
Reduce by training a machine learning surrogate.
If the regressor supports incremental extension via an
extendmethod and has already been fitted, only the new training data (added viaextend_training_data) is passed toextend. Otherwise, the regressor is fully retrained on all training data.Incremental extension requires that all scalers are either pre-fitted (via the
input_scaler_fitted/output_scaler_fittedflags) or not used, since unfitted scalers need to be refitted on the full dataset.- Parameters:
kwargs – Additional arguments that will be passed to the
fitmethod of the regressor.- Returns:
The data-driven reduced model.