コード例 #1
0
  /*
   * Obtain the values for the evidence plus function.
   */
  private void check_evidence_loop(ProbabilityFunction new_pf, ProbabilityFunction pf) {
    int i, j, k, l, m, p, last, current;
    int indexes[] = new int[bn.number_variables()];
    int value_lengths[] = new int[bn.number_variables()];

    for (i = 0; i < bn.number_variables(); i++) {
      indexes[i] = 0;
      value_lengths[i] = bn.get_probability_variable(i).number_values();
    }
    for (i = 0; i < bn.number_variables(); i++) {
      if (bn.get_probability_variable(i).is_observed()) {
        indexes[i] = bn.get_probability_variable(i).get_observed_index();
      }
    }
    last = new_pf.number_variables() - 1;
    for (i = 0; i < new_pf.number_values(); i++) {
      p = new_pf.get_position_from_indexes(indexes);
      new_pf.set_value(p, pf.evaluate(indexes));

      indexes[new_pf.get_index(last)]++;
      for (j = last; j > 0; j--) {
        current = new_pf.get_index(j);
        if (indexes[current] >= value_lengths[current]) {
          indexes[current] = 0;
          indexes[new_pf.get_index(j - 1)]++;
        } else break;
      }
    }
  }
コード例 #2
0
 /*
  * Transform an observed ProbabilityVariable into a ProbabilityFunction
  * to handle the case where the query involves an observed variable.
  */
 private ProbabilityFunction transform_to_probability_function(
     BayesNet bn, ProbabilityVariable pv) {
   ProbabilityFunction pf = new ProbabilityFunction(bn, 1, pv.number_values(), null);
   pf.set_variable(0, pv);
   int index_of_value = pv.get_observed_index();
   pf.set_value(index_of_value, 1.0);
   return (pf);
 }