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.
If a model defines a
custom_fitmethod, it will be called directly. Otherwise, a fit method is determined based on the types of the model and MLL.- Parameters:
mll (MarginalLogLikelihood) – A GPyTorch MarginalLogLikelihood instance.
closure (Callable[[], tuple[Tensor, Sequence[Tensor | None]]] | None) – Forward-backward closure for obtaining objective values and gradients. Responsible for setting parameters’
gradattributes. If no closure is provided, one will be obtained by callingget_loss_closure_with_grads.optimizer (Callable | None) – User specified optimization algorithm. When
optimizer is None, this keyword argument is omitted when calling the underlying fit routine.closure_kwargs (dict[str, Any] | None) – Keyword arguments passed when calling
closure.optimizer_kwargs (dict[str, Any] | None) – A dictionary of keyword arguments passed when calling
optimizer.**kwargs (Any) – Keyword arguments passed to the underlying fit routine. Unexpected keywords are ignored.
- Returns:
The
mllinstance. If fitting succeeded, thenmllwill be in evaluation mode, i.e.mll.training == False. Otherwise,mllwill be in training mode.- 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, seed=0)[source]
Fit a fully Bayesian model using the No-U-Turn-Sampler (NUTS)
Uses NumPyro’s NUTS implementation (backed by JAX) for MCMC inference.
- Parameters:
model (AbstractFullyBayesianSingleTaskGP | SaasFullyBayesianMultiTaskGP) – Fully Bayesian GP 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.
seed (int) – Random seed for JAX PRNG.
- Return type:
None
Example
>>> gp = SaasFullyBayesianSingleTaskGP(train_X, train_Y) >>> fit_fully_bayesian_model_nuts(gp)
- botorch.fit.get_fitted_map_saas_model(train_X, train_Y, train_Yvar=None, input_transform=None, outcome_transform=None, tau=None, optimizer_kwargs=None)[source]
Get a fitted MAP SAAS model with a Matern kernel.
- Parameters:
train_X (Tensor) – Tensor of shape
n x dwith training inputs.train_Y (Tensor) – Tensor of shape
n x 1with training targets.train_Yvar (Tensor | None) – Optional tensor of shape
n x 1with observed noise, inferred if None.input_transform (InputTransform | None) – An optional input transform.
outcome_transform (OutcomeTransform | None) – An optional outcome transform.
tau (Tensor | float | None) – Fixed value of the global shrinkage tau. If None, the model places a HC(0.1) prior on tau. Can be a tensor for batched models where each batch has a different sparsity prior.
optimizer_kwargs (dict[str, Any] | None) – A dict of options for the optimizer passed to fit_gpytorch_mll.
- Returns:
A fitted SingleTaskGP with a Matern kernel.
- Return type: