cenreg.metric package — cenreg 0.0.4 documentation

# 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_loglikelihood(dist, observed_times: ndarray, uncensored: ndarray | None = None, boundaries: ndarray | None = None, simplified: bool = True, EPS: float = 0.0001) → ndarray

  Compute negative log-likelihood (NLL).

  Parameters:

    - dist (distribution object) – Prediction results.

    - observed_times (ndarray) – Observed times (event times or censoring times). Array shape is [batch_size].

    - uncensored (ndarray(bool) or None) – Indicator (censored (False) or uncensored (True)) Array shape is [batch_size].

    - boundaries (ndarray or None) – Boundaries of the prediction to be evaluated. The first element must be at most the smallest observed time. The last element must be strictly larger than the largest observed time. If None, dist.boundaries is used.

    - simplified (bool) – Use simplified version for censored data points.

    - EPS (float) – Small positive value for numerical stability.

  Returns:

    NLL – Value of negative log-likelihood.

  Return type:

    ndarray

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) → float

  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 – Value of negative log-likelihood.

  Return type:

    float

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

## Module contents