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 to be true.`v` |

False |
`Variable.ConstrainFalse(bool v)` |
Constrains the bool random variable to be false.`v` |

Positivity |
`Variable.ConstrainPositive(double v)` |
Constrains the double random variable to be strictly positive (i.e. such that `v` ).`v>0` |

Between limits |
`Variable.ConstrainBetween(double x, double lowerBound, double upperBound)` |
Constrains the double random variable to be between the specified limits, such that `x` <= `lowerBound` < `x` `upperBound` . |

Equality |
`Variable.ConstrainEqual<T>(T a, T b)` |
Constrains the random variables and `a` to have equal values. The variables must have the same type `b` T. |

Stochastic equality |
`Variable.ConstrainEqualRandom<T,TDist>(T a, TDist b)` |
Constrains the random variable to be equal to a sample from a distribution `a` . If `b` a has type T, then must be a distribution with domain type `b` T. |