MultivariateNormal
DistributionMultivariateNormal(loc: Tensor, covariance_matrix: Tensor | None = None, precision_matrix: Tensor | None = None, scale_tril: Tensor | None = None, validate_args: bool | None = None)Multivariate Normal (Gaussian) distribution in .
MultivariateNormal(loc=μ, ...) defines the -dimensional
Gaussian with mean vector and a covariance structure
expressed in one of three equivalent forms. Internally all forms are
converted to the lower-triangular Cholesky factor of
(i.e. ), which is the numerically
preferred representation for both sampling and log-probability evaluation.
Specify exactly one of:
covariance_matrix(positive-definite, ),precision_matrix(positive-definite, inverted via Cholesky internally), orscale_tril(lower-triangular with positive diagonal).
Parameters
locTensor(..., D).(..., D, D).(..., D, D).(..., D, D)
with positive diagonal entries.validate_argsbool | None= NoneTrue, validate parameter constraints at construction time.Attributes
Notes
PDF:
Log-PDF (numerically stable via Cholesky, avoiding explicit inversion):
where is the squared Mahalanobis distance computed via triangular solve (no explicit matrix inversion).
Moments:
- Mean:
- Mode: (Gaussian is unimodal)
- Marginal variances: diagonal of
Entropy:
Reparameterised sampling uses the Cholesky factorisation:
Gradients propagate through and unobstructed.
Examples
>>> import lucid
>>> from lucid.distributions import MultivariateNormal
>>> # 2-d isotropic Gaussian
>>> dist = MultivariateNormal(
... loc=lucid.zeros(2),
... covariance_matrix=lucid.eye(2),
... )
>>> samples = dist.rsample((50,))
>>> samples.shape # (50, 2)
(50, 2)
>>> # Log-prob at the mean (maximum)
>>> dist.log_prob(lucid.zeros(2))Used by 2
Constructors
1__init__
→None__init__(loc: Tensor, covariance_matrix: Tensor | None = None, precision_matrix: Tensor | None = None, scale_tril: Tensor | None = None, validate_args: bool | None = None)Initialise a MultivariateNormal distribution.
Exactly one of covariance_matrix, precision_matrix, or
scale_tril must be provided. All parameterisations are
internally converted to the lower-triangular Cholesky factor L
via lucid.linalg.cholesky or triangular inversion.
Parameters
locTensor(..., D).(..., D, D).(..., D, D).(..., D, D)
with positive diagonal.validate_argsbool | None= NoneTrue, validate parameter constraints at construction time.Raises
ValueErrorProperties
4Full covariance matrix .
Returns
TensorPositive-definite covariance matrix of shape (*batch_shape, D, D).
Mean of the MultivariateNormal: .
Returns
TensorMean vector of shape (*batch_shape, D).
Mode of the MultivariateNormal: equal to the mean .
The Gaussian is unimodal; its unique maximum is at the mean.
Returns
TensorMode vector of shape (*batch_shape, D).
Marginal variances — diagonal entries of .
Returns
TensorVariance vector of shape (*batch_shape, D).
Instance methods
3Entropy of the MultivariateNormal distribution.
Returns
TensorEntropy values of shape batch_shape (nats).
Draw reparameterised samples via the Cholesky factorisation.
Gradients propagate through both and .
Parameters
sample_shapetuple[int, ...]= ()Returns
TensorSamples of shape (*sample_shape, *batch_shape, D).