예제 #1
0
 public void test_ToothacheCavityCatchModel_Distributions()
 {
     foreach (IBayesInference bi in getBayesInferenceImplementations())
     {
         test_ToothacheCavityCatchModel_Distributions(new FiniteBayesModel(
                                                          BayesNetExampleFactory
                                                          .constructToothacheCavityCatchNetwork(),
                                                          bi));
     }
 }
 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("===========================");
 }
예제 #3
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("=====================");
 } 
예제 #4
0
        public void testInferenceOnToothacheCavityCatchNetwork()
        {
            IBayesianNetwork bn = BayesNetExampleFactory
                                  .constructToothacheCavityCatchNetwork();

            ICategoricalDistribution d = bayesInference.Ask(
                new IRandomVariable[] { ExampleRV.CAVITY_RV },
                new AssignmentProposition[] { }, bn);

            // System.Console.WriteLine("P(Cavity)=" + d);
            Assert.AreEqual(2, d.getValues().Length);
            Assert.AreEqual(0.2, d.getValues()[0],
                            ProbabilityModelImpl.DEFAULT_ROUNDING_THRESHOLD);
            Assert.AreEqual(0.8, d.getValues()[1],
                            ProbabilityModelImpl.DEFAULT_ROUNDING_THRESHOLD);

            // AIMA3e pg. 493
            // P(Cavity | toothache) = <0.6, 0.4>
            d = bayesInference.Ask(new IRandomVariable[] { ExampleRV.CAVITY_RV },
                                   new AssignmentProposition[] { new AssignmentProposition(
                                                                     ExampleRV.TOOTHACHE_RV, true) }, bn);

            // System.Console.WriteLine("P(Cavity | toothache)=" + d);
            Assert.AreEqual(2, d.getValues().Length);
            Assert.AreEqual(0.6, d.getValues()[0],
                            ProbabilityModelImpl.DEFAULT_ROUNDING_THRESHOLD);
            Assert.AreEqual(0.4, d.getValues()[1],
                            ProbabilityModelImpl.DEFAULT_ROUNDING_THRESHOLD);

            // AIMA3e pg. 497
            // P(Cavity | toothache AND catch) = <0.871, 0.129>
            d = bayesInference
                .Ask(new IRandomVariable[] { ExampleRV.CAVITY_RV },
                     new AssignmentProposition[] {
                new AssignmentProposition(
                    ExampleRV.TOOTHACHE_RV, true),
                new AssignmentProposition(ExampleRV.CATCH_RV,
                                          true)
            }, bn);

            // System.Console.WriteLine("P(Cavity | toothache, catch)=" + d);
            Assert.AreEqual(2, d.getValues().Length);
            Assert.AreEqual(0.8709677419354839, d.getValues()[0],
                            ProbabilityModelImpl.DEFAULT_ROUNDING_THRESHOLD);
            Assert.AreEqual(0.12903225806451615, d.getValues()[1],
                            ProbabilityModelImpl.DEFAULT_ROUNDING_THRESHOLD);
        }