botorch.cross_validation¶
Crossvalidation utilities using batch evaluation mode.

class
botorch.cross_validation.
CVFolds
(train_X, test_X, train_Y, test_Y, train_Yvar, test_Yvar)[source]¶ Bases:
tuple
Create new instance of CVFolds(train_X, test_X, train_Y, test_Y, train_Yvar, test_Yvar)

property
train_X
¶ Alias for field number 0

property
test_X
¶ Alias for field number 1

property
train_Y
¶ Alias for field number 2

property
test_Y
¶ Alias for field number 3

property
train_Yvar
¶ Alias for field number 4

property
test_Yvar
¶ Alias for field number 5

property

class
botorch.cross_validation.
CVResults
(model, posterior, observed_Y, observed_Yvar)[source]¶ Bases:
tuple
Create new instance of CVResults(model, posterior, observed_Y, observed_Yvar)

property
model
¶ Alias for field number 0

property
posterior
¶ Alias for field number 1

property
observed_Y
¶ Alias for field number 2

property
observed_Yvar
¶ Alias for field number 3

property

botorch.cross_validation.
gen_loo_cv_folds
(train_X, train_Y, train_Yvar=None)[source]¶ Generate LOO CV folds w.r.t. to n.
 Parameters
train_X (
Tensor
) – A n x d or batch_shape x n x d (batch mode) tensor of training features.train_Y (
Tensor
) – A n x (m) or batch_shape x n x (m) (batch mode) tensor of training observations.train_Yvar (
Optional
[Tensor
]) – A batch_shape x n x (m) or batch_shape x n x (m) (batch mode) tensor of observed measurement noise.
 Return type
 Returns
CVFolds tuple with the following fields
train_X: A n x (n1) x d or batch_shape x n x (n1) x d tensor of training features.
test_X: A n x 1 x d or batch_shape x n x 1 x d tensor of test features.
train_Y: A n x (n1) x m or batch_shape x n x (n1) x m tensor of training observations.
test_Y: A n x 1 x m or batch_shape x n x 1 x m tensor of test observations.
train_Yvar: A n x (n1) x m or batch_shape x n x (n1) x m tensor of observed measurement noise.
test_Yvar: A n x 1 x m or batch_shape x n x 1 x m tensor of observed measurement noise.
Example
>>> train_X = torch.rand(10, 1) >>> train_Y = torch.sin(6 * train_X) + 0.2 * torch.rand_like(train_X) >>> cv_folds = gen_loo_cv_folds(train_X, train_Y)

botorch.cross_validation.
batch_cross_validation
(model_cls, mll_cls, cv_folds, fit_args=None, observation_noise=False)[source]¶ Perform cross validation by using gpytorch batch mode.
 Parameters
model_cls (
Type
[GPyTorchModel
]) – A GPyTorchModel class. This class must initialize the likelihood internally. Note: Multitask GPs are not currently supported.mll_cls (
Type
[MarginalLogLikelihood
]) – A MarginalLogLikelihood class.cv_folds (
CVFolds
) – A CVFolds tuple.fit_args (
Optional
[Dict
[str
,Any
]]) – Arguments passed along to fit_gpytorch_model
 Return type
 Returns
A CVResults tuple with the following fields
model: GPyTorchModel for batched cross validation
posterior: GPyTorchPosterior where the mean has shape n x 1 x m or batch_shape x n x 1 x m
observed_Y: A n x 1 x m or batch_shape x n x 1 x m tensor of observations.
observed_Yvar: A n x 1 x m or batch_shape x n x 1 x m tensor of observed measurement noise.
Example
>>> train_X = torch.rand(10, 1) >>> train_Y = torch.sin(6 * train_X) + 0.2 * torch.rand_like(train_X) >>> cv_folds = gen_loo_cv_folds(train_X, train_Y) >>> cv_results = batch_cross_validation( >>> SingleTaskGP, >>> ExactMarginalLogLikelihood, >>> cv_folds, >>> )
 WARNING: This function is currently very memory inefficient, use it only
for problems of small size.