Program: 131550
Project: 131550
Buggy source:
@Test public void testSrlLogLikelihood() throws Exception {
  List<CoNLL09Token> tokens=new ArrayList<CoNLL09Token>();
  tokens.add(new CoNLL09Token(2,"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str",getList("String_Node_Str"),getList("String_Node_Str"),2,2,"String_Node_Str","String_Node_Str",false,"String_Node_Str",getList("String_Node_Str")));
  tokens.add(new CoNLL09Token(3,"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str",getList("String_Node_Str"),getList("String_Node_Str"),0,0,"String_Node_Str","String_Node_Str",true,"String_Node_Str",getList("String_Node_Str")));
  CoNLL09Sentence sent=new CoNLL09Sentence(tokens);
  List<CoNLL09Sentence> sents=getList(sent);
  System.out.println("String_Node_Str");
  Alphabet<Feature> alphabet=new Alphabet<Feature>();
  SrlFgExampleBuilderPrm prm=new SrlFgExampleBuilderPrm();
  prm.fgPrm.makeUnknownPredRolesLatent=false;
  prm.fgPrm.roleStructure=RoleStructure.PREDS_GIVEN;
  prm.fgPrm.useProjDepTreeFactor=true;
  prm.fePrm.biasOnly=true;
  SrlFgExamplesBuilder builder=new SrlFgExamplesBuilder(prm,alphabet);
  FgExamples data=builder.getData(sents);
  System.out.println("String_Node_Str" + alphabet.size());
  FgModel model=new FgModel(alphabet);
  boolean logDomain=false;
  FgInferencerFactory infFactory=getInfFactory(logDomain);
  FgExample ex=data.get(0);
  FgInferencer infLat=infFactory.getInferencer(ex.getFgLat());
  FactorGraph fgLat=ex.updateFgLat(model.getParams(),infLat.isLogDomain());
  infLat.run();
  assertEquals(2,infLat.getPartition(),2);
  for (  Var v : fgLat.getVars()) {
    double partition=((BeliefPropagation)infLat).getPartitionFunctionAtVarNode(fgLat.getNode(v));
    assertEquals(2,logDomain ? Utilities.exp(partition) : partition,1e-3);
  }
  System.out.println("String_Node_Str");
  FgInferencer infLatPred=infFactory.getInferencer(ex.getFgLatPred());
  FactorGraph fgLatPred=ex.updateFgLatPred(model.getParams(),infLatPred.isLogDomain());
  infLatPred.run();
  assertEquals(4,infLatPred.getPartition(),2);
  BfsBpSchedule schedule=new BfsBpSchedule(fgLatPred);
  System.out.println();
  for (  FgEdge edge : schedule.getOrder()) {
    System.out.println(edge.toString());
  }
  System.out.println();
  for (  Factor f : fgLatPred.getFactors()) {
    System.out.println(f);
  }
  for (  Var v : fgLatPred.getVars()) {
    double partition=((BeliefPropagation)infLatPred).getPartitionFunctionAtVarNode(fgLatPred.getNode(v));
    System.out.format("String_Node_Str",v.toString(),partition);
    assertEquals(4,logDomain ? Utilities.exp(partition) : partition,1e-3);
  }
  CrfObjective obj=new CrfObjective(model.getNumParams(),data,infFactory);
  double ll=obj.getValue(model.getParams());
  assertEquals(0.5,Utilities.exp(ll),1e-13);
}

Fixed version (ground truth):
@Test public void testSrlLogLikelihood() throws Exception {
  List<CoNLL09Token> tokens=new ArrayList<CoNLL09Token>();
  tokens.add(new CoNLL09Token(2,"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str",getList("String_Node_Str"),getList("String_Node_Str"),2,2,"String_Node_Str","String_Node_Str",false,"String_Node_Str",getList("String_Node_Str")));
  tokens.add(new CoNLL09Token(3,"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str",getList("String_Node_Str"),getList("String_Node_Str"),0,0,"String_Node_Str","String_Node_Str",true,"String_Node_Str",getList("String_Node_Str")));
  CoNLL09Sentence sent=new CoNLL09Sentence(tokens);
  List<CoNLL09Sentence> sents=getList(sent);
  System.out.println("String_Node_Str");
  CorpusStatisticsPrm csPrm=new CorpusStatisticsPrm();
  CorpusStatistics cs=new CorpusStatistics(csPrm);
  cs.init(sents);
  Alphabet<Feature> alphabet=new Alphabet<Feature>();
  SrlFgExampleBuilderPrm prm=new SrlFgExampleBuilderPrm();
  prm.fgPrm.makeUnknownPredRolesLatent=false;
  prm.fgPrm.roleStructure=RoleStructure.PREDS_GIVEN;
  prm.fgPrm.useProjDepTreeFactor=true;
  prm.fePrm.biasOnly=true;
  SrlFgExamplesBuilder builder=new SrlFgExamplesBuilder(prm,alphabet,cs);
  FgExamples data=builder.getData(sents);
  System.out.println("String_Node_Str" + alphabet.size());
  FgModel model=new FgModel(alphabet);
  boolean logDomain=false;
  FgInferencerFactory infFactory=getInfFactory(logDomain);
  FgExample ex=data.get(0);
  FgInferencer infLat=infFactory.getInferencer(ex.getFgLat());
  FactorGraph fgLat=ex.updateFgLat(model.getParams(),infLat.isLogDomain());
  infLat.run();
  assertEquals(2,infLat.getPartition(),2);
  for (  Var v : fgLat.getVars()) {
    double partition=((BeliefPropagation)infLat).getPartitionFunctionAtVarNode(fgLat.getNode(v));
    assertEquals(2,logDomain ? Utilities.exp(partition) : partition,1e-3);
  }
  System.out.println("String_Node_Str");
  FgInferencer infLatPred=infFactory.getInferencer(ex.getFgLatPred());
  FactorGraph fgLatPred=ex.updateFgLatPred(model.getParams(),infLatPred.isLogDomain());
  infLatPred.run();
  assertEquals(4,infLatPred.getPartition(),2);
  BfsBpSchedule schedule=new BfsBpSchedule(fgLatPred);
  System.out.println();
  for (  FgEdge edge : schedule.getOrder()) {
    System.out.println(edge.toString());
  }
  System.out.println();
  for (  Factor f : fgLatPred.getFactors()) {
    System.out.println(f);
  }
  for (  Var v : fgLatPred.getVars()) {
    double partition=((BeliefPropagation)infLatPred).getPartitionFunctionAtVarNode(fgLatPred.getNode(v));
    System.out.format("String_Node_Str",v.toString(),partition);
    assertEquals(4,logDomain ? Utilities.exp(partition) : partition,1e-3);
  }
  CrfObjective obj=new CrfObjective(model.getNumParams(),data,infFactory);
  double ll=obj.getValue(model.getParams());
  assertEquals(0.5,Utilities.exp(ll),1e-13);
}