Infer.NET user guide

Frequently Asked Questions

Common questions and answers about the Infer.NET framework.


  • What is Infer.NET?

    Infer.NET is a framework for running Bayesian inference in graphical models.  If you don't know what that means, but would like to, take a look at the Resources and References page.  Infer.NET provides the state-of-the-art message-passing algorithms, graph algorithms, and linear algebra routines needed by modern machine learning applications (read more).

  • Who is behind Infer.NET?

    Infer.NET is being developed in the Machine Learning and Perception group at Microsoft Research Cambridge by Tom Minka, John Winn, John Guiver and David Knowles. Anitha Kannan was involved in earlier versions of the framework.

  • How do I cite Infer.NET?

    Please cite using the following text:

    T. Minka, J. Winn, J. Guiver, and D. Knowles
    Infer.NET 2.5, Microsoft Research Cambridge, 2012.

    or using the following BibTeX:

    author = "Minka, T. and Winn, J.M. and Guiver, J.P. and Knowles, D.A.",
    title = {{Infer.NET 2.5}},
    year = 2012,
    note = {Microsoft Research Cambridge.}
  • Do I have to use C#?

    No.  You can use Infer.NET from any .NET language such as C#, Managed C++, F#, IronPython, and others.  Examples of using Infer.NET from several of these languages are included in the user guide.

    The code generated by Infer.NET is in C#, but it can be invoked from any .NET language.

  • Can I use Infer.NET in a commercial application?

    At this time, commercial use of Infer.NET is limited to Microsoft. No other commercial licenses are available.

  • Where can I learn about graphical models and Bayesian inference?

    We have a list of resources relevant to Infer.NET here.

Running the examples

  • I get a Security Exception when running the example solutions.

    This happens when the example solutions are on a network drive. The easiest solution is to copy the example folders to a local drive. Security exceptions can also be avoided by setting the compiler's GenerateInMemory flag to true as described in Inference engine settings (this is the default setting).

  • I get "ValidateXaml task failed unexpectedly" error when running the Silverlight version of the Clinical Trial solution.

    This happens when the example solution is on a network drive. Move the folder to a local drive.


  • What models can Infer.NET handle?

    Infer.NET can handle Bayesian networks and undirected models (Markov Random Fields) containing both discrete and continuous variables.

  • What models can Infer.NET not handle?

    The following are not handled in the beta, but are likely to be supported in the full release.
      - Efficient support for chain and grid models. This is work in progress which we hope will be complete for the final release.

    The following are not planned to be supported in the full release but may be supported in future releases:
       - Non-parametric models (e.g. Dirichlet process).

  • Does Infer.NET support Hidden Markov Models (HMMs)?

    The current version does support Hidden Markov Models, except that they need to be 'unrolled' i.e. you cannot have random variable arrays for the variables along the HMM, they need to be separate variables.This unrolling means that compiling very large HMMs will be costly in both memory and time, and that also the resultant inference will be slightly slower.

    The click through model is a customised form of HMM, which is implemented as an unrolled set of variables.In this case, the number of variables is small and so the unrolling is not a problem.

    In future, we will be looking into support for rolled-up HMM models, which will make HMMs and similar chain-like models more efficient and allow them to be used for larger data sets.


  • What inference algorithms does Infer.NET support?

    Infer.NET supports expectation propagation (including belief propagation as a special case), variational message passing (also known as variational Bayes, variational EM) and block Gibbs sampling. Support for Power EP is planned for a future release.

  • How can I improve the speed/accuracy of inference with Infer.NET?

    Read the section on improving the speed and accuracy of inference.

  • How can I change the inference schedule?

    • At present, the only supported mechanism for changing the automatically generated inference schedule is to provide initial values for particular messages which will then indirectly affect the schedule.  If you have examples where the scheduler is giving a poor schedule, please let us know.
    • It is also possible to change the schedule manually by editing the generated code to re-order the message computations.
    • You can also affect the schedule by partitioning your model and using the concept of shared variables. The automatic schedule will run on each piece, but you have control over scheduling the submodels.
    • Finally, you can bypass the Infer.NET schedule altogether and call directly into the operator message methods.


  • Does Infer.NET scale to large models/data sets?

    Infer.NET has been designed from the ground up to be computationally efficient.  The compiler architecture means that the generated inference code often approaches the efficiency of hand-written code.  Infer.NET also supports batch-processing of large datasets by sharing variables between models and you can implement customised message operators to overcome particular performance bottlenecks.  However, there will always be cases where hand-coded solutions can exploit special cases to improve efficiency.  If you have an example where Infer.NET generated code is significantly less efficient than hand-written code, please let us know.

    Note that the model compiler in the beta is not itself particularly efficient.  We have focused our efforts so far on making the generated code efficient, rather than the generation process itself.  Hence you should ensure that you are only invoking the compiler once or, at most, a small number of times (i.e. not inside a loop).  Methods for doing this are presented in the tutorials.


  • Inference is running very slowly

    This is normally caused by the inference compiler running inside a loop.  You can avoid recompilation using observed values as described in this tutorial.  If this does not help, try reading the section on improving the speed and accuracy of inference.

    Another common reason for slow inference is that you are hitting memory limits on your system. Refer to the earlier bullet on memory efficiency for strategies to deal with that.

  • OutOfMemoryException during inference

    Infer.NET pre-allocates memory for all messages being passed during inference. This can be particularly severe when running models with large message types such as Dirichlet or Discrete messages, especially in cases where arrays of Discrete variables, each with a large value range, are used to switch on and off parts of a model - for example LDA models. All messages for all data instances for all values of the switch variable are stored, and the messages themselves are large, so such models quickly consume all available memory.

    To reduce memory consumption, see the section on how to build scalable applications.

  • IndexOutOfRangeException during inference

    The most common cause of this is setting the ObservedValue of an array variable to an array of the wrong length.  If you attach names to your arrays and enable debugging of generated code, then the line in the generated code where the exception is raised will tell you which array is the wrong size.

  • ImproperMessageException during inference

    To avoid this, depending on your model, use initialization (for an example of initialization, see the Mixture of Gaussians tutorial),  try changing priors or reorder the data.

  • AllZeroException during inference

    A current limitation of Infer.NET is that this exception will be thrown if any branch in your model is impossible.  For example, if your model has an If statement that makes x equal to true in one case and false in the other, and you observe that x is false, then you will get an AllZeroException when the first branch is visited.  To workaround this, avoid using point masses in your model definition.  For example, the first branch can generate x from a Bernoulli(0.99999) distribution, which is effectively equivalent to true but avoids the exception.

  • Inferred marginals are far from exact, even for a simple model

    All of the inference algorithms in Infer.NET will degrade if your model translates to a factor graph with a loop of strongly coupled variables, especially a deterministic loop.  If your model contains such a loop, try to rewrite it using some of the other factors available in Infer.NET.  See forum thread XOR Inference for an example.  A related issue is that Gibbs sampling requires a certain amount of stochasticity in the model, even without loops.  If the variables are too strongly coupled, then the sampler won't mix.

©2009-2013 Microsoft Corporation. All rights reserved.  Terms of Use | Trademarks | Privacy Statement