ExampleRV.TOOTHACHE_RV, Boolean.TRUE);
AssignmentProposition acatch = new AssignmentProposition(
ExampleRV.CATCH_RV, Boolean.TRUE);
AssignmentProposition acavity = new AssignmentProposition(
ExampleRV.CAVITY_RV, Boolean.TRUE);
ConjunctiveProposition sunnyAndCavity = new ConjunctiveProposition(
asunny, acavity);
// 0.6 (sunny) * 0.2 (cavity) = 0.12
Assert.assertEquals(0.12, model.prior(asunny, acavity), DELTA_THRESHOLD);
Assert.assertEquals(0.12, model.prior(sunnyAndCavity), DELTA_THRESHOLD);
// AIMA3e pg. 494
// P(toothache, catch, cavity, cloudy) =
// P(cloudy | toothache, catch, cavity)P(toothache, catch, cavity)
Assert.assertEquals(
model.prior(atoothache, acatch, acavity, acloudy),
model.posterior(acloudy, atoothache, acatch, acavity)
* model.prior(atoothache, acatch, acavity),
DELTA_THRESHOLD);
ConjunctiveProposition toothacheAndCatchAndCavityAndCloudy = new ConjunctiveProposition(
new ConjunctiveProposition(atoothache, acatch),
new ConjunctiveProposition(acavity, acloudy));
ConjunctiveProposition toothacheAndCatchAndCavity = new ConjunctiveProposition(
new ConjunctiveProposition(atoothache, acatch), acavity);
Assert.assertEquals(
model.prior(toothacheAndCatchAndCavityAndCloudy),
model.posterior(acloudy, atoothache, acatch, acavity)
* model.prior(toothacheAndCatchAndCavity),
DELTA_THRESHOLD);
// P(cloudy | toothache, catch, cavity) = P(cloudy)
// (13.10)
Assert.assertEquals(
model.posterior(acloudy, atoothache, acatch, acavity),
model.prior(acloudy), DELTA_THRESHOLD);
// P(toothache, catch, cavity, cloudy) =
// P(cloudy)P(tootache, catch, cavity)
Assert.assertEquals(
model.prior(atoothache, acatch, acavity, acloudy),
model.prior(acloudy) * model.prior(atoothache, acatch, acavity),
DELTA_THRESHOLD);
// P(a | b) = P(a)
Assert.assertEquals(model.posterior(acavity, acloudy),
model.prior(acavity), DELTA_THRESHOLD);
// P(b | a) = P(b)
Assert.assertEquals(model.posterior(acloudy, acavity),
model.prior(acloudy), DELTA_THRESHOLD);
// P(a AND b) = P(a)P(b)
Assert.assertEquals(model.prior(acavity, acloudy), model.prior(acavity)
* model.prior(acloudy), DELTA_THRESHOLD);
ConjunctiveProposition acavityAndacloudy = new ConjunctiveProposition(
acavity, acloudy);
Assert.assertEquals(model.prior(acavityAndacloudy),
model.prior(acavity) * model.prior(acloudy), DELTA_THRESHOLD);
}