Program: 131385
Project: 131385
Buggy source:
@Test public void testLogLinearModelTrainDecode2(){
  LogLinearXYData exs=new LogLinearXYData(2);
  exs.getFeatAlphabet().lookupIndex("String_Node_Str");
  exs.getFeatAlphabet().lookupIndex("String_Node_Str");
  exs.getFeatAlphabet().lookupIndex("String_Node_Str");
  exs.getXAlphabet().lookupIndex("String_Node_Str");
  exs.getYAlphabet().lookupIndex("String_Node_Str");
  exs.getYAlphabet().lookupIndex("String_Node_Str");
  FeatureVector[] fvs=new FeatureVector[4];
  for (int i=0; i < 4; i++) {
    fvs[i]=new FeatureVector();
  }
  fvs[0].add(0,1);
  fvs[0].add(1,1);
  fvs[0].add(2,1);
  fvs[1].add(0,1);
  fvs[1].add(1,1);
  fvs[2].add(0,1);
  fvs[2].add(2,1);
  fvs[3].add(0,1);
  fvs[3].add(1,1);
  exs.addEx(30,"String_Node_Str","String_Node_Str",Arrays.copyOfRange(fvs,0,2));
  exs.addEx(15,"String_Node_Str","String_Node_Str",Arrays.copyOfRange(fvs,0,2));
  exs.addEx(5,"String_Node_Str","String_Node_Str",Arrays.copyOfRange(fvs,2,4));
  exs.addEx(21,"String_Node_Str","String_Node_Str",Arrays.copyOfRange(fvs,2,4));
  List<LogLinearExample> data=exs.getData();
  LogLinearXYPrm prm=new LogLinearXYPrm();
  LogLinearXY td=new LogLinearXY(prm);
  FgModel model=td.train(exs);
  System.out.println(model);
{
    Pair<String,DenseFactor> p=td.decode(model,data.get(0));
    String predLabel=p.get1();
    DenseFactor dist=p.get2();
    System.out.println(Arrays.toString(dist.getValues()));
    assertEquals("String_Node_Str",predLabel);
    JUnitUtils.assertArrayEquals(new double[]{-0.56869180843596,-0.8353232329420138},dist.getValues(),1e-3);
  }
{
    Pair<String,DenseFactor> p=td.decode(model,data.get(2));
    String predLabel=p.get1();
    DenseFactor dist=p.get2();
    System.out.println(Arrays.toString(dist.getValues()));
    assertEquals("String_Node_Str",predLabel);
    JUnitUtils.assertArrayEquals(new double[]{-0.8277652102139692,-0.5745197983563534},dist.getValues(),1e-3);
  }
}

Fixed version (ground truth):
@Test public void testLogLinearModelTrainDecode2(){
  LogLinearXYData exs=new LogLinearXYData(2);
  exs.getFeatAlphabet().lookupIndex("String_Node_Str");
  exs.getFeatAlphabet().lookupIndex("String_Node_Str");
  exs.getFeatAlphabet().lookupIndex("String_Node_Str");
  exs.getXAlphabet().lookupIndex("String_Node_Str");
  exs.getYAlphabet().lookupIndex("String_Node_Str");
  exs.getYAlphabet().lookupIndex("String_Node_Str");
  FeatureVector[] fvs=new FeatureVector[4];
  for (int i=0; i < 4; i++) {
    fvs[i]=new FeatureVector();
  }
  fvs[0].add(0,1);
  fvs[0].add(1,1);
  fvs[0].add(2,1);
  fvs[1].add(0,1);
  fvs[1].add(1,1);
  fvs[2].add(0,1);
  fvs[2].add(2,1);
  fvs[3].add(0,1);
  fvs[3].add(1,1);
  exs.addEx(30,"String_Node_Str","String_Node_Str",Arrays.copyOfRange(fvs,0,2));
  exs.addEx(15,"String_Node_Str","String_Node_Str",Arrays.copyOfRange(fvs,0,2));
  exs.addEx(5,"String_Node_Str","String_Node_Str",Arrays.copyOfRange(fvs,2,4));
  exs.addEx(21,"String_Node_Str","String_Node_Str",Arrays.copyOfRange(fvs,2,4));
  List<LogLinearExample> data=exs.getData();
  LogLinearXYPrm prm=new LogLinearXYPrm();
  LogLinearXY td=new LogLinearXY(prm);
  FgModel model=td.train(exs);
  System.out.println(model);
{
    Pair<String,DenseFactor> p=td.decode(model,data.get(0));
    String predLabel=p.get1();
    DenseFactor dist=p.get2();
    System.out.println(Arrays.toString(dist.getValues()));
    assertEquals("String_Node_Str",predLabel);
  }
{
    Pair<String,DenseFactor> p=td.decode(model,data.get(2));
    String predLabel=p.get1();
    DenseFactor dist=p.get2();
    System.out.println(Arrays.toString(dist.getValues()));
    assertEquals("String_Node_Str",predLabel);
  }
}