base
base
¶
Base distribution abstraction for ngboost-lightning.
Distribution
¶
Bases: ABC
Abstract base class for probability distributions.
A Distribution represents a parametric family of distributions. Instances hold arrays of parameters (one set per sample) and provide methods for scoring, gradient computation, and sampling.
Subclasses must define
n_params: number of internal parametersfit(y): estimate initial parameters from datascore(y): per-sample negative log-likelihoodd_score(y): gradient of score w.r.t. internal paramsmetric(): Fisher Information matrixmean(): point prediction (conditional mean)sample(n): draw random samplescdf(y): cumulative distribution functionppf(q): percent point function (inverse CDF)logpdf(y): log probability density (or mass) function
Note on scoring rules
The score/d_score/metric methods implement the LogScore
(negative log-likelihood). CRPS is supported via separate
crps_score/crps_d_score/crps_metric methods — see
:mod:ngboost_lightning.scoring for the strategy-pattern wiring.
| ATTRIBUTE | DESCRIPTION |
|---|---|
n_params |
Number of internal (unconstrained) parameters.
TYPE:
|
Construct distribution from internal parameters.
| PARAMETER | DESCRIPTION |
|---|---|
params
|
Internal parameters, shape
TYPE:
|
Source code in ngboost_lightning/distributions/base.py
fit
abstractmethod
staticmethod
¶
Estimate initial parameters from target data.
| PARAMETER | DESCRIPTION |
|---|---|
y
|
Target values, shape
TYPE:
|
sample_weight
|
Per-sample weights, shape
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
NDArray[floating]
|
Internal parameter vector, shape |
NDArray[floating]
|
starting point for boosting (analogous to NGBoost's |
NDArray[floating]
|
|
Source code in ngboost_lightning/distributions/base.py
score
abstractmethod
¶
Per-sample negative log-likelihood (LogScore).
| PARAMETER | DESCRIPTION |
|---|---|
y
|
Observed target values, shape
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
NDArray[floating]
|
NLL values, shape |
Source code in ngboost_lightning/distributions/base.py
d_score
abstractmethod
¶
Gradient of score w.r.t. internal parameters.
| PARAMETER | DESCRIPTION |
|---|---|
y
|
Observed target values, shape
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
NDArray[floating]
|
Gradient array, shape |
Source code in ngboost_lightning/distributions/base.py
metric
abstractmethod
¶
Fisher Information matrix.
| RETURNS | DESCRIPTION |
|---|---|
NDArray[floating]
|
FI tensor, shape |
Note
For Normal with (mean, log_scale) parameterization, the FI is
diagonal: diag(1/scale^2, 2). The full
[n_samples, n_params, n_params] return shape is required
to support non-diagonal Fisher matrices in future distributions.
Source code in ngboost_lightning/distributions/base.py
mean
abstractmethod
¶
Conditional mean (point prediction).
| RETURNS | DESCRIPTION |
|---|---|
NDArray[floating]
|
Mean values, shape |
sample
abstractmethod
¶
Draw random samples from the distribution.
| PARAMETER | DESCRIPTION |
|---|---|
n
|
Number of samples to draw per distribution instance.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
NDArray[floating]
|
Samples, shape |
Source code in ngboost_lightning/distributions/base.py
cdf
abstractmethod
¶
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/base.py
ppf
abstractmethod
¶
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/base.py
logpdf
abstractmethod
¶
Log probability density (or mass) function.
For continuous distributions this is the log-PDF. For discrete distributions (e.g. Poisson) this returns the log-PMF.
| PARAMETER | DESCRIPTION |
|---|---|
y
|
Values at which to evaluate.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
NDArray[floating]
|
Log-density (or log-mass) values, same shape as |
Source code in ngboost_lightning/distributions/base.py
logsf
¶
Log survival function: log(1 - CDF(y)).
Required for right-censored survival analysis. Subclasses that
support censored observations (Exponential, LogNormal, Weibull)
should override this with scipy's numerically stable logsf.
| 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/base.py
crps_score
¶
Per-sample CRPS (Continuous Ranked Probability Score).
Subclasses that support CRPS must override this method.
| PARAMETER | DESCRIPTION |
|---|---|
y
|
Observed target values, shape
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
NDArray[floating]
|
CRPS values, shape |
Source code in ngboost_lightning/distributions/base.py
crps_d_score
¶
Gradient of CRPS w.r.t. internal parameters.
Subclasses that support CRPS must override this method.
| PARAMETER | DESCRIPTION |
|---|---|
y
|
Observed target values, shape
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
NDArray[floating]
|
Gradient array, shape |
Source code in ngboost_lightning/distributions/base.py
crps_metric
¶
Riemannian metric tensor for the CRPS natural gradient.
This is NOT the Fisher Information (which is the metric for LogScore). Each distribution must derive its own CRPS metric.
| RETURNS | DESCRIPTION |
|---|---|
NDArray[floating]
|
Metric tensor, shape |
Source code in ngboost_lightning/distributions/base.py
natural_gradient
¶
Compute the natural gradient: FI^{-1} @ d_score.
Default implementation solves the linear system. Subclasses with diagonal Fisher (e.g. Normal) can override for efficiency.
| PARAMETER | DESCRIPTION |
|---|---|
y
|
Observed target values, shape
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
NDArray[floating]
|
Natural gradient, shape |
Source code in ngboost_lightning/distributions/base.py
total_score
¶
Weighted mean negative log-likelihood across all samples.
| PARAMETER | DESCRIPTION |
|---|---|
y
|
Observed target values, shape
TYPE:
|
sample_weight
|
Per-sample weights, shape
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
float
|
Scalar (weighted) mean NLL. |