Program: 144087
Project: 144087
Buggy source:
public void performGibbsSampling(){
  for (int iterationNumber=0; iterationNumber < burnInIterations; iterationNumber++) {
    samplePriorsAndBurn(0);
    sampleLabelsAndBurn(0);
    sampleZAndBurnWithCollapsedErrorRates(0);
  }
  for (int iterationNumber=0; iterationNumber < numberOfSamples - 1; iterationNumber++) {
    for (int i=0; i < thinning; i++) {
      samplePriorsAndBurn(iterationNumber);
      sampleErrorRatesAndBurn(iterationNumber);
      sampleZAndBurn(iterationNumber);
      sampleLabelsAndBurn(iterationNumber);
    }
    samplePriors(iterationNumber);
    sampleErrorRates(iterationNumber);
    sampleZ(iterationNumber);
    sampleLabels(iterationNumber);
  }
  Set<Integer> uniqueClusters=new HashSet<>();
  for (int p=0; p < numberOfDomains; p++)   uniqueClusters.add(zSamples[zSamples.length - 1][p]);
  for (int sampleNumber=0; sampleNumber < numberOfSamples; sampleNumber++) {
    for (int p=0; p < numberOfDomains; p++) {
      priorMeans[p]+=priorSamples[sampleNumber][p];
      for (int j=0; j < numberOfFunctions; j++)       errorRateMeans[p][j]+=errorRateSamples[sampleNumber][zSamples[sampleNumber][p]][j];
      for (int i=0; i < numberOfDataSamples[p]; i++)       labelMeans[p][i]+=labelsSamples[sampleNumber][p][i];
    }
  }
  for (int p=0; p < numberOfDomains; p++) {
    priorMeans[p]/=numberOfSamples;
    for (int j=0; j < numberOfFunctions; j++)     errorRateMeans[p][j]/=numberOfSamples;
    for (int i=0; i < numberOfDataSamples[p]; i++)     labelMeans[p][i]/=numberOfSamples;
    for (int sampleNumber=0; sampleNumber < numberOfSamples; sampleNumber++) {
      double temp=priorSamples[sampleNumber][p] - priorMeans[p];
      priorVariances[p]+=temp * temp;
      for (int j=0; j < numberOfFunctions; j++) {
        temp=errorRateSamples[sampleNumber][zSamples[sampleNumber][p]][j] - errorRateMeans[p][j];
        errorRateVariances[p][j]+=temp * temp;
      }
      for (int i=0; i < numberOfDataSamples[p]; i++) {
        temp=labelsSamples[sampleNumber][p][i] - labelMeans[p][i];
        labelVariances[p][i]+=temp * temp;
      }
    }
    priorVariances[p]/=(numberOfIterations - burnInIterations - 1);
    for (int j=0; j < numberOfFunctions; j++)     errorRateVariances[p][j]/=(numberOfIterations - burnInIterations - 1);
    for (int i=0; i < numberOfDataSamples[p]; i++)     labelVariances[p][i]/=(numberOfIterations - burnInIterations - 1);
  }
}

Fixed version (ground truth):
public void performGibbsSampling(){
  for (int iterationNumber=0; iterationNumber < burnInIterations; iterationNumber++) {
    samplePriorsAndBurn(0);
    sampleLabelsAndBurnWithCollapsedErrorRates(0);
    sampleZAndBurnWithCollapsedErrorRates(0);
  }
  for (int iterationNumber=0; iterationNumber < numberOfSamples - 1; iterationNumber++) {
    for (int i=0; i < thinning; i++) {
      samplePriorsAndBurn(iterationNumber);
      sampleErrorRatesAndBurn(iterationNumber);
      sampleZAndBurn(iterationNumber);
      sampleLabelsAndBurn(iterationNumber);
    }
    samplePriors(iterationNumber);
    sampleErrorRates(iterationNumber);
    sampleZ(iterationNumber);
    sampleLabels(iterationNumber);
  }
  Set<Integer> uniqueClusters=new HashSet<>();
  for (int p=0; p < numberOfDomains; p++)   uniqueClusters.add(zSamples[zSamples.length - 1][p]);
  for (int sampleNumber=0; sampleNumber < numberOfSamples; sampleNumber++) {
    for (int p=0; p < numberOfDomains; p++) {
      priorMeans[p]+=priorSamples[sampleNumber][p];
      for (int j=0; j < numberOfFunctions; j++)       errorRateMeans[p][j]+=errorRateSamples[sampleNumber][zSamples[sampleNumber][p]][j];
      for (int i=0; i < numberOfDataSamples[p]; i++)       labelMeans[p][i]+=labelsSamples[sampleNumber][p][i];
    }
  }
  for (int p=0; p < numberOfDomains; p++) {
    priorMeans[p]/=numberOfSamples;
    for (int j=0; j < numberOfFunctions; j++)     errorRateMeans[p][j]/=numberOfSamples;
    for (int i=0; i < numberOfDataSamples[p]; i++)     labelMeans[p][i]/=numberOfSamples;
    for (int sampleNumber=0; sampleNumber < numberOfSamples; sampleNumber++) {
      double temp=priorSamples[sampleNumber][p] - priorMeans[p];
      priorVariances[p]+=temp * temp;
      for (int j=0; j < numberOfFunctions; j++) {
        temp=errorRateSamples[sampleNumber][zSamples[sampleNumber][p]][j] - errorRateMeans[p][j];
        errorRateVariances[p][j]+=temp * temp;
      }
      for (int i=0; i < numberOfDataSamples[p]; i++) {
        temp=labelsSamples[sampleNumber][p][i] - labelMeans[p][i];
        labelVariances[p][i]+=temp * temp;
      }
    }
    priorVariances[p]/=(numberOfIterations - burnInIterations - 1);
    for (int j=0; j < numberOfFunctions; j++)     errorRateVariances[p][j]/=(numberOfIterations - burnInIterations - 1);
    for (int i=0; i < numberOfDataSamples[p]; i++)     labelVariances[p][i]/=(numberOfIterations - burnInIterations - 1);
  }
}