Program: 144076
Project: 144076
Buggy source:
public void performGibbsSampling(){
  for (int iterationNumber=0; iterationNumber < burnInIterations; iterationNumber++) {
    samplePriorsAndBurn(0);
    sampleErrorRatesAndBurn(0);
    sampleZAndBurn(0);
    sampleLabelsAndBurn(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++)   for (int j=0; j < numberOfFunctions; j++)   uniqueClusters.add(zSamples[zSamples.length - 1][p][j]);
  System.out.println("String_Node_Str" + uniqueClusters.size());
  for (int sampleNumber=0; sampleNumber < numberOfSamples; sampleNumber++) {
    for (int p=0; p < numberOfDomains; p++) {
      int numberOfPhiBelowChance=0;
      for (int j=0; j < numberOfFunctions; j++)       if (errorRateSamples[sampleNumber][zSamples[sampleNumber][p][j]] < 0.5)       numberOfPhiBelowChance++;
      if (numberOfPhiBelowChance < numberOfFunctions / 2.0) {
        priorSamples[sampleNumber][p]=1 - priorSamples[sampleNumber][p];
        for (int j=0; j < numberOfFunctions; j++)         errorRateSamples[sampleNumber][zSamples[sampleNumber][p][j]]=1 - errorRateSamples[sampleNumber][zSamples[sampleNumber][p][j]];
      }
      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);
    sampleInternalTableTopicsAndBurnWithCollapsedErrorRates(0);
  }
  for (int iterationNumber=0; iterationNumber < numberOfSamples - 1; iterationNumber++) {
    for (int i=0; i < thinning; i++) {
      samplePriorsAndBurn(iterationNumber);
      sampleErrorRatesAndBurn(iterationNumber);
      sampleZAndBurn(iterationNumber);
      sampleTableTopicAndBurn(iterationNumber);
      sampleLabelsAndBurn(iterationNumber);
    }
    samplePriors(iterationNumber);
    sampleErrorRates(iterationNumber);
    sampleZ(iterationNumber);
    sampleTableTopic(iterationNumber);
    sampleLabels(iterationNumber);
  }
  Set<Integer> uniqueClusters=new HashSet<>();
  for (int p=0; p < numberOfDomains; p++)   for (int j=0; j < numberOfFunctions; j++)   uniqueClusters.add(zSamples[zSamples.length - 1][p][j]);
  System.out.println("String_Node_Str" + uniqueClusters.size());
  for (int sampleNumber=0; sampleNumber < numberOfSamples; sampleNumber++) {
    for (int p=0; p < numberOfDomains; p++) {
      int numberOfPhiBelowChance=0;
      for (int j=0; j < numberOfFunctions; j++)       if (errorRateSamples[sampleNumber][zSamples[sampleNumber][p][j]] < 0.5)       numberOfPhiBelowChance++;
      if (numberOfPhiBelowChance < numberOfFunctions / 2.0) {
        priorSamples[sampleNumber][p]=1 - priorSamples[sampleNumber][p];
        for (int j=0; j < numberOfFunctions; j++)         errorRateSamples[sampleNumber][zSamples[sampleNumber][p][j]]=1 - errorRateSamples[sampleNumber][zSamples[sampleNumber][p][j]];
      }
      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);
  }
}