nus-yam/ex-repair huggingface dataset:
Program: 131386
Project: 131386
Buggy source:
@Test public void testTrainNoLatentVars(){
  FactorTemplateList fts=new FactorTemplateList();
  ObsFeatureExtractor obsFe=new SimpleVCFeatureExtractor(fts);
  ObsFeatureConjoinerPrm prm=new ObsFeatureConjoinerPrm();
  prm.includeUnsupportedFeatures=true;
  ObsFeatureConjoiner ofc=new ObsFeatureConjoiner(prm,fts);
  FgAndVars fgv=getLinearChainFgWithVars(true,ofc,obsFe);
  VarConfig trainConfig=new VarConfig();
  trainConfig.put(fgv.w0,0);
  trainConfig.put(fgv.w1,1);
  trainConfig.put(fgv.w2,0);
  trainConfig.put(fgv.t0,0);
  trainConfig.put(fgv.t1,1);
  trainConfig.put(fgv.t2,1);
  FgExampleMemoryStore data=new FgExampleMemoryStore();
  data.add(new LabeledFgExample(fgv.fg,trainConfig,obsFe,fts));
  ofc.init(data);
  FgModel model=new FgModel(ofc.getNumParams());
  model=train(model,data);
  System.out.println(model);
  System.out.println(fts);
  System.out.println(DoubleArrays.toString(FgModelTest.getParams(model),"String_Node_Str"));
  JUnitUtils.assertArrayEquals(new double[]{3.58,-0.75,-2.16,-2.17,-3.58,0.75,2.16,2.17,-2.17,-2.17,3.59,0.75},FgModelTest.getParams(model),1e-2);
}

Fixed version (ground truth):
@Test public void testTrainNoLatentVars(){
  FactorTemplateList fts=new FactorTemplateList();
  ObsFeatureExtractor obsFe=new SimpleVCFeatureExtractor(fts);
  ObsFeatureConjoinerPrm prm=new ObsFeatureConjoinerPrm();
  prm.includeUnsupportedFeatures=true;
  ObsFeatureConjoiner ofc=new ObsFeatureConjoiner(prm,fts);
  FgAndVars fgv=getLinearChainFgWithVars(true,ofc,obsFe);
  VarConfig trainConfig=new VarConfig();
  trainConfig.put(fgv.w0,0);
  trainConfig.put(fgv.w1,1);
  trainConfig.put(fgv.w2,0);
  trainConfig.put(fgv.t0,0);
  trainConfig.put(fgv.t1,1);
  trainConfig.put(fgv.t2,1);
  FgExampleMemoryStore data=new FgExampleMemoryStore();
  data.add(new LabeledFgExample(fgv.fg,trainConfig,obsFe,fts));
  ofc.init(data);
  FgModel model=new FgModel(ofc.getNumParams());
  model=train(model,data);
  System.out.println(model);
  System.out.println(fts);
  System.out.println(DoubleArrays.toString(FgModelTest.getParams(model),"String_Node_Str"));
  JUnitUtils.assertArrayEquals(new double[]{-0.10,-0.10,0.10,0.10,-3.15,-3.15,-3.29,-3.29,5.30,5.30,1.14,1.14},FgModelTest.getParams(model),1e-2);
}
Program: 131387
Project: 131387
Buggy source:
@Test public void testTrainWithLatentVars(){
  FactorTemplateList fts=new FactorTemplateList();
  ObsFeatureExtractor obsFe=new SimpleVCFeatureExtractor(fts);
  ObsFeatureConjoinerPrm prm=new ObsFeatureConjoinerPrm();
  prm.includeUnsupportedFeatures=true;
  ObsFeatureConjoiner ofc=new ObsFeatureConjoiner(prm,fts);
  FgAndVars fgv=getLinearChainFgWithVarsLatent(true,ofc,obsFe);
  VarConfig trainConfig=new VarConfig();
  trainConfig.put(fgv.w0,0);
  trainConfig.put(fgv.w1,1);
  trainConfig.put(fgv.w2,0);
  trainConfig.put(fgv.t0,0);
  trainConfig.put(fgv.t1,1);
  trainConfig.put(fgv.t2,1);
  FgExampleMemoryStore data=new FgExampleMemoryStore();
  data.add(new LabeledFgExample(fgv.fg,trainConfig,obsFe,fts));
  ofc.init(data);
  FgModel model=new FgModel(ofc.getNumParams());
  model=train(model,data);
  System.out.println(fts);
  System.out.println(DoubleArrays.toString(FgModelTest.getParams(model),"String_Node_Str"));
  JUnitUtils.assertArrayEquals(new double[]{0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.31,0.31,-0.31,-0.31,-6.42,-6.52,10.24,2.69},FgModelTest.getParams(model),1e-2);
}

Fixed version (ground truth):
@Test public void testTrainWithLatentVars(){
  FactorTemplateList fts=new FactorTemplateList();
  ObsFeatureExtractor obsFe=new SimpleVCFeatureExtractor(fts);
  ObsFeatureConjoinerPrm prm=new ObsFeatureConjoinerPrm();
  prm.includeUnsupportedFeatures=true;
  ObsFeatureConjoiner ofc=new ObsFeatureConjoiner(prm,fts);
  FgAndVars fgv=getLinearChainFgWithVarsLatent(true,ofc,obsFe);
  VarConfig trainConfig=new VarConfig();
  trainConfig.put(fgv.w0,0);
  trainConfig.put(fgv.w1,1);
  trainConfig.put(fgv.w2,0);
  trainConfig.put(fgv.t0,0);
  trainConfig.put(fgv.t1,1);
  trainConfig.put(fgv.t2,1);
  FgExampleMemoryStore data=new FgExampleMemoryStore();
  data.add(new LabeledFgExample(fgv.fg,trainConfig,obsFe,fts));
  ofc.init(data);
  FgModel model=new FgModel(ofc.getNumParams());
  model=train(model,data);
  System.out.println(fts);
  System.out.println(DoubleArrays.toString(FgModelTest.getParams(model),"String_Node_Str"));
  JUnitUtils.assertArrayEquals(new double[]{-0.00,-0.00,-0.00,-0.00,0.01,0.01,0.01,0.01,-0.01,-0.01,-0.01,-0.01,-3.08,-3.08,-3.33,-3.33,5.25,5.25,1.16,1.16},FgModelTest.getParams(model),1e-2);
}
Program: 131388
Project: 131388
Buggy source:
@Test public void testSenseTrainAssignment() throws Exception {
  FactorTemplateList fts=new FactorTemplateList();
  InputStream inputStream=this.getClass().getResourceAsStream(CoNLL09ReadWriteTest.conll2009Example);
  CoNLL09FileReader cr=new CoNLL09FileReader(inputStream);
  List<CoNLL09Sentence> sents=cr.readSents(1);
  CorpusStatisticsPrm csPrm=new CorpusStatisticsPrm();
  csPrm.useGoldSyntax=true;
  SimpleAnnoSentenceCollection simpleSents=new SimpleAnnoSentenceCollection();
  for (  CoNLL09Sentence s : sents) {
    s.normalizeRoleNames();
    simpleSents.add(s.toSimpleAnnoSentence(csPrm.useGoldSyntax));
  }
  CorpusStatistics cs=new CorpusStatistics(csPrm);
  cs.init(simpleSents);
  JointNlpFgExampleBuilderPrm prm=new JointNlpFgExampleBuilderPrm();
  prm.fePrm.srlFePrm.fePrm.biasOnly=true;
  prm.fgPrm.srlPrm.roleStructure=RoleStructure.PREDS_GIVEN;
  prm.fgPrm.srlPrm.predictSense=true;
  ObsFeatureConjoiner ofc=new ObsFeatureConjoiner(new ObsFeatureConjoinerPrm(),fts);
  JointNlpFgExamplesBuilder builder=new JointNlpFgExamplesBuilder(prm,ofc,cs);
  FgExampleList data=builder.getData(simpleSents);
  ofc.init(data);
  FgExample ex=data.get(0);
  VarConfig vc=ex.getGoldConfig();
  System.out.println(vc.toString().replace("String_Node_Str","String_Node_Str"));
  assertEquals(18 + 1,vc.size());
  SrlGraph srlGraph=SrlDecoder.getSrlGraphFromVarConfig(vc,simpleSents.get(0).size());
  assertEquals(2,srlGraph.getPredAt(2).getPosition());
  assertEquals("String_Node_Str",srlGraph.getPredAt(2).getLabel());
}

