bayesvalidrox.surrogate_models.engine.Engine¶
- class bayesvalidrox.surrogate_models.engine.Engine(meta_model, model, exp_design, discrepancy=None)¶
Bases:
object
This class is responsible for collecting and managing the experimental design, the model and the metamodel for training and evaluations.
Attributes¶
- meta_modelobj
A bvr.MetaModel object. If no MetaModel should be trained and used, set this to None.
- modelobj
A model interface of type bvr.PyLinkForwardModel that can be run.
- exp_designobj
The experimental design that will be used to sample from the input space.
- discrepancyobj, optional
A bvr.Discrepancy object that describes the model uncertainty, i.e. the diagonal entries of the variance matrix for a multivariate normal likelihood. This is used during active learning. The default is None.
- __init__(meta_model, model, exp_design, discrepancy=None)¶
Methods
__init__
(meta_model, model, exp_design[, ...])eval_metamodel
([samples, nsamples, ...])Evaluates metamodel at the requested samples.
plot_adapt
(y_mod, y_metamod, y_metamod_std)Visualize the model and metamodel outputs
plot_posterior
(posterior, par_names, key)Plot the posterior of a specific key as a corner plot
Do all the preparations that need to be run before the actual training
train_normal
([parallel, verbose, save])Trains surrogate on static samples only.
train_sequential
([parallel, verbose, plot])Train the surrogate in a sequential manner.
- eval_metamodel(samples=None, nsamples=None, sampling_method='random', return_samples=False, parallel=False)¶
Evaluates metamodel at the requested samples. One can also generate nsamples.
Parameters¶
- samplesarray of shape (n_samples, n_params), optional
Samples to evaluate metamodel at. The default is None.
- nsamplesint, optional
Number of samples to generate, if no samples is provided. The default is None.
- sampling_methodstr, optional
Type of sampling, if no samples is provided. The default is ‘random’.
- return_samplesbool, optional
Retun samples, if no samples is provided. The default is False.
- parallelbool, optional
Set to True if the evaluations should be done in parallel. The default is False.
Returns¶
- mean_preddict
Mean of the predictions.
- std_preddict
Standard deviatioon of the predictions.
- plot_adapt(y_mod, y_metamod, y_metamod_std, x_values=None, plot_ed=False, save=True)¶
Visualize the model and metamodel outputs
Parameters¶
- y_moddict
Model outputs.
- y_metamoddict
Mean MetaModel outputs.
- y_metamod_stddict
Std of MetaModel outputs.
- x_valueslist, optional
Values to write on the x-axis. The default is None
- plot_edbool, optional
Toggles plotting the training samples as well. The default is False.
- savebool, optional
Toggles saving the figure. The defautl is True.
- plot_posterior(posterior, par_names, key)¶
Plot the posterior of a specific key as a corner plot
Parameters¶
- posterior2d np.array
Samples of the posterior.
- par_nameslist of strings
List of the parameter names.
- keystring
Output key that this posterior belongs to.
- start_engine() None ¶
Do all the preparations that need to be run before the actual training
Returns¶
None
- train_normal(parallel=False, verbose=False, save=False) None ¶
Trains surrogate on static samples only. Samples are taken from the experimental design and the specified model is run on them. Alternatively the samples can be read in from a provided hdf5 file. save: bool determines whether the trained surrogate and the hdf5 file should be saved
Returns¶
None
- train_sequential(parallel=False, verbose=False, plot=False) None ¶
Train the surrogate in a sequential manner. First build and train evereything on the static samples, then iterate choosing more samples and refitting the surrogate on them.
Parameters¶
- parallelbool, optional
Toggles parallelization in the MetaModel training. The default is False
- verbosebool, optional
Toggles verbose outputs during training. The default is False.
- plotbool, optional
Toggles the generation of plots for each sequential iteration. The default is False.
Returns¶
None