torch.distributions.interval
function interval(lower_bound: number, upper_bound: number): _IntervalCreates a constraint for values in an open interval (lower_bound, upper_bound).
Returns a constraint that validates whether tensor values satisfy lower_bound < x < upper_bound. Both bounds are exclusive. Useful for:
- Probability parameters (between 0 and 1)
- Scale/rate parameters with finite bounds
- Bounded continuous parameters
- Ensuring strict inequality constraints
- Open interval: Both bounds are exclusive (not including boundaries)
- Finite bounds: Both bounds must be specified
- Strict inequality: Uses and (not = or =)
- Use half_open_interval: For [lower, upper) or (lower, upper]
Parameters
lower_boundnumber- The lower bound (values must be this, not =)
upper_boundnumber- The upper bound (values must be this, not =)
Returns
_Interval– A constraint object that validates lower_bound x upper_boundExamples
const unit_interval = torch.distributions.constraints.interval(0, 1);
const probs = torch.tensor([0.1, 0.5, 0.9]);
unit_interval.check(probs); // Validates all values in (0, 1)
// Boundaries are exclusive
const boundary = torch.tensor([0, 1]);
unit_interval.check(boundary); // Returns false - boundaries excludedSee Also
- PyTorch torch.distributions.constraints.interval()
- half_open_interval - For partially inclusive boundaries
- greater_than - Single lower bound
- less_than - Single upper bound
- constraints - Other available constraints