Fixed version (ground truth):
@Test public void testSenseTrainAssignment() throws Exception {
  FactorTemplateList fts=new FactorTemplateList();
  InputStream inputStream=this.getClass().getResourceAsStream(CoNLL09ReadWriteTest.conll2009Example);
  CoNLL09FileReader cr=new CoNLL09FileReader(inputStream);
  List<CoNLL09Sentence> sents=cr.readSents(1);
  CorpusStatisticsPrm csPrm=new CorpusStatisticsPrm();
  csPrm.useGoldSyntax=true;
  SimpleAnnoSentenceCollection simpleSents=new SimpleAnnoSentenceCollection();
  for (  CoNLL09Sentence s : sents) {
    s.normalizeRoleNames();
    simpleSents.add(s.toSimpleAnnoSentence(csPrm.useGoldSyntax));
  }
  CorpusStatistics cs=new CorpusStatistics(csPrm);
  cs.init(simpleSents);
  JointNlpFgExampleBuilderPrm prm=new JointNlpFgExampleBuilderPrm();
  prm.fePrm.srlFePrm.fePrm.biasOnly=true;
  prm.fgPrm.srlPrm.roleStructure=RoleStructure.PREDS_GIVEN;
  prm.fgPrm.srlPrm.predictSense=true;
  prm.fgPrm.srlPrm.predictPredPos=false;
  ObsFeatureConjoiner ofc=new ObsFeatureConjoiner(new ObsFeatureConjoinerPrm(),fts);
  JointNlpFgExamplesBuilder builder=new JointNlpFgExamplesBuilder(prm,ofc,cs);
  FgExampleList data=builder.getData(simpleSents);
  ofc.init(data);
  FgExample ex=data.get(0);
  VarConfig vc=ex.getGoldConfig();
  System.out.println(vc.toString().replace("String_Node_Str","String_Node_Str"));
  assertEquals(18 + 1,vc.size());
  SrlGraph srlGraph=SrlDecoder.getSrlGraphFromVarConfig(vc,simpleSents.get(0).size());
  assertEquals(2,srlGraph.getPredAt(2).getPosition());
  assertEquals("String_Node_Str",srlGraph.getPredAt(2).getLabel());
}
Program: 131391
Project: 131391
Buggy source:
public SimpleAnnoSentenceCollection toSentences(Communication communication){
  SimpleAnnoSentenceCollection annoSents=new SimpleAnnoSentenceCollection();
  addSentences(communication,annoSents);
  return annoSents;
}

Fixed version (ground truth):
public SimpleAnnoSentenceCollection toSentences(Communication communication){
  SimpleAnnoSentenceCollection annoSents=new SimpleAnnoSentenceCollection();
  addSentences(communication,annoSents);
  annoSents.setSourceSents(communication);
  return annoSents;
}
Program: 131392
Project: 131392
Buggy source:
/** 
 * Gets a deep copy of these sentences with some annotation layers removed.
 * @param removeAts The annotation layers to remove.
 * @return The filtered deep copy.
 */
public SimpleAnnoSentenceCollection getWithAtsRemoved(List<AT> removeAts){
  SimpleAnnoSentenceCollection newSents=new SimpleAnnoSentenceCollection();
  for (  SimpleAnnoSentence sent : this) {
    SimpleAnnoSentence newSent=new SimpleAnnoSentence(sent);
    newSent.removeAts(removeAts);
    newSents.add(newSent);
  }
  return newSents;
}

Fixed version (ground truth):
/** 
 * Gets a deep copy of these sentences with some annotation layers removed.
 * @param removeAts The annotation layers to remove.
 * @return The filtered deep copy.
 */
public SimpleAnnoSentenceCollection getWithAtsRemoved(List<AT> removeAts){
  SimpleAnnoSentenceCollection newSents=new SimpleAnnoSentenceCollection();
  newSents.sourceSents=this.sourceSents;
  for (  SimpleAnnoSentence sent : this) {
    SimpleAnnoSentence newSent=new SimpleAnnoSentence(sent);
    newSent.removeAts(removeAts);
    newSents.add(newSent);
  }
  return newSents;
}
Program: 131393
Project: 131393
Buggy source:
@Override public void init(FgExample ex){
  FactorGraph fg=ex.getFgLatPred();
  this.feats=new FeatureVector[fg.getNumFactors()][];
  for (int a=0; a < fg.getNumFactors(); a++) {
    Factor f=fg.getFactor(a);
    if (f instanceof GlobalFactor) {
      continue;
    }
 else     if (f instanceof DenseFactor) {
      int numConfigs=f.getVars().calcNumConfigs();
      numConfigs=(numConfigs == 0) ? 1 : numConfigs;
      feats[a]=new FeatureVector[numConfigs];
    }
 else {
      throw new UnsupportedFactorTypeException(f);
    }
  }
}

Fixed version (ground truth):
@Override public void init(FgExample ex){
  this.featExtractor.init(ex);
  FactorGraph fg=ex.getFgLatPred();
  this.feats=new FeatureVector[fg.getNumFactors()][];
  for (int a=0; a < fg.getNumFactors(); a++) {
    Factor f=fg.getFactor(a);
    if (f instanceof GlobalFactor) {
      continue;
    }
 else     if (f instanceof DenseFactor) {
      int numConfigs=f.getVars().calcNumConfigs();
      numConfigs=(numConfigs == 0) ? 1 : numConfigs;
      feats[a]=new FeatureVector[numConfigs];
    }
 else {
      throw new UnsupportedFactorTypeException(f);
    }
  }
}
Program: 131394
Project: 131394
Buggy source:
/** 
 * Creates a new CoNLL09Sentence with both columns set for each field (i.e. PLEMMA and LEMMA are both set from the values on the SimpleAnnoSentence). The reason for setting both is that the CoNLL-2009 evaluation script uses the "gold" columns for evaluation, but we might want to utilize the predictions in some downstream task.
 */
