Program: 20171
Project: 20171
Buggy source:
public double modelLogLikelihood(){
  double logLikelihood=0.0;
  int nonZeroTopics;
  int[] topicCounts=new int[numTopics];
  double[] topicLogGammas=new double[numTopics];
  int[] docTopics;
  for (int topic=0; topic < numTopics; topic++) {
    topicLogGammas[topic]=Dirichlet.logGammaStirling(alpha[topic]);
  }
  for (int doc=0; doc < data.size(); doc++) {
    LabelSequence topicSequence=(LabelSequence)data.get(doc).topicSequence;
    docTopics=topicSequence.getFeatures();
    for (int token=0; token < docTopics.length; token++) {
      topicCounts[docTopics[token]]++;
    }
    for (int topic=0; topic < numTopics; topic++) {
      if (topicCounts[topic] > 0) {
        logLikelihood+=(Dirichlet.logGammaStirling(alpha[topic] + topicCounts[topic]) - topicLogGammas[topic]);
      }
    }
    logLikelihood-=Dirichlet.logGammaStirling(alphaSum + docTopics.length);
    Arrays.fill(topicCounts,0);
  }
  logLikelihood+=data.size() * Dirichlet.logGammaStirling(alphaSum);
  int nonZeroTypeTopics=0;
  for (int type=0; type < numTypes; type++) {
    topicCounts=typeTopicCounts[type];
    int index=0;
    while (index < topicCounts.length && topicCounts[index] > 0) {
      int topic=topicCounts[index] & topicMask;
      int count=topicCounts[index] >> topicBits;
      nonZeroTypeTopics++;
      logLikelihood+=Dirichlet.logGammaStirling(beta + count);
      if (Double.isNaN(logLikelihood)) {
        System.err.println(count);
        System.exit(1);
      }
      index++;
    }
  }
  for (int topic=0; topic < numTopics; topic++) {
    logLikelihood-=Dirichlet.logGammaStirling((beta * numTypes) + tokensPerTopic[topic]);
    if (Double.isNaN(logLikelihood)) {
      logger.info("String_Node_Str" + topic + "String_Node_Str"+ tokensPerTopic[topic]);
      System.exit(1);
    }
  }
  logLikelihood+=(Dirichlet.logGammaStirling(beta * numTypes)) - (Dirichlet.logGammaStirling(beta) * nonZeroTypeTopics);
  if (Double.isNaN(logLikelihood)) {
    logger.info("String_Node_Str");
    System.exit(1);
  }
  return logLikelihood;
}

Fixed version (ground truth):
public double modelLogLikelihood(){
  double logLikelihood=0.0;
  int nonZeroTopics;
  int[] topicCounts=new int[numTopics];
  double[] topicLogGammas=new double[numTopics];
  int[] docTopics;
  for (int topic=0; topic < numTopics; topic++) {
    topicLogGammas[topic]=Dirichlet.logGammaStirling(alpha[topic]);
  }
  for (int doc=0; doc < data.size(); doc++) {
    LabelSequence topicSequence=(LabelSequence)data.get(doc).topicSequence;
    docTopics=topicSequence.getFeatures();
    for (int token=0; token < docTopics.length; token++) {
      topicCounts[docTopics[token]]++;
    }
    for (int topic=0; topic < numTopics; topic++) {
      if (topicCounts[topic] > 0) {
        logLikelihood+=(Dirichlet.logGammaStirling(alpha[topic] + topicCounts[topic]) - topicLogGammas[topic]);
      }
    }
    logLikelihood-=Dirichlet.logGammaStirling(alphaSum + docTopics.length);
    Arrays.fill(topicCounts,0);
  }
  logLikelihood+=data.size() * Dirichlet.logGammaStirling(alphaSum);
  int nonZeroTypeTopics=0;
  for (int type=0; type < numTypes; type++) {
    topicCounts=typeTopicCounts[type];
    int index=0;
    while (index < topicCounts.length && topicCounts[index] > 0) {
      int topic=topicCounts[index] & topicMask;
      int count=topicCounts[index] >> topicBits;
      nonZeroTypeTopics++;
      logLikelihood+=Dirichlet.logGammaStirling(beta + count);
      if (Double.isNaN(logLikelihood)) {
        logger.warning("String_Node_Str");
        return 0;
      }
 else       if (Double.isInfinite(logLikelihood)) {
        logger.warning("String_Node_Str");
        return 0;
      }
      index++;
    }
  }
  for (int topic=0; topic < numTopics; topic++) {
    logLikelihood-=Dirichlet.logGammaStirling((beta * numTypes) + tokensPerTopic[topic]);
    if (Double.isNaN(logLikelihood)) {
      logger.info("String_Node_Str" + topic + "String_Node_Str"+ tokensPerTopic[topic]);
      return 0;
    }
 else     if (Double.isInfinite(logLikelihood)) {
      logger.info("String_Node_Str" + topic + "String_Node_Str"+ tokensPerTopic[topic]);
      return 0;
    }
  }
  logLikelihood+=(Dirichlet.logGammaStirling(beta * numTypes)) - (Dirichlet.logGammaStirling(beta) * nonZeroTypeTopics);
  if (Double.isNaN(logLikelihood)) {
    logger.info("String_Node_Str");
  }
 else   if (Double.isInfinite(logLikelihood)) {
    logger.info("String_Node_Str" + beta + "String_Node_Str"+ numTypes);
    return 0;
  }
  return logLikelihood;
}