public void testSampling3() { 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.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(x3, EventType.Outcome); query.setEventValue(x1, true); query.setEventValue(x3, true); query.execute(); testPercent(query.getProbability(), 50); }
public void testSampling1() { BayesianNetwork network = new BayesianNetwork(); BayesianEvent a = network.createEvent("a"); BayesianEvent b = network.createEvent("b"); network.createDependency(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); }
/** * Create a dependency between two labels. * * @param parentEventLabel The parent event. * @param childEventLabel The child event. */ public void createDependency(String parentEventLabel, String childEventLabel) { BayesianEvent parentEvent = getEventError(parentEventLabel); BayesianEvent childEvent = getEventError(childEventLabel); createDependency(parentEvent, childEvent); }