public static CoNLL09Sentence fromSimpleAnnoSentence(SimpleAnnoSentence sent){
  List<CoNLL09Token> toks=new ArrayList<CoNLL09Token>();
  for (int i=0; i < sent.size(); i++) {
    CoNLL09Token tok=new CoNLL09Token();
    tok.setId(i + 1);
    tok.setForm(sent.getWord(i));
    tok.setPlemma(sent.getLemma(i));
    tok.setPpos(sent.getPosTag(i));
    tok.setPfeat(sent.getFeats(i));
    tok.setPhead(sent.getParent(i) + 1);
    tok.setPdeprel(sent.getDeprel(i));
    tok.setLemma(sent.getLemma(i));
    tok.setPos(sent.getPosTag(i));
    tok.setFeat(sent.getFeats(i));
    tok.setHead(sent.getParent(i) + 1);
    tok.setDeprel(sent.getDeprel(i));
    toks.add(tok);
  }
  CoNLL09Sentence updatedSentence=new CoNLL09Sentence(toks);
  updatedSentence.setColsFromSrlGraph(sent.getSrlGraph(),false,true);
  return updatedSentence;
}

Fixed version (ground truth):
/** 
 * Creates a new CoNLL09Sentence with both columns set for each field (i.e. PLEMMA and LEMMA are both set from the values on the SimpleAnnoSentence). The reason for setting both is that the CoNLL-2009 evaluation script uses the "gold" columns for evaluation, but we might want to utilize the predictions in some downstream task.
 */
public static CoNLL09Sentence fromSimpleAnnoSentence(SimpleAnnoSentence sent){
  List<CoNLL09Token> toks=new ArrayList<CoNLL09Token>();
  for (int i=0; i < sent.size(); i++) {
    CoNLL09Token tok=new CoNLL09Token();
    tok.setId(i + 1);
    tok.setForm(sent.getWord(i));
    tok.setPlemma(sent.getLemma(i));
    tok.setPpos(sent.getPosTag(i));
    if (sent.getFeats() != null) {
      tok.setPfeat(sent.getFeats(i));
    }
    tok.setPhead(sent.getParent(i) + 1);
    tok.setPdeprel(sent.getDeprel(i));
    tok.setLemma(sent.getLemma(i));
    tok.setPos(sent.getPosTag(i));
    tok.setFeat(sent.getFeats(i));
    tok.setHead(sent.getParent(i) + 1);
    tok.setDeprel(sent.getDeprel(i));
    toks.add(tok);
  }
  CoNLL09Sentence updatedSentence=new CoNLL09Sentence(toks);
  updatedSentence.setColsFromSrlGraph(sent.getSrlGraph(),false,true);
  return updatedSentence;
}
Program: 131395
Project: 131395
Buggy source:
/** 
 * Creates a new CoNLLXSentence with all columns set for each field.
 */
public static CoNLLXSentence fromSimpleAnnoSentence(SimpleAnnoSentence sent){
  List<CoNLLXToken> toks=new ArrayList<CoNLLXToken>();
  for (int i=0; i < sent.size(); i++) {
    CoNLLXToken tok=new CoNLLXToken();
    tok.setId(i + 1);
    tok.setForm(sent.getWord(i));
    tok.setLemma(sent.getLemma(i));
    tok.setCpostag(sent.getCposTag(i));
    tok.setPostag(sent.getPosTag(i));
    tok.setFeats(sent.getFeats(i));
    tok.setHead(sent.getParent(i) + 1);
    tok.setPhead(sent.getParent(i) + 1);
    tok.setDeprel(sent.getDeprel(i));
    tok.setPdeprel(sent.getDeprel(i));
    toks.add(tok);
  }
  CoNLLXSentence updatedSentence=new CoNLLXSentence(toks);
  return updatedSentence;
}

Fixed version (ground truth):
/** 
 * Creates a new CoNLLXSentence with all columns set for each field.
 */
public static CoNLLXSentence fromSimpleAnnoSentence(SimpleAnnoSentence sent){
  List<CoNLLXToken> toks=new ArrayList<CoNLLXToken>();
  for (int i=0; i < sent.size(); i++) {
    CoNLLXToken tok=new CoNLLXToken();
    tok.setId(i + 1);
    tok.setForm(sent.getWord(i));
    tok.setLemma(sent.getLemma(i));
    tok.setCpostag(sent.getCposTag(i));
    tok.setPostag(sent.getPosTag(i));
    if (sent.getFeats() != null) {
      tok.setFeats(sent.getFeats(i));
    }
    tok.setHead(sent.getParent(i) + 1);
    tok.setPhead(sent.getParent(i) + 1);
    tok.setDeprel(sent.getDeprel(i));
    tok.setPdeprel(sent.getDeprel(i));
    toks.add(tok);
  }
  CoNLLXSentence updatedSentence=new CoNLLXSentence(toks);
  return updatedSentence;
}
Program: 131396
Project: 131396
Buggy source:
@Override public double getExpectedLogBelief(FgNode parent,Messages[] msgs,boolean logDomain){
  if (!warnedOnce) {
    log.warn("String_Node_Str");
    warnedOnce=true;
  }
  if (true) {
    return -10000;
  }
  double[] root=new double[n];
  double[][] child=new double[n][n];
  getLogOddsRatios(parent,msgs,logDomain,root,child);
  double logPi=getProductOfAllFalseMessages(parent,msgs,logDomain);
  SemiringExt s=new LogPosNegSemiring();
  Pair<FirstOrderDepParseHypergraph,Scores> pair=HyperDepParser.insideAlgorithmEntropyFoe(root,child);
  FirstOrderDepParseHypergraph graph=pair.get1();
  Scores scores=pair.get2();
  int rt=graph.getRoot().getId();
  double logZ=scores.beta[rt];
  double logRbar=scores.betaFoe[rt];
  double logPartition=logPi + logZ;
  double expectation=logPi - logPartition + FastMath.exp(logRbar - logZ);
  if (Double.isNaN(expectation)) {
    log.warn("String_Node_Str");
    return 0.0;
  }
  return expectation;
}

Fixed version (ground truth):
@Override public double getExpectedLogBelief(FgNode parent,Messages[] msgs,boolean logDomain){
}
Program: 131397
Project: 131397
Buggy source:
@Test public void testResultingMarginalsLogProb(){
  boolean logDomain=true;
  testResultMarginalsHelper(logDomain);
}

