Program: 143985
Project: 143985
Buggy source:
public double logLikelihood(List<boolean[][]> functionOutputs){
  numberOfDataSamples=new int[numberOfDomains];
  functionOutputsArray=new int[numberOfFunctions][numberOfDomains][];
  for (int p=0; p < numberOfDomains; p++) {
    numberOfDataSamples[p]=functionOutputs.get(p).length;
    for (int j=0; j < numberOfFunctions; j++) {
      functionOutputsArray[j][p]=new int[numberOfDataSamples[p]];
      for (int i=0; i < numberOfDataSamples[p]; i++)       functionOutputsArray[j][p][i]=functionOutputs.get(p)[i][j] ? 1 : 0;
    }
  }
  for (int p=0; p < numberOfDomains; p++) {
    labelsSamples[0][p]=new int[numberOfDataSamples[p]];
    for (int i=0; i < numberOfDataSamples[p]; i++) {
      int sum=0;
      for (int j=0; j < numberOfFunctions; j++)       sum+=functionOutputsArray[j][p][i];
      labelsSamples[0][p][i]=sum >= (numberOfFunctions / 2) ? 1 : 0;
    }
  }
  double logLikelihood=0;
  for (int sampleNumber=0; sampleNumber < numberOfSamples; sampleNumber++) {
    sampleLabels(sampleNumber);
    for (int p=0; p < numberOfDomains; p++) {
      logLikelihood+=(labelsPriorAlpha - 1) * Math.log(priorSamples[sampleNumber][p]) + (labelsPriorBeta - 1) * Math.log(1 - priorSamples[sampleNumber][p]);
      Map<Integer,AtomicInteger> clusterCounts=new HashMap<>();
      for (int j=0; j < numberOfFunctions; j++)       if (!clusterCounts.containsKey(clusterAssignmentSamples[sampleNumber][p][j]))       clusterCounts.put(clusterAssignmentSamples[sampleNumber][p][j],new AtomicInteger(1));
 else       clusterCounts.get(clusterAssignmentSamples[sampleNumber][p][j]).incrementAndGet();
      for (int j=0; j < numberOfFunctions; j++)       logLikelihood+=Math.log(clusterCounts.get(clusterAssignmentSamples[sampleNumber][p][j]).intValue()) - Math.log(numberOfFunctions);
      for (int i=0; i < numberOfDataSamples[p]; i++) {
        if (labelsSamples[sampleNumber][p][i] == 1)         logLikelihood+=Math.log(priorSamples[sampleNumber][p]);
 else         logLikelihood+=Math.log(1 - priorSamples[sampleNumber][p]);
      }
      for (      int clusterID : clusterCounts.keySet()) {
        logLikelihood+=confusionMatrixPrior[0][0] * Math.log(confusionMatrixSamples[sampleNumber][p][clusterID][0][0]);
        logLikelihood+=confusionMatrixPrior[0][1] * Math.log(confusionMatrixSamples[sampleNumber][p][clusterID][0][1]);
        logLikelihood+=confusionMatrixPrior[1][0] * Math.log(confusionMatrixSamples[sampleNumber][p][clusterID][1][0]);
        logLikelihood+=confusionMatrixPrior[1][1] * Math.log(confusionMatrixSamples[sampleNumber][p][clusterID][1][1]);
      }
      for (int j=0; j < numberOfFunctions; j++)       for (int i=0; i < numberOfDataSamples[p]; i++)       logLikelihood+=Math.log(confusionMatrixSamples[sampleNumber][p][clusterAssignmentSamples[sampleNumber][p][j]][labelsSamples[sampleNumber][p][i]][functionOutputsArray[j][p][i]]);
    }
  }
  return logLikelihood / numberOfSamples;
}

Fixed version (ground truth):
public double logLikelihood(List<boolean[][]> functionOutputs){
  numberOfDataSamples=new int[numberOfDomains];
  functionOutputsArray=new int[numberOfFunctions][numberOfDomains][];
  for (int p=0; p < numberOfDomains; p++) {
    numberOfDataSamples[p]=functionOutputs.get(p).length;
    for (int j=0; j < numberOfFunctions; j++) {
      functionOutputsArray[j][p]=new int[numberOfDataSamples[p]];
      for (int i=0; i < numberOfDataSamples[p]; i++)       functionOutputsArray[j][p][i]=functionOutputs.get(p)[i][j] ? 1 : 0;
    }
  }
  for (int p=0; p < numberOfDomains; p++) {
    labelsSamples[0][p]=new int[numberOfDataSamples[p]];
    for (int i=0; i < numberOfDataSamples[p]; i++) {
      int sum=0;
      for (int j=0; j < numberOfFunctions; j++)       sum+=functionOutputsArray[j][p][i];
      labelsSamples[0][p][i]=sum >= (numberOfFunctions / 2) ? 1 : 0;
    }
  }
  double logLikelihood=0;
  for (int sampleNumber=0; sampleNumber < numberOfSamples; sampleNumber++) {
    sampleLabels(sampleNumber);
    for (int p=0; p < numberOfDomains; p++) {
      logLikelihood+=(labelsPriorAlpha - 1) * Math.log(labelPriorsSamples[sampleNumber][p]) + (labelsPriorBeta - 1) * Math.log(1 - labelPriorsSamples[sampleNumber][p]);
      Map<Integer,AtomicInteger> clusterCounts=new HashMap<>();
      for (int j=0; j < numberOfFunctions; j++)       if (!clusterCounts.containsKey(clusterAssignmentSamples[sampleNumber][p][j]))       clusterCounts.put(clusterAssignmentSamples[sampleNumber][p][j],new AtomicInteger(1));
 else       clusterCounts.get(clusterAssignmentSamples[sampleNumber][p][j]).incrementAndGet();
      for (int j=0; j < numberOfFunctions; j++)       logLikelihood+=Math.log(clusterCounts.get(clusterAssignmentSamples[sampleNumber][p][j]).intValue()) - Math.log(numberOfFunctions);
      for (int i=0; i < numberOfDataSamples[p]; i++) {
        if (labelsSamples[sampleNumber][p][i] == 1)         logLikelihood+=Math.log(labelPriorsSamples[sampleNumber][p]);
 else         logLikelihood+=Math.log(1 - labelPriorsSamples[sampleNumber][p]);
      }
      for (      int clusterID : clusterCounts.keySet()) {
        logLikelihood+=confusionMatrixPrior[0][0] * Math.log(confusionMatrixSamples[sampleNumber][p][clusterID][0][0]);
        logLikelihood+=confusionMatrixPrior[0][1] * Math.log(confusionMatrixSamples[sampleNumber][p][clusterID][0][1]);
        logLikelihood+=confusionMatrixPrior[1][0] * Math.log(confusionMatrixSamples[sampleNumber][p][clusterID][1][0]);
        logLikelihood+=confusionMatrixPrior[1][1] * Math.log(confusionMatrixSamples[sampleNumber][p][clusterID][1][1]);
      }
      for (int j=0; j < numberOfFunctions; j++)       for (int i=0; i < numberOfDataSamples[p]; i++)       logLikelihood+=Math.log(confusionMatrixSamples[sampleNumber][p][clusterAssignmentSamples[sampleNumber][p][j]][labelsSamples[sampleNumber][p][i]][functionOutputsArray[j][p][i]]);
    }
  }
  return logLikelihood / numberOfSamples;
}