Skip to main content

GridSearch

GridSearch(objective, values)

Set the prior precision to the value from a grid that minimizes an objective.

Every entry of the prior precision (each block of Layerwise, each weight of Diagonal) takes the same value. Other hyperparameters, such as a learned sigma, stay as they are. The objective runs under torch.no_grad, so it needs no gradient.

nll = lk.objectives.predictive_nll(val_loader)
post = lk.tune(post, lk.GridSearch(nll, values=torch.logspace(-2, 3, 21)))

Parameters

Name Type Description Default
objective Objective[Any] The loss over a posterior, lower is better. required
values Iterable[float | Tensor] The candidate precisions. required

Methods

Name Description
check Check that the prior has a precision to tune.

check

GridSearch.check(prior, likelihood, batch, /)

Check that the prior has a precision to tune.

Parameters

Name Type Description Default
prior Prior The prior of the fit. required
likelihood Likelihood The likelihood of the fit. required
batch Batch The first batch of the data. required

Raises

Name Type Description
StructureError The prior is not a TunablePrior, or its tunable() breaks its rules.