AIMA.Test.Core.Unit.Probability.CommonProbabilityModelTests.test_ToothacheCavityCatchModel C# (CSharp) Метод

test_ToothacheCavityCatchModel() защищенный Метод

protected test_ToothacheCavityCatchModel ( ProbabilityModel model ) : void
model AIMA.Probability.ProbabilityModel
Результат void
        protected void test_ToothacheCavityCatchModel(ProbabilityModel model)
        {
            Assert.IsTrue(model.isValid());

            AssignmentProposition atoothache = new AssignmentProposition(
                ExampleRV.TOOTHACHE_RV, Boolean.TRUE);
            AssignmentProposition anottoothache = new AssignmentProposition(
                ExampleRV.TOOTHACHE_RV, Boolean.FALSE);
            AssignmentProposition acavity = new AssignmentProposition(
                ExampleRV.CAVITY_RV, Boolean.TRUE);
            AssignmentProposition anotcavity = new AssignmentProposition(
                ExampleRV.CAVITY_RV, Boolean.FALSE);
            AssignmentProposition acatch = new AssignmentProposition(
                ExampleRV.CATCH_RV, Boolean.TRUE);
            AssignmentProposition anotcatch = new AssignmentProposition(
                ExampleRV.CATCH_RV, Boolean.FALSE);

            // AIMA3e pg. 485
            Assert.AreEqual(0.2, model.prior(acavity), DELTA_THRESHOLD);
            Assert.AreEqual(0.6, model.posterior(acavity, atoothache),
                            DELTA_THRESHOLD);
            ConjunctiveProposition toothacheAndNotCavity = new ConjunctiveProposition(
                atoothache, anotcavity);
            Assert.AreEqual(0.0,
                            model.posterior(acavity, toothacheAndNotCavity),
                            DELTA_THRESHOLD);
            Assert.AreEqual(0.0,
                            model.posterior(acavity, atoothache, anotcavity),
                            DELTA_THRESHOLD);

            // AIMA3e pg. 492
            DisjunctiveProposition cavityOrToothache = new DisjunctiveProposition(
                acavity, atoothache);
            Assert.AreEqual(0.28, model.prior(cavityOrToothache),
                            DELTA_THRESHOLD);

            // AIMA3e pg. 493
            Assert.AreEqual(0.4, model.posterior(anotcavity, atoothache),
                            DELTA_THRESHOLD);

            Assert.AreEqual(1.0, model.prior(ExampleRV.TOOTHACHE_RV),
                            DELTA_THRESHOLD);
            Assert.AreEqual(1.0, model.prior(ExampleRV.CAVITY_RV),
                            DELTA_THRESHOLD);
            Assert.AreEqual(1.0, model.prior(ExampleRV.CATCH_RV),
                            DELTA_THRESHOLD);
            Assert.AreEqual(1.0,
                            model.posterior(ExampleRV.TOOTHACHE_RV, ExampleRV.CAVITY_RV),
                            DELTA_THRESHOLD);
            Assert.AreEqual(1.0,
                            model.posterior(ExampleRV.TOOTHACHE_RV, ExampleRV.CATCH_RV),
                            DELTA_THRESHOLD);
            Assert.AreEqual(1.0, model.posterior(ExampleRV.TOOTHACHE_RV,
                                                 ExampleRV.CAVITY_RV, ExampleRV.CATCH_RV), DELTA_THRESHOLD);
            Assert.AreEqual(1.0,
                            model.posterior(ExampleRV.CAVITY_RV, ExampleRV.TOOTHACHE_RV),
                            DELTA_THRESHOLD);
            Assert.AreEqual(1.0,
                            model.posterior(ExampleRV.CAVITY_RV, ExampleRV.CATCH_RV),
                            DELTA_THRESHOLD);
            Assert.AreEqual(1.0, model.posterior(ExampleRV.CAVITY_RV,
                                                 ExampleRV.TOOTHACHE_RV, ExampleRV.CATCH_RV), DELTA_THRESHOLD);
            Assert.AreEqual(1.0,
                            model.posterior(ExampleRV.CATCH_RV, ExampleRV.CAVITY_RV),
                            DELTA_THRESHOLD);
            Assert.AreEqual(1.0,
                            model.posterior(ExampleRV.CATCH_RV, ExampleRV.TOOTHACHE_RV),
                            DELTA_THRESHOLD);
            Assert.AreEqual(1.0, model.posterior(ExampleRV.CATCH_RV,
                                                 ExampleRV.CAVITY_RV, ExampleRV.TOOTHACHE_RV), DELTA_THRESHOLD);

            // AIMA3e pg. 495 - Bayes' Rule
            // P(b|a) = P(a|b)P(b)/P(a)
            Assert.AreEqual(model.posterior(acavity, atoothache),
                            (model.posterior(atoothache, acavity) * model.prior(acavity))
                            / model.prior(atoothache), DELTA_THRESHOLD);
            Assert.AreEqual(
                model.posterior(acavity, anottoothache),
                (model.posterior(anottoothache, acavity) * model.prior(acavity))
                / model.prior(anottoothache), DELTA_THRESHOLD);
            Assert.AreEqual(
                model.posterior(anotcavity, atoothache),
                (model.posterior(atoothache, anotcavity) * model
                                                             .prior(anotcavity)) / model.prior(atoothache),
                DELTA_THRESHOLD);
            Assert.AreEqual(
                model.posterior(anotcavity, anottoothache),
                (model.posterior(anottoothache, anotcavity) * model
                                                                .prior(anotcavity)) / model.prior(anottoothache),
                DELTA_THRESHOLD);
            //
            Assert.AreEqual(model.posterior(acavity, acatch),
                            (model.posterior(acatch, acavity) * model.prior(acavity))
                            / model.prior(acatch), DELTA_THRESHOLD);
            Assert.AreEqual(model.posterior(acavity, anotcatch),
                            (model.posterior(anotcatch, acavity) * model.prior(acavity))
                            / model.prior(anotcatch), DELTA_THRESHOLD);
            Assert.AreEqual(model.posterior(anotcavity, acatch),
                            (model.posterior(acatch, anotcavity) * model.prior(anotcavity))
                            / model.prior(acatch), DELTA_THRESHOLD);
            Assert.AreEqual(
                model.posterior(anotcavity, anotcatch),
                (model.posterior(anotcatch, anotcavity) * model
                                                            .prior(anotcavity)) / model.prior(anotcatch),
                DELTA_THRESHOLD);
        }