Debugging inferenceWhen you run inference by asking for a marginal there are two steps that take place. First your model is 'compiled' into some efficient engine code. Then, this code is run to provide your updated values (see how Infer.NET works). Either of these steps can fail for reasons which will now be discussed. Model CompilationThe compilation step may fail for one of the following reasons:
The compilation step will throw an exception in either of these cases. Here is an example of a program which will compile properly only if the algorithm is EP. This is because the 'Positive' constraint is not implemented or tractable for VMP.
In Inference engine settings, you saw how to set the browser mode to bring up a window showing the series of code transformations from your initial model in the modelling API to a compiled algorithm. In fact, the default browser mode is set to show the browser whenever an error occurs. In this case, the browser will show the following: ![]() This shows that the compilation failed when the model compiler was trying to create the message-passing code. In this case, the problem can be fixed by using EP as the inference algorithm. Debugging and profiling the inference algorithmIf the model compilation succeeds, the code will be run when you request a marginal from the model. The code that is run is available for viewing as source code, and as such can be debugged and profiled like any other piece of source code. This code is saved as a C# source file (.cs) in a 'GeneratedSource' folder. The name of the file is ModelName_EP.cs or ModelName_VMP.cs where, by default, ModelName is set to 'Model'. There are two exceptions for this. If more than one model is compiled in your program, then an integer is appended to 'Model' in order to make the name unique. Alternatively, you can set the ModelName property on the engine, prior to calling inference:
In this example, the name of the generated source code would be GaussianExample_VMP.cs. One common run-time error occurs when an algorithm diverges. For example, the example Gaussian model will often diverge for the EP algorithm unless additional initialisation is given. Before you can debug into the generated source code, you must set the model compiler's GenerateInMemory property to false and the WriteSourceFiles property to true:
|



