mixle.stats.matrix.lkj module¶
LKJ distribution over correlation matrices.
The Lewandowski-Kurowicka-Joe (LKJ) law places density f(R) = c_d(eta) * det(R)^(eta-1) on d x d
correlation matrices (symmetric, unit diagonal, positive definite). The concentration eta > 0 tilts
mass toward the identity: eta = 1 is uniform over correlation matrices, eta > 1 favours weak
correlations (R near I), and eta < 1 favours strong ones. It is the standard prior on
correlation matrices in hierarchical Bayesian models (Stan’s default), separating a covariance into
scales times a correlation.
Normalizer (C-vine derivation, verified to high precision against arbitrary-precision integration over
the correlation elliptope for d = 2, 3):
Z_d(eta) = prod_{k=1}^{d-1} B(eta + (d-1-k)/2, 1/2)^(d-k), c_d(eta) = 1 / Z_d(eta).
It samples exactly by the onion method (Lewandowski et al. 2009, sec. 3.2): each off-diagonal entry then
has the exact marginal (r + 1)/2 ~ Beta(eta + (d-2)/2, eta + (d-2)/2). Because the density depends on
R only through det(R), observations are encoded as log det(R), and eta is fit by maximum
likelihood (a 1-D root find: the mean log-determinant equals sum_k (d-k)[psi(eta+e_k) -
psi(eta+e_k+1/2)] with e_k = (d-1-k)/2).
Reference: Lewandowski, Kurowicka & Joe, “Generating random correlation matrices based on vines and extended onion method”, J. Multivariate Analysis 100 (2009).
- class LKJDistribution(dim, eta, name=None, keys=None)[source]
Bases:
SequenceEncodableProbabilityDistributionLKJ distribution over
dim x dimcorrelation matrices with concentrationeta > 0.- density(x)[source]
Return the probability density at a correlation matrix
x.
- log_density(x)[source]
Return the log-density at a
dim x dimcorrelation matrix (-infif not positive definite).
- seq_log_density(x)[source]
Return vectorized log-density for a sequence-encoded array of
log det(R)values.
- sampler(seed=None)[source]
Return an onion-method sampler for correlation matrices.
- Parameters:
seed (int | None)
- Return type:
LKJSampler
- estimator(pseudo_count=None)[source]
Return a maximum-likelihood estimator for the concentration
eta(dimfixed).- Parameters:
pseudo_count (float | None)
- Return type:
LKJEstimator
- dist_to_encoder()[source]
Return the data encoder (a correlation matrix is encoded as its log-determinant).
- Return type:
LKJDataEncoder
- class LKJSampler(dist, seed=None)[source]
Bases:
DistributionSamplerSample correlation matrices by the onion method (Lewandowski-Kurowicka-Joe 2009).
- Parameters:
dist (LKJDistribution)
seed (int | None)
- class LKJAccumulator(name=None, keys=None)[source]
Bases:
SequenceEncodableStatisticAccumulatorAccumulate
(count, sum of log det(R))– the sufficient statistics for the eta-MLE.- update(x, weight, estimate)[source]
Accumulate the weighted log determinant for one correlation matrix.
- initialize(x, weight, rng)[source]
Initialize the sufficient statistics with one weighted matrix.
- Parameters:
x (Any)
weight (float)
rng (RandomState | None)
- Return type:
None
- seq_update(x, weights, estimate)[source]
Accumulate weighted log determinants from encoded matrices.
- seq_initialize(x, weights, rng)[source]
Initialize the sufficient statistics from encoded log determinants.
- Parameters:
x (ndarray)
weights (ndarray)
rng (RandomState | None)
- Return type:
None
- combine(suff_stat)[source]
Merge serialized LKJ sufficient statistics into this accumulator.
- value()[source]
Return the total weight and weighted sum of log determinants.
- from_value(x)[source]
Restore the accumulator from serialized LKJ sufficient statistics.
- key_merge(stats_dict)[source]
Merge this accumulator into a keyed statistics dictionary.
- key_replace(stats_dict)[source]
Replace this accumulator from a keyed statistics dictionary.
- acc_to_encoder()[source]
Return an encoder that reduces correlation matrices to log determinants.
- Return type:
LKJDataEncoder
- class LKJAccumulatorFactory(name=None, keys=None)[source]
Bases:
StatisticAccumulatorFactoryFactory for LKJAccumulator.
- make()[source]
Create an empty LKJ accumulator.
- Return type:
LKJAccumulator
- class LKJEstimator(dim, eta_bounds=(0.05, 1.0e4), name=None, keys=None)[source]
Bases:
ParameterEstimatorMaximum-likelihood estimator for the concentration
etaat fixed dimensiondim.- accumulator_factory()[source]
Return a factory for LKJ sufficient-statistic accumulators.
- Return type:
LKJAccumulatorFactory