torchcell.transforms.coo_regression_to_classification.BaseBinningStrategy

class BaseBinningStrategy[source]

Bases: ABC

Base class for strategies that bin continuous values into classes.

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.

Threshold k is 1 when the clamped value is >= interior edge k + 1, the same left-closed convention as the one-hot path (bin i is [edge_i, edge_{i+1}), as torch.bucketize(..., right=True) - 1 and np.digitize): the number of ones equals the one-hot bin index, so a value exactly on an interior edge belongs to the bin that edge opens under both.

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.

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

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