Program: 4462
Project: 4462
Buggy source:
/** 
 * Given a series of anomaly scores, compute the likelihood for each score. This function should be called once on a bunch of historical anomaly scores for an initial estimate of the distribution. It should be called again every so often (say every 50 records) to update the estimate.
 * @param anomalyScores
 * @param averagingWindow
 * @param skipRecords
 * @return
 */
public AnomalyLikelihoodMetrics estimateAnomalyLikelihoods(List<Sample> anomalyScores,int averagingWindow,int skipRecords){
  if (anomalyScores.size() == 0) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  AveragedAnomalyRecordList records=anomalyScoreMovingAverage(anomalyScores,averagingWindow);
  Statistic distribution;
  if (records.averagedRecords.size() <= skipRecords) {
    distribution=nullDistribution();
  }
 else {
    TDoubleList samples=records.getMetrics();
    distribution=estimateNormal(samples.toArray(skipRecords,samples.size()),true);
    samples=records.getSamples();
    Statistic metricDistribution=estimateNormal(samples.toArray(skipRecords,samples.size()),false);
    if (metricDistribution.variance < 1.5e-5) {
      distribution=nullDistribution();
    }
  }
  int i=0;
  double[] likelihoods=new double[records.averagedRecords.size()];
  for (  Sample sample : records.averagedRecords) {
    likelihoods[i++]=normalProbability(sample.score,distribution);
  }
  double[] filteredLikelihoods=filterLikelihoods(likelihoods);
  int len=likelihoods.length;
  AnomalyParams params=new AnomalyParams(new String[]{"String_Node_Str","String_Node_Str","String_Node_Str"},distribution,new MovingAverage(records.historicalValues,records.total,averagingWindow),len > 0 ? Arrays.copyOfRange(likelihoods,len - Math.min(averagingWindow,len),len) : new double[0]);
  if (LOG.isDebugEnabled()) {
    LOG.debug("String_Node_Str",params,len,Arrays.copyOfRange(filteredLikelihoods,0,20));
  }
  return new AnomalyLikelihoodMetrics(filteredLikelihoods,records,params);
}

Fixed version (ground truth):
/** 
 * Given a series of anomaly scores, compute the likelihood for each score. This function should be called once on a bunch of historical anomaly scores for an initial estimate of the distribution. It should be called again every so often (say every 50 records) to update the estimate.
 * @param anomalyScores
 * @param averagingWindow
 * @param skipRecords
 * @return
 */
public AnomalyLikelihoodMetrics estimateAnomalyLikelihoods(List<Sample> anomalyScores,int averagingWindow,int skipRecords){
  if (anomalyScores.size() == 0) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  AveragedAnomalyRecordList records=anomalyScoreMovingAverage(anomalyScores,averagingWindow);
  Statistic distribution;
  if (records.averagedRecords.size() <= skipRecords) {
    distribution=nullDistribution();
  }
 else {
    TDoubleList samples=records.getMetrics();
    final int numRecordsToCopy=samples.size() - skipRecords;
    distribution=estimateNormal(samples.toArray(skipRecords,numRecordsToCopy),true);
    samples=records.getSamples();
    Statistic metricDistribution=estimateNormal(samples.toArray(skipRecords,numRecordsToCopy),false);
    if (metricDistribution.variance < 1.5e-5) {
      distribution=nullDistribution();
    }
  }
  int i=0;
  double[] likelihoods=new double[records.averagedRecords.size()];
  for (  Sample sample : records.averagedRecords) {
    likelihoods[i++]=normalProbability(sample.score,distribution);
  }
  double[] filteredLikelihoods=filterLikelihoods(likelihoods);
  int len=likelihoods.length;
  AnomalyParams params=new AnomalyParams(new String[]{"String_Node_Str","String_Node_Str","String_Node_Str"},distribution,new MovingAverage(records.historicalValues,records.total,averagingWindow),len > 0 ? Arrays.copyOfRange(likelihoods,len - Math.min(averagingWindow,len),len) : new double[0]);
  if (LOG.isDebugEnabled()) {
    LOG.debug("String_Node_Str",params,len,Arrays.copyOfRange(filteredLikelihoods,0,20));
  }
  return new AnomalyLikelihoodMetrics(filteredLikelihoods,records,params);
}