Program: 144099
Project: 144099
Buggy source:
private void sampleZAndBurnWithCollapsedErrorRates(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);
      }
      for (int k=0; k < z_probabilities.length; k++) {
        if (zSamples[iterationNumber][p][j] == k) {
          sum_1[j][k]-=numberOfDataSamples[p];
          sum_2[j][k]-=disagreements[j][p];
        }
        if (k != k_new) {
          double alpha=alpha_e + sum_2[j][k];
          double beta=beta_e + sum_1[j][k] - sum_2[j][k];
          for (int i=0; i < numberOfDataSamples[p]; i++)           if (functionOutputsArray[j][p][i] != labelsSamples[iterationNumber][p][i])           alpha++;
 else           beta++;
          z_probabilities[k]+=logBeta(alpha,beta) - logBeta(alpha_e + sum_2[j][k],beta_e + sum_1[j][k] - sum_2[j][k]);
        }
 else {
          int count=0;
          for (int i=0; i < numberOfDataSamples[p]; i++)           if (functionOutputsArray[j][p][i] != labelsSamples[iterationNumber][p][i])           count+=1;
          z_probabilities[k_new]+=logBeta(alpha_e + count,beta_e + numberOfDataSamples[p] - count);
        }
      }
      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;
          sum_1[j][k]+=numberOfDataSamples[p];
          sum_2[j][k]+=disagreements[j][p];
          break;
        }
      }
    }
  }
}

Fixed version (ground truth):
private void sampleZAndBurnWithCollapsedErrorRates(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 j=0; j < numberOfFunctions; j++) {
    for (int k=0; k < numberOfDomains; k++) {
      sum_2[j][k]=0;
      for (int p=0; p < numberOfDomains; p++) {
        if (zSamples[iterationNumber][p][j] == k)         sum_2[j][k]+=disagreements[j][p];
      }
    }
  }
  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);
      }
      for (int k=0; k < z_probabilities.length; k++) {
        if (zSamples[iterationNumber][p][j] == k) {
          sum_1[j][k]-=numberOfDataSamples[p];
          sum_2[j][k]-=disagreements[j][p];
        }
        if (k != k_new) {
          double alpha=alpha_e + sum_2[j][k] + disagreements[j][p];
          double beta=beta_e + sum_1[j][k] - sum_2[j][k] + numberOfDataSamples[p] - disagreements[j][p];
          z_probabilities[k]+=logBeta(alpha,beta) - logBeta(alpha_e + sum_2[j][k],beta_e + sum_1[j][k] - sum_2[j][k]);
        }
 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;
          sum_1[j][k]+=numberOfDataSamples[p];
          sum_2[j][k]+=disagreements[j][p];
          break;
        }
      }
      if (zSamples[iterationNumber][p][j] == z_probabilities.length - 1) {
        sum_1[j][z_probabilities.length - 1]+=numberOfDataSamples[p];
        sum_2[j][z_probabilities.length - 1]+=disagreements[j][p];
      }
    }
  }
}