torch.distributions.half_open_interval
function half_open_interval(lower_bound: number, upper_bound: number): _HalfOpenIntervalCreates a constraint for values in a half-open interval [lower_bound, upper_bound).
Returns a constraint that validates whether tensor values satisfy lower_bound <= x < upper_bound. The lower bound is inclusive, the upper bound is exclusive. Useful for:
- Indices and counts (0 to max, inclusive at min)
- Concentration parameters for Dirichlet
- Parameters where lower bound can equal zero
- Partially bounded constraints
- Half-open interval: Lower inclusive, upper exclusive [lower, upper)
- Left-closed: Allows values equal to lower_bound
- Right-open: Excludes upper_bound itself
- Use interval: For both exclusive (open) bounds
Parameters
lower_boundnumber- The lower bound (values must be = this)
upper_boundnumber- The upper bound (values must be this)
Returns
_HalfOpenInterval– A constraint object that validates lower_bound = x upper_boundExamples
const conc_interval = torch.distributions.constraints.half_open_interval(0, 1000);
const concentration = torch.tensor([0, 100, 500]);
conc_interval.check(concentration); // Validates all values in [0, 1000)
// Lower bound is inclusive, upper is exclusive
const zero = torch.tensor([0]);
const thousand = torch.tensor([1000]);
conc_interval.check(zero); // true (0 is included)
conc_interval.check(thousand); // false (1000 is excluded)See Also
- PyTorch torch.distributions.constraints.half_open_interval()
- interval - For both exclusive boundaries (open interval)
- integer_interval - For integer half-open intervals
- greater_than - Single lower bound
- constraints - Other available constraints