Program: 144068
Project: 144068
Buggy source:
private void sampleInternalTableTopicsAndBurnWithCollapsedErrorRates(int iterationNumber){
  for (int p=0; p < numberOfDomains; p++) {
    for (int j=0; j < numberOfFunctions; j++) {
      disagreements[j][p]=0;
      for (int i=0; i < numberOfDataSamples[p]; i++)       if (functionOutputsArray[j][p][i] != labelsSamples[iterationNumber][p][i])       disagreements[j][p]++;
    }
  }
  for (int k=0; k < numberOfDomains * numberOfFunctions; k++) {
    sum_2[k]=0;
    for (int j=0; j < numberOfFunctions; j++) {
      for (int p=0; p < numberOfDomains; p++) {
        if (zSamples[iterationNumber][p][j] == k)         sum_2[k]+=disagreements[j][p];
      }
    }
  }
  for (int p=0; p < numberOfDomains; p++) {
    int tables_ids[]=hdp.get_tables_taken(p);
    for (    int table_id : tables_ids) {
      int previous_topic=hdp.get_topic_table(p,table_id);
      int itm_lc[]=hdp.remove_tables_topic_assignment(p,table_id);
      double smc_1=0;
      double smc_2=0;
      for (      int j : itm_lc) {
        sum_1[previous_topic]-=numberOfDataSamples[p];
        smc_1+=numberOfDataSamples[p];
        sum_2[previous_topic]-=disagreements[j][p];
        smc_2+=disagreements[j][p];
      }
      int total_cnt=hdp.prob_topic_assignment_for_table(p,table_id);
      double z_probabilities[]=new double[total_cnt];
      for (int i=0; i < total_cnt; i++) {
        z_probabilities[i]=Math.log(hdp.pdf[i].prob);
      }
      for (int i=0; i < total_cnt - 1; i++) {
        int k=hdp.pdf[i].topic;
        double alpha=alpha_e + sum_2[k] + smc_2;
        double beta=beta_e + sum_1[k] - sum_2[k] + smc_1 - smc_2;
        z_probabilities[i]+=logBeta(alpha,beta) - logBeta(alpha_e + sum_2[k],beta_e + sum_1[k] - sum_2[k]);
      }
      z_probabilities[total_cnt - 1]+=logBeta(alpha_e + smc_2,beta_e + smc_1 - smc_2) - logBeta(alpha_e,beta_e);
      for (int i=1; i < total_cnt; i++) {
        z_probabilities[i]=MatrixUtilities.computeLogSumExp(z_probabilities[i - 1],z_probabilities[i]);
      }
      double uniform=Math.log(random.nextDouble()) + z_probabilities[total_cnt - 1];
      int sample_topic=hdp.pdf[total_cnt - 1].topic;
      for (int i=0; i < total_cnt - 1; i++) {
        if (z_probabilities[i] > uniform) {
          sample_topic=hdp.pdf[i].topic;
          break;
        }
      }
      hdp.add_tobles_topic_assignment(p,table_id,sample_topic);
      sum_1[sample_topic]+=smc_1;
      sum_2[sample_topic]+=smc_2;
      for (      int j : itm_lc) {
        zSamples[iterationNumber][p][j]=sample_topic;
      }
    }
  }
}

Fixed version (ground truth):
private void sampleInternalTableTopicsAndBurnWithCollapsedErrorRates(int iterationNumber){
  for (int p=0; p < numberOfDomains; p++) {
    int tables_ids[]=hdp.get_tables_taken(p);
    for (    int table_id : tables_ids) {
      int previous_topic=hdp.get_topic_table(p,table_id);
      int itm_lc[]=hdp.remove_tables_topic_assignment(p,table_id);
      double smc_1=0;
      double smc_2=0;
      for (      int j : itm_lc) {
        sum_1[previous_topic]-=numberOfDataSamples[p];
        smc_1+=numberOfDataSamples[p];
        sum_2[previous_topic]-=disagreements[j][p];
        smc_2+=disagreements[j][p];
      }
      int total_cnt=hdp.prob_topic_assignment_for_table(p,table_id);
      double z_probabilities[]=new double[total_cnt];
      for (int i=0; i < total_cnt; i++) {
        z_probabilities[i]=Math.log(hdp.pdf[i].prob);
      }
      for (int i=0; i < total_cnt - 1; i++) {
        int k=hdp.pdf[i].topic;
        double alpha=alpha_e + sum_2[k] + smc_2;
        double beta=beta_e + sum_1[k] - sum_2[k] + smc_1 - smc_2;
        z_probabilities[i]+=logBeta(alpha,beta) - logBeta(alpha_e + sum_2[k],beta_e + sum_1[k] - sum_2[k]);
      }
      z_probabilities[total_cnt - 1]+=logBeta(alpha_e + smc_2,beta_e + smc_1 - smc_2) - logBeta(alpha_e,beta_e);
      for (int i=1; i < total_cnt; i++) {
        z_probabilities[i]=MatrixUtilities.computeLogSumExp(z_probabilities[i - 1],z_probabilities[i]);
      }
      double uniform=Math.log(random.nextDouble()) + z_probabilities[total_cnt - 1];
      int sample_topic=hdp.pdf[total_cnt - 1].topic;
      for (int i=0; i < total_cnt - 1; i++) {
        if (z_probabilities[i] > uniform) {
          sample_topic=hdp.pdf[i].topic;
          break;
        }
      }
      hdp.add_tobles_topic_assignment(p,table_id,sample_topic);
      sum_1[sample_topic]+=smc_1;
      sum_2[sample_topic]+=smc_2;
      for (      int j : itm_lc) {
        zSamples[iterationNumber][p][j]=sample_topic;
      }
    }
  }
}