Package aima.core.probability.proposition

Examples of aima.core.probability.proposition.ConjunctiveProposition


  public double posterior(Proposition phi, Proposition... evidence) {

    Proposition conjEvidence = ProbUtil.constructConjunction(evidence);

    // P(A | B) = P(A AND B)/P(B) - (13.3 AIMA3e)
    Proposition aAndB = new ConjunctiveProposition(phi, conjEvidence);
    double probabilityOfEvidence = prior(conjEvidence);
    if (0 != probabilityOfEvidence) {
      return prior(aAndB) / probabilityOfEvidence;
    }
View Full Code Here


  public double posterior(Proposition phi, Proposition... evidence) {

    Proposition conjEvidence = ProbUtil.constructConjunction(evidence);

    // P(A | B) = P(A AND B)/P(B) - (13.3 AIMA3e)
    Proposition aAndB = new ConjunctiveProposition(phi, conjEvidence);
    double probabilityOfEvidence = prior(conjEvidence);
    if (0 != probabilityOfEvidence) {
      return prior(aAndB) / probabilityOfEvidence;
    }
View Full Code Here

  public double posterior(Proposition phi, Proposition... evidence) {

    Proposition conjEvidence = ProbUtil.constructConjunction(evidence);

    // P(A | B) = P(A AND B)/P(B) - (13.3 AIMA3e)
    Proposition aAndB = new ConjunctiveProposition(phi, conjEvidence);
    double probabilityOfEvidence = prior(conjEvidence);
    if (0 != probabilityOfEvidence) {
      return prior(aAndB) / probabilityOfEvidence;
    }
View Full Code Here

  private static Proposition constructConjunction(Proposition[] props, int idx) {
    if ((idx + 1) == props.length) {
      return props[idx];
    }

    return new ConjunctiveProposition(props[idx], constructConjunction(
        props, idx + 1));
  }
View Full Code Here

  public double posterior(Proposition phi, Proposition... evidence) {

    Proposition conjEvidence = ProbUtil.constructConjunction(evidence);

    // P(A | B) = P(A AND B)/P(B) - (13.3 AIMA3e)
    Proposition aAndB = new ConjunctiveProposition(phi, conjEvidence);
    double probabilityOfEvidence = prior(conjEvidence);
    if (0 != probabilityOfEvidence) {
      return prior(aAndB) / probabilityOfEvidence;
    }
View Full Code Here

      for (int d2 = 1; d2 <= 6; d2++) {
        AssignmentProposition ad1 = new AssignmentProposition(
            ExampleRV.DICE_1_RV, d1);
        AssignmentProposition ad2 = new AssignmentProposition(
            ExampleRV.DICE_2_RV, d2);
        ConjunctiveProposition d1AndD2 = new ConjunctiveProposition(
            ad1, ad2);

        Assert.assertEquals(1.0 / 6.0, model.prior(ad1),
            DELTA_THRESHOLD);
        Assert.assertEquals(1.0 / 6.0, model.prior(ad2),
View Full Code Here

    // AIMA3e pg. 485
    Assert.assertEquals(0.2, model.prior(acavity), DELTA_THRESHOLD);
    Assert.assertEquals(0.6, model.posterior(acavity, atoothache),
        DELTA_THRESHOLD);
    ConjunctiveProposition toothacheAndNotCavity = new ConjunctiveProposition(
        atoothache, anotcavity);
    Assert.assertEquals(0.0,
        model.posterior(acavity, toothacheAndNotCavity),
        DELTA_THRESHOLD);
    Assert.assertEquals(0.0,
View Full Code Here

        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);
  }
View Full Code Here

    // AIMA3e pg. 498
    // (13.17)
    // P<>(toothache AND catch | Cavity)
    // = P<>(toothache | Cavity)P<>(catch | Cavity)
    ConjunctiveProposition toothacheAndCatch = new ConjunctiveProposition(
        atoothache, acatch);
    Assert.assertArrayEquals(
        model.posteriorDistribution(toothacheAndCatch,
            ExampleRV.CAVITY_RV).getValues(),
        model.posteriorDistribution(atoothache, ExampleRV.CAVITY_RV)
            .multiplyBy(
                model.posteriorDistribution(acatch,
                    ExampleRV.CAVITY_RV)).getValues(),
        DELTA_THRESHOLD);

    // (13.18)
    // P<>(Cavity | toothache AND catch)
    // = &alpha;P<>(toothache | Cavity)P<>(catch | Cavity)P(Cavity)
    Assert.assertArrayEquals(
        model.posteriorDistribution(ExampleRV.CAVITY_RV,
            toothacheAndCatch).getValues(),
        model.posteriorDistribution(atoothache, ExampleRV.CAVITY_RV)
            .multiplyBy(
                model.posteriorDistribution(acatch,
                    ExampleRV.CAVITY_RV))
            .multiplyBy(
                model.priorDistribution(ExampleRV.CAVITY_RV))
            .normalize().getValues(), DELTA_THRESHOLD);

    // (13.19)
    // P<>(Toothache, Catch | Cavity)
    // = P<>(Toothache | Cavity)P<>(Catch | Cavity)
    ConjunctiveProposition toothacheAndCatchRV = new ConjunctiveProposition(
        ExampleRV.TOOTHACHE_RV, ExampleRV.CATCH_RV);
    Assert.assertArrayEquals(
        model.posteriorDistribution(toothacheAndCatchRV,
            ExampleRV.CAVITY_RV).getValues(),
        model.posteriorDistribution(ExampleRV.TOOTHACHE_RV,
View Full Code Here

    Assert.assertArrayEquals(new double[] { 0.12 }, model
        .priorDistribution(asunny, acavity).getValues(),
        DELTA_THRESHOLD);
    // P(sunny AND cavity)
    Assert.assertArrayEquals(new double[] { 0.12 }, model
        .priorDistribution(new ConjunctiveProposition(asunny, acavity))
        .getValues(), DELTA_THRESHOLD);
    // P(sunny) = <0.6>
    Assert.assertArrayEquals(new double[] { 0.6 },
        model.priorDistribution(asunny).getValues(), DELTA_THRESHOLD);
  }
View Full Code Here

TOP

Related Classes of aima.core.probability.proposition.ConjunctiveProposition

Copyright © 2018 www.massapicom. 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.