Examples of AssignmentProposition


Examples of aima.core.probability.proposition.AssignmentProposition

    final AssignmentProposition[] xt = new AssignmentProposition[tToTm1StateVarMap
        .size()];
    final Map<RandomVariable, AssignmentProposition> xtVarAssignMap = new HashMap<RandomVariable, AssignmentProposition>();
    i = 0;
    for (RandomVariable rv : tToTm1StateVarMap.keySet()) {
      xt[i] = new AssignmentProposition(tToTm1StateVarMap.get(rv),
          "<Dummy Value>");
      xtVarAssignMap.put(rv, xt[i]);
      i++;
    }
View Full Code Here

Examples of aima.core.probability.proposition.AssignmentProposition

    final AssignmentProposition[] ax_kp1 = new AssignmentProposition[tToTm1StateVarMap
        .size()];
    final Map<RandomVariable, AssignmentProposition> x_kp1VarAssignMap = new HashMap<RandomVariable, AssignmentProposition>();
    i = 0;
    for (RandomVariable rv : b_kp1t.getFor()) {
      ax_kp1[i] = new AssignmentProposition(rv, "<Dummy Value>");
      x_kp1VarAssignMap.put(rv, ax_kp1[i]);
      i++;
    }
    final Proposition x_kp1 = ProbUtil.constructConjunction(ax_kp1);
    props = new Proposition[e_kp1.size()];
View Full Code Here

Examples of aima.core.probability.proposition.AssignmentProposition

      indexes[i] = i;
      Map<RandomVariable, Object> sample = priorSampler
          .priorSample(this.dbn.getPriorNetwork());
      int idx = 0;
      for (Map.Entry<RandomVariable, Object> sa : sample.entrySet()) {
        S[i][idx] = new AssignmentProposition(this.dbn.getX_0_to_X_1()
            .get(sa.getKey()), sa.getValue());
        S_tp1[i][idx] = new AssignmentProposition(this.dbn
            .getX_0_to_X_1().get(sa.getKey()), sa.getValue());
        idx++;
      }
    }
View Full Code Here

Examples of aima.core.probability.proposition.AssignmentProposition

  //
  private void sampleFromTransitionModel(int i) {
    // x <- an event initialized with S[i]
    Map<RandomVariable, Object> x = new LinkedHashMap<RandomVariable, Object>();
    for (int n = 0; n < S[i].length; n++) {
      AssignmentProposition x1 = S[i][n];
      x.put(this.dbn.getX_1_to_X_0().get(x1.getTermVariable()),
          x1.getValue());
    }

    // foreach variable X<sub>1<sub>i</sub></sub> in
    // X<sub>1<sub>1</sub></sub>,...,X<sub>1<sub>n<</sub>/sub> do
    for (RandomVariable X1_i : dbn.getX_1_VariablesInTopologicalOrder()) {
      // x1[i] <- a random sample from
      // <b>P</b>(X<sub>1<sub>i</sub></sub> |
      // parents(X<sub>1<sub>i</sub></sub>))
      x.put(X1_i, ProbUtil.randomSample(dbn.getNode(X1_i), x, randomizer));
    }

    // S[i] <- sample from <b>P</b>(<b>X</b><sub>1</sub> |
    // <b>X</b><sub>0</sub> = S[i])
    for (int n = 0; n < S_tp1[i].length; n++) {
      AssignmentProposition x1 = S_tp1[i][n];
      x1.setValue(x.get(x1.getTermVariable()));
    }
  }
View Full Code Here

Examples of aima.core.probability.proposition.AssignmentProposition

    for (int i = 0; i < N; i++) {
      int sample = (Integer) ProbUtil.sample(randomizer.nextDouble(),
          sampleIndexes, normalizedW);
      for (int idx = 0; idx < S_tp1[i].length; idx++) {
        AssignmentProposition ap = S_tp1[sample][idx];
        newS[i][idx] = new AssignmentProposition(ap.getTermVariable(),
            ap.getValue());
      }
    }

    return newS;
  }
View Full Code Here

Examples of aima.core.probability.proposition.AssignmentProposition

              + parents.size() + "] for this CPT.");
    }
    AssignmentProposition[] aps = new AssignmentProposition[parentValues.length];
    int idx = 0;
    for (RandomVariable parentRV : parents) {
      aps[idx] = new AssignmentProposition(parentRV, parentValues[idx]);
      idx++;
    }

    return getConditioningCase(aps);
  }
View Full Code Here

