survival
survival
¶
Survival analysis support for ngboost-lightning.
Provides right-censored data handling, the CensoredLogScore scoring
rule, and the Y_from_censored helper for creating structured target
arrays.
Censoring convention: event=1 means the time is observed (uncensored),
event=0 means right-censored (the true event time is unknown, but
greater than the observed time).
CensoredLogScore
¶
Censored negative log-likelihood scoring rule.
For uncensored observations (event=1): loss = -logpdf(T)
For right-censored observations (event=0): loss = -logsf(T) (= -log(1 - CDF(T)))
The metric (Fisher Information) is the same as uncensored LogScore — this matches NGBoost's approach.
score
¶
score(
dist: Distribution, y: NDArray[void]
) -> NDArray[floating]
Per-sample censored NLL.
| PARAMETER | DESCRIPTION |
|---|---|
dist
|
Predicted distribution instance.
TYPE:
|
y
|
Structured target array with 'Event' and 'Time' fields.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
NDArray[floating]
|
Censored NLL values, shape |
Source code in ngboost_lightning/survival.py
d_score
¶
d_score(
dist: Distribution, y: NDArray[void]
) -> NDArray[floating]
Gradient of censored NLL w.r.t. distribution parameters.
Uses the uncensored analytical gradient for observed samples and numerical finite differences for censored samples. This avoids distribution-specific censored gradient derivations while remaining accurate.
| PARAMETER | DESCRIPTION |
|---|---|
dist
|
Predicted distribution instance.
TYPE:
|
y
|
Structured target array with 'Event' and 'Time' fields.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
NDArray[floating]
|
Gradient array, shape |
Source code in ngboost_lightning/survival.py
metric
¶
metric(dist: Distribution) -> NDArray[floating]
Fisher Information matrix (same as uncensored).
| PARAMETER | DESCRIPTION |
|---|---|
dist
|
Predicted distribution instance.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
NDArray[floating]
|
Metric tensor, shape |
Source code in ngboost_lightning/survival.py
natural_gradient
¶
natural_gradient(
dist: Distribution, y: NDArray[void]
) -> NDArray[floating]
Natural gradient for censored NLL.
| PARAMETER | DESCRIPTION |
|---|---|
dist
|
Predicted distribution instance.
TYPE:
|
y
|
Structured target array with 'Event' and 'Time' fields.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
NDArray[floating]
|
Natural gradient, shape |
Source code in ngboost_lightning/survival.py
total_score
¶
total_score(
dist: Distribution,
y: NDArray[void],
sample_weight: NDArray[floating] | None = None,
) -> float
Weighted mean censored NLL.
| PARAMETER | DESCRIPTION |
|---|---|
dist
|
Predicted distribution instance.
TYPE:
|
y
|
Structured target array with 'Event' and 'Time' fields.
TYPE:
|
sample_weight
|
Per-sample weights.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
float
|
Scalar (weighted) mean censored NLL. |
Source code in ngboost_lightning/survival.py
Y_from_censored
¶
Create a structured target array from times and event indicators.
| PARAMETER | DESCRIPTION |
|---|---|
T
|
Times to event or censoring, shape
TYPE:
|
E
|
Event indicators, shape
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
NDArray[void]
|
Structured array with fields |
NDArray[void]
|
(float64), shape |