Fixed version (ground truth):
@Test public void testResultingMarginalsLogProb(){
  boolean logDomain=true;
  testResultMarginalsHelper(logDomain,false);
  testResultMarginalsHelper(logDomain,true);
}
Program: 131398
Project: 131398
Buggy source:
@Test public void testPartitionWithAdditionalVariable(){
  boolean logDomain=false;
  double[] root=new double[]{1,2};
  double[][] child=new double[][]{{0,3},{4,0}};
  FactorGraph fg=new FactorGraph();
  int n=root.length;
  ProjDepTreeFactor treeFac=new ProjDepTreeFactor(n,VarType.PREDICTED);
  treeFac.updateFromModel(null,logDomain);
  LinkVar[] rootVars=treeFac.getRootVars();
  LinkVar[][] childVars=treeFac.getChildVars();
  for (int i=-1; i < n; i++) {
    for (int j=0; j < n; j++) {
      if (i != j) {
        ExplicitFactor f;
        if (i == -1) {
          f=new ExplicitFactor(new VarSet(rootVars[j]));
          f.setValue(LinkVar.TRUE,root[j]);
          f.setValue(LinkVar.FALSE,1.0);
        }
 else {
          f=new ExplicitFactor(new VarSet(childVars[i][j]));
          f.setValue(LinkVar.TRUE,child[i][j]);
          f.setValue(LinkVar.FALSE,1.0);
        }
        if (logDomain) {
          f.convertRealToLog();
        }
        fg.addFactor(f);
      }
    }
  }
  fg.addFactor(treeFac);
  Var roleVar=new Var(VarType.PREDICTED,2,"String_Node_Str",Lists.getList("String_Node_Str","String_Node_Str"));
  ExplicitFactor roleFac=new ExplicitFactor(new VarSet(roleVar,childVars[0][1]));
  roleFac.setValue(0,2);
  roleFac.setValue(1,3);
  roleFac.setValue(2,5);
  roleFac.setValue(3,7);
  System.out.println(roleFac);
  if (logDomain) {
    roleFac.convertRealToLog();
  }
  fg.addFactor(roleFac);
  BeliefPropagationPrm prm=new BeliefPropagationPrm();
  prm.maxIterations=1;
  prm.logDomain=logDomain;
  prm.schedule=BpScheduleType.TREE_LIKE;
  prm.updateOrder=BpUpdateOrder.SEQUENTIAL;
  prm.normalizeMessages=false;
  BeliefPropagation bp=new BeliefPropagation(fg,prm);
  bp.run();
  BfsBpSchedule schedule=new BfsBpSchedule(fg);
  System.out.println();
  for (  FgEdge edge : schedule.getOrder()) {
    System.out.println(edge.toString());
  }
  System.out.println();
  for (int i=-1; i < n; i++) {
    for (int j=0; j < n; j++) {
      if (i != j) {
        System.out.format("String_Node_Str",i,j,getExpectedCount(bp,rootVars,childVars,logDomain,i,j));
      }
    }
  }
  double Z=3 * 3 + 3 * 7 + 8 * 2 + 8 * 5;
  assertEquals(Z,logDomain ? FastMath.exp(bp.getPartition()) : bp.getPartition(),1e-3);
  assertEquals((3 * 3 + 3 * 7) / Z,getExpectedCount(bp,rootVars,childVars,logDomain,-1,0),1e-3);
  assertEquals((8 * 2 + 8 * 5) / Z,getExpectedCount(bp,rootVars,childVars,logDomain,1,0),1e-3);
  BruteForceInferencer bf=new BruteForceInferencer(fg,logDomain);
  bf.run();
  BeliefPropagationTest.assertEqualMarginals(fg,bf,bp);
}

Fixed version (ground truth):
@Test public void testPartitionWithAdditionalVariable(){
  testPartitionWithAdditionalVariableHelper(false,false);
  testPartitionWithAdditionalVariableHelper(true,false);
  testPartitionWithAdditionalVariableHelper(true,true);
  testPartitionWithAdditionalVariableHelper(false,true);
}
Program: 131400
Project: 131400
Buggy source:
@Test public void testResultingMarginalsProb(){
  boolean logDomain=false;
  testResultMarginalsHelper(logDomain);
}

Fixed version (ground truth):
@Test public void testResultingMarginalsProb(){
  boolean logDomain=false;
  testResultMarginalsHelper(logDomain,false);
  testResultMarginalsHelper(logDomain,true);
}
Program: 131401
Project: 131401
Buggy source:
/** 
 * Runs the inside algorithm on a hypergraph with the first-order expectation semiring.
 * @param graph The hypergraph.
 * @return The beta value for each Hypernode. Where beta[i] is the insidescore for the i'th node in the Hypergraph, graph.getNodes().get(i).
 */
public static void insideAlgorithmFirstOrderExpect(final Hypergraph graph,final HyperpotentialFoe w,final SemiringExt s,final Scores scores){
  final int n=graph.getNodes().size();
  final double[] beta=new double[n];
  final double[] betaFoe=new double[n];
  Arrays.fill(beta,s.zero());
  Arrays.fill(betaFoe,s.zero());
  graph.applyTopoSort(new HyperedgeFn(){
    @Override public void apply(    Hyperedge e){
      double prod=s.one();
      double prodFoe=s.zero();
      for (      Hypernode jNode : e.getTailNodes()) {
        int j=jNode.getId();
        double p1=prod;
        double p2=beta[j];
        double r1=prodFoe;
        double r2=betaFoe[j];
        prod=s.times(p1,p2);
        prodFoe=s.plus(s.times(p1,r2),s.times(p2,r1));
      }
      double p1=prod;
      double p2=w.getScore(e,s);
      double r1=prodFoe;
      double r2=w.getScoreFoe(e,s);
      prod=s.times(p1,p2);
      prodFoe=s.plus(s.times(p1,r2),s.times(p2,r1));
      int i=e.getHeadNode().getId();
      beta[i]=s.plus(beta[i],prod);
      betaFoe[i]=s.plus(betaFoe[i],prodFoe);
    }
  }
);
  scores.beta=beta;
  scores.betaFoe=betaFoe;
}

Fixed version (ground truth):
/** 
 * Runs the inside algorithm on a hypergraph with the first-order expectation semiring.
 * @param graph The hypergraph.
 * @return The beta value for each Hypernode. Where beta[i] is the insidescore for the i'th node in the Hypergraph, graph.getNodes().get(i).
 */
public static void insideAlgorithmFirstOrderExpect(final Hypergraph graph,final HyperpotentialFoe w,final SemiringExt s,final Scores scores){
}
Program: 131402
Project: 131402
Buggy source:
@Override public double getScoreFoe(Hyperedge e,SemiringExt s){
  double p_e=w.getScore(e,s);
  if (p_e == s.zero()) {
    return p_e;
  }
  return s.times(p_e,s.fromReal(FastMath.log(s.toReal(p_e))));
}

Fixed version (ground truth):
@Override public double getScoreFoe(Hyperedge e,SemiringExt s){
}
Program: 131403
Project: 131403
Buggy source:
@Override public double getExpectedLogBelief(FgNode parent,Messages[] msgs,boolean logDomain){
  double[] root=new double[n];
  double[][] child=new double[n][n];
  getLogOddsRatios(parent,msgs,logDomain,root,child);
  double logPi=getProductOfAllFalseMessages(parent,msgs,logDomain);
  SemiringExt s=new LogPosNegSemiring();
  Pair<FirstOrderDepParseHypergraph,Scores> pair=HyperDepParser.insideAlgorithmEntropyFoe(root,child);
  FirstOrderDepParseHypergraph graph=pair.get1();
  Scores scores=pair.get2();
  int rt=graph.getRoot().getId();
  double logZ=scores.beta[rt];
  double logRbar=scores.betaFoe[rt];
  double logPartition=logPi + logZ;
  double expectation=logPi - logPartition + FastMath.exp(logRbar - logZ);
  if (Double.isNaN(expectation)) {
    log.warn("String_Node_Str");
    return 0.0;
  }
  return expectation;
}

