data_models.surrogates.api
data_models.surrogates.api
Classes
| Name | Description |
|---|---|
| Surrogate | Model that predicts the outputs from the inputs. |
| SingleTaskGPSurrogate | Gaussian process assembled from a kernel, a mean and a likelihood, with its |
| MultiTaskGPSurrogate | Gaussian process over several related tasks, which learns how strongly they are |
| RandomForestSurrogate | Random forest regressor: an average over many decision trees, each fitted to a |
| MLPEnsemble | Ensemble of small neural networks (multilayer perceptrons). |
| SelectionSurrogate | Surrogate that chooses one of several complete surrogates by cross-validation. |
| LBFGSB | L-BFGS-B, the optimizer that fits a Gaussian process’s hyperparameters by |
| BotorchSurrogates | The surrogates of a BoTorch strategy, one per output. |
Surrogate
data_models.surrogates.api.Surrogate()Model that predicts the outputs from the inputs.
Most surrogates are fitted to experiments; deterministic ones compute their predictions from a given formula or mapping. Strategies use surrogates to model the black-box function, which is used when deciding which experiment to carry out next.
Attributes
| Name | Description |
|---|---|
| input_preprocessing_specs | Pre-model tensorization: every categorical is ordinal-encoded (the in-model |
Methods
| Name | Description |
|---|---|
| is_output_implemented | Abstract method to check output type for surrogate models |
is_output_implemented
data_models.surrogates.api.Surrogate.is_output_implemented(my_type)Abstract method to check output type for surrogate models Args: outputs: objective functions for the surrogate my_type: continuous or categorical output Returns: bool: True if the output type is valid for the surrogate chosen, False otherwise
SingleTaskGPSurrogate
data_models.surrogates.api.SingleTaskGPSurrogate()Gaussian process assembled from a kernel, a mean and a likelihood, with its hyperparameters fitted to the data.
The kernel decides which experiments the model considers similar, the mean what it predicts far from any data, and the likelihood how much of the spread in the data it attributes to measurement noise. The default is BoTorch’s default single-task GP: an RBF kernel with a lengthscale per input and priors scaled to the number of inputs.
Examples
>>> SingleTaskGPSurrogate(inputs=inputs, outputs=outputs)
>>> SingleTaskGPSurrogate(
... inputs=inputs,
... outputs=outputs,
... kernel=ScaleKernel(base_kernel=MaternKernel(ard=True, nu=2.5)),
... )Methods
| Name | Description |
|---|---|
| additive_map_saas | Single-task GP for many inputs of which only a few are expected to matter. |
| is_output_implemented | Abstract method to check output type for surrogate models |
| linear | Single-task GP whose response is linear in the inputs. |
| mixed | Single-task GP for continuous and categorical inputs, as BoTorch’s |
| options | Single-task GPs that differ in kernel and priors, as options to choose from. |
| polynomial | Single-task GP whose response is a polynomial in the inputs. |
| robust | Single-task GP that detects outliers and discounts them: BoTorch’s |
| tanimoto | Single-task GP over molecular inputs, with the Tanimoto similarity of the |
| validate_sparse_outlier_likelihood | Outlier noise levels are fitted for one output only. |
additive_map_saas
data_models.surrogates.api.SingleTaskGPSurrogate.additive_map_saas(
inputs,
outputs,
n_taus=4,
*,
engineered_features=None,
)Single-task GP for many inputs of which only a few are expected to matter.
The maximum-a-posteriori approximation of the fully Bayesian SAAS model, as BoTorch’s AdditiveMapSaasSingleTaskGP builds it: an additive sparse kernel, a constant mean with a standard normal prior bounded to [-10, 10], and the default likelihood.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| inputs | Inputs | The input features. | required |
| outputs | Outputs | The output feature. | required |
| engineered_features | Optional[EngineeredFeatures] | Quantities derived from the inputs that the model sees as well; the kernel works on them too. If not provided, none. | None |
| n_taus | int | Number of sparse kernels summed up, each at its own sparsity level. | 4 |
Returns
| Name | Type | Description |
|---|---|---|
| SingleTaskGPSurrogate | The surrogate, with an additive MAP-SAAS kernel. |
is_output_implemented
data_models.surrogates.api.SingleTaskGPSurrogate.is_output_implemented(my_type)Abstract method to check output type for surrogate models Args: my_type: continuous or categorical output Returns: bool: True if the output type is valid for the surrogate chosen, False otherwise
linear
data_models.surrogates.api.SingleTaskGPSurrogate.linear(
inputs,
outputs,
*,
engineered_features=None,
)Single-task GP whose response is linear in the inputs.
Equivalent to Bayesian linear regression. The noise has a THREESIX prior with a lower bound of 1e-4; every other field keeps its default.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| inputs | Inputs | The input features. | required |
| outputs | Outputs | The output feature. | required |
| engineered_features | Optional[EngineeredFeatures] | Quantities derived from the inputs that the model sees as well; the kernel works on them too. If not provided, none. | None |
Returns
| Name | Type | Description |
|---|---|---|
| SingleTaskGPSurrogate | The surrogate, with a linear kernel. |
mixed
data_models.surrogates.api.SingleTaskGPSurrogate.mixed(
inputs,
outputs,
*,
engineered_features=None,
)Single-task GP for continuous and categorical inputs, as BoTorch’s MixedSingleTaskGP builds it.
Categorical inputs without descriptor data are encoded as ordinal codes and compared by a Hamming kernel; all other inputs and the engineered features by an RBF kernel with the HVARFNER prior. The kernel is the sum of the two plus their product, each scaled; without other inputs, the scaled Hamming kernel.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| inputs | Inputs | The input features, at least one of them categorical without descriptor data. | required |
| outputs | Outputs | The output feature. | required |
| engineered_features | Optional[EngineeredFeatures] | Quantities derived from the inputs that the model sees as well; the RBF kernel works on them. If not provided, none. | None |
Returns
| Name | Type | Description |
|---|---|---|
| SingleTaskGPSurrogate | The surrogate. |
Raises
| Name | Type | Description |
|---|---|---|
| ValueError | If no categorical input lacks descriptor data, or if an engineered feature replaces the features it is computed from. |
options
data_models.surrogates.api.SingleTaskGPSurrogate.options(
inputs,
outputs,
*,
engineered_features=None,
)Single-task GPs that differ in kernel and priors, as options to choose from.
One for each combination of base kernel (RBF, Matern 1.5, Matern 2.5), set of noise, lengthscale and outputscale priors (MBO, THREESIX, HVARFNER), with and without a scale kernel, and with and without ARD: 36 in all. Every other field keeps its default.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| inputs | Inputs | The input features of every option. | required |
| outputs | Outputs | The output feature of every option. | required |
| engineered_features | Optional[EngineeredFeatures] | Quantities derived from the inputs that every option sees as well; the kernel works on them too. If not provided, none. | None |
Returns
| Name | Type | Description |
|---|---|---|
| List[SingleTaskGPSurrogate] | The options, each with its own kernel and likelihood. |
polynomial
data_models.surrogates.api.SingleTaskGPSurrogate.polynomial(
inputs,
outputs,
power=2,
*,
engineered_features=None,
)Single-task GP whose response is a polynomial in the inputs.
The noise has a THREESIX prior with a lower bound of 1e-4; every other field keeps its default.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| inputs | Inputs | The input features. | required |
| outputs | Outputs | The output feature. | required |
| engineered_features | Optional[EngineeredFeatures] | Quantities derived from the inputs that the model sees as well; the kernel works on them too. If not provided, none. | None |
| power | int | Degree of the polynomial. | 2 |
Returns
| Name | Type | Description |
|---|---|---|
| SingleTaskGPSurrogate | The surrogate, with a polynomial kernel of the given power. |
robust
data_models.surrogates.api.SingleTaskGPSurrogate.robust(
inputs,
outputs,
*,
engineered_features=None,
)Single-task GP that detects outliers and discounts them: BoTorch’s RobustRelevancePursuitSingleTaskGP, with the lengthscales bounded at 0.05 instead of 0.025.
The likelihood adds an extra noise variance for observations treated as outliers to the HVARFNER noise model. The kernel is an RBF kernel with the HVARFNER prior whose lengthscales are at least 0.05, so that the model cannot simply explain the outliers.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| inputs | Inputs | The input features. | required |
| outputs | Outputs | The output feature, exactly one. | required |
| engineered_features | Optional[EngineeredFeatures] | Quantities derived from the inputs that the model sees as well; the kernel works on them too. If not provided, none. | None |
Returns
| Name | Type | Description |
|---|---|---|
| SingleTaskGPSurrogate | The surrogate, with a SparseOutlierGaussianLikelihood. |
tanimoto
data_models.surrogates.api.SingleTaskGPSurrogate.tanimoto(
inputs,
outputs,
fingerprints=None,
)Single-task GP over molecular inputs, with the Tanimoto similarity of the molecules’ fingerprints as kernel.
Every input is a categorical whose categories have structure data; the similarities between all categories of an input are computed once. With one input the kernel is a scaled Tanimoto kernel. With several, it is the scaled product of one Tanimoto kernel per input: two points are similar if each of their molecules is. The THREESIX outputscale prior and the THREESIX likelihood are used.
For other combinations (a sum of the molecules’ kernels, different fingerprints per molecule, further continuous inputs) build the kernel from TanimotoKernels directly.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| inputs | Inputs | The input features: one or more categoricals with structure data. | required |
| outputs | Outputs | The output feature. | required |
| fingerprints | Optional[DescriptorEncoding] | How the fingerprints are computed from the structures, the same for every input. If not provided, Morgan fingerprints of 2048 bits. | None |
Returns
| Name | Type | Description |
|---|---|---|
| SingleTaskGPSurrogate | The surrogate. |
Raises
| Name | Type | Description |
|---|---|---|
| ValueError | If an input is not a categorical with structure data. |
validate_sparse_outlier_likelihood
data_models.surrogates.api.SingleTaskGPSurrogate.validate_sparse_outlier_likelihood(
)Outlier noise levels are fitted for one output only.
MultiTaskGPSurrogate
data_models.surrogates.api.MultiTaskGPSurrogate()Gaussian process over several related tasks, which learns how strongly they are correlated and transfers what it learns about one task to the others.
The tasks are the categories of the one CategoricalTaskInput, e.g. a cheap simulation and the real experiment, or a previous and the current campaign. The covariance is the kernel over the other inputs times a learned correlation between the tasks (intrinsic coregionalization). By default every task has a mean and a noise level of its own, so tasks may differ in offset and in measurement precision; with a plain mean or Gaussian likelihood, all tasks share one. Predictions for a task use the data of all tasks, weighted by how strongly they correlate with it.
Examples
>>> MultiTaskGPSurrogate(
... inputs=Inputs(features=[
... ContinuousInput(key="x", bounds=(0, 1)),
... CategoricalTaskInput(key="task", categories=["simulation", "experiment"]),
... ]),
... outputs=Outputs(features=[ContinuousOutput(key="y")]),
... )Methods
| Name | Description |
|---|---|
| is_output_implemented | Abstract method to check output type for surrogate models |
is_output_implemented
data_models.surrogates.api.MultiTaskGPSurrogate.is_output_implemented(my_type)Abstract method to check output type for surrogate models Args: my_type: continuous or categorical output Returns: bool: True if the output type is valid for the surrogate chosen, False otherwise
RandomForestSurrogate
data_models.surrogates.api.RandomForestSurrogate()Random forest regressor: an average over many decision trees, each fitted to a random resample of the data.
The spread of the individual trees’ predictions serves as the uncertainty. The model assumes neither a smooth response nor a characteristic lengthscale, so it copes with abrupt changes and with responses that vary on different scales in different regions. It can’t extrapolate beyond the data, and its uncertainty is a heuristic, unlike the analytic uncertainty of a Gaussian process. The hyperparameters are those of scikit-learn’s RandomForestRegressor, with its defaults.
Examples
>>> RandomForestSurrogate(inputs=inputs, outputs=outputs, n_estimators=200)Methods
| Name | Description |
|---|---|
| is_output_implemented | Abstract method to check output type for surrogate models |
is_output_implemented
data_models.surrogates.api.RandomForestSurrogate.is_output_implemented(my_type)Abstract method to check output type for surrogate models Args: my_type: continuous or categorical output Returns: bool: True if the output type is valid for the surrogate chosen, False otherwise
MLPEnsemble
data_models.surrogates.api.MLPEnsemble()Ensemble of small neural networks (multilayer perceptrons).
Every network is trained on a resample of the experiments drawn with replacement; predictions average over the networks, and their spread serves as the uncertainty. Suited to larger data sets than a Gaussian process.
SelectionSurrogate
data_models.surrogates.api.SelectionSurrogate()Surrogate that chooses one of several complete surrogates by cross-validation.
When fitted, every option is cross-validated on the data, and the one with the best score in metric is fitted on all of the data and makes the predictions. Every option has the inputs and the single continuous output of this surrogate.
Examples
>>> SelectionSurrogate(
... inputs=inputs,
... outputs=outputs,
... options=SingleTaskGPSurrogate.options(inputs, outputs),
... )Methods
| Name | Description |
|---|---|
| validate_options | Check that every option has the inputs and output of this surrogate. |
validate_options
data_models.surrogates.api.SelectionSurrogate.validate_options()Check that every option has the inputs and output of this surrogate.
Raises
| Name | Type | Description |
|---|---|---|
| ValueError | If an option’s inputs or outputs differ from this surrogate’s, or if there is more than one output. |
LBFGSB
data_models.surrogates.api.LBFGSB()L-BFGS-B, the optimizer that fits a Gaussian process’s hyperparameters by maximizing the marginal likelihood.
Options left at None keep BoTorch’s defaults: scipy’s for an ordinary fit, and its own (at most 10000 iterations, tolerances of 1e-8) for the relevance pursuit of a GP with a SparseOutlierGaussianLikelihood.
Examples
>>> LBFGSB(maxiter=200)BotorchSurrogates
data_models.surrogates.api.BotorchSurrogates()The surrogates of a BoTorch strategy, one per output.
Each surrogate predicts one output; together they cover every output of the domain exactly once and use every input of the domain.