Program: 144070
Project: 144070
Buggy source:
private void sampleLabelsAndBurnWithCollapsedErrorRates(int iterationNumber){
  int topics[]=hdp.get_topics();
  TIntIntHashMap hmp=new TIntIntHashMap();
  for (int i=0; i < topics.length; i++) {
    hmp.put(topics[i],i);
  }
  for (int p=0; p < numberOfDomains; p++) {
    for (int i=0; i < numberOfDataSamples[p]; i++) {
      double mistake[][]=new double[topics.length][2];
      double matches[][]=new double[topics.length][2];
      for (int j=0; j < numberOfFunctions; j++) {
        if (functionOutputsArray[j][p][i] == 1) {
          mistake[hmp.get(zSamples[iterationNumber][p][j])][0]+=1;
          matches[hmp.get(zSamples[iterationNumber][p][j])][1]+=1;
        }
 else {
          mistake[hmp.get(zSamples[iterationNumber][p][j])][1]+=1;
          matches[hmp.get(zSamples[iterationNumber][p][j])][0]+=1;
        }
        if (functionOutputsArray[j][p][i] != labelsSamples[iterationNumber][p][i]) {
          disagreements[j][p]--;
          sum_2[zSamples[iterationNumber][j][p]]--;
        }
        sum_1[zSamples[iterationNumber][j][p]]--;
      }
      double p1=Math.log(priorSamples[iterationNumber][p]);
      double p0=Math.log(1 - priorSamples[iterationNumber][p]);
      for (      int tp : topics) {
        for (int l=0; l < mistake[hmp.get(tp)][0]; l++) {
          p0+=Math.log(alpha_e + sum_2[tp] + l);
        }
        for (int l=0; l < mistake[hmp.get(tp)][1]; l++) {
          p1+=Math.log(alpha_e + sum_2[tp] + l);
        }
        for (int l=0; l < matches[hmp.get(tp)][0]; l++) {
          p0+=Math.log(beta_e + sum_1[tp] - sum_2[tp] + l);
        }
        for (int l=0; l < matches[hmp.get(tp)][1]; l++) {
          p1+=Math.log(beta_e + sum_1[tp] - sum_2[tp] + l);
        }
      }
      double logsum=MatrixUtilities.computeLogSumExp(p1,p0);
      labelsSamples[iterationNumber][p][i]=randomDataGenerator.nextBinomial(1,Math.exp(p1 - logsum));
      for (int j=0; j < numberOfFunctions; j++) {
        if (functionOutputsArray[j][p][i] != labelsSamples[iterationNumber][p][i]) {
          disagreements[j][p]++;
          sum_2[zSamples[iterationNumber][j][p]]++;
        }
        sum_1[zSamples[iterationNumber][j][p]]++;
      }
    }
  }
}

Fixed version (ground truth):
private void sampleLabelsAndBurnWithCollapsedErrorRates(int iterationNumber){
  int topics[]=hdp.get_topics();
  TIntIntHashMap hmp=new TIntIntHashMap();
  for (int i=0; i < topics.length; i++) {
    hmp.put(topics[i],i);
  }
  for (int p=0; p < numberOfDomains; p++) {
    for (int i=0; i < numberOfDataSamples[p]; i++) {
      double mistake[][]=new double[topics.length][2];
      double matches[][]=new double[topics.length][2];
      for (int j=0; j < numberOfFunctions; j++) {
        if (functionOutputsArray[j][p][i] == 1) {
          mistake[hmp.get(zSamples[iterationNumber][p][j])][0]+=1;
          matches[hmp.get(zSamples[iterationNumber][p][j])][1]+=1;
        }
 else {
          mistake[hmp.get(zSamples[iterationNumber][p][j])][1]+=1;
          matches[hmp.get(zSamples[iterationNumber][p][j])][0]+=1;
        }
        if (functionOutputsArray[j][p][i] != labelsSamples[iterationNumber][p][i]) {
          disagreements[j][p]--;
          sum_2[zSamples[iterationNumber][p][j]]--;
        }
        sum_1[zSamples[iterationNumber][p][j]]--;
      }
      double p1=Math.log(priorSamples[iterationNumber][p]);
      double p0=Math.log(1 - priorSamples[iterationNumber][p]);
      for (      int tp : topics) {
        for (int l=0; l < mistake[hmp.get(tp)][0]; l++) {
          p0+=Math.log(alpha_e + sum_2[tp] + l);
        }
        for (int l=0; l < mistake[hmp.get(tp)][1]; l++) {
          p1+=Math.log(alpha_e + sum_2[tp] + l);
        }
        for (int l=0; l < matches[hmp.get(tp)][0]; l++) {
          p0+=Math.log(beta_e + sum_1[tp] - sum_2[tp] + l);
        }
        for (int l=0; l < matches[hmp.get(tp)][1]; l++) {
          p1+=Math.log(beta_e + sum_1[tp] - sum_2[tp] + l);
        }
      }
      double logsum=MatrixUtilities.computeLogSumExp(p1,p0);
      labelsSamples[iterationNumber][p][i]=randomDataGenerator.nextBinomial(1,Math.exp(p1 - logsum));
      for (int j=0; j < numberOfFunctions; j++) {
        if (functionOutputsArray[j][p][i] != labelsSamples[iterationNumber][p][i]) {
          disagreements[j][p]++;
          sum_2[zSamples[iterationNumber][p][j]]++;
        }
        sum_1[zSamples[iterationNumber][p][j]]++;
      }
    }
  }
}