Fixed version (ground truth):
@Override public double getExpectedLogBelief(FgNode parent,Messages[] msgs,boolean logDomain){
  if (!warnedOnce) {
    log.warn("String_Node_Str");
    warnedOnce=true;
  }
  if (true) {
    return -10000;
  }
  double[] root=new double[n];
  double[][] child=new double[n][n];
  getLogOddsRatios(parent,msgs,logDomain,root,child);
  double logPi=getProductOfAllFalseMessages(parent,msgs,logDomain);
  SemiringExt s=new LogPosNegSemiring();
  Pair<FirstOrderDepParseHypergraph,Scores> pair=HyperDepParser.insideAlgorithmEntropyFoe(root,child);
  FirstOrderDepParseHypergraph graph=pair.get1();
  Scores scores=pair.get2();
  int rt=graph.getRoot().getId();
  double logZ=scores.beta[rt];
  double logRbar=scores.betaFoe[rt];
  double logPartition=logPi + logZ;
  double expectation=logPi - logPartition + FastMath.exp(logRbar - logZ);
  if (Double.isNaN(expectation)) {
    log.warn("String_Node_Str");
    return 0.0;
  }
  return expectation;
}
Program: 131405
Project: 131405
Buggy source:
public static void backward(final Hypergraph graph,final Hyperpotential w,final SemiringExt s,final Scores scores){
  outsideAdjoint(graph,w,s,scores);
  insideAdjoint(graph,w,s,scores);
  weightAdjoint(graph,w,s,scores);
}

Fixed version (ground truth):
public static void backward(final Hypergraph graph,final Hyperpotential w,final SemiringExt s,final Scores scores){
  if (scores.marginalAdj == null) {
    throw new IllegalStateException("String_Node_Str");
  }
  outsideAdjoint(graph,w,s,scores);
  insideAdjoint(graph,w,s,scores);
  weightAdjoint(graph,w,s,scores);
}
Program: 131406
Project: 131406
Buggy source:
/** 
 * Computes the adjoints of the outside scores. INPUT: scores.beta, scores.marginalAdj. OUTPUT: scores.alphaAdj.
 * @param graph The hypergraph
 * @param w The potential function.
 * @param s The semiring.
 * @param scores Input and output struct.
 */
public static void outsideAdjoint(final Hypergraph graph,final Hyperpotential w,final SemiringExt s,final Scores scores){
  final int n=graph.getNodes().size();
  final double[] marginalAdj=scores.marginalAdj;
  final double[] beta=scores.beta;
  final double[] alphaAdj=new double[n];
  Arrays.fill(alphaAdj,s.zero());
  for (  Hypernode iNode : graph.getNodes()) {
    int i=iNode.getId();
    double prod=s.times(marginalAdj[i],beta[i]);
    prod=s.divide(prod,beta[graph.getRoot().getId()]);
    alphaAdj[i]=s.plus(alphaAdj[i],prod);
  }
  graph.applyTopoSort(new HyperedgeFn(){
    @Override public void apply(    Hyperedge e){
      int i=e.getHeadNode().getId();
      for (      Hypernode j : e.getTailNodes()) {
        double prod=s.times(alphaAdj[j.getId()],w.getScore(e));
        for (        Hypernode k : e.getTailNodes()) {
          if (k == j) {
            continue;
          }
          prod=s.times(prod,beta[k.getId()]);
        }
        alphaAdj[i]=s.plus(alphaAdj[i],prod);
      }
    }
  }
);
  scores.alphaAdj=alphaAdj;
}

Fixed version (ground truth):
/** 
 * Computes the adjoints of the outside scores. INPUT: scores.beta, scores.marginalAdj. OUTPUT: scores.alphaAdj.
 * @param graph The hypergraph
 * @param w The potential function.
 * @param s The semiring.
 * @param scores Input and output struct.
 */
public static void outsideAdjoint(final Hypergraph graph,final Hyperpotential w,final SemiringExt s,final Scores scores){
  final int n=graph.getNodes().size();
  final double[] marginalAdj=scores.marginalAdj;
  final double[] beta=scores.beta;
  final double[] alphaAdj=new double[n];
  Arrays.fill(alphaAdj,s.zero());
  for (  Hypernode iNode : graph.getNodes()) {
    int i=iNode.getId();
    double prod=s.times(marginalAdj[i],beta[i]);
    prod=s.divide(prod,beta[graph.getRoot().getId()]);
    alphaAdj[i]=s.plus(alphaAdj[i],prod);
  }
  graph.applyTopoSort(new HyperedgeFn(){
    @Override public void apply(    Hyperedge e){
      int i=e.getHeadNode().getId();
      for (      Hypernode j : e.getTailNodes()) {
        double prod=s.times(alphaAdj[j.getId()],w.getScore(e,s));
        for (        Hypernode k : e.getTailNodes()) {
          if (k == j) {
            continue;
          }
          prod=s.times(prod,beta[k.getId()]);
        }
        alphaAdj[i]=s.plus(alphaAdj[i],prod);
      }
    }
  }
);
  scores.alphaAdj=alphaAdj;
}
Program: 131407
Project: 131407
Buggy source:
public void updateFromModel(FgModel model,boolean logDomain){
}

Fixed version (ground truth):
public void updateFromModel(FgModel model,boolean logDomain){
  this.logDomain=logDomain;
}
Program: 131408
Project: 131408
Buggy source:
@Override public double getUnormalizedScore(int configId){
  return 1.0;
}

