Infer.NET user guide : Controlling how inference is performed

Structure of generated inference code

Infer.NET generates a C# class for performing inference on your model. By default, the source of this class is placed at: (Debug/Release)\\bin\\GeneratedSource\\[ModelName].cs. There are circumstances where it is useful to use this generated code directly, for example, to use a precompiled inference algorithm or to manually modify the message-passing schedule or some other aspect of the code. To help with this, we will now describe the structure of the generated class. Generated source code files also contain full documentation for the class, fields and methods so you can also refer to these directly.

The Generated Class

The class is an ordinary C# class of name [ModelName]_[Algorithm], for example Model0_EP. It typically contains a number of public fields and several standard methods. Fields are created for:

  • each non-random variable in the model
  • all forwards and backwards messages needed to compute requested marginals
  • all requested marginals

Methods are created for:

  • Setting constant fields and initialising messages
  • Performing inference by recursively updating messages
  • Retrieving posterior marginals and output messages

Each field and method has a documentation comment describing its purpose.

Generated Methods for Performing Inference

The methods in the table below are used when performing inference. The Reset, Initialise and Update methods can all be called through the IIterativeProcess interface.

Method
Purpose
Reset()

Configures constant values that will not change during the lifetime of the class.

This method should be called once only after the class is instantiated. In future, it will likely become the class constructor.

Initialise()

Creates message arrays and initialises their values ready for inference to be performed.

This method should be called once each time inference is performed. Since the initialisation procedure normally depends on external values such as priors and array sizes, all external values must be set before calling this method.

As well as initialising message arrays, this method also performs any message passing that the scheduler determines need only be carried out once.

Update()

Performs one iteration of inference.

This method should be called multiple times, after calling Initialise(), in order to perform multiple iterations of message passing. You can call methods to retrieve posterior marginals at any time - the returned marginal will be the estimated marginal given the current state of the message passing algorithm. This can be useful for monitoring convergence of the algorithm.

Where the scheduler has determined inference can be performed without iteration, this method does nothing.

XXXMarginal()
Computes and returns the marginal for the variable 'XXX'.
This method can be called at any time during message passing to return the current estimate of the marginal distribution, as given by the current state of the inference algorithm.
XXXOutput()
Computes and returns the output message for the variable 'XXX'.
This method is similar to XXXMarginal() methods but returns the 'output message' which is the current marginal for the variable divided by the prior. This message is very useful when models are being combined in a modular fashion and is the mechanism used when sharing variables between models.
Output methods are only generated for variables which are marked with the output attribute.

Last modified at 10/7/2009 12:11 PM  by John Winn 
©2009 Microsoft Corporation. All rights reserved.  Terms of Use | Trademarks | Privacy Statement