Improving the speed and accuracy of inferenceThere are often multiple ways of using Infer.NET to solve a particular problem. The list below suggests ways in which you can change your Infer.NET code to improve its speed and/or the accuracy of the solution given.
- Use observed random variables rather than constants
Avoid using constants for data and/or priors, and use observed variables instead - this means that your model can be run multiple times with different data and priors without recompiling the model. See the truncated Gaussian tutorial for an example of this.
- Use variable arrays and ranges rather than .NET arrays.
Where possible, use variable arrays made with Variable.Array() instead of arrays of Variable instances (see Learning a Gaussian tutorial).
- Specify the exact variables to be inferred
Use the InferAll() method on the inference engine to specify exactly which variables you want to infer. This is more efficient than the Infer() method which opportunistically computes all marginals that may be needed (see Mixture of Gaussians for an example).
- Reduce the number of factors
In general, the fewer factors in your factor graph, the faster and more accurate inference can be. Try to rewrite your model to reduce the number of factors if possible. The ShowFactorGraph option on the inference engine should help.
- Profile the inference code
You can profile the generated inference code to find bottlenecks, as described in debugging inference.
- Use release libraries
Both debug and release libraries are provided - check you are using the release libraries for maximum performance.
- Reduce the number of iterations of inference
The default number of iterations is 50 - your model may need fewer iterations to converge. Modify NumberOfIterations in the inference engine settings or use a custom convergence criterion.
- Use parallel for loops (experimental feature)
You can get the model compiler to emit parallel for loops, allowing multiple cores to be used when running inference. Set the compiler UseParallelForLoops property to true. You will need to have the Microsoft Parallel Extensions CTP installed.
|