Mittwoch, 28. März 2012 16:23
I'm currently experimenting a bit with Infer.Net, trying to use it for Bayesian networks (very much in the same way as the 'Sprinkler, Cloudy, Rain'-example that can be found in the tutorials).
I have a question regarding when the network decides to compile the Model. I assume that the ideal way is to: build a network, compile it once, and then run inference over it numerous times.
When I look at the messages (Engine.ShowProgress) I see that after I add a new ObservedValue to one of my Variables, and perform Inference, Infer.Net re-compiles the model (before running Inference).
When you look at the example that can be found in the tutorials ('Sprinkler, Cloudy, Rain'-example), and turn on 'ShowProgress, Infer.Net re-compiles the model for every new query of Inference.
For example the output of the first two queries, is like this:
Am I wrong in thinking that compiling the model should only happen once?
Thank you in advance for your help.
Mittwoch, 28. März 2012 16:36
Maybe a better question should be: Can I determine the posteriors of the network after adding Observed Values.
I understand that I would have to run Inference, but don't really agree on re-compiling the whole network again.
I've tried to do this in the following ways (both re compile the model):
// Adding observed values: ... myVariable1.ObservedValue = myObservedValue1; myVariable2.ObservedValue = myObservedValue2; ... // Running Inference - method 1: var myPosterior = Engine.Infer<Discrete>(myVariable1); Vector myProbs = myPosterior.GetProbs(); ... // Running Inference - method 2: var ca = Engine.GetCompiledInferenceAlgorithm(myVariable1); var myPosterior = ca.Marginal<Discrete>(myVariable1.NameInGeneratedCode);
Vector myProbs = myPosterior.GetProbs();
- Bearbeitet ThoFlam Mittwoch, 28. März 2012 16:38
Freitag, 30. März 2012 17:37Besitzer
A model is recompiled when the pattern of observations change, not when the observations themselves change. If you observe something one time, and not the next time, you are removing a constraint from the model, and the generated inference code to give the best approximation to the posterior must change also. To avoid recompilation, you should create a seperate instance of your model class for each pattern of observations. Then there will be one compilation for each pattern, but thereafter no more recompilations. In a typical simple situation, you have a model for which you (a) want to learn the parameters, then (b) fix the parameters and do predictions. In this case, create a model class that defines the model, along with methods to run (a) and (b), but then create two instances.
Mittwoch, 4. April 2012 16:46
Besides John Guiver's solution, another approach is to build the model to handle missing data. Then you do not have to recompile when the pattern of observations changes.