normal
normal
¶
Normal distribution for ngboost-lightning.
Normal
¶
Bases: Distribution
Normal (Gaussian) distribution with log-scale parameterization.
Internal parameters are [mean, log_scale] where
scale = exp(log_scale). The log-link for scale avoids constrained
optimization during boosting.
Note on Fisher Information
For Normal(mean, log_scale), the Fisher Information is diagonal:
diag(1/scale^2, 2). This means the external natural gradient
(full FI inverse) and diagonal approximation give identical results.
This equivalence does NOT hold for non-Normal distributions.
| ATTRIBUTE | DESCRIPTION |
|---|---|
n_params |
Always 2 (mean and log_scale).
|
loc |
Mean values, shape
TYPE:
|
scale |
Standard deviation values, shape
TYPE:
|
var |
Variance values, shape
TYPE:
|
Construct Normal from internal parameters.
| PARAMETER | DESCRIPTION |
|---|---|
params
|
Internal parameters, shape
TYPE:
|
Source code in ngboost_lightning/distributions/normal.py
fit
staticmethod
¶
Estimate initial (mean, log_scale) 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/normal.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/normal.py
d_score
¶
Analytical gradient of NLL w.r.t. [mean, log_scale].
Derivation
NLL = -log N(y | loc, scale) = 0.5log(2pi) + log(scale) + 0.5*((y - loc)/scale)^2
d(NLL)/d(loc) = (loc - y) / scale^2 d(NLL)/d(log_scale) = 1 - ((y - loc) / scale)^2 (chain rule: d(NLL)/d(log_scale) = d(NLL)/d(scale) * d(scale)/d(log_scale) = d(NLL)/d(scale) * scale)
| PARAMETER | DESCRIPTION |
|---|---|
y
|
Observed target values, shape
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
NDArray[floating]
|
Gradient array, shape |
Source code in ngboost_lightning/distributions/normal.py
metric
¶
Fisher Information: diag(1/scale^2, 2) for each sample.
| RETURNS | DESCRIPTION |
|---|---|
NDArray[floating]
|
FI tensor, shape |
Source code in ngboost_lightning/distributions/normal.py
natural_gradient
¶
Natural gradient via diagonal Fisher (fast path).
Since the Fisher Information for Normal is diagonal, the natural gradient is simply element-wise division: nat_grad[:, 0] = d_score[:, 0] / (1/scale^2) = d_score[:, 0] * scale^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/normal.py
mean
¶
Conditional mean (point prediction).
| RETURNS | DESCRIPTION |
|---|---|
NDArray[floating]
|
Mean values, shape |
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/normal.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/normal.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/normal.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/normal.py
crps_score
¶
Per-sample CRPS for Normal.
Closed form (Gneiting & Raftery 2007):
CRPS = scale * (z * (2*Phi(z) - 1) + 2*phi(z) - 1/sqrt(pi))
where z = (y - loc) / scale.
| PARAMETER | DESCRIPTION |
|---|---|
y
|
Observed target values, shape
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
NDArray[floating]
|
CRPS values, shape |
Source code in ngboost_lightning/distributions/normal.py
crps_d_score
¶
Gradient of CRPS w.r.t. [mean, log_scale].
Derivation
d(CRPS)/d(loc) = -(2*Phi(z) - 1)
d(CRPS)/d(log_scale) = CRPS + (y - loc) * d(CRPS)/d(loc)
(chain rule through z and the leading scale factor)
| PARAMETER | DESCRIPTION |
|---|---|
y
|
Observed target values, shape
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
NDArray[floating]
|
Gradient array, shape |
Source code in ngboost_lightning/distributions/normal.py
crps_metric
¶
Riemannian metric for CRPS natural gradient.
For Normal(loc, log_scale), the CRPS metric is:
diag(1/sqrt(pi), scale^2/sqrt(pi)) / (2*sqrt(pi))
Simplified from NGBoost's NormalCRPScore.metric.
| RETURNS | DESCRIPTION |
|---|---|
NDArray[floating]
|
Metric tensor, shape |
Source code in ngboost_lightning/distributions/normal.py
crps_natural_gradient
¶
Natural gradient under CRPS metric (fast diagonal path).
Since the metric is diagonal
nat_grad[:, 0] = d_score[:, 0] / met[0, 0] nat_grad[:, 1] = d_score[:, 1] / met[1, 1]
| PARAMETER | DESCRIPTION |
|---|---|
y
|
Observed target values, shape
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
NDArray[floating]
|
Natural gradient, shape |