Skip to content

Posterior Handler

gpjax.decision_making.posterior_handler

LikelihoodBuilder = Callable[[int], AbstractLikelihood] module-attribute

Type alias for likelihood builders, which take the number of datapoints as input and return a likelihood object initialised with the given number of datapoints.

PosteriorHandler dataclass

Class for handling the creation and updating of a GP posterior as new data is observed.

Attributes:

Name Type Description
prior AbstractPrior

Prior to use when forming the posterior.

likelihood_builder LikelihoodBuilder

Function which takes the number of

optimization_objective AbstractObjective

Objective to use for optimizing the

optimizer GradientTransformation

Optax optimizer to use for optimizing the

num_optimization_iterations int

Number of iterations to optimize

prior: AbstractPrior instance-attribute
likelihood_builder: LikelihoodBuilder instance-attribute
optimization_objective: AbstractObjective instance-attribute
optimizer: ox.GradientTransformation instance-attribute
num_optimization_iters: int instance-attribute
__init__(prior: AbstractPrior, likelihood_builder: LikelihoodBuilder, optimization_objective: AbstractObjective, optimizer: ox.GradientTransformation, num_optimization_iters: int) -> None
__post_init__()
get_posterior(dataset: Dataset, optimize: bool, key: Optional[KeyArray] = None) -> AbstractPosterior

Initialise (and optionally optimize) a posterior using the given dataset.

Parameters:

Name Type Description Default
dataset Dataset

Dataset to get posterior for.

required
optimize bool

Whether to optimize the posterior hyperparameters.

required
key Optional[KeyArray]

A JAX PRNG key which is used for optimizing the posterior

None

Returns:

Type Description
AbstractPosterior

Posterior for the given dataset.

update_posterior(dataset: Dataset, previous_posterior: AbstractPosterior, optimize: bool, key: Optional[KeyArray] = None) -> AbstractPosterior

Update the given posterior with the given dataset. This needs to be done when the number of datapoints in the (training) dataset of the posterior changes, as the AbstractLikelihood class requires the number of datapoints to be specified. Hyperparameters may or may not be optimized, depending on the value of the optimize parameter. Note that the updated poterior will be initialised with the same prior hyperparameters as the previous posterior, but the likelihood will be re-initialised with the new number of datapoints, and hyperparameters set as in the likelihood_builder function.

Parameters:

Name Type Description Default
dataset Dataset

Dataset to get posterior for.

required
previous_posterior AbstractPosterior

Posterior being updated. This is supplied as one may

required
optimize bool

Whether to optimize the posterior hyperparameters.

required
key Optional[KeyArray]

A JAX PRNG key which is used for optimizing the posterior

None