LogNormal

class LogNormal[source]

Bases: ContinuousDistribution

Sampling from and properties of the log-normal distribution.

The log-normal distribution is a continuous probability distribution derived from the normal distribution, specifically the log of the normal distribution.

Parameters

\(\mu \in \mathbb{R}\), location

\(\sigma \in \mathbb{R}_+^*\), scale

Support

\(x \in \mathbb{R}_+^*\)

classmethod cdf(support: Tensor | float, loc: Tensor | float, scale: Tensor | float) Tensor[source]

Computes the cumulative distribution function.

\[P(X \leq x; \mu, \sigma) = \frac{1}{2} \left[ 1 + \text{erf} \left( \frac{\log x - \mu}{\sigma \sqrt{2}} \right) \right]\]
Parameters:
Returns:

resulting cumulative probabilities.

Return type:

torch.Tensor

classmethod logcdf(support: Tensor | float, loc: Tensor | float, scale: Tensor | float) Tensor[source]

Computes the natural logarithm of the cumulative distribution function.

\[\log P(X \leq x; \mu, \sigma) = \log \frac{1}{2} \left[ 1 + \text{erf} \left( \frac{\log x - \mu}{\sigma \sqrt{2}} \right) \right]\]
Parameters:
Returns:

resulting cumulative probabilities.

Return type:

torch.Tensor

classmethod logpdf(support: Tensor | float, loc: Tensor | float, scale: Tensor | float) Tensor[source]

Computes the natural logarithm of the probability density function.

\[\log P(X=x; \mu, \sigma) = - \log \sigma - \log x - \frac{1}{2} \left[ \log 2 \pi + \left(\frac{\mu - \log x}{\sigma}\right)^2 \right]\]
Parameters:
Returns:

log of the resulting relative likelihoods.

Return type:

torch.Tensor

classmethod mean(loc: Tensor | float, scale: Tensor | float) Tensor[source]

Computes the expected value of the distribution.

\[\text{E}[X \mid X \sim \text{LogNormal}(\mu, \sigma)] = \exp\left( \mu + \frac{\sigma^2}{2} \right)\]
Parameters:
Returns:

mean of the distribution with given parameters.

Return type:

torch.Tensor

classmethod params_mv(mean: Tensor | float, variance: Tensor | float) tuple[Tensor, Tensor][source]

Computes parameters of the log-normal distribution targeting a given mean and variance.

Computes the location \(\mu\) and scale \(\sigma\) as follows.

\[\mu = \log \left[ \frac{\mu_X^2}{\sqrt{\mu_X^2 + \sigma_X^2}} \right] \qquad \sigma = \sqrt{\log \left[ 1 + \frac{\sigma_X^2}{\mu_X^2} \right]}\]
Parameters:
Returns:

tuple of the corresponding loc and scale.

Return type:

tuple[torch.Tensor, torch.Tensor]

classmethod pdf(support: Tensor | float, loc: Tensor | float, scale: Tensor | float) Tensor[source]

Computes the probability density function.

\[P(X=x; \mu, \sigma) = \frac{1}{x \sigma \sqrt{2 \pi}} \exp \left( - \left( \frac{\log x - \mu}{\sigma\sqrt{2}} \right)^2 \right)\]
Parameters:
Returns:

resulting relative likelihoods.

Return type:

torch.Tensor

classmethod sample(loc: Tensor | float, scale: Tensor | float, generator: Generator | None = None) Tensor[source]

Samples random variates from a log-normal distribution.

\[\log X \sim \mathcal{N}(\mu, \sigma)\]
Parameters:
  • loc (torch.Tensor) – distribution location \(\mu\).

  • scale (torch.Tensor) – distribution scale \(\sigma\).

  • generator (torch.Generator | None, optional) – pseudorandom number generator to use for sampling. Defaults to None.

Returns:

resulting random variates \(X\).

Return type:

torch.Tensor

classmethod sample_mv(mean: Tensor | float, variance: Tensor | float, generator: Generator | None = None) Tensor[source]

Samples random variates with desired mean and variance from a log-normal distribution.

\[\log X \sim \mathcal{N} \left( \log \left[ \frac{\mu_X^2}{\sqrt{\mu_X^2 + \sigma_X^2}} \right], \sqrt{\log \left[ 1 + \frac{\sigma_X^2}{\mu_X^2} \right]} \right)\]
Parameters:
  • mean (torch.Tensor | float) – target sample mean, \(\mu_X\).

  • variance (torch.Tensor | float) – target sample variance, \(\sigma_X^2\).

  • generator (torch.Generator | None, optional) – pseudorandom number generator to use for sampling. Defaults to None.

Returns:

resulting random variates \(X\).

Return type:

torch.Tensor

classmethod validate(loc: Tensor | float | None = None, scale: Tensor | float | None = None, support: Tensor | float | None = None) dict[str, bool | None][source]

Tests if the arguments are valid for a Normal distribution.

Parameters:
  • loc (torch.Tensor | float | None, optional) – location of the distribution, \(\mu\). Defaults to None.

  • scale (torch.Tensor | float | None, optional) – scale of the distribution, \(\sigma\). Defaults to None.

  • support (torch.Tensor | float | None, optional) – support of observation, \(x\). Defaults to None.

Returns:

argument name and if it is valid, returned as a tensor of dtype torch.bool if a non-scalar tensor is given, None if not given.

Return type:

dict[str, torch.Tensor | bool | None]

classmethod variance(loc: Tensor | float, scale: Tensor | float) Tensor[source]

Computes the variance of the distribution.

\[\text{Var}[X \mid X \sim \text{LogNormal}(\mu, \sigma)] = \left( \exp\left( \sigma^2 \right) - 1 \right) \exp\left( 2 \mu + \sigma^2 \right)\]
Parameters:
Returns:

variance of the distribution with given parameters.

Return type:

torch.Tensor