Program: 143973
Project: 143973
Buggy source:
private void sampleClusterAssignments(int sampleNumber){
  for (int p=0; p < numberOfDomains; p++) {
    for (int j=0; j < numberOfFunctions; j++) {
      updateCountsBeforeSamplingClusterAssignment(sampleNumber,p,j);
      int currentNumberOfClusters=dpPriors[p].computeClustersDistribution();
      double cdf[]=new double[currentNumberOfClusters];
      double max=Double.NEGATIVE_INFINITY;
      for (int k=0; k < currentNumberOfClusters; k++) {
        int clusterID=dpPriors[p].getClusterID(k);
        cdf[k]=Math.log(dpPriors[p].getClusterUnnormalizedProbability(clusterID));
        cdf[k]+=confusionMatrixCounts[p][clusterID][0][0] * Math.log(confusionMatrixSamples[sampleNumber][p][clusterID][0][0]);
        cdf[k]+=confusionMatrixCounts[p][clusterID][0][1] * Math.log(confusionMatrixSamples[sampleNumber][p][clusterID][0][1]);
        cdf[k]+=confusionMatrixCounts[p][clusterID][1][0] * Math.log(confusionMatrixSamples[sampleNumber][p][clusterID][1][0]);
        cdf[k]+=confusionMatrixCounts[p][clusterID][1][1] * Math.log(confusionMatrixSamples[sampleNumber][p][clusterID][1][1]);
        if (max < cdf[k])         max=cdf[k];
      }
      cdf[0]-=max;
      for (int k=1; k < currentNumberOfClusters; k++) {
        cdf[k]-=max;
        cdf[k]=Math.log(Math.exp(cdf[k - 1]) + Math.exp(cdf[k]));
      }
      double uniform=Math.log(random.nextDouble()) + cdf[currentNumberOfClusters - 1];
      int newClusterID=dpPriors[p].getClusterID(currentNumberOfClusters - 1);
      clusterAssignmentSamples[sampleNumber][p][j]=newClusterID;
      for (int k=0; k < currentNumberOfClusters - 1; k++) {
        if (cdf[k] > uniform) {
          int clusterID=dpPriors[p].getClusterID(k);
          clusterAssignmentSamples[sampleNumber][p][j]=clusterID;
          break;
        }
      }
      updateCountsAfterSamplingClusterAssignment(sampleNumber,p,j);
    }
  }
}

Fixed version (ground truth):
private void sampleClusterAssignments(int sampleNumber){
  for (int p=0; p < numberOfDomains; p++) {
    for (int j=0; j < numberOfFunctions; j++) {
      int cnt_errs[][]=new int[2][2];
      for (int i=0; i < numberOfDataSamples[p]; i++)       cnt_errs[labelsSamples[sampleNumber][p][i]][functionOutputsArray[j][p][i]]++;
      updateCountsBeforeSamplingClusterAssignment(sampleNumber,p,j);
      int currentNumberOfClusters=dpPriors[p].computeClustersDistribution();
      double cdf[]=new double[currentNumberOfClusters];
      double max=Double.NEGATIVE_INFINITY;
      for (int k=0; k < currentNumberOfClusters; k++) {
        int clusterID=dpPriors[p].getClusterID(k);
        cdf[k]=Math.log(dpPriors[p].getClusterUnnormalizedProbability(clusterID));
        cdf[k]+=cnt_errs[0][0] * Math.log(confusionMatrixSamples[sampleNumber][p][clusterID][0][0]);
        cdf[k]+=cnt_errs[0][1] * Math.log(confusionMatrixSamples[sampleNumber][p][clusterID][0][1]);
        cdf[k]+=cnt_errs[1][0] * Math.log(confusionMatrixSamples[sampleNumber][p][clusterID][1][0]);
        cdf[k]+=cnt_errs[1][1] * Math.log(confusionMatrixSamples[sampleNumber][p][clusterID][1][1]);
        if (max < cdf[k])         max=cdf[k];
      }
      cdf[0]-=max;
      for (int k=1; k < currentNumberOfClusters; k++) {
        cdf[k]-=max;
        cdf[k]=Math.log(Math.exp(cdf[k - 1]) + Math.exp(cdf[k]));
      }
      double uniform=Math.log(random.nextDouble()) + cdf[currentNumberOfClusters - 1];
      int newClusterID=dpPriors[p].getClusterID(currentNumberOfClusters - 1);
      clusterAssignmentSamples[sampleNumber][p][j]=newClusterID;
      for (int k=0; k < currentNumberOfClusters - 1; k++) {
        if (cdf[k] > uniform) {
          int clusterID=dpPriors[p].getClusterID(k);
          clusterAssignmentSamples[sampleNumber][p][j]=clusterID;
          break;
        }
      }
      updateCountsAfterSamplingClusterAssignment(sampleNumber,p,j);
    }
  }
}