cellmil.datamodels.transforms.time_discretizer

Survival discretization transform for converting continuous survival times to discrete bins.

Classes

TimeDiscretizerTransform([n_bins, eps])

Transform for discretizing continuous survival times into bins.

class cellmil.datamodels.transforms.time_discretizer.TimeDiscretizerTransform(n_bins: int = 4, eps: float = 1e-08)[source]

Bases: FittableLabelTransform

Transform for discretizing continuous survival times into bins.

This transform bins survival times using quantiles computed on uncensored patients only. It’s designed for discrete-time survival analysis where we convert the regression problem into a classification problem.

Parameters:
  • n_bins (int) – Number of bins to create (e.g., 4 for quartiles)

  • eps (float) – Small epsilon value to adjust bin boundaries

__init__(n_bins: int = 4, eps: float = 1e-08)[source]

Initialize the fittable label transform.

Parameters:

name – Name of the transform for identification

fit(labels: Dict[str, Union[int, Tuple[float, int]]], **kwargs: Any) TimeDiscretizerTransform[source]

Fit the discretizer on survival data.

Parameters:
  • labels – Dictionary mapping slide IDs to (duration, event) tuples

  • **kwargs – Additional keyword arguments (not used, for API compatibility)

Returns:

Self for method chaining

_transform_labels_impl(labels: Dict[str, Union[int, Tuple[float, int]]]) Dict[str, Union[int, Tuple[float, int]]][source]

Implementation of the label transform operation.

Parameters:

labels – Dictionary mapping slide IDs to (duration, event) tuples

Returns:

Dictionary mapping slide IDs to (bin_index, event) tuples

get_config() Dict[str, Any][source]

Get configuration for saving.

classmethod from_config(config: dict[str, Any])[source]

Create instance from configuration.

save(path: Path) None[source]

Save transform to disk.

classmethod load(path: Path)[source]

Load transform from disk.