Survival¶
The survival task models time-to-event with right censoring. The
aggregator is the method home for the bag → slide-level step that feeds the
head — see Aggregators.
The survival task offers two losses, selected via task.params.loss:
nll(default) — discrete-time survival modeling. The continuous time axis is split intonum_binsbins; the head emits one hazard logit per bin and trains with the sigmoid-hazard negative log-likelihood (the Gensheimer / HIPTNLLSurvLossformulation).cox— continuous-time CoxPH. The head emits a single risk scalar and trains with the Breslow partial-likelihood loss. The risk set must contain several samples, and the loader uses an event-balanced sampler so every batch/window contains at least one event (gradient_accumulationmust be1). Two modes, switched bytask.params.cox_window:Padded mode (
cox_windowunset /1): the risk set is the batch (batch_size >= 2). Works on single-embedding slide/patient features (no aggregator) or on MIL bags (any ofabmil/transmil/mean_pool), where variable-length bags are padded and masking keeps the result exact.Accumulation mode (
cox_window >= 2): for large variable-size MIL bags.batch_sizeis pinned to1and an aggregator is required; the trainer forwardscox_windowbags un-padded, keeps their risk scalars graph-connected, and computes one Cox loss over the window (one optimiser step per window). This avoids the padding-memory cost of padded mode. Note it does ~``cox_window``× fewer optimiser steps per epoch, so budget a higher learning rate and/or more epochs.
Both losses rank with Harrell’s C-index via scikit-survival.
Survival datasets reuse the label column for the time-to-event /
time-to-last-follow-up and add two columns:
Column |
Meaning |
|---|---|
|
Continuous time-to-event (uncensored) or time-to-last-follow-up (censored). |
|
|
|
Index of the discrete time bin containing |
Supported dataset_type values are slide and patient (tile is
rejected). For patient pipelines, all slides of a patient must agree on the
survival target. The CLAM and DTFD-MIL aggregators are rejected for survival
because their label-aware auxiliary losses assume classification. Survival MIL
uses aggregators without label-aware auxiliary classification losses, such as
abmil, transmil, mean_pool, or hierarchical hipt features.
Task heads¶
- class soma.tasks.survival.SurvivalHead(input_dim, num_bins, alpha=0.15, metrics=None)¶
Bases:
TaskHeadDiscrete-time survival head (sigmoid-hazard NLL).
- Parameters:
input_dim (
int) – Dimension of the input representation.num_bins (
int) – Number of discrete time bins (model output width).alpha (
float) – Up-weighting of the uncensored NLL term (HIPT default 0.15).metrics (
list[str] |None) – Metrics to compute. Empty list uses the survival default (c_index).
- class soma.tasks.survival.CoxSurvivalHead(input_dim, ties='breslow', min_events_per_window=1, cox_window=1, metrics=None)¶
Bases:
TaskHeadContinuous-time CoxPH survival head (Breslow partial likelihood).
Emits a single risk scalar per sample; the Cox partial likelihood is computed over a risk set of multiple samples. Unlike
SurvivalHead, there is no binning and risk is the raw model output — higher means higher hazard / shorter survival, which is whatconcordance_index_censoredexpects. (Reusing the NLL head’s-sum(surv)derivation here would double-invert the C-index sign.)Selected via
task.params.loss: cox. Two training modes, switched bytask.params.cox_window(carried here asaccumulation_window):Padded mode (
cox_windowunset / 1): the risk set is the batch. Single-embedding slide/patient features (no aggregator,batch_size >= 2) or padded MIL bags (batch_size >= 2, masking handles padding).Accumulation mode (
cox_window >= 2): for large variable-size MIL bags.batch_sizeis pinned to 1; the trainer forwardscox_windowbags un-padded, keeps their risk scalars graph-connected, and computes one Cox loss over the window.accumulates_predictionssignals this to the trainer.
In both modes the pipeline builds the training loader with an event-balanced sampler (
needs_event_balanced_batches) and the tune loss is computed over the whole cohort (full_cohort_eval_loss). Config validation enforces the mode constraints.- Parameters:
input_dim (
int) – Dimension of the input representation.ties (
str) – Tie-handling method. Only"breslow"is implemented.min_events_per_window (
int) – Minimum events the event-balanced sampler guarantees per batch / window (>= 1).cox_window (
int) – Prediction-accumulation window size.1(default) selects padded mode;>= 2selects accumulation mode with this risk-set size.metrics (
list[str] |None) – Metrics to compute. Empty list uses the survival default (c_index).