Program: 144112
Project: 144112
Buggy source:
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 * numberOfFunctions; 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 * numberOfFunctions];
      for (int p_inner=0; p_inner < numberOfDomains; p_inner++)       for (int j_inner=0; j_inner < numberOfFunctions; j_inner++)       if (p_inner != p || j_inner != j)       z_probabilities[zSamples[iterationNumber][p_inner][j_inner]]++;
      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];
      }
    }
  }
}

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 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++) {
    for (int j=0; j < numberOfFunctions; j++) {
      double[] z_probabilities=new double[numberOfDomains * numberOfFunctions];
      for (int p_inner=0; p_inner < numberOfDomains; p_inner++)       for (int j_inner=0; j_inner < numberOfFunctions; j_inner++)       if (p_inner != p || j_inner != j)       z_probabilities[zSamples[iterationNumber][p_inner][j_inner]]++;
      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[k]-=numberOfDataSamples[p];
          sum_2[k]-=disagreements[j][p];
        }
        if (k != k_new) {
          double alpha=alpha_e + sum_2[k] + disagreements[j][p];
          double beta=beta_e + sum_1[k] - sum_2[k] + numberOfDataSamples[p] - disagreements[j][p];
          z_probabilities[k]+=logBeta(alpha,beta) - logBeta(alpha_e + sum_2[k],beta_e + sum_1[k] - sum_2[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[k]+=numberOfDataSamples[p];
          sum_2[k]+=disagreements[j][p];
          break;
        }
      }
      if (zSamples[iterationNumber][p][j] == z_probabilities.length - 1) {
        sum_1[z_probabilities.length - 1]+=numberOfDataSamples[p];
        sum_2[z_probabilities.length - 1]+=disagreements[j][p];
      }
    }
  }
}