Program: 131341
Project: 131341
Buggy source:
/** 
 * Reads a Bayesian Network from a network InputStream and a CPD InputStream, and returns a factor graph representation of it.
 */
public FactorGraph readBnAsFg(InputStream networkIs,InputStream cpdIs) throws IOException {
  BufferedReader networkReader=new BufferedReader(new InputStreamReader(networkIs));
  int numVars=Integer.parseInt(networkReader.readLine().trim());
  varMap=new HashMap<String,Var>();
  VarSet allVars=new VarSet();
  for (int i=0; i < numVars; i++) {
    Var var=parseVar(networkReader.readLine());
    allVars.add(var);
    varMap.put(var.getName(),var);
  }
  assert(allVars.size() == numVars);
  networkReader.close();
  BufferedReader cpdReader=new BufferedReader(new InputStreamReader(cpdIs));
  factorMap=new LinkedHashMap<VarSet,ExplicitFactor>();
  String line;
  while ((line=cpdReader.readLine()) != null) {
    VarConfig config=new VarConfig();
    String[] assns=whitespaceOrComma.split(line);
    for (int i=0; i < assns.length - 1; i++) {
      String assn=assns[i];
      String[] va=equals.split(assn);
      assert(va.length == 2);
      String varName=va[0];
      String stateName=va[1];
      config.put(varMap.get(varName),stateName);
    }
    double value=Double.parseDouble(assns[assns.length - 1]);
    VarSet vars=config.getVars();
    ExplicitFactor f=factorMap.get(vars);
    if (f == null) {
      f=new ExplicitFactor(vars);
    }
    f.setValue(config.getConfigIndex(),value);
    factorMap.put(vars,f);
  }
  cpdReader.close();
  FactorGraph fg=new FactorGraph();
  for (  ExplicitFactor f : factorMap.values()) {
    fg.addFactor(f);
  }
  return fg;
}

Fixed version (ground truth):
/** 
 * Reads a Bayesian Network from a network InputStream and a CPD InputStream, and returns a factor graph representation of it.
 */
public FactorGraph readBnAsFg(InputStream networkIs,InputStream cpdIs) throws IOException {
  BufferedReader networkReader=new BufferedReader(new InputStreamReader(networkIs));
  int numVars=Integer.parseInt(networkReader.readLine().trim());
  varMap=new HashMap<String,Var>();
  VarSet allVars=new VarSet();
  for (int i=0; i < numVars; i++) {
    Var var=parseVar(networkReader.readLine());
    allVars.add(var);
    varMap.put(var.getName(),var);
  }
  assert(allVars.size() == numVars);
  networkReader.close();
  BufferedReader cpdReader=new BufferedReader(new InputStreamReader(cpdIs));
  factorMap=new LinkedHashMap<VarSet,ExplicitFactor>();
  String line;
  while ((line=cpdReader.readLine()) != null) {
    VarConfig config=new VarConfig();
    String[] assns=whitespaceOrComma.split(line);
    for (int i=0; i < assns.length - 1; i++) {
      String assn=assns[i];
      String[] va=equals.split(assn);
      assert(va.length == 2);
      String varName=va[0];
      String stateName=va[1];
      config.put(varMap.get(varName),stateName);
    }
    double value=Double.parseDouble(assns[assns.length - 1]);
    value=FastMath.log(value);
    VarSet vars=config.getVars();
    ExplicitFactor f=factorMap.get(vars);
    if (f == null) {
      f=new ExplicitFactor(vars);
    }
    f.setValue(config.getConfigIndex(),value);
    factorMap.put(vars,f);
  }
  cpdReader.close();
  FactorGraph fg=new FactorGraph();
  for (  ExplicitFactor f : factorMap.values()) {
    fg.addFactor(f);
  }
  return fg;
}