botorch.fit

Model fitting routines.

botorch.fit.fit_gpytorch_mll(mll, closure=None, optimizer=None, closure_kwargs=None, optimizer_kwargs=None, **kwargs)[source]

Clearing house for fitting models passed as GPyTorch MarginalLogLikelihoods.

Parameters:
  • mll (MarginalLogLikelihood) – A GPyTorch MarginalLogLikelihood instance.

  • closure (Optional[Callable[[], Tuple[Tensor, Sequence[Optional[Tensor]]]]]) – Forward-backward closure for obtaining objective values and gradients. Responsible for setting parameters’ grad attributes. If no closure is provided, one will be obtained by calling get_loss_closure_with_grads.

  • optimizer (Optional[Callable]) – User specified optimization algorithm. When optimizer is None, this keyword argument is omitted when calling the dispatcher.

  • closure_kwargs (Optional[Dict[str, Any]]) – Keyword arguments passed when calling closure.

  • optimizer_kwargs (Optional[Dict[str, Any]]) – A dictionary of keyword arguments passed when calling optimizer.

  • **kwargs (Any) – Keyword arguments passed down through the dispatcher to fit subroutines. Unexpected keywords are ignored.

Returns:

The mll instance. If fitting succeeded, then mll will be in evaluation mode, i.e. mll.training == False. Otherwise, mll will be in training mode.

Return type:

MarginalLogLikelihood

botorch.fit.fit_gpytorch_model(mll, optimizer=None, optimizer_kwargs=None, exclude=None, max_retries=None, **kwargs)[source]

Convenience method for fitting GPyTorch models using legacy API. For more details, see fit_gpytorch_mll.

Parameters:
  • mll (MarginalLogLikelihood) – A GPyTorch MarginalLogLikelihood instance.

  • optimizer (Optional[Callable]) – User specified optimization algorithm. When optimizer is None, this keyword argument is omitted when calling the dispatcher from inside fit_gpytorch_mll.

  • optimizer_kwargs (Optional[dict]) – Keyword arguments passed to optimizer.

  • exclude (Optional[Iterable[str]]) – Legacy argument for specifying parameters x that should be held fixed during optimization. Internally, used to temporarily set x.requires_grad to False.

  • max_retries (Optional[int]) – Legacy name for max_attempts. When max_retries is None, this keyword argument is omitted when calling fit_gpytorch_mll.

  • kwargs (Any) –

Return type:

MarginalLogLikelihood

botorch.fit.fit_fully_bayesian_model_nuts(model, max_tree_depth=6, warmup_steps=512, num_samples=256, thinning=16, disable_progbar=False, jit_compile=False)[source]

Fit a fully Bayesian model using the No-U-Turn-Sampler (NUTS)

Parameters:
  • model (Union[SaasFullyBayesianSingleTaskGP, SaasFullyBayesianMultiTaskGP]) – SaasFullyBayesianSingleTaskGP to be fitted.

  • max_tree_depth (int) – Maximum tree depth for NUTS

  • warmup_steps (int) – The number of burn-in steps for NUTS.

  • num_samples (int) – The number of MCMC samples. Note that with thinning, num_samples / thinning samples are retained.

  • thinning (int) – The amount of thinning. Every nth sample is retained.

  • disable_progbar (bool) – A boolean indicating whether to print the progress bar and diagnostics during MCMC.

  • jit_compile (bool) – Whether to use jit. Using jit may be ~2X faster (rough estimate), but it will also increase the memory usage and sometimes result in runtime errors, e.g., https://github.com/pyro-ppl/pyro/issues/3136.

Return type:

None

Example

>>> gp = SaasFullyBayesianSingleTaskGP(train_X, train_Y)
>>> fit_fully_bayesian_model_nuts(gp)