Program: 131404
Project: 131404
Buggy source:
/** 
 * Computes the adjoints of the inside scores. INPUT: scores.alpha, scores.beta, scores.marginalAdj. OUTPUT: scores.betaAdj.
 * @param graph The hypergraph
 * @param w The potential function.
 * @param s The semiring.
 * @param scores Input and output struct.
 */
public static void insideAdjoint(final Hypergraph graph,final Hyperpotential w,final SemiringExt s,final Scores scores){
  final int n=graph.getNodes().size();
  final double[] alpha=scores.alpha;
  final double[] beta=scores.beta;
  final double[] marginalAdj=scores.marginalAdj;
  final double[] alphaAdj=scores.alphaAdj;
  final double[] betaAdj=new double[n];
  int root=graph.getRoot().getId();
  Arrays.fill(betaAdj,s.zero());
  for (  Hypernode jNode : graph.getNodes()) {
    int j=jNode.getId();
    if (j == root) {
      continue;
    }
    double prod=s.times(marginalAdj[j],alpha[j]);
    prod=s.times(prod,beta[j]);
    prod=s.divide(prod,s.times(beta[root],beta[root]));
    betaAdj[root]=s.minus(betaAdj[root],prod);
  }
  for (  Hypernode jNode : graph.getNodes()) {
    int j=jNode.getId();
    if (j == root) {
      continue;
    }
    double prod=s.divide(s.times(marginalAdj[j],alpha[j]),beta[root]);
    betaAdj[j]=s.plus(betaAdj[j],prod);
  }
  graph.applyRevTopoSort(new HyperedgeFn(){
    @Override public void apply(    Hyperedge e){
      int i=e.getHeadNode().getId();
      for (      Hypernode jNode : e.getTailNodes()) {
        int j=jNode.getId();
        double prod=s.times(betaAdj[i],w.getScore(e));
        for (        Hypernode kNode : e.getTailNodes()) {
          int k=kNode.getId();
          if (j == k) {
            continue;
          }
          prod=s.times(prod,beta[k]);
        }
        betaAdj[j]=s.plus(betaAdj[j],prod);
        for (        Hypernode kNode : e.getTailNodes()) {
          int k=kNode.getId();
          if (k == j) {
            continue;
          }
          ;
          prod=s.times(marginalAdj[k],w.getScore(e));
          prod=s.times(prod,alpha[i]);
          for (          Hypernode lNode : e.getTailNodes()) {
            int l=lNode.getId();
            prod=s.times(beta[l],prod);
          }
          betaAdj[j]=s.plus(betaAdj[j],prod);
        }
      }
    }
  }
);
  scores.betaAdj=betaAdj;
}

Fixed version (ground truth):
/** 
 * Computes the adjoints of the inside scores. INPUT: scores.alpha, scores.beta, scores.marginalAdj. OUTPUT: scores.betaAdj.
 * @param graph The hypergraph
 * @param w The potential function.
 * @param s The semiring.
 * @param scores Input and output struct.
 */
public static void insideAdjoint(final Hypergraph graph,final Hyperpotential w,final SemiringExt s,final Scores scores){
  final int n=graph.getNodes().size();
  final double[] alpha=scores.alpha;
  final double[] beta=scores.beta;
  final double[] marginalAdj=scores.marginalAdj;
  final double[] alphaAdj=scores.alphaAdj;
  final double[] betaAdj=new double[n];
  int root=graph.getRoot().getId();
  Arrays.fill(betaAdj,s.zero());
  for (  Hypernode jNode : graph.getNodes()) {
    int j=jNode.getId();
    if (j == root) {
      continue;
    }
    double prod=s.times(marginalAdj[j],alpha[j]);
    prod=s.times(prod,beta[j]);
    prod=s.divide(prod,s.times(beta[root],beta[root]));
    betaAdj[root]=s.minus(betaAdj[root],prod);
  }
  for (  Hypernode jNode : graph.getNodes()) {
    int j=jNode.getId();
    if (j == root) {
      continue;
    }
    double prod=s.divide(s.times(marginalAdj[j],alpha[j]),beta[root]);
    betaAdj[j]=s.plus(betaAdj[j],prod);
  }
  graph.applyRevTopoSort(new HyperedgeFn(){
    @Override public void apply(    Hyperedge e){
      int i=e.getHeadNode().getId();
      for (      Hypernode jNode : e.getTailNodes()) {
        int j=jNode.getId();
        double prod=s.times(betaAdj[i],w.getScore(e,s));
        for (        Hypernode kNode : e.getTailNodes()) {
          int k=kNode.getId();
          if (j == k) {
            continue;
          }
          prod=s.times(prod,beta[k]);
        }
        betaAdj[j]=s.plus(betaAdj[j],prod);
        for (        Hypernode kNode : e.getTailNodes()) {
          int k=kNode.getId();
          if (k == j) {
            continue;
          }
          ;
          prod=s.times(alphaAdj[k],w.getScore(e,s));
          prod=s.times(prod,alpha[i]);
          for (          Hypernode lNode : e.getTailNodes()) {
            int l=lNode.getId();
            if (l == j || l == k) {
              continue;
            }
            prod=s.times(prod,beta[l]);
          }
          betaAdj[j]=s.plus(betaAdj[j],prod);
        }
      }
    }
  }
);
  scores.betaAdj=betaAdj;
}