botorch.cross_validation¶
Cross-validation 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) - Parameters:
- train_X (Tensor) – 
- test_X (Tensor) – 
- train_Y (Tensor) – 
- test_Y (Tensor) – 
- train_Yvar (Optional[Tensor]) – 
- test_Yvar (Optional[Tensor]) – 
 
 - train_X: Tensor¶
- Alias for field number 0 
 - test_X: Tensor¶
- Alias for field number 1 
 - train_Y: Tensor¶
- Alias for field number 2 
 - test_Y: Tensor¶
- Alias for field number 3 
 - train_Yvar: Optional[Tensor]¶
- Alias for field number 4 
 - test_Yvar: Optional[Tensor]¶
- Alias for field number 5 
 
- 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) - Parameters:
- model (GPyTorchModel) – 
- posterior (GPyTorchPosterior) – 
- observed_Y (Tensor) – 
- observed_Yvar (Optional[Tensor]) – 
 
 - model: GPyTorchModel¶
- Alias for field number 0 
 - posterior: GPyTorchPosterior¶
- Alias for field number 1 
 - observed_Y: Tensor¶
- Alias for field number 2 
 - observed_Yvar: Optional[Tensor]¶
- Alias for field number 3 
 
- 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. 
 
- Returns:
- CVFolds tuple with the following fields - train_X: A n x (n-1) x d or batch_shape x n x (n-1) 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 (n-1) x m or batch_shape x n x (n-1) 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 (n-1) x m or batch_shape x n x (n-1) 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. 
 
- Return type:
 - 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: Multi-task 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_mll. 
- observation_noise (bool) – 
 
- 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. 
 
- Return type:
 - 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. 
 
