none
Basic Network Model Setup involving discrete choices

    Domanda

  • Hello,

      I'm new to the concept of Probabilistic Programming and am having an issue setting up basic networks involving discrete choices.

    As a simple model I have a variable A, which can be 0 or 1.  If A is 0, B is true; if A is 1, C is true. If either B or C is true, then D will be true.

    When inferring the value of D, I would expect to get an answer of Bernoulli(1) because D is always true regardless of the value of A.  Instead,  I get something smaller depending on the initial distribution of A.  Could you give me any guidance on the correct way to specify this network?

    Below is my implementation which leads to the incorrect value of .75.

    Thanks!

    static void Main(string[] args)
    {
    	Variable<int> a = Variable.Discrete(new double[] { 0.5, 0.5 });
    	Variable<bool> b = Variable.New<bool>();
    	Variable<bool> c = Variable.New<bool>();
    	Variable<bool> d = Variable.New<bool>();
    	using (Variable.Case(a, 0))
    	{
    		b.SetTo(true);
    		c.SetTo(false);
    	}
    	using (Variable.Case(a, 1))
    	{
    		b.SetTo(false);
    		c.SetTo(true);
    	}
    	d = b | c;
    	InferenceEngine ie = new InferenceEngine();
    	Console.WriteLine("d: " + ie.Infer(d)); //d = Bernoulli(.75) should be Bernoulli(1)
    }
    

     

    giovedì 29 settembre 2011 01:20

Tutte le risposte

  • Hi

    A very similar problem is described in this thread: http://social.microsoft.com/Forums/en-US/infer.net/thread/ffaa6ffd-498e-41e8-8787-011b16be348f As with that model, your model has a deterministic loop which is difficult for the approximate inference algorithms in Infer.NET to handle. You can also see this as a problem with the factorisation assumptions being made: the approximate marginal for both b and c will be Bernoulli(.5). One way to improve the accuracy of the inference is to use gates to induce a more structured approximation, as described in Section 5 of this paper: http://research.microsoft.com/apps/pubs/default.aspx?id=78857. On your example this would look this:

                Variable<int> a = Variable.Discrete(new double[] { 0.5, 0.5 });
                Variable<bool> b = Variable.New<bool>();
                Variable<bool> c = Variable.New<bool>();
                Variable<bool> d = Variable.New<bool>();
                using (Variable.Case(a, 0))
                {
                    b.SetTo(true);
                    c.SetTo(false);
                    d = b | c;
                }
                using (Variable.Case(a, 1))
                {
                    b.SetTo(false);
                    c.SetTo(true);
                    d = b | c;
                }
                InferenceEngine ie = new InferenceEngine();
                Console.WriteLine("b: " + ie.Infer(b)); // d = Bernoulli(1)
    

    This gives the exact answer. Note that you can also get the exact answer in this case using Gibbs sampling simply by setting your InferenceEngine as follows:

    InferenceEngine ie = new InferenceEngine(new GibbsSampling());
    

    Hope that helps!

    David and the Infer.NET team.

     

     

    giovedì 29 settembre 2011 14:08