예제 #1
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.createDependancy(a, x1, x2, x3);
    network.finalizeStructure();

    a.getTable().addLine(0.5, true); // P(A) = 0.5
    x1.getTable().addLine(0.2, true, true); // p(x1|a) = 0.2
    x1.getTable().addLine(0.6, true, false); // p(x1|~a) = 0.6
    x2.getTable().addLine(0.2, true, true); // p(x2|a) = 0.2
    x2.getTable().addLine(0.6, true, false); // p(x2|~a) = 0.6
    x3.getTable().addLine(0.2, true, true); // p(x3|a) = 0.2
    x3.getTable().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.getProbability(), 18);
  }
예제 #2
0
  public void testSampling1() {
    BayesianNetwork network = new BayesianNetwork();
    BayesianEvent a = network.createEvent("a");
    BayesianEvent b = network.createEvent("b");

    network.createDependancy(a, b);
    network.finalizeStructure();
    a.getTable().addLine(0.5, true); // P(A) = 0.5
    b.getTable().addLine(0.2, true, true); // p(b|a) = 0.2
    b.getTable().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.getProbability(), 20);
  }