locked
Newbie question, playing with example #1 RRS feed

  • General discussion

  • Hello,

    I am new to infer.net, so I apologize if my questions are dumb (you've been warned ;-) )

    I've tried to add some coins to the example, and added some (naive) variables:

                Variable<bool> firstCoinHead = Variable.Bernoulli(0.5);
                Variable<bool> secondCoinHead = Variable.Bernoulli(0.5);
                Variable<bool> thirdCoinHead = Variable.Bernoulli(0.5);
                Variable<bool> FourthCoinHead = Variable.Bernoulli(0.5);

                Variable<bool> oneHead = firstCoinHead | secondCoinHead | thirdCoinHead | FourthCoinHead;
                Variable<bool> twoHead = (firstCoinHead & secondCoinHead) | (secondCoinHead & thirdCoinHead) | (thirdCoinHead & FourthCoinHead) | (FourthCoinHead & firstCoinHead);
                Variable<bool> threeHead = (firstCoinHead & secondCoinHead) | (secondCoinHead & thirdCoinHead) | (thirdCoinHead & FourthCoinHead) | (FourthCoinHead & firstCoinHead);

                InferenceEngine ie = new InferenceEngine();

                twoHead.ObservedValue = false;

                Console.WriteLine("oneHead: " + ie.Infer(oneHead));
                Console.WriteLine("twoHead: " + ie.Infer(twoHead));
                Console.WriteLine("threeHead: " + ie.Infer(threeHead));

    ...

    My problem is that, although both twoHead and threeHead are equal it gives me:

    oneHead: Bernoulli(0,7258)
    twoHead: Bernoulli(0)
    threeHead: Bernoulli(0,2723)

    ...

    My understanding was that threeHead was supposed to be equal to twoHead... :-S

    My fear is that if I try to build on this engine and work on a more complex network, I'll get in the end some wrong meaningless numbers.

    • Edited by dumesnil Wednesday, February 29, 2012 6:41 PM
    Wednesday, February 29, 2012 6:04 PM

All replies

  • The posteriors on twoHead and threeHead should not be equal. You are observing twoHead to be false, so the posterior on twoHead must be Bernoulli(0). This observation means that posteriors on firstCoinHead etc are correctly reduced (if you run ie.Infer(firstCoinHead) you will get a Bernoulli(0.2764) and likewise the others). threeHead on the other hand is not constrained but its posterior will be affected by the observation on twoHead via the dependency on firstCoinHead etc.

    Having said that, there are situations where you need to be careful with approximate inference with such logic problems. Please see the thread at http://social.microsoft.com/Forums/en-US/infer.net/thread/ffaa6ffd-498e-41e8-8787-011b16be348f.

    John

    Friday, March 2, 2012 9:29 AM
    Owner