Prior module

Definition of prior distribution

class svb.prior.ARDPrior(nvertices, mean, var, **kwargs)[source]

Automatic Relevance Determination prior

class svb.prior.ConstantMRFSpatialPrior(nvertices, mean, var, idx=None, nn=None, n2=None, **kwargs)[source]

Prior which performs adaptive spatial regularization based on the contents of neighbouring vertices using the Markov Random Field method

This is equivalent to the Fabber ‘M’ type spatial prior

class svb.prior.FabberMRFSpatialPrior(nvertices, mean, var, idx=None, post=None, nn=None, n2=None, **kwargs)[source]

Prior designed to mimic the ‘M’ type spatial prior in Fabber.

Note that this uses update equations for ak which is not in the spirit of the stochastic method. ‘Native’ SVB MRF spatial priors are also defined which simply treat the spatial precision parameter as an inference variable.

This code has been verified to generate the same ak estimate given the same input as Fabber, however in practice it does not optimize to the same value. We don’t yet know why.

class svb.prior.FactorisedPrior(priors, **kwargs)[source]

Prior for a collection of parameters where there is no prior covariance

In this case the mean log PDF can be summed from the contributions of each parameter

log_det_cov()[source]

Determinant of diagonal matrix is product of diagonal entries

mean_log_pdf(samples)[source]
Parameters:samples – A tensor of shape [W, P, S] where W is the number of parameter vertices, P is the number of parameters in the prior (possibly 1) and S is the number of samples
Returns:A tensor of shape [W] where W is the number of parameter vertices containing the mean log PDF of the parameter samples provided
class svb.prior.MRF2SpatialPrior(nvertices, mean, var, idx=None, post=None, nn=None, n2=None, **kwargs)[source]

Prior which performs adaptive spatial regularization based on the contents of neighbouring vertices using the Markov Random Field method

This uses the same formalism as the Fabber ‘M’ type spatial prior but treats the ak as a parameter of the optimization. It differs from MRFSpatialPrior by using the PDF formulation of the PDF rather than the matrix formulation (the two are equivalent but currently we keep both around for checking that they really are!)

FIXME currently this does not work unless sample size=1

mean_log_pdf(samples)[source]
Parameters:samples – A tensor of shape [W, P, S] where W is the number of parameter vertices, P is the number of parameters in the prior (possibly 1) and S is the number of samples
Returns:A tensor of shape [W] where W is the number of parameter vertices containing the mean log PDF of the parameter samples provided
class svb.prior.MRFSpatialPrior(nvertices, mean, var, idx=None, post=None, nn=None, n2=None, **kwargs)[source]

Prior which performs adaptive spatial regularization based on the contents of neighbouring vertices using the Markov Random Field method

This uses the same formalism as the Fabber ‘M’ type spatial prior but treats the ak as a parameter of the optimization.

mean_log_pdf(samples)[source]

mean log PDF for the MRF spatial prior.

This is calculating:

\(\log P = \frac{1}{2} \log \phi - \frac{\phi}{2}\underline{x^T} D \underline{x}\)

class svb.prior.NormalPrior(nvertices, mean, var, **kwargs)[source]

Prior based on a vertexwise univariate normal distribution

mean_log_pdf(samples)[source]

Mean log PDF for normal distribution

Note that term1 is a constant offset when the prior variance is fixed and hence in earlier versions of the code this was neglected, along with other constant offsets such as factors of pi. However when this code is inherited by spatial priors and ARD the variance is no longer fixed and this term must be included.

class svb.prior.Prior(**kwargs)[source]

Base class for a prior, defining methods that must be implemented

mean_log_pdf(samples)[source]
Parameters:samples – A tensor of shape [W, P, S] where W is the number of parameter vertices, P is the number of parameters in the prior (possibly 1) and S is the number of samples
Returns:A tensor of shape [W] where W is the number of parameter vertices containing the mean log PDF of the parameter samples provided
svb.prior.get_prior(param, data_model, **kwargs)[source]

Factory method to return a vertexwise prior