locked
Flipping a coin example RRS feed

  • Question

  • I looked at the example given in the user guide (A simple example), and extended it to try and further my understanding of Infer.Net. I am a beginner when it comes to statistics, so if this is an absolute newbie question, my apologies.

    Variable<bool> firstCoin = Variable.Bernoulli(0.5).Named("firstCoin");
    Variable<bool> secondCoin = Variable.Bernoulli(0.5).Named("secondCoin");
    Variable<bool> thirdCoin = Variable.Bernoulli(0.5).Named("thirdCoin");
    Variable<bool> fourthCoin = Variable.Bernoulli(0.5).Named("fourthCoin");
     
    Variable<bool> fourHeads = (firstCoin & secondCoin & thirdCoin & fourthCoin).Named("fourHeads");
    Variable<bool> fourTails = (!firstCoin & !secondCoin & !thirdCoin & !fourthCoin).Named("fourTails");
     
    InferenceEngine ie = newInferenceEngine()
    {
        ShowFactorGraph = true,
        NumberOfIterations = 1000
    };
     
    Console.WriteLine("Probability four heads" + ie.Infer(fourHeads));
    Console.WriteLine("Probability four tails" + ie.Infer(fourTails));
    Console.WriteLine("Probability four same" + ie.Infer(fourHeads | fourTails));

    Output:

    Compiling model...done.
    Probability four headsBernoulli(0.0625)
    Probability four tailsBernoulli(0.0625)
    Compiling model...done.
    Probability four sameBernoulli(0.1211)

    If I look at the FactorGraphs, they look like I would expect. Also, the result for four head and four tales (1/2^4) - I understand.

    What I don't understand is the or ('|') of the heads and tales. How does it get to 0.1211 instead of 0.0625+0.0625 = 0.125?

    Thank you.

     

    Friday, April 5, 2013 5:53 PM

All replies