Wishart
DistributionWishart(df: Tensor | float, covariance_matrix: Tensor | None = None, precision_matrix: Tensor | None = None, scale_tril: Tensor | None = None, validate_args: bool | None = None)Wishart distribution over symmetric positive-definite matrices.
Matrix-variate generalisation of the
lucid.distributions.Chi2 / Gamma distribution: the
distribution of the (unnormalised) sample covariance matrix
formed
from independent Multivariate Normal draws
. It is the
conjugate prior of the precision matrix of a Multivariate Normal
with known mean.
Specify exactly one of covariance_matrix, precision_matrix, or
scale_tril — the other parameterisations are derived internally
via Cholesky factorisation.
Parameters
dfTensor or floatcovariance_matrixTensor= None(..., D, D).precision_matrixTensor= None(..., D, D).scale_trilTensor= None(..., D, D) with
positive diagonal.validate_argsbool= NoneTrue, validate parameter constraints at construction time.Notes
Probability density on the cone of symmetric positive-definite matrices:
where is the multivariate gamma function:
Moments:
Special cases / relations:
- → .
- Inverse: if then follows the inverse-Wishart distribution, the conjugate prior of the covariance (not precision) matrix.
- Bartlett decomposition: with lower-triangular containing draws on the diagonal and standard Normals below — used for sampling.
Examples
>>> import lucid
>>> from lucid.distributions import Wishart
>>> Sigma = lucid.tensor([[2.0, 0.5], [0.5, 1.0]])
>>> d = Wishart(df=5.0, covariance_matrix=Sigma)
>>> d.sample((4,))
Tensor([...])Methods (6)
__init__
→None__init__(df: Tensor | float, covariance_matrix: Tensor | None = None, precision_matrix: Tensor | None = None, scale_tril: Tensor | None = None, validate_args: bool | None = None)Initialise a Wishart distribution.
Converts covariance_matrix or precision_matrix to a Cholesky
factor internally. Exactly one scale specification must be provided.
Parameters
dfTensor | floatcovariance_matrixTensor | None= None(..., D, D).precision_matrixTensor | None= None(..., D, D). Converted via .scale_trilTensor | None= None(..., D, D) with positive diagonal.validate_argsbool | None= NoneTrue, validate parameter constraints at construction time.support
→Constraintsupport: ConstraintConstraint: positive-definite symmetric matrices.
mean
→Tensormean: Tensordf · Σ.
variance
→Tensorvariance: TensorVar[W_{ij}] = df · (Σ_{ij}² + Σ_{ii} Σ_{jj}).
sample
→Tensorsample(sample_shape: tuple[int, ...] = ())Draw a sample via the Bartlett decomposition.
Each sample is L A Aᵀ Lᵀ where L = scale_tril and A
is a random lower-triangular matrix with:
- diagonal
A_{ii} ~ sqrt(χ²_{df − i})fori = 0, …, d−1, - off-diagonal
A_{ij} ~ N(0, 1)fori > j.
log_prob
→Tensorlog_prob(value: Tensor)Log-density of the Wishart distribution.
.. code::
log p(X) = (df − d − 1)/2 · log|X| − tr(Σ⁻¹ X) / 2 − df · d / 2 · log 2 − df/2 · log|Σ| − log Γ_d(df/2)
where Γ_d is the multivariate gamma function.