mixle.stats.matrix.inverse_wishart module¶
Inverse-Wishart distribution – a distribution over symmetric positive-definite matrices.
If X^{-1} ~ Wishart(df, scale^{-1}) then X ~ InverseWishart(df, scale); it is the conjugate
prior for a multivariate-normal covariance and the standard model for a random covariance matrix
(rather than a random precision). With df > p - 1 and scale matrix Psi,
- log f(X) = df/2 log|Psi| - df p/2 log 2 - log Gamma_p(df/2)
(df+p+1)/2 log|X| - 1/2 tr(Psi X^{-1}).
df is a fixed, known parameter; since E[X] = Psi / (df - p - 1) the scale is estimated in closed
form as Psi = (df - p - 1) * mean(X) (for df > p + 1).
Reference: Mardia, Kent & Bibby, Multivariate Analysis (Academic Press, 1979).
- class InverseWishartDistribution(df, scale, name=None, keys=None)[source]
Bases:
SequenceEncodableProbabilityDistributionInverse-Wishart distribution with
dfdegrees of freedom and scale matrixscale(p, p).- density(x)[source]
Return the density at a single
(p, p)SPD matrix.
- log_density(x)[source]
Return the log-density at a single
(p, p)SPD matrix (-infif not positive definite).
- seq_log_density(x)[source]
Vectorized log-density for a stack of SPD matrices, shape
(N, p, p).
- sampler(seed=None)[source]
Return a sampler for drawing SPD matrices from this distribution.
- Parameters:
seed (int | None)
- Return type:
InverseWishartSampler
- estimator(pseudo_count=None)[source]
Return a closed-form estimator for the scale at the fixed degrees of freedom
df.- Parameters:
pseudo_count (float | None)
- Return type:
InverseWishartEstimator
- dist_to_encoder()[source]
Return the data encoder used by this distribution for vectorized methods.
- Return type:
InverseWishartDataEncoder
- class InverseWishartSampler(dist, seed=None)[source]
Bases:
DistributionSamplerDraw SPD matrices by inverting a
Wishart(df, scale^{-1})draw.- Parameters:
dist (InverseWishartDistribution)
seed (int | None)
- sample(size=None)[source]
Draw observations.
Combinator samplers (mixture/sequence/…) accept
batched. Withbatched=True(the default) each child stream is drawn in one vectorized call instead of a per-draw Python loop – far faster. Because every child sampler owns an independentRandomState, batching consumes each stream in the same order as the loop, so the draws are identical to the legacy path.batched=Falseforces that legacy per-draw loop as a guaranteed- stable reference. Leaf samplers are already vectorized and ignore the flag.
- class InverseWishartAccumulator(dim, name=None, keys=None)[source]
Bases:
_MeanScatterAccumulatorAccumulate the weighted sum of matrices
sum_i w_i X_iand the total weight.- acc_to_encoder()[source]
- Return type:
InverseWishartDataEncoder
- class InverseWishartAccumulatorFactory(dim, name=None, keys=None)[source]
Bases:
StatisticAccumulatorFactoryFactory for InverseWishartAccumulator.
- make()[source]
- Return type:
InverseWishartAccumulator