mixle.stats.bayes.multivariate_normal_gamma module

Multivariate (factorized) Normal-Gamma distribution over (mu, tau) for a vector of independent Gaussians with unknown means and precisions.

Each component i is an independent NormalGamma:

tau_i ~ Gamma(a_i, b_i), mu_i | tau_i ~ Gaussian(mu0_i, 1/(lam_i*tau_i))

Data type: (Tuple[np.ndarray, np.ndarray]): A pair (mu, tau) of length-d

vectors; the log-density is the sum of the d univariate NormalGamma log-densities.

This is the conjugate prior used by the diagonal DiagonalGaussianDistribution (see its prior= argument) and the vectorized counterpart of NormalGamma. It is a parameter prior: it is scored on (mu, tau) parameter pairs, not fit from data by EM.

class MultivariateNormalGammaDistribution(mu, lam, a, b, name=None, prior=None)[source]

Bases: SequenceEncodableProbabilityDistribution

Vector of independent NormalGamma distributions over per-component (mu_i, tau_i) pairs; conjugate prior for diagonal Gaussians.

Parameters:
get_parameters()[source]

Returns the parameter tuple (mu, lam, a, b) of vectors.

set_parameters(value)[source]

Set the parameters from a tuple of vectors.

Parameters:

value – Tuple (mu, lam, a, b) of length-d arrays.

Return type:

None

cross_entropy(dist)[source]

Cross-entropy H(self, dist) = -E_self[log dist], summed over components, for a MultivariateNormalGamma argument.

Parameters:

dist (MultivariateNormalGammaDistribution)

Return type:

float

entropy()[source]

Returns the entropy (in nats), summed over components.

Return type:

float

density(x)[source]

Density at x = (mu, tau); see log_density().

Parameters:

x (tuple[Sequence[float] | ndarray, Sequence[float] | ndarray])

Return type:

float

log_density(x)[source]

Log-density at x = (mu, tau), summed over the d components.

Parameters:

x (FlexDatumType) – Tuple (mu, tau) of length-d vectors with tau_i > 0.

Returns:

Log-density at x.

Return type:

float

seq_log_density(x)[source]

Vectorized log-density over a sequence of (mu, tau) pairs.

Return type:

ndarray

sampler(seed=None)[source]

Create a MultivariateNormalGammaSampler for this distribution.

Parameters:

seed (int | None)

Return type:

MultivariateNormalGammaSampler

estimator(pseudo_count=None)[source]

MultivariateNormalGamma is a parameter prior; not fit from data by EM.

Parameters:

pseudo_count (float | None)

Return type:

ParameterEstimator

dist_to_encoder()[source]

Returns a MultivariateNormalGammaDataEncoder for encoding (mu, tau) pairs.

Return type:

MultivariateNormalGammaDataEncoder

class MultivariateNormalGammaSampler(dist, seed=None)[source]

Bases: DistributionSampler

Draws (mu, tau) samples from a MultivariateNormalGammaDistribution.

Parameters:
  • dist (MultivariateNormalGammaDistribution)

  • seed (int | None)

sample(size=None)[source]

Draw size samples (a single (mu, tau) pair when size is None).

Return type:

Any

class MultivariateNormalGammaDataEncoder[source]

Bases: DataSequenceEncoder

Encodes a sequence of (mu, tau) parameter pairs (identity passthrough).

seq_encode(x)[source]

Encode the iid observation sequence x for vectorized evaluation.

Parameters:

x (Any)

Return type:

Any