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)
- 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 the encoder compatible with the accumulated matrix statistics.
- Return type:
InverseWishartDataEncoder
- class InverseWishartAccumulatorFactory(dim, name=None, keys=None)[source]
Bases:
StatisticAccumulatorFactoryFactory for InverseWishartAccumulator.
- make()[source]
Create an accumulator for weighted inverse-Wishart matrix observations.
- Return type:
InverseWishartAccumulator
- class InverseWishartEstimator(dim, df, name=None, keys=None)[source]
Bases:
ParameterEstimatorClosed-form scale estimator at fixed
df:Psi = (df-p-1) * mean(X)sinceE[X] = Psi/(df-p-1).- accumulator_factory()[source]
Return an accumulator factory for estimating the fixed-df scale matrix.
- Return type:
InverseWishartAccumulatorFactory