torch.distributions.constraints.is_dependent
function is_dependent(constraint: Constraint | _DependentProperty): booleanChecks if a constraint is a dependent constraint.
Returns true if the constraint depends on other distribution parameters or depends on the values of the distribution itself (rather than being a fixed constraint). Dependent constraints have their range determined by other parameters. Useful for:
- Parameter validation: Checking constraint type during distribution construction
- Distribution implementation: Handling parameter-dependent constraints differently
- Type detection: Distinguishing dependent from independent constraints
- Shape computation: Determining event shapes for dependent constraints
- Constraint implementation: Special handling for parameter-dependent constraints
Dependent constraints are constraints where the valid range depends on the values of other distribution parameters. For example, the concentration parameters of a Dirichlet constraint are dependent on the shape parameter.
- DependentProperty support: Also works with _DependentProperty objects
- Type safety: Can be used as a type guard for dependent constraints
- Distribution-specific: Meaning varies based on distribution type
- Parameter dependency: Dependent constraints need access to parent distribution
- Shape computation: Event shape may not be computable for dependent constraints
Parameters
constraintConstraint | _DependentProperty- Constraint or DependentProperty to check
Returns
boolean– True if the constraint is dependent on other parameters, false if independentExamples
// Check independent constraint
const positive = torch.distributions.constraints.positive;
torch.distributions.is_dependent(positive); // false// Check dependent constraint
const dependent = torch.distributions.dependent;
torch.distributions.is_dependent(dependent); // true// Use in distribution implementation
function validate_constraint(constraint: Constraint) {
if (torch.distributions.is_dependent(constraint)) {
// Handle dependent constraint specially
return constraint.event_shape;
} else {
// Handle independent constraint
return simpleShape;
}
}See Also
- PyTorch torch.distributions.constraints.is_dependent()
- dependent - Singleton dependent constraint
- dependent_discrete - Dependent constraint for discrete spaces
- Constraint - Base constraint class