torchcell.transforms.regression_to_classification.LabelBinningTransform

class LabelBinningTransform(dataset: Neo4jCellDataset, label_configs: dict[str, dict[str, Any]], normalizer: LabelNormalizationTransform | None = None)[source]

Bases: BaseTransform

Transform converting continuous labels into binned classification targets.

forward(data: HeteroData) → HeteroData[source]

Transform the data by binning specified labels.

inverse(data: HeteroData, seed: int = 42) → HeteroData[source]

Inverse transform from binned predictions back to continuous values.

Rows containing a NaN map to NaN. The other rows are decoded per label type:

  • categorical: the softmax argmax bin, then a uniform draw within that bin.

  • ordinal: the number of entries above 0.5 selects the bin, then a uniform draw within it.

  • soft: deterministic, no sampling. The softmax of the row is averaged over the bin centers in a five-bin window around its argmax (renormalized within the window). When that window would cross the first or last edge, i.e. the argmax is within two bins of an edge, the argmax bin center is returned.

The uniform draws come from the global generator reseeded with seed.

get_bin_info(label: str) → dict[str, Any][source]

Get binning information for a label.