mixle.stats.matrix.wishart module¶
Wishart distribution – a distribution over symmetric positive-definite p-by-p matrices.
The Wishart is the distribution of a scatter matrix X = sum_{i=1}^{df} z_i z_i^T with
z_i ~ N(0, scale); it is the matrix generalisation of the chi-square / gamma and the standard model
for random covariance matrices (and the conjugate prior for a Gaussian precision). With df >= p
degrees of freedom and scale matrix V,
log f(X) = (df-p-1)/2 log|X| - 1/2 tr(V^{-1} X) - df p/2 log 2 - df/2 log|V| - log Gamma_p(df/2),
where Gamma_p is the multivariate gamma. Since E[X] = df V the scale V is estimated in closed
form as the mean scatter divided by df. The degrees of freedom may be supplied (WishartEstimator(dim,
df=value)) or estimated by maximum likelihood (WishartEstimator(dim, df=None)) – the latter adds the
sum log det(X) sufficient statistic and solves the profile-likelihood score for df by Newton’s
method.
Reference: Wishart, ‘The generalised product moment distribution in samples…’, Biometrika (1928).
- class WishartDistribution(df, scale, name=None, keys=None)[source]
Bases:
SequenceEncodableProbabilityDistributionWishart 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:
WishartSampler
- 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:
WishartEstimator
- dist_to_encoder()[source]
Return the data encoder used by this distribution for vectorized methods.
- Return type:
WishartDataEncoder
- class WishartSampler(dist, seed=None)[source]
Bases:
DistributionSamplerDraw SPD matrices by the Bartlett decomposition
X = L A A^T L^TwithV = L L^T.- Parameters:
dist (WishartDistribution)
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 WishartAccumulator(dim, name=None, keys=None)[source]
Bases:
_MeanScatterAccumulatorAccumulate
sum_i w_i X_i, the total weight, andsum_i w_i log det(X_i).The extra
sum_logdetstatistic is what enables maximum-likelihood estimation of the degrees of freedom (the inverse-Wishart base accumulator, which does not need it, is left untouched).- update(x, weight, estimate)[source]
- seq_update(x, weights, estimate)[source]
- combine(suff_stat)[source]
- scale(c)[source]
Scale linear sufficient statistics in-place by
c.The structural default is correct for ordinary weighted sums, nested tuples/lists/dicts, and numeric arrays. Families whose
value()payload includes non-linear metadata such as support bounds must override this method and leave that metadata unscaled.- Parameters:
c (float)
- Return type:
WishartAccumulator
- acc_to_encoder()[source]
- Return type:
WishartDataEncoder
- class WishartAccumulatorFactory(dim, name=None, keys=None)[source]
Bases:
StatisticAccumulatorFactoryFactory for WishartAccumulator.
- make()[source]
- Return type:
WishartAccumulator
- class WishartEstimator(dim, df=None, name=None, keys=None)[source]
Bases:
ParameterEstimatorClosed-form scale estimator (
V = mean(X)/df);df=Nonealso fits the degrees of freedom by MLE.With a fixed
dfthe estimator returns only the closed-form scale (E[X] = df V). Withdf=Noneit additionally estimates the degrees of freedom fromsum_i w_i log det(X_i)via Newton’s method on the profile log-likelihood (_solve_wishart_df()).- accumulator_factory()[source]
- Return type:
WishartAccumulatorFactory