Fixed version (ground truth):
@Override public double getUnormalizedScore(int configId){
  if (logDomain) {
    return 0.0;
  }
 else {
    return 1.0;
  }
}
Program: 131409
Project: 131409
Buggy source:
@Override protected void createMessages(FgNode parent,Messages[] msgs,boolean logDomain){
  assert(this == parent.getFactor());
  double[] root=new double[n];
  double[][] child=new double[n][n];
  DoubleArrays.fill(root,Double.NEGATIVE_INFINITY);
  DoubleArrays.fill(child,Double.NEGATIVE_INFINITY);
  for (  FgEdge inEdge : parent.getInEdges()) {
    LinkVar link=(LinkVar)inEdge.getVar();
    DenseFactor inMsg=msgs[inEdge.getId()].message;
    double oddsRatio;
    if (logDomain) {
      oddsRatio=inMsg.getValue(LinkVar.TRUE) - inMsg.getValue(LinkVar.FALSE);
    }
 else {
      oddsRatio=inMsg.getValue(LinkVar.TRUE) / inMsg.getValue(LinkVar.FALSE);
      oddsRatio=FastMath.log(oddsRatio);
    }
    if (link.getParent() == -1) {
      root[link.getChild()]=oddsRatio;
    }
 else {
      child[link.getParent()][link.getChild()]=oddsRatio;
    }
  }
  DepIoChart chart=ProjectiveDependencyParser.insideOutsideAlgorithm(root,child);
  double pi=logDomain ? 0.0 : 1.0;
  for (  FgEdge inEdge : parent.getInEdges()) {
    DenseFactor inMsg=msgs[inEdge.getId()].message;
    if (logDomain) {
      pi+=inMsg.getValue(LinkVar.FALSE);
    }
 else {
      pi*=inMsg.getValue(LinkVar.FALSE);
    }
  }
  double partition=logDomain ? pi + chart.getLogPartitionFunction() : pi * FastMath.exp(chart.getLogPartitionFunction());
  if (log.isTraceEnabled()) {
    log.trace(String.format("String_Node_Str",partition));
  }
  for (  FgEdge outEdge : parent.getOutEdges()) {
    LinkVar link=(LinkVar)outEdge.getVar();
    double beliefTrue;
    double beliefFalse;
    if (logDomain) {
      beliefTrue=pi + chart.getLogSumOfPotentials(link.getParent(),link.getChild());
      if (partition < beliefTrue) {
        beliefFalse=FastMath.log(Math.abs(partition - beliefTrue));
      }
 else {
        beliefFalse=FastMath.logSubtract(partition,beliefTrue);
      }
    }
 else {
      beliefTrue=pi * FastMath.exp(chart.getLogSumOfPotentials(link.getParent(),link.getChild()));
      beliefFalse=partition - beliefTrue;
    }
    if (log.isTraceEnabled()) {
      log.trace(String.format("String_Node_Str",link.getParent(),link.getChild(),beliefTrue));
      log.trace(String.format("String_Node_Str",link.getParent(),link.getChild(),beliefFalse));
    }
    FgEdge inEdge=outEdge.getOpposing();
    DenseFactor inMsg=msgs[inEdge.getId()].message;
    if (logDomain) {
      beliefTrue-=inMsg.getValue(LinkVar.TRUE);
      beliefFalse-=inMsg.getValue(LinkVar.FALSE);
    }
 else {
      beliefTrue/=inMsg.getValue(LinkVar.TRUE);
      beliefFalse/=inMsg.getValue(LinkVar.FALSE);
    }
    msgs[outEdge.getId()].newMessage.setValue(LinkVar.FALSE,beliefFalse);
    msgs[outEdge.getId()].newMessage.setValue(LinkVar.TRUE,beliefTrue);
  }
}

Fixed version (ground truth):
@Override protected void createMessages(FgNode parent,Messages[] msgs,boolean logDomain){
}
Program: 131410
Project: 131410
Buggy source:
private List<Integer> getPositionList(PositionList pl,LocalObservations local){
  int pidx=local.getPidx();
  int cidx=local.getCidx();
  FeaturizedToken tok;
  FeaturizedTokenPair pair;
switch (pl) {
case CHILDREN_P:
    tok=getFeatTok(pidx);
  return tok.getChildren();
case NO_FAR_CHILDREN_P:
tok=getFeatTok(pidx);
return tok.getNoFarChildren();
case CHILDREN_C:
tok=getFeatTok(cidx);
return tok.getChildren();
case NO_FAR_CHILDREN_C:
tok=getFeatTok(cidx);
return tok.getNoFarChildren();
case LINE_P_C:
pair=getFeatTokPair(pidx,cidx);
return pair.getLinePath();
case LINE_RI_RK:
pair=getFeatTokPair(local.getRStartIdx(),local.getREndIdx());
return pair.getLinePath();
case BTWN_P_C:
pair=getFeatTokPair(pidx,cidx);
List<Integer> posList=pair.getLinePath();
if (posList.size() > 2) {
posList=posList.subList(1,posList.size() - 1);
}
 else {
posList=Collections.emptyList();
}
return posList;
default :
throw new IllegalStateException();
}
}

Fixed version (ground truth):
private List<Integer> getPositionList(PositionList pl,LocalObservations local){
  FeaturizedToken tok;
  FeaturizedTokenPair pair;
switch (pl) {
case CHILDREN_P:
    tok=getFeatTok(local.getPidx());
  return tok.getChildren();
case NO_FAR_CHILDREN_P:
tok=getFeatTok(local.getPidx());
return tok.getNoFarChildren();
case CHILDREN_C:
tok=getFeatTok(local.getCidx());
return tok.getChildren();
case NO_FAR_CHILDREN_C:
tok=getFeatTok(local.getCidx());
return tok.getNoFarChildren();
case LINE_P_C:
pair=getFeatTokPair(local.getPidx(),local.getCidx());
return pair.getLinePath();
case LINE_RI_RK:
pair=getFeatTokPair(local.getRStartIdx(),local.getREndIdx());
return pair.getLinePath();
case BTWN_P_C:
pair=getFeatTokPair(local.getPidx(),local.getCidx());
List<Integer> posList=pair.getLinePath();
if (posList.size() > 2) {
posList=posList.subList(1,posList.size() - 1);
}
 else {
posList=Collections.emptyList();
}
return posList;
default :
throw new IllegalStateException();
}
}
Program: 131411
Project: 131411
Buggy source:
@Override public Factor getClamped(VarConfig clmpVarConfig){
  if (clmpVarConfig.size() > 0) {
    throw new IllegalStateException("String_Node_Str");
  }
  return this;
}

Fixed version (ground truth):
@Override public Factor getClamped(VarConfig clmpVarConfig){
  if (clmpVarConfig.size() == 0) {
    return this;
  }
 else   if (clmpVarConfig.size() == vars.size()) {
    return new ProjDepTreeFactor(0,VarType.OBSERVED);
  }
 else {
    throw new IllegalStateException("String_Node_Str");
  }
}
Program: 131412
Project: 131412
Buggy source:
/** 
 * Computes the Bethe free energy of the factor graph. For acyclic graphs, this is equal to -log(Z) where Z is the exact partition function. For  loopy graphs it can be used as an approximation.
 */
private double getBetheFreeEnergy(){
  double bethe=0.0;
  Set<Class<?>> ignoredClasses=new HashSet<Class<?>>();
  for (int a=0; a < fg.getFactors().size(); a++) {
    Factor f=fg.getFactors().get(a);
    if (f instanceof ExplicitFactor) {
      int numConfigs=f.getVars().calcNumConfigs();
      DenseFactor beliefs=getMarginalsForFactorId(a);
      for (int c=0; c < numConfigs; c++) {
        double chi_c=((ExplicitFactor)f).getValue(c);
        if (beliefs.getValue(c) != 0) {
          if (prm.logDomain) {
            bethe+=FastMath.exp(beliefs.getValue(c)) * (beliefs.getValue(c) - chi_c);
          }
 else {
            bethe+=beliefs.getValue(c) * FastMath.log(beliefs.getValue(c) / chi_c);
          }
        }
      }
    }
 else {
      ignoredClasses.add(f.getClass());
    }
  }
  for (int i=0; i < fg.getVars().size(); i++) {
    Var v=fg.getVars().get(i);
    int numNeighbors=fg.getVarNode(i).getOutEdges().size();
    DenseFactor beliefs=getMarginalsForVarId(i);
    double sum=0.0;
    for (int c=0; c < v.getNumStates(); c++) {
      if (prm.logDomain) {
        sum+=FastMath.exp(beliefs.getValue(c)) * beliefs.getValue(c);
      }
 else {
        sum+=beliefs.getValue(c) * FastMath.log(beliefs.getValue(c));
      }
    }
    bethe-=(numNeighbors - 1) * sum;
  }
  for (  Class<?> clazz : ignoredClasses) {
    log.warn("String_Node_Str" + clazz);
    return Double.NaN;
  }
  return bethe;
}

