lognormal
lognormal
¶
Log-Normal distribution for ngboost-lightning.
LogNormal
¶
Bases: Distribution
Log-Normal distribution with (mu, log_sigma) parameterization.
Internal parameters are [mu, log_sigma] where the underlying normal
has mean mu and scale sigma = exp(log_sigma). A random variable
Y ~ LogNormal(mu, sigma) means log(Y) ~ Normal(mu, sigma).
scipy.stats.lognorm convention: lognorm(s=sigma, scale=exp(mu)).
Note on Fisher Information
For LogNormal(mu, log_sigma), the Fisher Information is diagonal:
diag(1/sigma^2, 2). This is identical to the Normal case because
the sufficient statistics in log-space are the same.
| ATTRIBUTE | DESCRIPTION |
|---|---|
n_params |
Always 2 (mu and log_sigma).
|
mu |
Mean of log(Y), shape
TYPE:
|
sigma |
Std dev of log(Y), shape
TYPE:
|
var |
Variance of log(Y), shape
TYPE:
|
Construct LogNormal from internal parameters.
| PARAMETER | DESCRIPTION |
|---|---|
params
|
Internal parameters, shape
TYPE:
|
Source code in ngboost_lightning/distributions/lognormal.py
fit
staticmethod
¶
Estimate initial (mu, log_sigma) from target data.
| PARAMETER | DESCRIPTION |
|---|---|
y
|
Target values, shape
TYPE:
|
sample_weight
|
Per-sample weights, shape
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
NDArray[floating]
|
Parameter vector |
Source code in ngboost_lightning/distributions/lognormal.py
score
¶
Per-sample negative log-likelihood.
| PARAMETER | DESCRIPTION |
|---|---|
y
|
Observed target values, shape
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
NDArray[floating]
|
NLL values, shape |
Source code in ngboost_lightning/distributions/lognormal.py
d_score
¶
Analytical gradient of NLL w.r.t. [mu, log_sigma].
Derivation
NLL = -log f(y | mu, sigma) = log(y) + 0.5log(2pi) + log(sigma) + 0.5*((log(y) - mu)/sigma)^2
d(NLL)/d(mu) = -(log(y) - mu) / sigma^2 d(NLL)/d(log_sigma) = 1 - ((log(y) - mu) / sigma)^2 (chain rule: d(NLL)/d(log_sigma) = d(NLL)/d(sigma) * d(sigma)/d(log_sigma) = d(NLL)/d(sigma) * sigma)
| PARAMETER | DESCRIPTION |
|---|---|
y
|
Observed target values, shape
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
NDArray[floating]
|
Gradient array, shape |
Source code in ngboost_lightning/distributions/lognormal.py
metric
¶
Fisher Information: diag(1/sigma^2, 2) for each sample.
| RETURNS | DESCRIPTION |
|---|---|
NDArray[floating]
|
FI tensor, shape |
Source code in ngboost_lightning/distributions/lognormal.py
natural_gradient
¶
Natural gradient via diagonal Fisher (fast path).
Since the Fisher Information for LogNormal is diagonal, the natural gradient is simply element-wise division: nat_grad[:, 0] = d_score[:, 0] / (1/sigma^2) = d_score[:, 0] * sigma^2 nat_grad[:, 1] = d_score[:, 1] / 2
| PARAMETER | DESCRIPTION |
|---|---|
y
|
Observed target values, shape
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
NDArray[floating]
|
Natural gradient, shape |
Source code in ngboost_lightning/distributions/lognormal.py
mean
¶
Conditional mean (point prediction).
| RETURNS | DESCRIPTION |
|---|---|
NDArray[floating]
|
Mean values |
sample
¶
Draw n samples per distribution instance.
| PARAMETER | DESCRIPTION |
|---|---|
n
|
Number of samples to draw.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
NDArray[floating]
|
Samples, shape |
Source code in ngboost_lightning/distributions/lognormal.py
cdf
¶
Cumulative distribution function.
| PARAMETER | DESCRIPTION |
|---|---|
y
|
Values at which to evaluate the CDF.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
NDArray[floating]
|
CDF values, same shape as |
Source code in ngboost_lightning/distributions/lognormal.py
ppf
¶
Percent point function (inverse CDF / quantile function).
| PARAMETER | DESCRIPTION |
|---|---|
q
|
Quantiles, values in [0, 1].
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
NDArray[floating]
|
Values at the given quantiles, same shape as |
Source code in ngboost_lightning/distributions/lognormal.py
logpdf
¶
Log probability density function.
| PARAMETER | DESCRIPTION |
|---|---|
y
|
Values at which to evaluate.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
NDArray[floating]
|
Log-density values, same shape as |
Source code in ngboost_lightning/distributions/lognormal.py
logsf
¶
Log survival function: log(1 - CDF(y)).
| PARAMETER | DESCRIPTION |
|---|---|
y
|
Values at which to evaluate.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
NDArray[floating]
|
Log-survival values, same shape as |
Source code in ngboost_lightning/distributions/lognormal.py
crps_score
¶
Per-sample CRPS for LogNormal.
Since log(Y) ~ Normal(mu, sigma), the CRPS is computed in
log-space with z = (log(y) - mu) / sigma:
``CRPS = sigma * (z*(2*Phi(z) - 1) + 2*phi(z) - 1/sqrt(pi))``
This follows the uncensored path of NGBoost's
LogNormalCRPScoreCensored.
| PARAMETER | DESCRIPTION |
|---|---|
y
|
Observed target values, shape
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
NDArray[floating]
|
CRPS values, shape |
Source code in ngboost_lightning/distributions/lognormal.py
crps_d_score
¶
Gradient of CRPS w.r.t. [mu, log_sigma].
Derivation (same structure as Normal CRPS gradient in log-space): d(CRPS)/d(mu) = -(2*Phi(z) - 1) d(CRPS)/d(log_sigma) = CRPS + (log(y) - mu) * d(CRPS)/d(mu)
| PARAMETER | DESCRIPTION |
|---|---|
y
|
Observed target values, shape
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
NDArray[floating]
|
Gradient array, shape |
Source code in ngboost_lightning/distributions/lognormal.py
crps_metric
¶
Riemannian metric for CRPS natural gradient.
Identical structure to Normal's CRPS metric (diagonal), with
sigma playing the role of scale:
diag(2/(2*sqrt(pi)), sigma^2/(2*sqrt(pi)))
| RETURNS | DESCRIPTION |
|---|---|
NDArray[floating]
|
Metric tensor, shape |
Source code in ngboost_lightning/distributions/lognormal.py
crps_natural_gradient
¶
Natural gradient under CRPS metric (fast diagonal path).
| PARAMETER | DESCRIPTION |
|---|---|
y
|
Observed target values, shape
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
NDArray[floating]
|
Natural gradient, shape |