Program: 20169
Project: 20169
Buggy source:
public double getValue(){
  if (!cacheStale) {
    return cachedValue;
  }
  if (objWeight == 0) {
    return 0.0;
  }
  for (  MaxEntGEConstraint constraint : constraints) {
    constraint.zeroExpectations();
  }
  Arrays.fill(cachedGradient,0);
  int numFeatures=trainingList.getDataAlphabet().size() + 1;
  int numLabels=trainingList.getTargetAlphabet().size();
  double[][] scores=new double[trainingList.size()][numLabels];
  double[] constraintValue=new double[numLabels];
  for (int ii=0; ii < trainingList.size(); ii++) {
    Instance instance=trainingList.get(ii);
    double instanceWeight=trainingList.getInstanceWeight(instance);
    if (instance.getTarget() != null) {
      continue;
    }
    FeatureVector fv=(FeatureVector)instance.getData();
    classifier.getClassificationScoresWithTemperature(instance,temperature,scores[ii]);
    for (    MaxEntGEConstraint constraint : constraints) {
      constraint.computeExpectations(fv,scores[ii],instanceWeight);
    }
  }
  double value=0;
  for (  MaxEntGEConstraint constraint : constraints) {
    value+=constraint.getValue();
  }
  value*=objWeight;
  for (int ii=0; ii < trainingList.size(); ii++) {
    Instance instance=trainingList.get(ii);
    if (instance.getTarget() != null) {
      continue;
    }
    Arrays.fill(constraintValue,0);
    double instanceExpectation=0;
    double instanceWeight=trainingList.getInstanceWeight(instance);
    FeatureVector fv=(FeatureVector)instance.getData();
    for (    MaxEntGEConstraint constraint : constraints) {
      constraint.preProcess(fv);
      for (int label=0; label < numLabels; label++) {
        double val=constraint.getCompositeConstraintFeatureValue(fv,label);
        constraintValue[label]+=val;
        instanceExpectation+=val * scores[ii][label];
      }
    }
    for (int label=0; label < numLabels; label++) {
      if (scores[ii][label] == 0)       continue;
      assert(!Double.isInfinite(scores[ii][label]));
      double weight=objWeight * instanceWeight * scores[ii][label]* (constraintValue[label] - instanceExpectation) / temperature;
      assert(!Double.isNaN(weight));
      MatrixOps.rowPlusEquals(cachedGradient,numFeatures,label,fv,weight);
      cachedGradient[numFeatures * label + defaultFeatureIndex]+=weight;
    }
  }
  cachedValue=value;
  cacheStale=false;
  double reg=getRegularization();
  progressLogger.info("String_Node_Str" + value + "String_Node_Str"+ reg+ "String_Node_Str"+ cachedValue);
  return value;
}

Fixed version (ground truth):
public double getValue(){
  if (!cacheStale) {
    return cachedValue;
  }
  if (objWeight == 0) {
    return 0.0;
  }
  for (  MaxEntGEConstraint constraint : constraints) {
    constraint.zeroExpectations();
  }
  Arrays.fill(cachedGradient,0);
  int numFeatures=trainingList.getDataAlphabet().size() + 1;
  int numLabels=trainingList.getTargetAlphabet().size();
  double[][] scores=new double[trainingList.size()][numLabels];
  double[] constraintValue=new double[numLabels];
  for (int ii=0; ii < trainingList.size(); ii++) {
    Instance instance=trainingList.get(ii);
    double instanceWeight=trainingList.getInstanceWeight(instance);
    if (instance.getTarget() != null) {
      continue;
    }
    FeatureVector fv=(FeatureVector)instance.getData();
    classifier.getClassificationScoresWithTemperature(instance,temperature,scores[ii]);
    for (    MaxEntGEConstraint constraint : constraints) {
      constraint.computeExpectations(fv,scores[ii],instanceWeight);
    }
  }
  double value=0;
  for (  MaxEntGEConstraint constraint : constraints) {
    value+=constraint.getValue();
  }
  value*=objWeight;
  for (int ii=0; ii < trainingList.size(); ii++) {
    Instance instance=trainingList.get(ii);
    if (instance.getTarget() != null) {
      continue;
    }
    Arrays.fill(constraintValue,0);
    double instanceExpectation=0;
    double instanceWeight=trainingList.getInstanceWeight(instance);
    FeatureVector fv=(FeatureVector)instance.getData();
    for (    MaxEntGEConstraint constraint : constraints) {
      constraint.preProcess(fv);
      for (int label=0; label < numLabels; label++) {
        double val=constraint.getCompositeConstraintFeatureValue(fv,label);
        constraintValue[label]+=val;
        instanceExpectation+=val * scores[ii][label];
      }
    }
    for (int label=0; label < numLabels; label++) {
      if (scores[ii][label] == 0)       continue;
      assert(!Double.isInfinite(scores[ii][label]));
      double weight=objWeight * instanceWeight * scores[ii][label]* (constraintValue[label] - instanceExpectation) / temperature;
      assert(!Double.isNaN(weight));
      MatrixOps.rowPlusEquals(cachedGradient,numFeatures,label,fv,weight);
      cachedGradient[numFeatures * label + defaultFeatureIndex]+=weight;
    }
  }
  cachedValue=value;
  cacheStale=false;
  double reg=getRegularization();
  progressLogger.info("String_Node_Str" + value + "String_Node_Str"+ reg+ "String_Node_Str"+ cachedValue);
  return cachedValue;
}