def METHOD_NAME(
    self,
    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.
    Args:
        dataset: Dataset to get posterior for.
        previous_posterior: 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: Whether to optimize the posterior hyperparameters.
        key: A JAX PRNG key which is used for optimizing the posterior
        hyperparameters.
    """
    posterior = previous_posterior.prior * self.likelihood_builder(dataset.n)
    if optimize:
        if key is None:
            raise ValueError(
                "A key must be provided in order to optimize the posterior."
            )
        posterior = self._optimize_posterior(posterior, dataset, key)
    return posterior