Examples of aima.core.probability.proposition.AssignmentProposition

  //
  private static void demoToothacheCavityCatchModel(
      FiniteProbabilityModel model) {
    System.out.println("Toothache, Cavity, and Catch Model");
    System.out.println("----------------------------------");
    AssignmentProposition atoothache = new AssignmentProposition(
        ExampleRV.TOOTHACHE_RV, Boolean.TRUE);
    AssignmentProposition acavity = new AssignmentProposition(
        ExampleRV.CAVITY_RV, Boolean.TRUE);
    AssignmentProposition anotcavity = new AssignmentProposition(
        ExampleRV.CAVITY_RV, Boolean.FALSE);
    AssignmentProposition acatch = new AssignmentProposition(
        ExampleRV.CATCH_RV, Boolean.TRUE);

    // AIMA3e pg. 485
    System.out.println("P(cavity) = " + model.prior(acavity));
    System.out.println("P(cavity | toothache) = "
View Full Code Here

Examples of aima.core.probability.proposition.AssignmentProposition

  private static void demoBurglaryAlarmModel(FiniteProbabilityModel model) {
    System.out.println("--------------------");
    System.out.println("Burglary Alarm Model");
    System.out.println("--------------------");

    AssignmentProposition aburglary = new AssignmentProposition(
        ExampleRV.BURGLARY_RV, Boolean.TRUE);
    AssignmentProposition anotburglary = new AssignmentProposition(
        ExampleRV.BURGLARY_RV, Boolean.FALSE);
    AssignmentProposition anotearthquake = new AssignmentProposition(
        ExampleRV.EARTHQUAKE_RV, Boolean.FALSE);
    AssignmentProposition aalarm = new AssignmentProposition(
        ExampleRV.ALARM_RV, Boolean.TRUE);
    AssignmentProposition anotalarm = new AssignmentProposition(
        ExampleRV.ALARM_RV, Boolean.FALSE);
    AssignmentProposition ajohnCalls = new AssignmentProposition(
        ExampleRV.JOHN_CALLS_RV, Boolean.TRUE);
    AssignmentProposition amaryCalls = new AssignmentProposition(
        ExampleRV.MARY_CALLS_RV, Boolean.TRUE);

    // AIMA3e pg. 514
    System.out.println("P(j,m,a,~b,~e) = "
        + model.prior(ajohnCalls, amaryCalls, aalarm, anotburglary,
View Full Code Here

Examples of aima.core.probability.proposition.AssignmentProposition

              + parents.size() + "] for this CPT.");
    }
    AssignmentProposition[] aps = new AssignmentProposition[parentValues.length];
    int idx = 0;
    for (RandomVariable parentRV : parents) {
      aps[idx] = new AssignmentProposition(parentRV, parentValues[idx]);
      idx++;
    }

    return getConditioningCase(aps);
  }
View Full Code Here

Examples of aima.core.probability.proposition.AssignmentProposition

  protected void test_RollingPairFairDiceModel(ProbabilityModel model) {
    Assert.assertTrue(model.isValid());

    // Ensure each dice has 1/6 probability
    for (int d = 1; d <= 6; d++) {
      AssignmentProposition ad1 = new AssignmentProposition(
          ExampleRV.DICE_1_RV, d);
      AssignmentProposition ad2 = new AssignmentProposition(
          ExampleRV.DICE_2_RV, d);

      Assert.assertEquals(1.0 / 6.0, model.prior(ad1), DELTA_THRESHOLD);
      Assert.assertEquals(1.0 / 6.0, model.prior(ad2), DELTA_THRESHOLD);
    }

    // Ensure each combination is 1/36
    for (int d1 = 1; d1 <= 6; d1++) {
      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),
            DELTA_THRESHOLD);

        // pg. 485 AIMA3e
        Assert.assertEquals(1.0 / 36.0, model.prior(ad1, ad2),
            DELTA_THRESHOLD);
        Assert.assertEquals(1.0 / 36.0, model.prior(d1AndD2),
            DELTA_THRESHOLD);

        Assert.assertEquals(1.0 / 6.0, model.posterior(ad1, ad2),
            DELTA_THRESHOLD);
        Assert.assertEquals(1.0 / 6.0, model.posterior(ad2, ad1),
            DELTA_THRESHOLD);
      }
    }

    // Test Sets of events defined via constraint propositions
    IntegerSumProposition total11 = new IntegerSumProposition("Total11",
        new FiniteIntegerDomain(11), ExampleRV.DICE_1_RV,
        ExampleRV.DICE_2_RV);
    Assert.assertEquals(2.0 / 36.0, model.prior(total11), DELTA_THRESHOLD);
    EquivalentProposition doubles = new EquivalentProposition("Doubles",
        ExampleRV.DICE_1_RV, ExampleRV.DICE_2_RV);
    Assert.assertEquals(1.0 / 6.0, model.prior(doubles), DELTA_THRESHOLD);
    SubsetProposition evenDice1 = new SubsetProposition("EvenDice1",
        new FiniteIntegerDomain(2, 4, 6), ExampleRV.DICE_1_RV);
    Assert.assertEquals(0.5, model.prior(evenDice1), DELTA_THRESHOLD);
    SubsetProposition oddDice2 = new SubsetProposition("OddDice2",
        new FiniteIntegerDomain(1, 3, 5), ExampleRV.DICE_2_RV);
    Assert.assertEquals(0.5, model.prior(oddDice2), DELTA_THRESHOLD);

    // pg. 485 AIMA3e
    AssignmentProposition dice1Is5 = new AssignmentProposition(
        ExampleRV.DICE_1_RV, 5);
    Assert.assertEquals(1.0 / 6.0, model.posterior(doubles, dice1Is5),
        DELTA_THRESHOLD);

    Assert.assertEquals(1.0, model.prior(ExampleRV.DICE_1_RV),
        DELTA_THRESHOLD);
    Assert.assertEquals(1.0, model.prior(ExampleRV.DICE_2_RV),
        DELTA_THRESHOLD);
    Assert.assertEquals(1.0,
        model.posterior(ExampleRV.DICE_1_RV, ExampleRV.DICE_2_RV),
        DELTA_THRESHOLD);
    Assert.assertEquals(1.0,
        model.posterior(ExampleRV.DICE_2_RV, ExampleRV.DICE_1_RV),
        DELTA_THRESHOLD);

    // Test a disjunctive proposition pg.489
    // P(a OR b) = P(a) + P(b) - P(a AND b)
    // = 1/6 + 1/6 - 1/36
    AssignmentProposition dice2Is5 = new AssignmentProposition(
        ExampleRV.DICE_2_RV, 5);
    DisjunctiveProposition dice1Is5OrDice2Is5 = new DisjunctiveProposition(
        dice1Is5, dice2Is5);
    Assert.assertEquals(1.0 / 6.0 + 1.0 / 6.0 - 1.0 / 36.0,
        model.prior(dice1Is5OrDice2Is5), 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.