Fixed version (ground truth):
/** 
 * Computes the Bethe free energy of the factor graph. For acyclic graphs, this is equal to -log(Z) where Z is the exact partition function. For  loopy graphs it can be used as an approximation.
 */
private double getBetheFreeEnergy(){
}
Program: 131413
Project: 131413
Buggy source:
/** 
 * @inheritDoc 
 */
@Override public double getPartition(){
  if (prm.schedule == BpScheduleType.TREE_LIKE && prm.normalizeMessages == false) {
    double partition=prm.logDomain ? 0.0 : 1.0;
    for (    FgNode node : fg.getConnectedComponents()) {
      if (!node.isVar()) {
        if (node.getOutEdges().size() == 0) {
          continue;
        }
 else {
          node=node.getOutEdges().get(0).getChild();
          assert(node.isVar());
        }
      }
      double nodePartition=getPartitionFunctionAtVarNode(node);
      if (prm.logDomain) {
        partition+=nodePartition;
      }
 else {
        partition*=nodePartition;
      }
    }
    return partition;
  }
  if (!prm.logDomain) {
    return Math.exp(-getBetheFreeEnergy());
  }
 else {
    return -getBetheFreeEnergy();
  }
}

Fixed version (ground truth):
/** 
 * @inheritDoc 
 */
@Override public double getPartition(){
}
Program: 131414
Project: 131414
Buggy source:
/** 
 * Creates a message and stores it in the "pending message" slot for this edge.
 * @param edge The directed edge for which the message should be created.
 * @param iter The iteration number.
 */
private void createMessage(FgEdge edge,int iter){
  int edgeId=edge.getId();
  Var var=edge.getVar();
  Factor factor=edge.getFactor();
  if (!edge.isVarToFactor() && factor instanceof GlobalFactor) {
    log.trace("String_Node_Str");
    GlobalFactor globalFac=(GlobalFactor)factor;
    globalFac.createMessages(edge.getParent(),msgs,prm.logDomain,iter);
    return;
  }
 else   if (!edge.isVarToFactor() && !(factor instanceof ExplicitFactor)) {
    throw new UnsupportedFactorTypeException(factor);
  }
  DenseFactor msg=msgs[edgeId].newMessage;
  msg.set(prm.logDomain ? 0.0 : 1.0);
  if (edge.isVarToFactor()) {
    getProductOfMessages(edge.getParent(),msg,edge.getChild());
  }
 else {
    DenseFactor prod=new DenseFactor(factor.getVars());
    prod.set((DenseFactor)factor);
    getProductOfMessages(edge.getParent(),prod,edge.getChild());
    if (prm.logDomain) {
      msg=prod.getLogMarginal(new VarSet(var),false);
    }
 else {
      msg=prod.getMarginal(new VarSet(var),false);
    }
  }
  assert(msg.getVars().equals(new VarSet(var)));
  if (prm.normalizeMessages) {
    if (prm.logDomain) {
      msg.logNormalize();
    }
 else {
      msg.normalize();
    }
  }
  msgs[edgeId].newMessage=msg;
}

Fixed version (ground truth):
/** 
 * Creates a message and stores it in the "pending message" slot for this edge.
 * @param edge The directed edge for which the message should be created.
 * @param iter The iteration number.
 */
private void createMessage(FgEdge edge,int iter){
}
Program: 131415
Project: 131415
Buggy source:
/** 
 * Provide the dot product of the features and model weights for this configuration (make sure to exp that value if !logDomain). Note that this method can be overridden for an efficient product of an ExpFamFactor and a hard factor (that rules out some configurations). Just return 0/-infinity here before extracting features for configurations that are eliminated by the hard factor. 
 */
public double getDotProd(int config,FgModel model,boolean logDomain){
  FeatureVector fv=getFeatures(config);
  double dot=model.dot(fv);
  if (logDomain)   return dot;
 else   return FastMath.exp(dot);
}

Fixed version (ground truth):
@Override public double getDotProd(int config,FgModel model,boolean logDomain){
  return unclmpFactor.getDotProd(config,model,logDomain);
}
Program: 131416
Project: 131416
Buggy source:
/** 
 * If this factor depends on the model, this method wil updates this factor's internal representation accordingly.
 * @param model The model.
 * @param logDomain Whether to store values in the probability orlog-probability domain.
 */
void updateFromModel(FgModel model,boolean logDomain);

Fixed version (ground truth):
/** 
 * If this factor depends on the model, this method will updates this factor's internal representation accordingly.
 * @param model The model.
 * @param logDomain Whether to store values in the probability orlog-probability domain.
 */
void updateFromModel(FgModel model,boolean logDomain);
Program: 131417
Project: 131417
Buggy source:
private static Map<String,MutableInt> addWord(Map<String,MutableInt> inputHash,String w){
  MutableInt count=inputHash.get(w);
  if (count == null) {
    inputHash.put(w,new MutableInt());
  }
 else {
    count.increment();
  }
  return inputHash;
}

Fixed version (ground truth):
private static void addWord(Map<String,MutableInt> inputHash,String w){
  MutableInt count=inputHash.get(w);
  if (count == null) {
    inputHash.put(w,new MutableInt());
  }
 else {
    count.increment();
  }
}
Program: 131419
Project: 131419
Buggy source:
/** 
 * If this factor depends on the model, this method wil updates this factor's internal representation accordingly.
 * @param model The model.
 * @param logDomain Whether to store values in the probability orlog-probability domain.
 */
public void updateFromModel(FgModel model,boolean logDomain){
  if (iter != null) {
    iter.reset();
  }
  ExpFamFactor f=this;
  int numConfigs=f.getVars().calcNumConfigs();
  for (int c=0; c < numConfigs; c++) {
    int config=(iter != null) ? iter.next() : c;
    FeatureVector fv=getFeatures(config);
    double dot=model.dot(fv);
    if (logDomain) {
      f.setValue(c,dot);
    }
 else {
      f.setValue(c,FastMath.exp(dot));
    }
  }
  assert(iter == null || !iter.hasNext());
}

Fixed version (ground truth):
/** 
 * If this factor depends on the model, this method wil updates this factor's internal representation accordingly.
 * @param model The model.
 * @param logDomain Whether to store values in the probability orlog-probability domain.
 */
