Models and computer experiments¶
Model construction starts with a ComputerExperiment and a
ModelContainer. The ComputerExperiment describes the callable problem:
input dimension, input box, outputs, and optional constraint bounds. The
ModelContainer stores one gpmp.core.Model per output and manages
parameter selection, prediction, diagnosis, and stored state.
Prediction and parameter-selection computations are done by gpmp. The
container classes in gpmp-contrib configure the mean form, covariance
function, initial-guess procedure, selection criterion, and per-output state.
Shapes¶
Array shapes:
xiObservation points, shape
(n, d).ziObserved values. Shape
(n,)or(n, 1)for one output, and(n, output_dim)for several outputs.xtPrediction points, shape
(m, d).zpmandzpvPosterior means and variances returned by
predict. Shape(m, output_dim).
ComputerExperiment¶
ComputerExperiment defines the input dimension, input box, and outputs. It
can wrap one callable, separate objective and constraint callables, or callable
metadata for multiple outputs.
import numpy as np
import gpmpcontrib as gpc
def objective(x):
return (x[:, 0] - 0.25) ** 2 + (x[:, 1] - 0.75) ** 2
def constraint(x):
return x[:, 0] + x[:, 1]
problem = gpc.ComputerExperiment(
2,
[[0.0, 0.0], [1.0, 1.0]],
single_objective=objective,
single_constraint={"function": constraint, "bounds": [0.5, np.inf]},
)
problem(x) evaluates all outputs. problem.eval_objectives(x) and
problem.eval_constraints(x) return the corresponding blocks.
ModelContainer¶
ModelContainer is a per-output container. For output k, model[k]
stores an entry with the underlying gpmp.core.Model and the state built by
select_params:
model.select_params(xi, zi)
entry = model[0]
gp_model = entry["model"]
param = entry.get_param()
info = entry["info"]
The entry is described in Model state and parameter objects. Raw vectors are stored in
entry["model"]. Readable parameter information is stored in
entry.get_param().
Matérn model used by the provided classes¶
For each output, the provided Matérn classes define a scalar-valued GP
where \(Z_0\) is a centered GP with Matérn covariance \(K_\theta\). The mean term depends on the class:
Model_ConstantMean_Maternp_MLuses a parameterized constant mean and selects the mean coefficient with the covariance parameters.Model_ConstantMean_Maternp_REMLand REMAP subclasses use a linear-predictor mean with constant or linear basis functions. The criterion is optimized over covariance parameters.
The covariance parameter vector is
covparam = [log(sigma2), -log(rho_0), ..., -log(rho_{d-1})]
Thus
The raw lengthscale coordinates are -log(rho_j). Larger raw values mean
shorter physical lengthscales.
Posterior prediction¶
For fixed covariance parameters and a fixed mean, the conditional-Gaussian prediction formula has the form
and
Here \(K_\theta(X,X)\) is the observation covariance matrix and
\(k_\theta(x,X)\) is the row vector of covariances between \(x\) and
the observation points. The provided classes call gpmp.core.Model for this
computation. When the mean is parameterized or profiled, gpmp applies the
corresponding kriging formulas internally.
Mean and covariance specifications¶
The Hartmann4 examples in this guide use:
mean_specification = {"type": "constant"}
covariance_specification = {"p": 2}
p is the Matérn smoothness parameter used by gpmp.kernel. The exact
set of accepted specifications depends on the selected container class.
Provided Matérn container classes¶
Model_ConstantMean_Maternp_MLConstant mean with explicit mean parameter. Mean and covariance parameters are selected by maximum likelihood.
Model_ConstantMean_Maternp_REMLLinear-predictor mean. Covariance parameters are selected by restricted likelihood.
Model_ConstantMean_Maternp_REMAPCurrent default REMAP class. It aliases
Model_ConstantMean_Maternp_REMAP_logsigma2_and_logrho_prior.Model_ConstantMean_Maternp_REMAP_logsigma2REMAP class with a Gaussian prior on
log(sigma^2).Model_ConstantMean_Maternp_REMAP_logsigma2_and_logrho_priorREMAP class with a Gaussian prior on
log(sigma^2)and a barrier-linear prior onlogrho.Model_Noisy_ConstantMean_Maternp_REMLNoisy-observation class. The input matrix carries physical coordinates and observation-noise variance columns expected by the noisy covariance wrapper.
Constructor arguments¶
The provided Matérn classes share the same core constructor arguments:
nameLabel used in displays and stored model entries.
output_dimNumber of scalar outputs. The container builds one independent
gpmp.core.Modelper output.mean_specificationDictionary describing the mean form. For the examples in this guide,
{"type": "constant"}is used.covariance_specificationDictionary describing the Matérn covariance. The key
"p"selects the Matérn smoothness parameter passed togpmp.kernel.
REMAP constructors also accept optional prior hyperparameters. The same values
can be set later with set_prior before select_params. See
Priors for REMAP selection.
Minimal construction¶
model = gpc.Model_ConstantMean_Maternp_REML(
"hartmann4",
output_dim=problem.output_dim,
mean_specification={"type": "constant"},
covariance_specification={"p": 3},
)
model.select_params(xi, zi)
zpm, zpv = model.predict(xi, zi, xt)
After this call, model[0]["model"].covparam contains the selected raw
covariance vector, model[0].get_param() gives the readable parameter object,
and model[0]["info"] stores the optimizer report.
Where to continue¶
Use Parameter selection to understand optimizer starts, bounds, and ML/REML/REMAP criteria.
Use Model state and parameter objects to inspect stored vectors and parameter objects.
Use Diagnostics and inspection to interpret the printed summaries.