Posterior module

Definition of the posterior distribution

class svb.posterior.FactorisedPosterior(posts, **kwargs)[source]

Posterior distribution for a set of parameters with no covariance

entropy(_samples=None)[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. This parameter may or may not be used in the calculation. If it is required, the implementation class must check that it is provided

:return Tensor of shape [W] containing vertexwise distribution entropy

latent_loss(prior)[source]

Analytic expression for latent loss which can be used when posterior and prior are Gaussian

https://en.wikipedia.org/wiki/Multivariate_normal_distribution#Kullback%E2%80%93Leibler_divergence

Parameters:prior – Vertexwise Prior instance which defines the mean and cov vertices attributes
log_det_cov()[source]

Determinant of diagonal matrix is product of diagonal entries

sample(nsamples)[source]
Parameters:nsamples – Number of samples to return per parameter vertex / parameter
Returns:A tensor of shape [W, P, S] where W is the number of parameter vertices, P is the number of parameters in the distribution (possibly 1) and S is the number of samples
set_state(state)[source]
Parameters:state – State of variables in this posterior, as returned by previous call to state()
:return Sequence of tf.Operation objects containing which will set the variables in
this posterior to the specified state
state()[source]

:return Sequence of tf.Tensor objects containing the state of all variables in this posterior. The tensors returned will be evaluated to create a savable state which may then be passed back into set_state()

class svb.posterior.GaussianGlobalPosterior(idx, mean, var, **kwargs)[source]

Posterior which has the same value at every parameter vertex

entropy(_samples=None)[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. This parameter may or may not be used in the calculation. If it is required, the implementation class must check that it is provided

:return Tensor of shape [W] containing vertexwise distribution entropy

sample(nsamples)[source]

FIXME should each parameter vertex get the same sample? Currently YES

set_state(state)[source]
Parameters:state – State of variables in this posterior, as returned by previous call to state()
:return Sequence of tf.Operation objects containing which will set the variables in
this posterior to the specified state
state()[source]

:return Sequence of tf.Tensor objects containing the state of all variables in this posterior. The tensors returned will be evaluated to create a savable state which may then be passed back into set_state()

class svb.posterior.MVNPosterior(posts, **kwargs)[source]

Multivariate Normal posterior distribution

entropy(_samples=None)[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. This parameter may or may not be used in the calculation. If it is required, the implementation class must check that it is provided

:return Tensor of shape [W] containing vertexwise distribution entropy

log_det_cov()[source]

Determinant of a matrix can be calculated from the Cholesky decomposition which may be faster and more stable than tf.matrix_determinant

sample(nsamples)[source]
Parameters:nsamples – Number of samples to return per parameter vertex / parameter
Returns:A tensor of shape [W, P, S] where W is the number of parameter vertices, P is the number of parameters in the distribution (possibly 1) and S is the number of samples
set_state(state)[source]
Parameters:state – State of variables in this posterior, as returned by previous call to state()
:return Sequence of tf.Operation objects containing which will set the variables in
this posterior to the specified state
state()[source]

:return Sequence of tf.Tensor objects containing the state of all variables in this posterior. The tensors returned will be evaluated to create a savable state which may then be passed back into set_state()

class svb.posterior.NormalPosterior(idx, mean, var, **kwargs)[source]

Posterior distribution for a single vertexwise parameter with a normal distribution

entropy(_samples=None)[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. This parameter may or may not be used in the calculation. If it is required, the implementation class must check that it is provided

:return Tensor of shape [W] containing vertexwise distribution entropy

sample(nsamples)[source]
Parameters:nsamples – Number of samples to return per parameter vertex / parameter
Returns:A tensor of shape [W, P, S] where W is the number of parameter vertices, P is the number of parameters in the distribution (possibly 1) and S is the number of samples
set_state(state)[source]
Parameters:state – State of variables in this posterior, as returned by previous call to state()
:return Sequence of tf.Operation objects containing which will set the variables in
this posterior to the specified state
state()[source]

:return Sequence of tf.Tensor objects containing the state of all variables in this posterior. The tensors returned will be evaluated to create a savable state which may then be passed back into set_state()

class svb.posterior.Posterior(idx, **kwargs)[source]

Posterior distribution

entropy(samples=None)[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. This parameter may or may not be used in the calculation. If it is required, the implementation class must check that it is provided

:return Tensor of shape [W] containing vertexwise distribution entropy

sample(nsamples)[source]
Parameters:nsamples – Number of samples to return per parameter vertex / parameter
Returns:A tensor of shape [W, P, S] where W is the number of parameter vertices, P is the number of parameters in the distribution (possibly 1) and S is the number of samples
set_state(state)[source]
Parameters:state – State of variables in this posterior, as returned by previous call to state()
:return Sequence of tf.Operation objects containing which will set the variables in
this posterior to the specified state
state()[source]
:return Sequence of tf.Tensor objects containing the state of all variables in this
posterior. The tensors returned will be evaluated to create a savable state which may then be passed back into set_state()
svb.posterior.get_posterior(idx, param, t, data_model, **kwargs)[source]

Factory method to return a posterior

Parameters:param – svb.parameter.Parameter instance

: