Infer.NET user guide

Frequently Asked Questions

Common questions and answers about the Infer.NET framework.

General

  • 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. The framework was conceived and designed by Tom Minka and John Winn who remain technical leaders, principal researchers, and key developers on the project. Early contributors include John Guiver, Anitha Kannan, and David Knowles. The current team consists of Tom Minka, John Winn, John Guiver, Sam Webster, Yordan Zaykov, Boris Yangel, and John Bronskill.

  • How do I cite Infer.NET?

    Please cite using the following text:

    T. Minka, J. Winn, J. Guiver, S. Webster, Y. Zaykov, B. Yangel, A. Spengler, and J. Bronskill
    Infer.NET 2.6, Microsoft Research Cambridge, 2014.
    http://research.microsoft.com/infernet

    or using the following BibTeX:

    @misc{InferNET14, 
    author = "Minka, T. and Winn, J.M. and Guiver, J.P. and Webster, S. and Zaykov, Y. and Yangel, B. and Spengler, A. and  Bronskill, J.",
    title = {{Infer.NET 2.6}},
    year = 2014,
    note = {Microsoft Research Cambridge. http://research.microsoft.com/infernet}
    }
  • Do I have to use C#?

    No.  You can use Infer.NET from any .NET language such as C#, C++/CLI, 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).

Modelling

  • 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?

    Non-parametric models, e.g. Dirichlet processes (except for Gaussian Processes which are supported).

Inference

  • 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), max product (for discrete models), and block Gibbs sampling.

  • 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 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.

Troubleshooting

  • 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.

  • Results are bad and I don't know why

    First determine if the problem is due to inference or modelling.  Generate a dataset by sampling from the model and see if you can recover the generating parameters, as done in the examples.  If you can recover them, then it is probably a modelling issue.  If not, check the following:

    1. Is there enough data?
    2. Does the model have a strong enough link between the parameters and the data for them to be recovered?  For example, is the noise level too high?
    3. Does the model have parameter symmetries, i.e. different settings of the parameters that produce the same data distribution?  See the Recommender System example.
    4. Has the inference algorithm converged?  You can determine this by running for different numbers of iterations.
    5. Try initializing the algorithm near the true values. If this helps, then the problem may have multiple solutions.
    6. Try a different inference algorithm.
    7. Try simplifying the model by observing some of the parameters to their true values.
©2009-2014 Microsoft Corporation. All rights reserved.  Terms of Use | Trademarks | Privacy Statement