Adding attributes to your model
Infer.NET allows models to be annotated with attributes that provide information to the inference engine. Such attributes can be used to affect how inference is performed in particular parts of the model.
Attributes can be added to a variable using the following syntax:
|
where x is of type Variable<T>. It is often convenient to add attributes to a variable when it is created, using the following inline syntax:
|
Any object can be attached as an attribute to your model. The following attribute types are currently recognised by the inference engine:
|
Attribute class |
Description |
Example | |
|
MarginalPrototype |
In certain circumstances, the inference engine is unable to determine what type of distribution to use as the marginal for a particular variable. In this case, you will receive an error asking you to specify the 'marginal prototype' for that variable. A marginal prototype is an instance of a distribution class e.g. new Gaussian() which indicates the form of the desired marginal. The parameters of the supplied distribution are not used, just the class and dimensionality.
To specify a marginal prototype for a variable, add a MarginalPrototype attribute. |
| |
|
Output |
When a variable is being shared between multiple models, it is necessary to infer the marginal distribution excluding the effect of the prior. In Infer.NET terminology, this is called an output message. It will only be computed by the inference engine for variables marked as output variables using the Output attribute. The SharedVariable class will automatically add this attribute. However, it may also be added manually.
For a variable v which was marked with this attribute, the output message can be retrieved using the GetOutputMessage(v) method on the inference engine. |
| |
| TraceMessages | Causes all messages related to this variable to be printed to the console during inference |
| |
| DoNotInfer | Tells the inference engine that this variable will not be inferred, so that more efficient code can be generated. | ||
| DivideMessages | Says whether outgoing messages from a variable should be calculated by division. This is especially relevant to the Expectation Propagation algorithm where division is much more efficient. However division can be less accurate numerically, and this attribute gives the option to use multiplication instead. |
| |
| QueryType |
This attribute is only currently relevant to Gibbs sampling, and allows you to specify what type information you want to retrieve for a variable when you query the model. Setting this attribute for various query types tells the model compiler to generate additional code for the different query types. The |
|
Some attributes are set by a method on the variable, and these are shown in the following table. Although these attributes can be added in the standard way as in the previously table, there is some additional processing that needs to be done when setting these attributes, and this is handled in the method:

