Skip to main content

Infer.NET user guide : Factors and Constraints

Constraints

This page lists the built-in methods for applying constraints. In these methods, you can often pass in random variables as arguments e.g. Variable<double> instead of double. For compactness, this is not shown in the syntax below.

These methods provide a convenient short alternative to using Variable.Constrain and passing in the constraint method, as described on this page.

Constraint Syntax Description
True Variable.ConstrainTrue(bool v) Constrains the bool random variable v to be true.
False Variable.ConstrainFalse(bool v) Constrains the bool random variable v to be false.
Positivity Variable.ConstrainPositive(double v) Constrains the double random variable v to be strictly positive (i.e. such that v>0).
Between limits Variable.ConstrainBetween(double x, double lowerBound, double upperBound) Constrains the double random variable x to be between the specified limits, such that lowerBound <= x < upperBound.
Equality Variable.ConstrainEqual<T>(T a, T b) Constrains the random variables a and b to have equal values. The variables must have the same type T.
Stochastic equality Variable.ConstrainEqualRandom<T,TDist>(T a, TDist b) Constrains the random variable a to be equal to a sample from a distribution b. Equivalently, increment the log-density by b.GetLogProb(a). If a has type T, then b must be a distribution with domain type T.