mixle.stats.bayes.normal_wishart module

Normal-Wishart distribution over (mu, Lambda) for a d-dimensional Gaussian with unknown mean and precision matrix.

q(mu, Lambda) = N(mu | m, (kappa*Lambda)^{-1}) * Wishart(Lambda | W, nu)

with scale matrix W (d x d positive definite) and degrees of freedom nu > d - 1. This is the conjugate prior for the multivariate MultivariateGaussianDistribution (see its prior= argument) and the d-dimensional generalization of NormalGamma (d=1: nu = 2a, W = 1/(2b)). It is a parameter prior: it is scored on (mu, Lambda) parameter pairs, not fit from data by EM.

class NormalWishartDistribution(mu, kappa, w_mat, nu, name=None, prior=None)[source]

Bases: SequenceEncodableProbabilityDistribution

Normal-Wishart distribution over (mu, Lambda); conjugate prior for the multivariate Gaussian with unknown mean and precision matrix.

Parameters:
  • kappa (float)

  • nu (float)

  • name (str | None)

  • prior (SequenceEncodableProbabilityDistribution | None)

get_parameters()[source]

Returns the parameter tuple (mu, kappa, w_mat, nu).

set_parameters(params)[source]

Set the parameters and refresh the cached Wishart log-normalizer.

Parameters:

params – Tuple (mu, kappa, w_mat, nu) with w_mat positive definite and nu > d - 1.

Return type:

None

expected_log_det()[source]

E[ln |Lambda|] under the Wishart factor.

Return type:

float

expected_precision()[source]

E[Lambda] = nu * W.

Return type:

ndarray

density(x)[source]

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

Return type:

float

log_density(x)[source]

Log density at x = (mu, Lambda) with Lambda a precision matrix.

Returns -inf when Lambda is not positive definite.

Return type:

float

cross_entropy(dist)[source]

H(self, dist) = -E_self[log dist] for a NormalWishart argument.

Parameters:

dist (NormalWishartDistribution)

Return type:

float

entropy()[source]

Returns the entropy of the Normal-Wishart distribution (in nats).

Return type:

float

seq_log_density(x)[source]

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

Return type:

ndarray

sampler(seed=None)[source]

Create a NormalWishartSampler for this distribution.

Parameters:

seed (int | None)

Return type:

NormalWishartSampler

estimator(pseudo_count=None)[source]

NormalWishart is a parameter prior and is not fit from data by EM.

Parameters:

pseudo_count (float | None)

Return type:

ParameterEstimator

dist_to_encoder()[source]

Returns a NormalWishartDataEncoder object for encoding (mu, Lambda) pairs.

Return type:

NormalWishartDataEncoder

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

Bases: DistributionSampler

Draws (mu, Lambda) samples from a NormalWishartDistribution.

Parameters:
  • dist (NormalWishartDistribution)

  • seed (int | None)

sample(size=None)[source]

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

Lambda is drawn from the Wishart factor, then mu from N(m, (kappa*Lambda)^-1).

Return type:

Any

scipy_wishart_sample(rng, nu, w_mat)[source]

Draw one Wishart(nu, W) sample via the Bartlett decomposition.

Parameters:
Return type:

ndarray

class NormalWishartDataEncoder[source]

Bases: DataSequenceEncoder

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

seq_encode(x)[source]

Encode the iid observation sequence x for vectorized evaluation.

Parameters:

x (Any)

Return type:

Any