protected void test_RollingPairFairDiceModel_Distributions(
FiniteProbabilityModel model) {
AssignmentProposition ad1_1 = new AssignmentProposition(
ExampleRV.DICE_1_RV, 1);
CategoricalDistribution dD1_1 = model.priorDistribution(ad1_1);
Assert.assertArrayEquals(new double[] { 1.0 / 6.0 }, dD1_1.getValues(),
DELTA_THRESHOLD);
CategoricalDistribution dPriorDice1 = model
.priorDistribution(ExampleRV.DICE_1_RV);
Assert.assertArrayEquals(new double[] { 1.0 / 6.0, 1.0 / 6.0,
1.0 / 6.0, 1.0 / 6.0, 1.0 / 6.0, 1.0 / 6.0 },
dPriorDice1.getValues(), DELTA_THRESHOLD);
CategoricalDistribution dPriorDice2 = model
.priorDistribution(ExampleRV.DICE_2_RV);
Assert.assertArrayEquals(new double[] { 1.0 / 6.0, 1.0 / 6.0,
1.0 / 6.0, 1.0 / 6.0, 1.0 / 6.0, 1.0 / 6.0 },
dPriorDice2.getValues(), DELTA_THRESHOLD);
CategoricalDistribution dJointDice1Dice2 = model.jointDistribution(
ExampleRV.DICE_1_RV, ExampleRV.DICE_2_RV);
Assert.assertEquals(36, dJointDice1Dice2.getValues().length);
for (int i = 0; i < dJointDice1Dice2.getValues().length; i++) {
Assert.assertEquals(1.0 / 36.0, dJointDice1Dice2.getValues()[i],
DELTA_THRESHOLD);
}
CategoricalDistribution dJointDice2Dice1 = model.jointDistribution(
ExampleRV.DICE_2_RV, ExampleRV.DICE_1_RV);
Assert.assertEquals(36, dJointDice2Dice1.getValues().length);
for (int i = 0; i < dJointDice2Dice1.getValues().length; i++) {
Assert.assertEquals(1.0 / 36.0, dJointDice2Dice1.getValues()[i],
DELTA_THRESHOLD);
}
//
// Test Sets of events
IntegerSumProposition total11 = new IntegerSumProposition("Total",
new FiniteIntegerDomain(11), ExampleRV.DICE_1_RV,
ExampleRV.DICE_2_RV);
// P<>(Total = 11) = <2.0/36.0>
Assert.assertArrayEquals(new double[] { 2.0 / 36.0 }, model
.priorDistribution(total11).getValues(), DELTA_THRESHOLD);
// P<>(Dice1, Total = 11)
// = <0.0, 0.0, 0.0, 0.0, 1.0/36.0, 1.0/36.0>
Assert.assertArrayEquals(new double[] { 0, 0, 0, 0, 1.0 / 36.0,
1.0 / 36.0 },
model.priorDistribution(ExampleRV.DICE_1_RV, total11)
.getValues(), DELTA_THRESHOLD);
EquivalentProposition doubles = new EquivalentProposition("Doubles",
ExampleRV.DICE_1_RV, ExampleRV.DICE_2_RV);
// P(Doubles) = <1.0/6.0>
Assert.assertArrayEquals(new double[] { 1.0 / 6.0 }, model
.priorDistribution(doubles).getValues(), DELTA_THRESHOLD);
//
// Test posterior
//
// P<>(Dice1, Total = 11)
// = <0.0, 0.0, 0.0, 0.0, 0.5, 0.5>
Assert.assertArrayEquals(new double[] { 0, 0, 0, 0, 0.5, 0.5 }, model
.posteriorDistribution(ExampleRV.DICE_1_RV, total11)
.getValues(), DELTA_THRESHOLD);
// P<>(Dice1 | Doubles) = <1/6, 1/6, 1/6, 1/6, 1/6, 1/6>
Assert.assertArrayEquals(new double[] { 1.0 / 6.0, 1.0 / 6.0,
1.0 / 6.0, 1.0 / 6.0, 1.0 / 6.0, 1.0 / 6.0 }, model
.posteriorDistribution(ExampleRV.DICE_1_RV, doubles)
.getValues(), DELTA_THRESHOLD);
CategoricalDistribution dPosteriorDice1GivenDice2 = model
.posteriorDistribution(ExampleRV.DICE_1_RV, ExampleRV.DICE_2_RV);
Assert.assertEquals(36, dPosteriorDice1GivenDice2.getValues().length);
for (int i = 0; i < dPosteriorDice1GivenDice2.getValues().length; i++) {
Assert.assertEquals(1.0 / 6.0,
dPosteriorDice1GivenDice2.getValues()[i], DELTA_THRESHOLD);
}
CategoricalDistribution dPosteriorDice2GivenDice1 = model
.posteriorDistribution(ExampleRV.DICE_2_RV, ExampleRV.DICE_1_RV);
Assert.assertEquals(36, dPosteriorDice2GivenDice1.getValues().length);
for (int i = 0; i < dPosteriorDice2GivenDice1.getValues().length; i++) {
Assert.assertEquals(1.0 / 6.0,
dPosteriorDice2GivenDice1.getValues()[i], DELTA_THRESHOLD);
}
}