public void test_BurglaryAlarmModel_Distributions()
 {
     foreach (IBayesInference bi in getBayesInferenceImplementations())
     {
         test_BurglaryAlarmModel_Distributions(new FiniteBayesModel(
                                                   BayesNetExampleFactory.constructBurglaryAlarmNetwork(), bi));
     }
 }
示例#2
0
        public void testInferenceOnBurglaryAlarmNetwork()
        {
            IBayesianNetwork bn = BayesNetExampleFactory
                                  .constructBurglaryAlarmNetwork();

            // AIMA3e. pg. 514
            ICategoricalDistribution d = bayesInference
                                         .Ask(new IRandomVariable[] { ExampleRV.ALARM_RV },
                                              new AssignmentProposition[] {
                new AssignmentProposition(
                    ExampleRV.BURGLARY_RV, false),
                new AssignmentProposition(
                    ExampleRV.EARTHQUAKE_RV, false),
                new AssignmentProposition(
                    ExampleRV.JOHN_CALLS_RV, true),
                new AssignmentProposition(
                    ExampleRV.MARY_CALLS_RV, true)
            }, bn);

            // System.Console.WriteLine("P(Alarm | ~b, ~e, j, m)=" + d);
            Assert.AreEqual(2, d.getValues().Length);
            Assert.AreEqual(0.5577689243027888, d.getValues()[0],
                            ProbabilityModelImpl.DEFAULT_ROUNDING_THRESHOLD);
            Assert.AreEqual(0.44223107569721115, d.getValues()[1],
                            ProbabilityModelImpl.DEFAULT_ROUNDING_THRESHOLD);

            // AIMA3e pg. 523
            // P(Burglary | JohnCalls = true, MaryCalls = true) = <0.284, 0.716>
            d = bayesInference
                .Ask(new IRandomVariable[] { ExampleRV.BURGLARY_RV },
                     new AssignmentProposition[] {
                new AssignmentProposition(
                    ExampleRV.JOHN_CALLS_RV, true),
                new AssignmentProposition(
                    ExampleRV.MARY_CALLS_RV, true)
            }, bn);

            // System.Console.WriteLine("P(Burglary | j, m)=" + d);
            Assert.AreEqual(2, d.getValues().Length);
            Assert.AreEqual(0.2841718353643929, d.getValues()[0],
                            ProbabilityModelImpl.DEFAULT_ROUNDING_THRESHOLD);
            Assert.AreEqual(0.7158281646356071, d.getValues()[1],
                            ProbabilityModelImpl.DEFAULT_ROUNDING_THRESHOLD);

            // AIMA3e pg. 528
            // P(JohnCalls | Burglary = true)
            d = bayesInference.Ask(
                new IRandomVariable[] { ExampleRV.JOHN_CALLS_RV },
                new AssignmentProposition[] { new AssignmentProposition(
                                                  ExampleRV.BURGLARY_RV, true) }, bn);
            // System.Console.WriteLine("P(JohnCalls | b)=" + d);
            Assert.AreEqual(2, d.getValues().Length);
            Assert.AreEqual(0.8490169999999999, d.getValues()[0],
                            ProbabilityModelImpl.DEFAULT_ROUNDING_THRESHOLD);
            Assert.AreEqual(0.15098299999999998, d.getValues()[1],
                            ProbabilityModelImpl.DEFAULT_ROUNDING_THRESHOLD);
        }
 static void bayesEnumerationAskDemo()
 {
     System.Console.WriteLine("DEMO: Bayes Enumeration Ask");
     System.Console.WriteLine("===========================");
     demoToothacheCavityCatchModel(new FiniteBayesModel(
                                       BayesNetExampleFactory.constructToothacheCavityCatchNetwork(),
                                       new EnumerationAsk()));
     demoBurglaryAlarmModel(new FiniteBayesModel(
                                BayesNetExampleFactory.constructBurglaryAlarmNetwork(),
                                new EnumerationAsk()));
     System.Console.WriteLine("===========================");
 }
示例#4
0
 static void bayesGibbsAskDemo()
 {
     System.Console.WriteLine("DEMO: Bayes Gibbs Ask N = " + NUM_SAMPLES);
     System.Console.WriteLine("=====================");
     demoToothacheCavityCatchModel(new FiniteBayesModel(
             BayesNetExampleFactory.constructToothacheCavityCatchNetwork(),
             new BayesInferenceApproxAdapter(new GibbsAsk(), NUM_SAMPLES)));
     demoBurglaryAlarmModel(new FiniteBayesModel(
             BayesNetExampleFactory.constructBurglaryAlarmNetwork(),
             new BayesInferenceApproxAdapter(new GibbsAsk(), NUM_SAMPLES)));
     System.Console.WriteLine("=====================");
 }