Program: 144069
Project: 144069
Buggy source:
private void sampleTableTopic(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) {
        for (int i=0; i < numberOfDataSamples[p]; i++) {
          if (functionOutputsArray[j][p][i] != labelsSamples[iterationNumber][p][i])           smc_2++;
        }
        smc_1+=numberOfDataSamples[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;
        z_probabilities[i]+=smc_2 * Math.log(errorRateSamples[iterationNumber + 1][k]);
        z_probabilities[i]+=(smc_1 - smc_2) * Math.log(1 - errorRateSamples[iterationNumber + 1][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);
      for (      int j : itm_lc) {
        zSamples[iterationNumber + 1][p][j]=sample_topic;
      }
    }
  }
}

Fixed version (ground truth):
private void sampleTableTopic(int iterationNumber){
  for (int p=0; p < numberOfDomains; p++) {
    int tables_ids[]=hdp.get_tables_taken(p);
    for (    int table_id : tables_ids) {
      int itm_lc[]=hdp.remove_tables_topic_assignment(p,table_id);
      double smc_1=0;
      double smc_2=0;
      for (      int j : itm_lc) {
        for (int i=0; i < numberOfDataSamples[p]; i++) {
          if (functionOutputsArray[j][p][i] != labelsSamples[iterationNumber][p][i])           smc_2++;
        }
        smc_1+=numberOfDataSamples[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;
        z_probabilities[i]+=smc_2 * Math.log(errorRateSamples[iterationNumber + 1][k]);
        z_probabilities[i]+=(smc_1 - smc_2) * Math.log(1 - errorRateSamples[iterationNumber + 1][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);
      for (      int j : itm_lc) {
        zSamples[iterationNumber + 1][p][j]=sample_topic;
      }
    }
  }
}