Posterior
The Posterior
class from the inference.posterior
module provides a
simple way to combine a likelihood and a prior to form a posterior distribution.
Example code demonstrating its use can be found in the
the Gaussian fitting jupyter notebook demo.
- class inference.posterior.Posterior(likelihood, prior)
Class for constructing a posterior distribution object for a given likelihood and prior.
- Parameters
likelihood (callable) – A callable which returns the log-likelihood probability when passed a vector of the model parameters.
prior (callable) – A callable which returns the log-prior probability when passed a vector of the model parameters.
- __call__(theta)
Returns the log-posterior probability for the given set of model parameters.
- Parameters
theta – The model parameters as a 1D
numpy.ndarray
.- Returns
The log-posterior probability.
- cost(theta)
Returns the ‘cost’, defined as the negative log-posterior probability, for the given set of model parameters. Minimising the value of the cost therefore maximises the log-posterior probability.
- Parameters
theta – The model parameters as a 1D
numpy.ndarray
.- Returns
The negative log-posterior probability.
- cost_gradient(theta)
Returns the gradient of the negative log-posterior with respect to model parameters.
- Parameters
theta – The model parameters as a 1D
numpy.ndarray
.- Returns
The gradient of the negative log-posterior as a 1D
numpy.ndarray
.
- gradient(theta)
Returns the gradient of the log-posterior with respect to model parameters.
- Parameters
theta – The model parameters as a 1D
numpy.ndarray
.- Returns
The gradient of the log-posterior as a 1D
numpy.ndarray
.