cenreg.model package
Submodules
cenreg.model.copula module
- class cenreg.model.copula.FrankCopula(theta: float)
Bases:
object
Frank copula implemented with numpy.
- cdf(u: ndarray) ndarray
Compute cumulative distribution function.
- Parameters:
u (ndarray (float)) – ndarray of shape [batch_size, 2]. Each element should be in [0, 1].
- Returns:
cumulative probability – ndarray of shape [batch_size].
- Return type:
ndarray (float)
- class cenreg.model.copula.IndependenceCopula
Bases:
object
Independence copula implemented with numpy.
- cdf(u: ndarray) ndarray
Compute cumulative distribution function.
- Parameters:
u (ndarray (float)) – ndarray of shape [batch_size, 2]. Each element should be in [0, 1].
- Returns:
probability – ndarray of shape [batch_size].
- Return type:
ndarray (float)
- class cenreg.model.copula.SurvivalCopula(copula)
Bases:
object
Survival copula implemented with pytorch.
- cdf(u: ndarray) ndarray
- cenreg.model.copula.create(name: str, theta: float)
cenreg.model.copula_graphic module
- class cenreg.model.copula_graphic.CopulaGraphicDistribution(observed_times: ndarray, uncensored: ndarray, copula, weights: ndarray | None = None)
Bases:
object
Distribution class of Copula-Graphic estimator.
Notes
The first observation time must be strictly greater than 0. At least one data point is uncensored. CDF values can be strictly less than 1.0 after the last uncensored data point. Survival rates can be strictly greater than 0.0 after the last uncensored data point. Inverse CDF values may not be correct for large quantiles (due to the above notes).
- average_cdf(t: ndarray)
- cdf(t: ndarray)
Compute cumulative distribution function.
- Parameters:
t (ndarray (float)) – ndarray of shape [batch_size] containing time points.
- Returns:
cumulative probability – ndarray of shape [batch_size] containing cumulative probability of event occurrence.
- Return type:
ndarray (float)
- icdf(quantiles: ndarray)
Compute cumulative distribution function.
- Parameters:
quantiles (ndarray (float)) – ndarray of shape [batch_size] containing quantiles.
- Returns:
cumulative probability – ndarray of shape [batch_size] containing cumulative probability of event occurrence.
- Return type:
ndarray (float)
- survival_function(t: ndarray)
Compute survival function.
- Parameters:
t (ndarray (float)) – ndarray of shape [batch_size] containing time points.
- Returns:
survival_rates – ndarray of shape [batch_size] containing survival rates.
- Return type:
ndarray (float)
- cenreg.model.copula_graphic.estimate_curve(observed_times: ndarray, uncensored: ndarray, copula, weights: ndarray = None)
Copula-Graphic estimator. This method receives any copula.
- Parameters:
observed_times (ndarray (float)) – One-dimensional ndarray containing observed times.
uncensored (ndarray (bool)) – One-dimensional ndarray containing censored (False) or uncensored (True).
copula (object) – Copula function.
weights (ndarray (float) or None) – One-dimensional ndarray containing weights. If None, all weights are set to 1.
- Returns:
times (ndarray (float)) – One-dimensional ndarray containing time points.
values (ndarray (float)) – One-dimensional ndarray containing survival rates.
- cenreg.model.copula_graphic.estimate_curve_Archimedean(observed_times: ndarray, uncensored: ndarray, generator, generator_inv)
Simpler copula-graphic estimator proposed by [Rivest and Wells, 2001]. This method assumes that the copula is Archimedean.
- Parameters:
observed_times (ndarray (float)) – One-dimensional ndarray containing observed times.
uncensored (ndarray (bool)) – One-dimensional ndarray containing censored (False) or uncensored (True).
generator (function) – Generator function of the copula.
generator_inv (function) – Inverse generator function of the copula.
- Returns:
times (ndarray (float)) – One-dimensional ndarray containing time points.
values (ndarray (float)) – One-dimensional ndarray containing survival rates.
- cenreg.model.copula_graphic.independence_generator(t_array)
- cenreg.model.copula_graphic.independence_generator_inv(t_array)
cenreg.model.jd2marginal_np module
- cenreg.model.jd2marginal_np.Fpred2jdpred(F_pred: ndarray, copula, w: List[int], num_risks: int, k: int, list_K: List[int]) ndarray
Convert F_pred into jd_pred.
- Parameters:
F_pred (np.ndarray of shape [batch_size, num_risks, 3]) – The three elements in the last axis are the lower bound, the current value, and the upper bound.
copula (function)
w (list of weight parameters (between 0 and 1))
num_risks (int) – The number of risks.
k (int) – The index of the risk.
list_K (list of int) – The list of indices of the risks.
- Returns:
jd_pred
- Return type:
np.ndarray of shape [batch_size, num_risks]
- cenreg.model.jd2marginal_np.estimate(jd_pred: ndarray, copula, focal_risk: int) ndarray
Estimate marginal distribution from joint distribution.
- Parameters:
jd_pred (np.ndarray of shape [batch_size, num_risks, num_bin_predictions])
num_risks (the number of risks)
copula (function)
focal_risk (int)
evaluate_num_bin (bool) – Set True only if you want to evaluate the number of bins.
- Returns:
F_pred – np.ndarray of shape [batch_size, num_risks, num_bin_predictions+1]
- Return type:
estimated CDF.
- cenreg.model.jd2marginal_np.evaluate_F_pred(jd_pred: ndarray, F_pred: ndarray, focal_risk: int, num_risks: int, copula) float
- cenreg.model.jd2marginal_np.hazard(jd_pred: ndarray) ndarray
Estimate marginal distribution from joint distribution.
- Parameters:
jd_pred (np.ndarray of shape [batch_size, num_risks, num_bin_predictions])
- Returns:
F_pred – np.ndarray of shape [batch_size, num_risks, num_bin_predictions+1]
- Return type:
estimated CDF.
- cenreg.model.jd2marginal_np.sequential_allocation(jd_pred: ndarray, focal_risk: int) ndarray
Estimate marginal distribution from joint distribution.
This algorithm works only if the number of risks is two.
- Parameters:
jd_pred (np.ndarray of shape [batch_size, num_risks, num_bin_predictions])
focal_risk (int)
- Returns:
F_pred – np.ndarray of shape [batch_size, num_risks, num_bin_predictions+1]
- Return type:
estimated CDF.
cenreg.model.kaplan_meier module
- class cenreg.model.kaplan_meier.KaplanMeierDistribution
Bases:
object
Distribution class of Kaplan-Meier estimator. This class does not use any interpolation.
Notes
At least one data point must be uncensored. CDF values can be strictly less than 1.0 after the last uncensored data point. Survival rates can be strictly greater than 0.0 after the last uncensored data point. Inverse CDF values may not be correct for large quantiles (due to the above notes). While the original Kaplan-Meier estimator is defined for non-negative times, this implementation can handle negative times.
- average_cdf(t: ndarray)
Compute average cumulative distribution function.
- Parameters:
t (ndarray (float)) – ndarray of shape [batch_size] containing time points.
- Returns:
average cumulative probability – ndarray of shape [batch_size] containing average cumulative probability of event occurrence.
- Return type:
ndarray (float)
- cdf(t: ndarray, add_edges: bool = False)
Compute cumulative distribution function.
- Parameters:
t (ndarray (float)) – ndarray of shape [num_bins] containing time points.
add_edges (bool) – If True, add 0.0 at the start time and 1.0 at the last observed time.
- Returns:
cumulative probability – ndarray of shape [num_bins] containing cumulative probability of event occurrence.
- Return type:
ndarray (float)
- fit(observed_times: ndarray, uncensored: ndarray, weights: ndarray | None = None, alpha: float | None = None)
- icdf(quantiles: ndarray)
Compute cumulative distribution function.
- Parameters:
quantiles (ndarray (float)) – ndarray of shape [batch_size] containing quantiles.
- Returns:
cumulative probability – ndarray of shape [batch_size] containing cumulative probability of event occurrence.
- Return type:
ndarray (float)
- survival_function(t: ndarray)
Compute survival function.
- Parameters:
t (ndarray (float)) – Survival rates are computed for values t. t must be one or two-dimensional ndarray.
- Returns:
survival_rates – ndarray of the same shape as t containing survival rates.
- Return type:
ndarray (float)
- cenreg.model.kaplan_meier.createCdfLinear(observed_times: ndarray, uncensored: ndarray, boundaries: ndarray)
Create CdfLinear object from Kaplan-Meier estimator.
- Parameters:
observed_times (ndarray (float)) – One-dimensional ndarray containing observed times.
uncensored (ndarray (bool)) – One-dimensional ndarray containing censored (False) or uncensored (True).
boundaries (ndarray (float)) – One-dimensional sorted ndarray containing time boundaries. The first element must be 0.0. The last element must be larger than maximum time of observed_times.
- Return type:
CdfLinear object
- cenreg.model.kaplan_meier.createQuantilesLinear(observed_times: ndarray, uncensored: ndarray, qk_levels: ndarray, max_time: float)
Create QuantilesLinear object from Kaplan-Meier estimator.
- Parameters:
observed_times (ndarray (float)) – One-dimensional ndarray containing observed times.
uncensored (ndarray (bool)) – One-dimensional ndarray containing censored (False) or uncensored (True).
qk_levels (ndarray (float)) – One-dimensional ndarray containing quantile levels.
max_time (float) – max_time must be larger than maximum time of observed_times.
- Return type:
QuantilesLinear object