public void TestCount()
 {
     BayesianNetwork network = new BayesianNetwork();
     BayesianEvent a = network.CreateEvent("a");
     BayesianEvent b = network.CreateEvent("b");
     BayesianEvent c = network.CreateEvent("c");
     BayesianEvent d = network.CreateEvent("d");
     BayesianEvent e = network.CreateEvent("e");
     network.CreateDependency(a, b, d, e);
     network.CreateDependency(c, d);
     network.CreateDependency(b, e);
     network.CreateDependency(d, e);
     network.FinalizeStructure();
     Assert.AreEqual(16, network.CalculateParameterCount());
 }
예제 #2
0
        public void Execute(IExampleInterface app)
        {
            // build the bayesian network structure
            BayesianNetwork network = new BayesianNetwork();
            BayesianEvent BlueTaxi = network.CreateEvent("blue_taxi");
            BayesianEvent WitnessSawBlue = network.CreateEvent("saw_blue");
            network.CreateDependency(BlueTaxi, WitnessSawBlue);
            network.FinalizeStructure();
            // build the truth tales
            BlueTaxi.Table.AddLine(0.85, true);
            WitnessSawBlue.Table.AddLine(0.80, true, true);
            WitnessSawBlue.Table.AddLine(0.20, true, false);

            // validate the network
            network.Validate();
            // display basic stats
            Console.WriteLine(network.ToString());
            Console.WriteLine("Parameter count: " + network.CalculateParameterCount());
            EnumerationQuery query = new EnumerationQuery(network);
            //SamplingQuery query = new SamplingQuery(network);
            query.DefineEventType(WitnessSawBlue, EventType.Evidence);
            query.DefineEventType(BlueTaxi, EventType.Outcome);
            query.SetEventValue(WitnessSawBlue, false);
            query.SetEventValue(BlueTaxi, false);
            query.Execute();
            Console.WriteLine(query.ToString());
        }
예제 #3
0
        public void TestSampling2()
        {
            BayesianNetwork network = new BayesianNetwork();
            BayesianEvent a = network.CreateEvent("a");
            BayesianEvent x1 = network.CreateEvent("x1");
            BayesianEvent x2 = network.CreateEvent("x2");
            BayesianEvent x3 = network.CreateEvent("x3");

            network.CreateDependency(a, x1, x2, x3);
            network.FinalizeStructure();

            a.Table.AddLine(0.5, true); // P(A) = 0.5
            x1.Table.AddLine(0.2, true, true); // p(x1|a) = 0.2
            x1.Table.AddLine(0.6, true, false);// p(x1|~a) = 0.6
            x2.Table.AddLine(0.2, true, true); // p(x2|a) = 0.2
            x2.Table.AddLine(0.6, true, false);// p(x2|~a) = 0.6
            x3.Table.AddLine(0.2, true, true); // p(x3|a) = 0.2
            x3.Table.AddLine(0.6, true, false);// p(x3|~a) = 0.6
            network.Validate();

            SamplingQuery query = new SamplingQuery(network);
            query.DefineEventType(x1, EventType.Evidence);
            query.DefineEventType(x2, EventType.Evidence);
            query.DefineEventType(x3, EventType.Evidence);
            query.DefineEventType(a, EventType.Outcome);
            query.SetEventValue(a, true);
            query.SetEventValue(x1, true);
            query.SetEventValue(x2, true);
            query.SetEventValue(x3, false);
            query.Execute();
            TestPercent(query.Probability, 18);
        }
        public void TestIndependant()
        {
            BayesianNetwork network = new BayesianNetwork();
            BayesianEvent a = network.CreateEvent("a");
            BayesianEvent b = network.CreateEvent("b");
            BayesianEvent c = network.CreateEvent("c");
            BayesianEvent d = network.CreateEvent("d");
            BayesianEvent e = network.CreateEvent("e");
            network.CreateDependency(a, b, d, e);
            network.CreateDependency(c, d);
            network.CreateDependency(b, e);
            network.CreateDependency(d, e);
            network.FinalizeStructure();

            Assert.IsFalse(network.IsCondIndependent(c, e, a));
            Assert.IsFalse(network.IsCondIndependent(b, d, c, e));
            Assert.IsFalse(network.IsCondIndependent(a, c, e));
            Assert.IsTrue(network.IsCondIndependent(a, c, b));
        }
예제 #5
0
        public BayesianNetwork Create()
        {
            BayesianNetwork network = new BayesianNetwork();
            BayesianEvent a = network.CreateEvent("a");
            BayesianEvent b = network.CreateEvent("b");

            network.CreateDependency(a, b);
            network.FinalizeStructure();
            a.Table.AddLine(0.5, true); // P(A) = 0.5
            b.Table.AddLine(0.2, true, true); // p(b|a) = 0.2
            b.Table.AddLine(0.8, true, false);// p(b|~a) = 0.8
            network.Validate();
            return network;
        }
예제 #6
0
        public void TestSampling1()
        {
            BayesianNetwork network = new BayesianNetwork();
            BayesianEvent a = network.CreateEvent("a");
            BayesianEvent b = network.CreateEvent("b");

            network.CreateDependency(a, b);
            network.FinalizeStructure();
            a.Table.AddLine(0.5, true); // P(A) = 0.5
            b.Table.AddLine(0.2, true, true); // p(b|a) = 0.2
            b.Table.AddLine(0.8, true, false);// p(b|~a) = 0.8
            network.Validate();

            SamplingQuery query = new SamplingQuery(network);
            query.DefineEventType(a, EventType.Evidence);
            query.DefineEventType(b, EventType.Outcome);
            query.SetEventValue(b, true);
            query.SetEventValue(a, true);
            query.Execute();
            TestPercent(query.Probability, 20);
        }