Infer.NET user guide : Factors and Constraints

## Undirected factors

All factors listed on this page are **experimental** and currently are only supported when using the MaxProductBeliefPropagation algorithm. Support for undirected models will be extended in future releases of Infer.NET.

This page lists the built-in methods for creating common undirected factors, as used in many undirected graphical models. Strictly speaking these are stochastic constraints, but we follow convention and refer to them as undirected factors. In these methods, you can usually 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 undirected factor method, as described on this page.

Factor |
Syntax |
Description |
---|---|---|

Potts (bool) |
`Variable.Potts(bool a, bool b, double logCost)` |
Adds a Potts factor between two bool random variables which evaluates to 1 if a==b and exp(-logCost) otherwise. |

Potts (int) |
`Variable.Potts(int a, int b, double logCost)` |
Adds a Potts factor between two int random variables which evaluates to 1 if a==b and exp(-logCost) otherwise. |

Linear (int) |
`Variable.Linear(int a, int b, double logUnitCost)` |
Adds a linear factor between two int random variables which evaluates to exp(-abs(a-b)*logUnitCost). |

Truncated linear (int) |
`Variable.LinearTrunc(int a, int b, double logUnitCost, double maxCost)` |
Adds a truncated linear factor between two int random variables which evaluates to exp(-min(abs(a-b)*logUnitCost, maxCost)). |