Skip to content

Posterior Handler

LikelihoodBuilder module-attribute

LikelihoodBuilder = Callable[[int], AbstractLikelihood]

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

PosteriorHandler(prior, likelihood_builder, optimization_objective, optimizer, num_optimization_iters)

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

Attributes:

  • prior (AbstractPrior) –

    prior to use when forming the posterior.

  • likelihood_builder (LikelihoodBuilder) –

    function which takes the number of datapoints as input and returns a likelihood object initialised with the given number of datapoints.

  • optimization_objective (Objective) –

    objective to use for optimizing the posterior hyperparameters.

  • optimizer (GradientTransformation) –

    an optax optimizer to use for optimizing the posterior hyperparameters.

  • num_optimization_iterations (GradientTransformation) –

    the number of iterations to optimize the posterior hyperparameters for.

get_posterior

get_posterior(dataset, optimize, key=None)

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

Parameters:

  • dataset (Dataset) –

    dataset to get posterior for.

  • optimize (bool) –

    whether to optimize the posterior hyperparameters.

  • key (Optional[KeyArray], default: None ) –

    a JAX PRNG key which is used for optimizing the posterior hyperparameters.

Returns:

update_posterior

update_posterior(dataset, previous_posterior, optimize, key=None)

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:

  • dataset (Dataset) –

    dataset to get posterior for.

  • previous_posterior (AbstractPosterior) –

    posterior being updated. This is supplied as one may wish to simply increase the number of datapoints in the likelihood, without optimizing the posterior hyperparameters, in which case the previous posterior can be used to obtain the previously set prior hyperparameters.

  • optimize (bool) –

    whether to optimize the posterior hyperparameters.

  • key (Optional[KeyArray], default: None ) –

    A JAX PRNG key which is used for optimizing the posterior hyperparameters.