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:
support (torch.Tensor | float) – location of observation, \(x\).
loc (torch.Tensor | float) – mean of the distribution, \(\mu\).
scale (torch.Tensor | float) – standard deviation of the distribution, \(\sigma\).
- Returns:
resulting cumulative probabilities.
- Return type:
- 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:
support (torch.Tensor | float) – location of observation, \(x\).
loc (torch.Tensor | float) – mean of the distribution, \(\mu\).
scale (torch.Tensor | float) – standard deviation of the distribution, \(\sigma\).
- Returns:
resulting cumulative probabilities.
- Return type:
- 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:
support (torch.Tensor | float) – location of observation, \(x\).
loc (torch.Tensor | float) – mean of the distribution, \(\mu\).
scale (torch.Tensor | float) – standard deviation of the distribution, \(\sigma\).
- Returns:
log of the resulting relative likelihoods.
- Return type:
- 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:
loc (torch.Tensor | float) – distribution location \(\mu\).
scale (torch.Tensor | float) – distribution scale \(\sigma\).
- Returns:
mean of the distribution with given parameters.
- Return type:
- 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:
mean (torch.Tensor | float) – desired mean, \(\mu_X\).
variance (torch.Tensor | float) – desired variance, \(\sigma_X^2\).
- Returns:
tuple of the corresponding
loc
andscale
.- Return type:
- 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:
support (torch.Tensor | float) – location of observation, \(x\).
loc (torch.Tensor | float) – mean of the distribution, \(\mu\).
scale (torch.Tensor | float) – standard deviation of the distribution, \(\sigma\).
- Returns:
resulting relative likelihoods.
- Return type:
- 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:
- 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:
- 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:
loc (torch.Tensor) – distribution location \(\mu\).
scale (torch.Tensor) – distribution scale \(\sigma\).
- Returns:
variance of the distribution with given parameters.
- Return type: