weibull
weibull
¶
Weibull distribution for ngboost-lightning.
Weibull
¶
Bases: Distribution
Weibull (minimum) distribution with log-link parameterization.
Internal parameters are [log_shape, log_scale] where
shape = exp(log_shape) (k) and scale = exp(log_scale) (lambda).
The Weibull PDF is
f(y) = (k/lambda) * (y/lambda)^(k-1) * exp(-(y/lambda)^k)
for y >= 0.
Note on Fisher Information
For Weibull(log_shape, log_scale), the Fisher Information is
non-diagonal. This distribution relies on the base class
np.linalg.solve for the natural gradient.
| ATTRIBUTE | DESCRIPTION |
|---|---|
n_params |
Always 2 (log_shape and log_scale).
|
shape |
Shape parameter values (k), shape
TYPE:
|
scale |
Scale parameter values (lambda), shape
TYPE:
|
Construct Weibull from internal parameters.
| PARAMETER | DESCRIPTION |
|---|---|
params
|
Internal parameters, shape
TYPE:
|
Source code in ngboost_lightning/distributions/weibull.py
fit
staticmethod
¶
Estimate initial (log_shape, log_scale) from positive data.
Uses scipy's MLE for unweighted data, and a simple moment-based approximation for weighted 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/weibull.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/weibull.py
d_score
¶
Analytical gradient of NLL w.r.t. [log_shape, log_scale].
Derivation (let k=shape, lam=scale, z=y/lam): NLL = -log(k) + log(lam) - (k-1)*log(z) + z^k
d(NLL)/d(k) = -1/k - log(z) + z^k * log(z)
d(NLL)/d(log_k) = k * d(NLL)/d(k)
= -1 + k * log(z) * (z^k - 1)
d(NLL)/d(log_lam) = 1 + (k-1) - k * z^k
= k * (1 - z^k)
| PARAMETER | DESCRIPTION |
|---|---|
y
|
Observed target values, shape
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
NDArray[floating]
|
Gradient array, shape |
Source code in ngboost_lightning/distributions/weibull.py
metric
¶
Fisher Information for (log_shape, log_scale) parameterization.
For Weibull with standard params (k, lam), the FI is: FI_kk = (pi^2/6 + (1-gamma)^2) / k^2 FI_kl = -(1-gamma) / lam FI_ll = k^2 / lam^2
Applying the Jacobian J = diag(k, lam) for log-links: FI_log = J^T @ FI @ J
FI_log[0,0] = k^2 * FI_kk = pi^2/6 + (1-gamma)^2
FI_log[0,1] = k * lam * FI_kl = -k*(1-gamma)
FI_log[1,0] = FI_log[0,1]
FI_log[1,1] = lam^2 * FI_ll = k^2
| RETURNS | DESCRIPTION |
|---|---|
NDArray[floating]
|
FI tensor, shape |
Source code in ngboost_lightning/distributions/weibull.py
mean
¶
Conditional mean: scale * Gamma(1 + 1/shape).
| RETURNS | DESCRIPTION |
|---|---|
NDArray[floating]
|
Mean values, shape |
Source code in ngboost_lightning/distributions/weibull.py
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/weibull.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/weibull.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/weibull.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/weibull.py
logsf
¶
Log survival function: log(1 - CDF(y)).
For Weibull(k, lam), logsf(y) = -(y/lam)^k.
| PARAMETER | DESCRIPTION |
|---|---|
y
|
Values at which to evaluate.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
NDArray[floating]
|
Log-survival values, same shape as |