Examples of AssignmentProposition


Examples of aima.core.probability.proposition.AssignmentProposition

    // AIMA3e pg. 533
    // <b>P</b>(Rain | Cloudy = true, WetGrass = true)
    BayesianNetwork bn = BayesNetExampleFactory
        .constructCloudySprinklerRainWetGrassNetwork();
    AssignmentProposition[] e = new AssignmentProposition[] {
        new AssignmentProposition(ExampleRV.CLOUDY_RV, Boolean.TRUE),
        new AssignmentProposition(ExampleRV.WET_GRASS_RV, Boolean.TRUE) };
    // sample P(Sprinkler | Cloudy = true) = <0.1, 0.9>; suppose
    // Sprinkler=false
    // sample P(Rain | Cloudy = true) = <0.8, 0.2>; suppose Rain=true
    MockRandomizer r = new MockRandomizer(new double[] { 0.5, 0.5 });
View Full Code Here

Examples of aima.core.probability.proposition.AssignmentProposition

        ProbabilityModel.DEFAULT_ROUNDING_THRESHOLD);

    // AIMA3e pg. 493
    // P(Cavity | toothache) = <0.6, 0.4>
    d = bayesInference.ask(new RandomVariable[] { ExampleRV.CAVITY_RV },
        new AssignmentProposition[] { new AssignmentProposition(
            ExampleRV.TOOTHACHE_RV, true) }, bn);

    // System.out.println("P(Cavity | toothache)=" + d);
    Assert.assertEquals(2, d.getValues().length);
    Assert.assertEquals(0.6, d.getValues()[0],
        ProbabilityModel.DEFAULT_ROUNDING_THRESHOLD);
    Assert.assertEquals(0.4, d.getValues()[1],
        ProbabilityModel.DEFAULT_ROUNDING_THRESHOLD);

    // AIMA3e pg. 497
    // P(Cavity | toothache AND catch) = <0.871, 0.129>
    d = bayesInference
        .ask(new RandomVariable[] { ExampleRV.CAVITY_RV },
            new AssignmentProposition[] {
                new AssignmentProposition(
                    ExampleRV.TOOTHACHE_RV, true),
                new AssignmentProposition(ExampleRV.CATCH_RV,
                    true) }, bn);

    // System.out.println("P(Cavity | toothache, catch)=" + d);
    Assert.assertEquals(2, d.getValues().length);
    Assert.assertEquals(0.8709677419354839, d.getValues()[0],
View Full Code Here

Examples of aima.core.probability.proposition.AssignmentProposition

    // AIMA3e. pg. 514
    CategoricalDistribution d = bayesInference
        .ask(new RandomVariable[] { ExampleRV.ALARM_RV },
            new AssignmentProposition[] {
                new AssignmentProposition(
                    ExampleRV.BURGLARY_RV, false),
                new AssignmentProposition(
                    ExampleRV.EARTHQUAKE_RV, false),
                new AssignmentProposition(
                    ExampleRV.JOHN_CALLS_RV, true),
                new AssignmentProposition(
                    ExampleRV.MARY_CALLS_RV, true) }, bn);

    // System.out.println("P(Alarm | ~b, ~e, j, m)=" + d);
    Assert.assertEquals(2, d.getValues().length);
    Assert.assertEquals(0.5577689243027888, d.getValues()[0],
        ProbabilityModel.DEFAULT_ROUNDING_THRESHOLD);
    Assert.assertEquals(0.44223107569721115, d.getValues()[1],
        ProbabilityModel.DEFAULT_ROUNDING_THRESHOLD);

    // AIMA3e pg. 523
    // P(Burglary | JohnCalls = true, MaryCalls = true) = <0.284, 0.716>
    d = bayesInference
        .ask(new RandomVariable[] { ExampleRV.BURGLARY_RV },
            new AssignmentProposition[] {
                new AssignmentProposition(
                    ExampleRV.JOHN_CALLS_RV, true),
                new AssignmentProposition(
                    ExampleRV.MARY_CALLS_RV, true) }, bn);

    // System.out.println("P(Burglary | j, m)=" + d);
    Assert.assertEquals(2, d.getValues().length);
    Assert.assertEquals(0.2841718353643929, d.getValues()[0],
        ProbabilityModel.DEFAULT_ROUNDING_THRESHOLD);
    Assert.assertEquals(0.7158281646356071, d.getValues()[1],
        ProbabilityModel.DEFAULT_ROUNDING_THRESHOLD);

    // AIMA3e pg. 528
    // P(JohnCalls | Burglary = true)
    d = bayesInference.ask(
        new RandomVariable[] { ExampleRV.JOHN_CALLS_RV },
        new AssignmentProposition[] { new AssignmentProposition(
            ExampleRV.BURGLARY_RV, true) }, bn);
    // System.out.println("P(JohnCalls | b)=" + d);
    Assert.assertEquals(2, d.getValues().length);
    Assert.assertEquals(0.8490169999999999, d.getValues()[0],
        ProbabilityModel.DEFAULT_ROUNDING_THRESHOLD);
View Full Code Here

Examples of aima.core.probability.proposition.AssignmentProposition

  @Test
  public void testGibbsAsk_basic() {
    BayesianNetwork bn = BayesNetExampleFactory
        .constructCloudySprinklerRainWetGrassNetwork();
    AssignmentProposition[] e = new AssignmentProposition[] { new AssignmentProposition(
        ExampleRV.SPRINKLER_RV, Boolean.TRUE) };
    MockRandomizer r = new MockRandomizer(new double[] { 0.5, 0.5, 0.5,
        0.5, 0.5, 0.5, 0.6, 0.5, 0.5, 0.6, 0.5, 0.5 });

    GibbsAsk ga = new GibbsAsk(r);
View Full Code Here

Examples of aima.core.probability.proposition.AssignmentProposition

  @Test
  public void testPriorSample_basic() {

    BayesianNetwork bn = BayesNetExampleFactory
        .constructCloudySprinklerRainWetGrassNetwork();
    AssignmentProposition[] e = new AssignmentProposition[] { new AssignmentProposition(
        ExampleRV.SPRINKLER_RV, Boolean.TRUE) };
    MockRandomizer r = new MockRandomizer(new double[] { 0.1 });
    RejectionSampling rs = new RejectionSampling(new PriorSample(r));

    double[] estimate = rs.rejectionSampling(
View Full Code Here

Examples of aima.core.probability.proposition.AssignmentProposition

  public void testRejectionSampling_AIMA3e_pg532() {
    // AIMA3e pg. 532

    BayesianNetwork bn = BayesNetExampleFactory
        .constructCloudySprinklerRainWetGrassNetwork();
    AssignmentProposition[] e = new AssignmentProposition[] { new AssignmentProposition(
        ExampleRV.SPRINKLER_RV, Boolean.TRUE) };

    // 400 required as 4 variables and 100 samples planned
    double[] ma = new double[400];
    for (int i = 0; i < ma.length; i += 4) {
View Full Code Here

Examples of aima.core.probability.proposition.AssignmentProposition

        return null; // N/A
      }
    };

    answer.clear();
    ptABC.iterateOverTable(pti, new AssignmentProposition(aRV, true));
    Assert.assertEquals(1111.0, sumOf(answer), DELTA_THRESHOLD);

    answer.clear();
    ptABC.iterateOverTable(pti, new AssignmentProposition(aRV, false));
    Assert.assertEquals(11110000.0, sumOf(answer), DELTA_THRESHOLD);

    answer.clear();
    ptABC.iterateOverTable(pti, new AssignmentProposition(bRV, true));
    Assert.assertEquals(110011.0, sumOf(answer), DELTA_THRESHOLD);

    answer.clear();
    ptABC.iterateOverTable(pti, new AssignmentProposition(bRV, false));
    Assert.assertEquals(11001100.0, sumOf(answer), DELTA_THRESHOLD);

    answer.clear();
    ptABC.iterateOverTable(pti, new AssignmentProposition(cRV, true));
    Assert.assertEquals(1010101.0, sumOf(answer), DELTA_THRESHOLD);

    answer.clear();
    ptABC.iterateOverTable(pti, new AssignmentProposition(cRV, false));
    Assert.assertEquals(10101010.0, sumOf(answer), DELTA_THRESHOLD);

    answer.clear();
    ptABC.iterateOverTable(pti, new AssignmentProposition(bRV, true),
        new AssignmentProposition(cRV, true));
    Assert.assertEquals(10001.0, sumOf(answer), DELTA_THRESHOLD);
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.