Beispiel #1
0
  private Assignment doOnePass(FactorGraph mdl, Assignment initial) {
    Assignment ret = (Assignment) initial.duplicate();
    for (int vidx = 0; vidx < ret.size(); vidx++) {
      Variable var = mdl.get(vidx);
      DiscreteFactor subcpt = constructConditionalCpt(mdl, var, ret);
      int value = subcpt.sampleLocation(r);
      ret.setValue(var, value);
    }

    return ret;
  }
Beispiel #2
0
 // Warning: destructively modifies ret's assignment to fullAssn (I could save and restore, but I
 // don't care
 private DiscreteFactor constructConditionalCpt(
     FactorGraph mdl, Variable var, Assignment fullAssn) {
   List ptlList = mdl.allFactorsContaining(var);
   LogTableFactor ptl = new LogTableFactor(var);
   for (AssignmentIterator it = ptl.assignmentIterator(); it.hasNext(); it.advance()) {
     Assignment varAssn = it.assignment();
     fullAssn.setValue(var, varAssn.get(var));
     ptl.setRawValue(varAssn, sumValues(ptlList, fullAssn));
   }
   ptl.normalize();
   return ptl;
 }