Пример #1
0
 /**
  * This method calculates the correlation in a running sum.
  *
  * @param iterator, SimpleIterator iterating over the data structure (the file with less distinct
  *     words)
  * @param counter, the "other" data structure (the file with more distinct words)
  * @param iterSum, total number of words in the file with less distinct words
  * @param counterSum, total number of words in the "other" file
  * @return correlation, a double.
  */
 private static double compare(
     SimpleIterator<DataCount<String>> iterator,
     DataCounter<String> counter,
     int iterSum,
     int counterSum) {
   double corr = 0;
   while (iterator.hasNext()) {
     DataCount<String> current = iterator.next();
     double i = (double) current.count;
     double freq = i / iterSum;
     if (freq < .01 && freq > .0001) {
       double iCounter = (double) counter.getCount(current.data);
       double freqCounter = iCounter / counterSum;
       if (freqCounter < .01 && freqCounter > .0001) {
         corr += Math.pow((freq - freqCounter), 2);
       }
     }
   }
   return corr;
 }