Program: 131399
Project: 131399
Buggy source:
private void testResultMarginalsHelper(boolean logDomain){
  double[] root=new double[]{1,2,3};
  double[][] child=new double[][]{{0,4,5},{6,0,7},{8,9,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);
  BeliefPropagationPrm prm=new BeliefPropagationPrm();
  prm.maxIterations=1;
  prm.logDomain=logDomain;
  prm.schedule=BpScheduleType.TREE_LIKE;
  prm.updateOrder=BpUpdateOrder.SEQUENTIAL;
  prm.normalizeMessages=true;
  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=45 + 28 + 20+ 84+ 162+ 216+ 96;
  assertEquals((28 + 84) / Z,getExpectedCount(bp,rootVars,childVars,logDomain,1,2),1e-3);
  assertEquals((45 + 162 + 216) / Z,getExpectedCount(bp,rootVars,childVars,logDomain,2,1),1e-3);
  assertEquals((28 + 20 + 96) / Z,getExpectedCount(bp,rootVars,childVars,logDomain,0,1),1e-3);
  assertEquals((96 + 216) / Z,getExpectedCount(bp,rootVars,childVars,logDomain,2,0),1e-3);
  assertEquals((45 + 28 + 20) / Z,getExpectedCount(bp,rootVars,childVars,logDomain,-1,0),1e-13);
  assertEquals((162 + 216 + 96) / Z,getExpectedCount(bp,rootVars,childVars,logDomain,-1,2),1e-3);
  double[] trees=new double[]{45,28,20,84,162,216,96};
  double expectedRbar=0;
  for (int t=0; t < trees.length; t++) {
    expectedRbar+=trees[t] * FastMath.log(trees[t]);
  }
  System.out.println("String_Node_Str" + expectedRbar);
  assertEquals(45 + 28 + 20+ 84+ 162+ 216+ 96,logDomain ? FastMath.exp(bp.getPartition()) : bp.getPartition(),1e-3);
  BruteForceInferencer bf=new BruteForceInferencer(fg,logDomain);
  bf.run();
  BeliefPropagationTest.assertEqualMarginals(fg,bf,bp,1e-10);
}

Fixed version (ground truth):
private void testResultMarginalsHelper(boolean logDomain,boolean normalizeMessages){
  double[] root=new double[]{1,2,3};
  double[][] child=new double[][]{{0,4,5},{6,0,7},{8,9,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);
  BeliefPropagationPrm prm=new BeliefPropagationPrm();
  prm.maxIterations=1;
  prm.logDomain=logDomain;
  prm.schedule=BpScheduleType.TREE_LIKE;
  prm.updateOrder=BpUpdateOrder.SEQUENTIAL;
  prm.normalizeMessages=normalizeMessages;
  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=45 + 28 + 20+ 84+ 162+ 216+ 96;
  assertEquals((28 + 84) / Z,getExpectedCount(bp,rootVars,childVars,logDomain,1,2),1e-3);
  assertEquals((45 + 162 + 216) / Z,getExpectedCount(bp,rootVars,childVars,logDomain,2,1),1e-3);
  assertEquals((28 + 20 + 96) / Z,getExpectedCount(bp,rootVars,childVars,logDomain,0,1),1e-3);
  assertEquals((96 + 216) / Z,getExpectedCount(bp,rootVars,childVars,logDomain,2,0),1e-3);
  assertEquals((45 + 28 + 20) / Z,getExpectedCount(bp,rootVars,childVars,logDomain,-1,0),1e-13);
  assertEquals((162 + 216 + 96) / Z,getExpectedCount(bp,rootVars,childVars,logDomain,-1,2),1e-3);
  double[] trees=new double[]{45,28,20,84,162,216,96};
  double expectedRbar=0;
  for (int t=0; t < trees.length; t++) {
    expectedRbar+=trees[t] * FastMath.log(trees[t]);
  }
  System.out.println("String_Node_Str" + expectedRbar);
  assertEquals(45 + 28 + 20+ 84+ 162+ 216+ 96,logDomain ? FastMath.exp(bp.getPartition()) : bp.getPartition(),1e-3);
  BruteForceInferencer bf=new BruteForceInferencer(fg,logDomain);
  bf.run();
  BeliefPropagationTest.assertEqualMarginals(fg,bf,bp,1e-10);
}