Program: 144100
Project: 144100
Buggy source:
private void sampleZAndBurn(int iterationNumber){
  for (int p=0; p < numberOfDomains; p++) {
    for (int j=0; j < numberOfFunctions; j++) {
      double[] z_probabilities=new double[numberOfDomains];
      for (int p_inner=0; p_inner < numberOfDomains; p_inner++)       z_probabilities[zSamples[iterationNumber][p_inner][j]]+=1;
      int k_new=-1;
      for (int k=0; k < z_probabilities.length; k++)       if (z_probabilities[k] == 0.0) {
        z_probabilities[k]=alpha;
        k_new=k;
        break;
      }
      for (int k=0; k < z_probabilities.length; k++) {
        z_probabilities[k]=Math.log(z_probabilities[k]);
        z_probabilities[k]-=Math.log(numberOfDomains - 1 + alpha);
      }
      int count=0;
      for (int i=0; i < numberOfDataSamples[p]; i++)       if (functionOutputsArray[j][p][i] != labelsSamples[iterationNumber][p][i])       count++;
      for (int k=0; k < z_probabilities.length; k++) {
        if (k != k_new) {
          z_probabilities[k]+=count * Math.log(errorRateSamples[iterationNumber][k][j]);
          z_probabilities[k]+=(numberOfDataSamples[p] - count) * Math.log(1 - errorRateSamples[iterationNumber][k][j]);
        }
 else {
          z_probabilities[k_new]+=logBeta(alpha_e + count,beta_e + numberOfDataSamples[p] - count) - logBeta(alpha_e,beta_e);
        }
      }
      double normalizationConstant=MatrixUtilities.computeLogSumExp(z_probabilities);
      for (int k=0; k < z_probabilities.length; k++)       z_probabilities[k]=Math.exp(z_probabilities[k] - normalizationConstant);
      double[] z_cdf=new double[z_probabilities.length];
      z_cdf[0]=z_probabilities[0];
      for (int i=1; i < z_probabilities.length; i++)       z_cdf[i]=z_cdf[i - 1] + z_probabilities[i];
      double uniform=random.nextDouble();
      zSamples[iterationNumber][p][j]=z_probabilities.length - 1;
      for (int k=0; k < z_probabilities.length - 1; k++) {
        if (z_cdf[k] > uniform) {
          zSamples[iterationNumber][p][j]=k;
          break;
        }
      }
    }
  }
}

Fixed version (ground truth):
private void sampleZAndBurn(int iterationNumber){
  for (int p=0; p < numberOfDomains; p++) {
    for (int j=0; j < numberOfFunctions; j++) {
      double[] z_probabilities=new double[numberOfDomains];
      for (int p_inner=0; p_inner < numberOfDomains; p_inner++)       if (p_inner != p)       z_probabilities[zSamples[iterationNumber][p_inner][j]]+=1;
      int k_new=-1;
      for (int k=0; k < z_probabilities.length; k++)       if (z_probabilities[k] == 0.0) {
        z_probabilities[k]=alpha;
        k_new=k;
        break;
      }
      for (int k=0; k < z_probabilities.length; k++) {
        z_probabilities[k]=Math.log(z_probabilities[k]);
        z_probabilities[k]-=Math.log(numberOfDomains - 1 + alpha);
      }
      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 < z_probabilities.length; k++) {
        if (k != k_new) {
          z_probabilities[k]+=disagreements[j][p] * Math.log(errorRateSamples[iterationNumber][k][j]);
          z_probabilities[k]+=(numberOfDataSamples[p] - disagreements[j][p]) * Math.log(1 - errorRateSamples[iterationNumber][k][j]);
        }
 else {
          z_probabilities[k_new]+=logBeta(alpha_e + disagreements[j][p],beta_e + numberOfDataSamples[p] - disagreements[j][p]) - logBeta(alpha_e,beta_e);
        }
      }
      double normalizationConstant=MatrixUtilities.computeLogSumExp(z_probabilities);
      for (int k=0; k < z_probabilities.length; k++)       z_probabilities[k]=Math.exp(z_probabilities[k] - normalizationConstant);
      double[] z_cdf=new double[z_probabilities.length];
      z_cdf[0]=z_probabilities[0];
      for (int i=1; i < z_probabilities.length; i++)       z_cdf[i]=z_cdf[i - 1] + z_probabilities[i];
      double uniform=random.nextDouble();
      zSamples[iterationNumber][p][j]=z_probabilities.length - 1;
      for (int k=0; k < z_probabilities.length - 1; k++) {
        if (z_cdf[k] > uniform) {
          zSamples[iterationNumber][p][j]=k;
          break;
        }
      }
    }
  }
}