cenreg.metric package
Submodules
cenreg.metric.cdf module
- cenreg.metric.cdf.brier(dist, y: ndarray, y_bins: ndarray) ndarray
Compute the (original) Brier score.
- Parameters:
dist (predicted distribution)
y (Array of shape [batch_size])
y_bins (Array of shape [num_bins+1])
- Returns:
loss
- Return type:
Array of shape [batch_size]
- cenreg.metric.cdf.km_calibration(dist, observed_times: ndarray, uncensored: ndarray | None = None, y_bins: ndarray | None = None, eps: float = 0.0001) float
Compute KM-Calibration
- Parameters:
dist (distribution object) – Prediction results.
observed_times (ndarray) – Observation time (event time or censored time) Array shape is [batch_size].
uncensored (ndarray) – Censored (False) or uncensored (True) Array shape is [batch_size].
y_bins (ndarray) – Bins for the prediction to be evaluated. Each element in observed_times must be STRICTLY smaller than y_bins[-1]
eps (float) – Small positive value for numerical stability
- Returns:
KM-Calibration – A non-negative float number.
- Return type:
float
- cenreg.metric.cdf.negative_log_likelihood_interval(dist, lb: ndarray, ub: ndarray, proportional: bool = True, eps: float = 0.0001) ndarray
Compute Negative log-likelihood for interval-censored data.
- Parameters:
dist (predicted distribution) – Must be an instance of cenreg.distribution.cdf.CumulativeDist with linear interpolation.
lb (ndarray of shape [batch_size]) – lower bounds of the intervals
ub (ndarray of shape [batch_size]) – upper bounds of the intervals
proportional (bool) – whether to distribute the probability mass proportionally for censored data
eps (float) – small value to avoid numerical issues
- Returns:
loss
- Return type:
ndarray of shape [batch_size]
- cenreg.metric.cdf.negative_log_likelihood_survival(dist, y: ndarray, uncensored: ndarray | None = None, proportional: bool = True, eps: float = 0.0001) ndarray
Compute Negative log-likelihood for survival data.
- Parameters:
dist (predicted distribution) – Must be an instance of cenreg.distribution.cdf.CumulativeDist with linear interpolation.
y (ndarray of shape [batch_size]) – observed times
uncensored (ndarray of shape [batch_size]) – boolean array indicating whether the event was observed (True) or censored (False)
proportional (bool) – whether to distribute the probability mass proportionally for censored data
eps (float) – small value to avoid numerical issues
- Returns:
loss
- Return type:
ndarray of shape [batch_size]
- cenreg.metric.cdf.nll_sc(list_dist, observed_times: ndarray, events: ndarray, survival_copula, eps: float = 0.0001)
Compute Negative Log-Likelihood based on Survival Copula (NLL-SC).
- cenreg.metric.cdf.ranked_probability_score(dist, y: ndarray, y_bins: ndarray) ndarray
Compute the ranked probability score.
- Parameters:
dist (predicted distribution)
y (Array of shape [batch_size])
y_bins (Array of shape [num_col])
- Returns:
loss
- Return type:
Array of shape [batch_size]
cenreg.metric.cjd module
- cenreg.metric.cjd.brier(observed_times: ndarray, events: ndarray, num_risks: int, f_pred: ndarray, boundaries: ndarray) float
Compute Brier score for censoree joint distribution.
- Parameters:
observed_times (ndarray) – Observed times (event times or censoring times). Array shape is [batch_size].
events (ndarray) – Event index (0 usually corresponds to censoring) Array shape is [batch_size].
num_risks (int) – Number of risks.
f_pred (ndarray) – Estimated joint distribution. Array shape is [batch_size, num_bin*num_risks].
boundaries (ndarray) – Bin boundaries used to represent f_pred. boundaries[0] = 0.0 and boundaries[-1] = max_time. Array shape is [num_bin+1].
- Returns:
Brier – Value of Brier score.
- Return type:
float
- cenreg.metric.cjd.kolmogorov_smirnov_calibration_error(observed_times: ndarray, events: ndarray, f_pred: ndarray, boundaries: ndarray) float
Sum of Kolmogorov-Sminov calibration error.
- Parameters:
observed_times (ndarray) – Observed times (event times or censoring times). Array shape is [batch_size].
events (ndarray) – Event index (0 usually corresponds to censoring) Array shape is [batch_size].
f_pred (ndarray) – Estimated joint distribution. Array shape is [batch_size, num_bin*num_risks].
boundaries (ndarray) – Bin boundaries used to represent f_pred. boundaries[0] = 0.0 and boundaries[-1] = max_time. Array shape is [num_bin+1].
- Returns:
KS – Sum of Kolmogorov-Sminov calibration error.
- Return type:
float
- cenreg.metric.cjd.negative_loglikelihood(observed_times: ndarray, events: ndarray, f_pred: ndarray, boundaries: ndarray, epsilon: float = 0.0001) ndarray
Compute negative log-likelihood (NLL).
- Parameters:
observed_times (ndarray) – Observed times (event times or censoring times). Array shape is [batch_size].
events (ndarray) – Event index (0 usually corresponds to censoring) Array shape is [batch_size].
f_pred (ndarray) – Estimated joint distribution. Array shape is [batch_size, num_bin*num_risks].
boundaries (ndarray) – Bin boundaries used to represent f_pred. boundaries[0] = 0.0 and boundaries[-1] = max_time. Array shape is [num_bin+1].
epsilon (float) – Small value to avoid log(0).
- Returns:
NLL – Per-sample negative log-likelihood values. Array shape is [batch_size].
- Return type:
ndarray
- cenreg.metric.cjd.ranked_probability_score(observed_times: ndarray, events: ndarray, num_risks: int, f_pred: ndarray, boundaries: ndarray) float
Ranked probability score (RPS).
- Parameters:
observed_times (ndarray) – Observed times (event times or censoring times). Array shape is [batch_size].
events (ndarray) – Event index (0 usually corresponds to censoring) Array shape is [batch_size].
num_risks (int) – Number of risks.
f_pred (ndarray) – Estimated joint distribution. Array shape is [batch_size, num_bin*num_risks].
boundaries (ndarray) – Bin boundaries used to represent f_pred. boundaries[0] = 0.0 and boundaries[-1] = max_time. Array shape is [num_bin+1].
- Returns:
RPS – Value of ranked probability score.
- Return type:
float
cenreg.metric.quantile module
- cenreg.metric.quantile.d_calibration(dist, observed_times: ndarray, uncensored: ndarray, boundaries: ndarray | int | None = None) float
Compute D-Calibration.
- Parameters:
dist (distribution object) – Predicted distribution.
observed_times (ndarray (float) of shape [batch_size]) – Observation time (event time or censored time)
uncensored (ndarray (bool) of shape [batch_size]) – Indicator (censored (False) or uncensored (True))
boundaries (ndarray (float) of shape [num_bin+1] or int or None) – Bin boundaries used to compute D-calibration. boundaries[0] = 0.0 and boundaries[-1] = 1.0. If boundaries is int, then boundaries = np.linspace(0.0, 1.0, boundaries + 1). If boundaries is None, then boundaries = np.linspace(0.0, 1.0, 11).
- Returns:
D-Calibration – Value of D-Calibration.
- Return type:
float
- cenreg.metric.quantile.ic_calibration(dist, lb: ndarray, ub: ndarray, p: float = 2.0, b: ndarray | None = None, EPS: float = 0.0001) float
Interval-Censored Calibration (IC-Cal).
- Parameters:
dist (distribution object) – Predicted distribution.
lb (ndarray (float) of shape [batch_size]) – Lower bound of the interval.
ub (ndarray (float) of shape [batch_size]) – Upper bound of the interval.
p (float) – Power for the calibration error. Only p=2 is implemented.
b (ndarray (float) or None) – Bin boundaries used to compute IC-Cal. If None, default boundaries are used.
EPS (float) – Small value to avoid division by zero.
- Returns:
IC-Cal – Value of IC-Cal.
- Return type:
float