torchcell.transforms.regression_to_classification.BaseBinningStrategy

class BaseBinningStrategy[source]

Bases: ABC

Base strategy providing shared clamping and encoding for label binning.

clamp_values(values: Tensor, bin_edges: Tensor) → Tensor[source]

Clamp values to be within bin edge range.

compute_ordinal_labels(values: Tensor, bin_edges: Tensor) → Tensor[source]

Compute ordinal labels with clamping for out-of-bounds values.

compute_soft_labels(values: Tensor, bin_edges: Tensor, strategy: str = 'equal_width', sigma_scale: float = 3) → Tensor[source]

Compute soft labels with clamping for out-of-bounds values.

Each row is a Gaussian on the bin centers normalized to sum to one, computed as a softmax of the log-weights -0.5 * (distance / sigma) ** 2. The softmax subtracts the row maximum before exponentiating, so a narrow sigma whose raw weights would all underflow to 0 still yields a distribution (all mass on the nearest center) rather than a row of zeros.

compute_onehot_labels(values: Tensor, bin_edges: Tensor) → Tensor[source]

Compute one-hot labels with clamping for out-of-bounds values.