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[, ...])add_to_valid
(name, values, v_type[, storage])Add the validation output to the valid_metrics.
eval_metamodel
([samples, nsamples, ...])Evaluates metamodel at the requested samples.
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])Train the surrogate in a sequential manner.
validate
([store, verbose])Evaluate the metamodel for validation.
- add_to_valid(name: str, values: dict, v_type: str, storage=None)¶
Add the validation output to the valid_metrics.
Parameters¶
- namestr
Name of validation criteria
- valuesdict
Values evaluated for the criteria, one value per output.
- v_typestr
Type of validation criteria, supports ‘valid’ and ‘bayes’.
- storagelist of dicts, optional
Dictionaries to store the values in, if not to be stored in self.valid_metrics/bayes_metrics
- 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.
- 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) 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.
Returns¶
None
- validate(store=True, verbose=False) None ¶
Evaluate the metamodel for validation. Two types of validation methods are considered: - Prediction validation: RMSE, MSE, R2, mean and stdev errors - Bayesian validation: BME, DKL, InfEntropy
Parameters¶
- storebool, optional
Validation results are stored in internal dictionary if set to True. If set to False, they are collected and returned. The default is ‘True’.
- verbosebool, optional
Verbosity of this functin. If set to True, will print the calculated metrics. The default is ‘False’.