poisson
poisson
¶
Poisson distribution for ngboost-lightning.
Poisson
¶
Bases: Distribution
Poisson distribution with log-rate parameterization.
Internal parameter is [log_rate] where rate = exp(log_rate).
The log-link ensures rate stays positive during unconstrained boosting.
This is a discrete distribution: score uses logPMF, not logPDF.
| ATTRIBUTE | DESCRIPTION |
|---|---|
n_params |
Always 1 (log_rate).
|
rate |
Poisson rate (lambda) values, shape
TYPE:
|
Construct Poisson from internal parameters.
| PARAMETER | DESCRIPTION |
|---|---|
params
|
Internal parameters, shape
TYPE:
|
Source code in ngboost_lightning/distributions/poisson.py
fit
staticmethod
¶
Estimate initial log_rate from target data.
| PARAMETER | DESCRIPTION |
|---|---|
y
|
Target values (counts), shape
TYPE:
|
sample_weight
|
Per-sample weights, shape
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
NDArray[floating]
|
Parameter vector |
Source code in ngboost_lightning/distributions/poisson.py
score
¶
Per-sample negative log-likelihood (using logPMF).
| PARAMETER | DESCRIPTION |
|---|---|
y
|
Observed count values, shape
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
NDArray[floating]
|
NLL values, shape |
Source code in ngboost_lightning/distributions/poisson.py
d_score
¶
Analytical gradient of NLL w.r.t. [log_rate].
Derivation
NLL = -(y * log(rate) - rate - gammaln(y + 1)) d(NLL)/d(rate) = -(y / rate - 1) = 1 - y / rate d(NLL)/d(log_rate) = d(NLL)/d(rate) * d(rate)/d(log_rate) = (1 - y / rate) * rate = rate - y
| PARAMETER | DESCRIPTION |
|---|---|
y
|
Observed count values, shape
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
NDArray[floating]
|
Gradient array, shape |
Source code in ngboost_lightning/distributions/poisson.py
metric
¶
Fisher Information for Poisson with log-rate parameterization.
For Poisson(rate), Var(Y) = rate, and the Fisher information w.r.t. rate is 1/rate. Applying the chain rule for the log-rate parameterization: FI(log_rate) = rate^2 * (1/rate) = rate.
| RETURNS | DESCRIPTION |
|---|---|
NDArray[floating]
|
FI tensor, shape |
Source code in ngboost_lightning/distributions/poisson.py
natural_gradient
¶
Natural gradient via scalar Fisher (fast path).
Since n_params=1, the natural gradient is simply d_score / rate: nat_grad[:, 0] = (rate - y) / rate = 1 - y / rate
| PARAMETER | DESCRIPTION |
|---|---|
y
|
Observed count values, shape
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
NDArray[floating]
|
Natural gradient, shape |
Source code in ngboost_lightning/distributions/poisson.py
mean
¶
Conditional mean (point prediction).
| RETURNS | DESCRIPTION |
|---|---|
NDArray[floating]
|
Rate 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/poisson.py
cdf
¶
Cumulative distribution function P(X <= y).
| 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/poisson.py
ppf
¶
Percent point function (inverse CDF / quantile function).
For discrete distributions, returns the smallest integer k such that CDF(k) >= q.
| PARAMETER | DESCRIPTION |
|---|---|
q
|
Quantiles, values in [0, 1].
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
NDArray[floating]
|
Integer-valued quantiles, same shape as |
Source code in ngboost_lightning/distributions/poisson.py
logpdf
¶
Log probability mass function.
Note: For ABC compatibility this method is named logpdf, but
for this discrete distribution it returns the log-PMF.
| PARAMETER | DESCRIPTION |
|---|---|
y
|
Values at which to evaluate.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
NDArray[floating]
|
Log-PMF values, same shape as |
Source code in ngboost_lightning/distributions/poisson.py
crps_score
¶
Per-sample CRPS for Poisson.
Closed form (Czado, Gneiting & Held 2009):
CRPS = (y - lam)*(2*F(y; lam) - 1)
+ 2*lam*f(floor(y); lam)
- lam*exp(-2*lam)*(I_0(2*lam) + I_1(2*lam))
where lam = rate, F is the Poisson CDF, f is the PMF,
and I_0, I_1 are modified Bessel functions of the first kind.
Uses exponentially-scaled Bessel functions (i0e, i1e) to
avoid overflow for large lam:
exp(-2*lam)*I_k(2*lam) = i_ke(2*lam)
| PARAMETER | DESCRIPTION |
|---|---|
y
|
Observed count values, shape
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
NDArray[floating]
|
CRPS values, shape |
Source code in ngboost_lightning/distributions/poisson.py
crps_d_score
¶
Gradient of CRPS w.r.t. [log_rate].
Uses central finite differences on the internal parameter. The analytical gradient involves derivatives of both the Poisson CDF and modified Bessel functions, making finite differences the more robust approach.
| PARAMETER | DESCRIPTION |
|---|---|
y
|
Observed count values, shape
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
NDArray[floating]
|
Gradient array, shape |
Source code in ngboost_lightning/distributions/poisson.py
crps_metric
¶
Riemannian metric for CRPS natural gradient (MC estimate).
Uses a Monte Carlo estimate: sample from the distribution, compute CRPS gradients, and average the outer product.
| RETURNS | DESCRIPTION |
|---|---|
NDArray[floating]
|
Metric tensor, shape |