Skip to content

lognormal

RL4CRN.distributions.lognormal

Multivariate log-normal distribution.

This module defines MultivariateLogNormal, a distribution obtained by exponentiating a multivariate normal random variable:

\[X \sim \mathcal{N}(\mu, \Sigma), \qquad Y = \exp(X),\]

where the exponential is applied element-wise. The parameters loc and covariance_matrix therefore live in log-space (they parameterize \(X\), not \(Y\)).

Change of variables

The log-density is computed via the standard Jacobian correction. For \(y \in \mathbb{R}^d_{+}\) and \(x = \log y\):

\[\log p_Y(y) = \log p_X(\log y) - \sum_{i=1}^d \log y_i = \log p_X(x) - \sum_{i=1}^d x_i.\]
Moments

For \(X \sim \mathcal{N}(\mu, \Sigma)\) and \(Y = \exp(X)\):

\[\mathbb{E}[Y_i] = \exp\left(\mu_i + \tfrac{1}{2}\Sigma_{ii}\right),\]
\[\operatorname{Var}(Y_i) = \left(\exp(\Sigma_{ii}) - 1\right)\exp\left(2\mu_i + \Sigma_{ii}\right),\]
\[\operatorname{Cov}(Y_i, Y_j) = \exp\left(\mu_i + \mu_j + \tfrac{1}{2}(\Sigma_{ii} + \Sigma_{jj})\right) \left(\exp(\Sigma_{ij}) - 1\right).\]
Entropy

Using the transformation \(Y = \exp(X)\),

\[H(Y) = H(X) + \sum_{i=1}^d \mu_i.\]
Support

Y is element-wise nonnegative; the distribution uses constraints.independent(constraints.nonnegative, 1) as support.

MultivariateLogNormal

Bases: Distribution

Multivariate log-normal distribution implemented via a base MVN in log-space.

Parameters are specified in log-space: \(X \sim \mathcal{N}(\mu, \Sigma)\) with loc \(\mu\) covariance matrix \(\Sigma\), and samples \(Y = \exp(X)\).

PARAMETER DESCRIPTION
loc

Mean vector \(\mu\) of the underlying multivariate normal in log-space. Shape (..., d).

covariance_matrix

Covariance matrix \(\Sigma\) of the underlying multivariate normal in log-space. Shape (..., d, d).

validate_args

Passed to torch.distributions.Distribution to enable/disable argument validation.

DEFAULT: None

ATTRIBUTE DESCRIPTION
mvn

The underlying torch.distributions.MultivariateNormal distribution for \(X\).

mean property

Mean of the distribution.

For \(Y = \exp(X)\) with \(X \sim \mathcal{N}(\mu,\Sigma)\):

\[\mathbb{E}[Y_i] = \exp\left(\mu_i + \tfrac{1}{2}\Sigma_{ii}\right).\]
RETURNS DESCRIPTION

Tensor of shape batch_shape + (d,).

variance property

Marginal variances (diagonal of the covariance of \(Y\)).

\[\operatorname{Var}(Y_i) = \left(\exp(\Sigma_{ii}) - 1\right) \exp\left(2\mu_i + \Sigma_{ii}\right).\]
RETURNS DESCRIPTION

Tensor of shape batch_shape + (d,).

real_covariance_matrix property

Covariance matrix of \(Y\) in real space.

\[\operatorname{Cov}(Y_i, Y_j) = \exp\left(\mu_i + \mu_j + \tfrac{1}{2}(\Sigma_{ii} + \Sigma_{jj})\right) \left(\exp(\Sigma_{ij}) - 1\right).\]
RETURNS DESCRIPTION

Tensor of shape batch_shape + (d, d).

sample(sample_shape=torch.Size())

Draw samples.

Samples are generated by sampling \(X \sim \mathcal{N}(\mu,\Sigma)\) and returning \(Y = \exp(X)\).

PARAMETER DESCRIPTION
sample_shape

Optional leading sample shape.

DEFAULT: Size()

RETURNS DESCRIPTION

Samples of shape sample_shape + batch_shape + event_shape.

log_prob(value)

Compute log-probability of a sample.

Uses the change-of-variables identity:

\[\log p_Y(y) = \log p_X(\log y) - \sum_i \log y_i.\]
PARAMETER DESCRIPTION
value

Tensor of samples y with shape (..., d).

RETURNS DESCRIPTION

Tensor of log-probabilities with shape value.shape[:-1].

RAISES DESCRIPTION
ValueError

If validate_args=True and value violates the support constraint (nonnegativity).

entropy()

Differential entropy of the log-normal distribution.

Using \(Y = \exp(X)\) with \(X \sim \mathcal{N}(\mu,\Sigma)\):

\[H(Y) = H(X) + \sum_i \mu_i.\]
RETURNS DESCRIPTION

Tensor of entropies with shape batch_shape.