public void updateFromModel(FgModel model,boolean logDomain){
  if (iter != null) {
    iter.reset();
  }
  ExpFamFactor f=this;
  int numConfigs=f.getVars().calcNumConfigs();
  if (numConfigs > 0) {
    for (int c=0; c < numConfigs; c++) {
      int config=(iter != null) ? iter.next() : c;
      FeatureVector fv=getFeatures(config);
      double dot=model.dot(fv);
      if (logDomain) {
        f.setValue(c,dot);
      }
 else {
        f.setValue(c,FastMath.exp(dot));
      }
    }
    assert(iter == null || !iter.hasNext());
  }
}
Program: 131421
Project: 131421
Buggy source:
@Test public void testCorrectNumFeatures() throws Exception {
  SrlFactorGraphPrm fgPrm=new SrlFactorGraphPrm();
  fgPrm.alwaysIncludeLinkVars=true;
  SrlFactorGraph sfg=getSrlFg(fgPrm);
  FactorTemplateList fts=new FactorTemplateList();
  InputStream inputStream=this.getClass().getResourceAsStream(CoNLL09ReadWriteTest.conll2009Example);
  CoNLL09FileReader cr=new CoNLL09FileReader(inputStream);
  CorpusStatisticsPrm csPrm=new CorpusStatisticsPrm();
  SimpleAnnoSentenceCollection sents=CoNLL09Sentence.toSimpleAnno(cr.readSents(1),csPrm.useGoldSyntax);
  CorpusStatistics cs=new CorpusStatistics(csPrm);
  cs.init(sents);
  fts.update(sfg);
  SrlFeatureExtractorPrm prm=new SrlFeatureExtractorPrm();
  prm.fePrm.biasOnly=true;
  prm.featureHashMod=-1;
  SrlFeatureExtractor featExt=new SrlFeatureExtractor(prm,sents.get(0),cs);
  featExt.init(new VarConfig(),fts);
  for (int a=0; a < sfg.getNumFactors(); a++) {
    featExt.calcObsFeatureVector((ObsFeExpFamFactor)sfg.getFactor(a));
  }
  System.out.println(fts);
  assertEquals(3,fts.getNumObsFeats());
}

Fixed version (ground truth):
@Test public void testCorrectNumFeatures() throws Exception {
  SrlFactorGraphPrm fgPrm=new SrlFactorGraphPrm();
  fgPrm.alwaysIncludeLinkVars=true;
  SrlFactorGraph sfg=getSrlFg(fgPrm);
  FactorTemplateList fts=new FactorTemplateList();
  InputStream inputStream=this.getClass().getResourceAsStream(CoNLL09ReadWriteTest.conll2009Example);
  CoNLL09FileReader cr=new CoNLL09FileReader(inputStream);
  CorpusStatisticsPrm csPrm=new CorpusStatisticsPrm();
  SimpleAnnoSentenceCollection sents=CoNLL09Sentence.toSimpleAnno(cr.readSents(1),csPrm.useGoldSyntax);
  CorpusStatistics cs=new CorpusStatistics(csPrm);
  cs.init(sents);
  fts.lookupTemplateIds(sfg);
  SrlFeatureExtractorPrm prm=new SrlFeatureExtractorPrm();
  prm.fePrm.biasOnly=true;
  prm.featureHashMod=-1;
  SrlFeatureExtractor featExt=new SrlFeatureExtractor(prm,sents.get(0),cs);
  featExt.init(new VarConfig(),fts);
  for (int a=0; a < sfg.getNumFactors(); a++) {
    featExt.calcObsFeatureVector((ObsFeExpFamFactor)sfg.getFactor(a));
  }
  System.out.println(fts);
  assertEquals(3,fts.getNumObsFeats());
}
Program: 131422
Project: 131422
Buggy source:
@Test public void testCorrectNumFeaturesWithFeatureHashing() throws Exception {
  SrlFactorGraphPrm fgPrm=new SrlFactorGraphPrm();
  SrlFactorGraph sfg=getSrlFg(fgPrm);
  FactorTemplateList fts=new FactorTemplateList();
  InputStream inputStream=this.getClass().getResourceAsStream(CoNLL09ReadWriteTest.conll2009Example);
  CoNLL09FileReader cr=new CoNLL09FileReader(inputStream);
  List<CoNLL09Sentence> sents=cr.readSents(1);
  SimpleAnnoSentenceCollection simpleSents=new SimpleAnnoSentenceCollection();
  CorpusStatisticsPrm csPrm=new CorpusStatisticsPrm();
  CorpusStatistics cs=new CorpusStatistics(csPrm);
  for (  CoNLL09Sentence s : sents) {
    s.normalizeRoleNames();
    simpleSents.add(s.toSimpleAnnoSentence(csPrm.useGoldSyntax));
  }
  cs.init(simpleSents);
  fts.update(sfg);
  SentFeatureExtractorPrm fePrm=new SentFeatureExtractorPrm();
  fePrm.useNaradFeats=true;
  fePrm.useSimpleFeats=false;
  fePrm.useZhaoFeats=false;
  fePrm.useLexicalDepPathFeats=false;
  SrlFeatureExtractorPrm prm=new SrlFeatureExtractorPrm();
  prm.fePrm=fePrm;
  prm.featureHashMod=10;
  SrlFeatureExtractor featExt=new SrlFeatureExtractor(prm,simpleSents.get(0),cs);
  featExt.init(new VarConfig(),fts);
  for (int a=0; a < sfg.getNumFactors(); a++) {
    featExt.calcObsFeatureVector((ObsFeExpFamFactor)sfg.getFactor(a));
  }
  System.out.println(fts);
  assertEquals(11,fts.getNumObsFeats());
}

Fixed version (ground truth):
@Test public void testCorrectNumFeaturesWithFeatureHashing() throws Exception {
  SrlFactorGraphPrm fgPrm=new SrlFactorGraphPrm();
  SrlFactorGraph sfg=getSrlFg(fgPrm);
  FactorTemplateList fts=new FactorTemplateList();
  InputStream inputStream=this.getClass().getResourceAsStream(CoNLL09ReadWriteTest.conll2009Example);
  CoNLL09FileReader cr=new CoNLL09FileReader(inputStream);
  List<CoNLL09Sentence> sents=cr.readSents(1);
  SimpleAnnoSentenceCollection simpleSents=new SimpleAnnoSentenceCollection();
  CorpusStatisticsPrm csPrm=new CorpusStatisticsPrm();
  CorpusStatistics cs=new CorpusStatistics(csPrm);
  for (  CoNLL09Sentence s : sents) {
    s.normalizeRoleNames();
    simpleSents.add(s.toSimpleAnnoSentence(csPrm.useGoldSyntax));
  }
  cs.init(simpleSents);
  fts.lookupTemplateIds(sfg);
  SentFeatureExtractorPrm fePrm=new SentFeatureExtractorPrm();
  fePrm.useNaradFeats=true;
  fePrm.useSimpleFeats=false;
  fePrm.useZhaoFeats=false;
  fePrm.useLexicalDepPathFeats=false;
  SrlFeatureExtractorPrm prm=new SrlFeatureExtractorPrm();
  prm.fePrm=fePrm;
  prm.featureHashMod=10;
  SrlFeatureExtractor featExt=new SrlFeatureExtractor(prm,simpleSents.get(0),cs);
  featExt.init(new VarConfig(),fts);
  for (int a=0; a < sfg.getNumFactors(); a++) {
    featExt.calcObsFeatureVector((ObsFeExpFamFactor)sfg.getFactor(a));
  }
  System.out.println(fts);
  assertEquals(11,fts.getNumObsFeats());
}
Program: 131423
Project: 131423
Buggy source:
@Override public int next(){
  if (!hasNext()) {
    throw new IllegalStateException();
  }
  cur=cur + incr;
  return cur;
}

Fixed version (ground truth):
@Override public int next(){
  if (!hasNext()) {
    throw new IllegalStateException();
  }
  int tmp=cur;
  cur+=incr;
  return tmp;
}
Program: 131424
Project: 131424
Buggy source:
@Override public boolean hasNext(){
  return cur + incr < end;
}

Fixed version (ground truth):
@Override public boolean hasNext(){
  return cur < end;
}