Program: 131190
Project: 131190
Buggy source:
/** 
 * Gets the marginal conditional log-likelihood of the i'th example for the given model parameters. We return: <p> \log p(y|x) = \log \sum_z p(y, z | x) </p> where y are the predicted variables, x are the observed variables, and z are the latent variables.
 * @param fgLat The factor graph with the predicted and observed variables clamped. 
 * @param infLat The inferencer for fgLat.
 * @param fgLatPred The factor graph with the observed variables clamped. 
 * @param infLatPred The inferencer for fgLatPred.
 * @param i The data example.
 */
public double getValue(LFgExample ex,FactorGraph fgLat,FgInferencer infLat,FactorGraph fgLatPred,FgInferencer infLatPred,int i){
  double numerator=infLat.getLogPartition();
  double denominator=infLatPred.getLogPartition();
  int numFullyClamped=0;
  for (int a=0; a < fgLatPred.getNumFactors(); a++) {
    Factor f=fgLatPred.getFactor(a);
    boolean isNumeratorClamped=fgLat.getFactor(a).getVars().size() == 0;
    boolean isDenominatorClamped=fgLatPred.getFactor(a).getVars().size() == 0;
    if (f instanceof GlobalFactor) {
      GlobalFactor gf=(GlobalFactor)f;
      if (isNumeratorClamped) {
        VarConfig goldConfig=ex.getGoldConfig().getIntersection(fgLatPred.getFactor(a).getVars());
        numerator+=gf.getLogUnormalizedScore(goldConfig);
        numFullyClamped++;
        if (isDenominatorClamped) {
          denominator+=gf.getLogUnormalizedScore(goldConfig);
        }
      }
    }
 else {
      if (isNumeratorClamped) {
        int goldConfig=ex.getGoldConfig().getConfigIndexOfSubset(f.getVars());
        numerator+=f.getLogUnormalizedScore(goldConfig);
        numFullyClamped++;
        if (isDenominatorClamped) {
          denominator+=f.getLogUnormalizedScore(goldConfig);
        }
      }
    }
  }
  double ll=numerator - denominator;
  log.trace(String.format("String_Node_Str",ll,numerator,denominator));
  log.trace(String.format("String_Node_Str",numFullyClamped,fgLatPred.getFactors().size()));
  if (ll > MAX_LOG_LIKELIHOOD) {
    log.warn("String_Node_Str" + i + "String_Node_Str"+ ll);
  }
  return ll * ex.getWeight();
}

Fixed version (ground truth):
/** 
 * Gets the marginal conditional log-likelihood of the i'th example for the given model parameters. We return: <p> \log p(y|x) = \log \sum_z p(y, z | x) </p> where y are the predicted variables, x are the observed variables, and z are the latent variables.
 * @param fgLat The factor graph with the predicted and observed variables clamped. 
 * @param infLat The inferencer for fgLat.
 * @param fgLatPred The factor graph with the observed variables clamped. 
 * @param infLatPred The inferencer for fgLatPred.
 * @param i The data example.
 * @param goldConfig The assignment to the predicted variables.
 * @param weight The weight of this training example.
 * @return The weighted CLL.
 */
public static double getValue(FactorGraph fgLat,FgInferencer infLat,FactorGraph fgLatPred,FgInferencer infLatPred,int i,VarConfig goldConfig,double weight){
  double numerator=infLat.getLogPartition();
  double denominator=infLatPred.getLogPartition();
  int numFullyClamped=0;
  for (int a=0; a < fgLatPred.getNumFactors(); a++) {
    Factor f=fgLatPred.getFactor(a);
    boolean isNumeratorClamped=fgLat.getFactor(a).getVars().size() == 0;
    boolean isDenominatorClamped=fgLatPred.getFactor(a).getVars().size() == 0;
    if (f instanceof GlobalFactor) {
      GlobalFactor gf=(GlobalFactor)f;
      if (isNumeratorClamped) {
        VarConfig facConfig=goldConfig.getIntersection(fgLatPred.getFactor(a).getVars());
        numerator+=gf.getLogUnormalizedScore(facConfig);
        numFullyClamped++;
        if (isDenominatorClamped) {
          denominator+=gf.getLogUnormalizedScore(facConfig);
        }
      }
    }
 else {
      if (isNumeratorClamped) {
        int facConfig=goldConfig.getConfigIndexOfSubset(f.getVars());
        numerator+=f.getLogUnormalizedScore(facConfig);
        numFullyClamped++;
        if (isDenominatorClamped) {
          denominator+=f.getLogUnormalizedScore(facConfig);
        }
      }
    }
  }
  double ll=numerator - denominator;
  log.trace(String.format("String_Node_Str",ll,numerator,denominator));
  log.trace(String.format("String_Node_Str",numFullyClamped,fgLatPred.getFactors().size()));
  if (ll > MAX_LOG_LIKELIHOOD) {
    log.warn("String_Node_Str" + i + "String_Node_Str"+ ll);
  }
  return ll * weight;
}