001    /*
002     * Created on Dec 28, 2004
003     *
004     */
005    package aima.test.probabilitytest;
006    
007    import junit.framework.TestCase;
008    import aima.probability.EnumerateJointAsk;
009    import aima.probability.ProbabilityDistribution;
010    import aima.probability.Query;
011    
012    /**
013     * @author Ravi Mohan
014     * 
015     */
016    
017    public class EnumerationJointAskTest extends TestCase {
018    
019            public void testBasicUsage() {
020                    // >>> P[T, T, T] = 0.108; P[T, T, F] = 0.012; P[F, T, T] = 0.072; P[F,
021                    // T, F] = 0.008
022                    // >>> P[T, F, T] = 0.016; P[T, F, F] = 0.064; P[F, F, T] = 0.144; P[F,
023                    // F, F] = 0.576
024    
025                    ProbabilityDistribution jp = new ProbabilityDistribution("ToothAche",
026                                    "Cavity", "Catch");
027                    jp.set(true, true, true, 0.108);
028                    jp.set(true, true, false, 0.012);
029                    jp.set(false, true, true, 0.072);
030                    jp.set(false, true, false, 0.008);
031                    jp.set(true, false, true, 0.016);
032                    jp.set(true, false, false, 0.064);
033                    jp.set(false, false, true, 0.144);
034                    jp.set(false, false, false, 0.008);
035    
036                    Query q = new Query("Cavity", new String[] { "ToothAche" },
037                                    new boolean[] { true });
038                    double[] probs = EnumerateJointAsk.ask(q, jp);
039                    assertEquals(0.6, probs[0], 0.001);
040                    assertEquals(0.4, probs[1], 0.001);
041    
042            }
043    
044    }