Approximate inference

This module provides tools for approximate inference.

conditional_sample

inference.approx.conditional_sample(posterior: callable, bounds: list, conditioning_point: ndarray, n_samples: int) ndarray

Generates samples from each of the 1D conditional distributions of the posterior and combines them to approximate samples from the posterior itself. This can be a reasonable approximation if the posterior is close to conditionally independent, but is likely to underestimate uncertainties when correlations are present.

Parameters
  • posterior – A function which returns the posterior log-probability when given a numpy ndarray of the model parameters.

  • bounds – A list of length-2 tuples specifying the lower and upper bounds on each parameter, in the form (lower, upper).

  • conditioning_point – The point in the parameter space around which the conditional distributions are evaluated. This point should correspond the posterior mode if the conditional distribution samples are to be used as approximate posterior samples.

  • n_samples – Number of samples to draw.

Return samples

The samples as a 2D numpy ndarray which has shape (n_samples, n_parameters).

get_conditionals

inference.approx.get_conditionals(posterior: callable, bounds: list, conditioning_point: ndarray, grid_size: int = 64)

Evaluates each of the 1D conditional distributions of the posterior around a given point in the parameter space. For each conditional, the space within the given bounds is searched to determine the range of values containing non-negligible probability, and the conditional is evaluated on a uniform grid covering that range.

Parameters
  • posterior – A function which returns the posterior log-probability when given a numpy ndarray of the model parameters.

  • bounds – A list of length-2 tuples specifying the lower and upper bounds on each parameter, in the form (lower, upper).

  • conditioning_point – The point in the parameter space around which the conditional distributions are evaluated.

  • grid_size – The number of points used to evaluate each of the conditional distributions.

Return samples

The samples as a 2D numpy ndarray which has shape (n_samples, n_parameters).