Beispiel #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;
      }
    }
  }
Beispiel #2
0
 /*
  * Build an array of markers. The marker for a
  * variable is true only if the variable is present in the
  * input ProbabilityFunction pf and is not observed.
  * Even explanatory variables can be observed and taken as
  * evidence.
  */
 private int build_evidence_markers(ProbabilityFunction pf, boolean markers[]) {
   int i, n;
   // Initialize the markers
   for (i = 0; i < markers.length; i++) markers[i] = false;
   // Insert the variables of the ProbabilityFunction
   for (i = 0; i < pf.number_variables(); i++) markers[pf.get_index(i)] = true;
   // Take the evidence out
   for (i = 0; i < bn.number_variables(); i++) {
     if (bn.get_probability_variable(i).is_observed()) markers[i] = false;
   }
   // Count how many variables remain
   n = 0;
   for (i = 0; i < markers.length; i++) {
     if (markers[i] == true) n++;
   }
   return (n);
 }