package yi.ai.classifiers;

import java.util.*;

/**
 * Result analysis of classifications.  (eg. precise, recall)
 */

public class ResultAnalysis {
  public static ClassificationPerformance ResultAnalysis(Collection objs, Collection found) {
    HashSet objs_set = new HashSet(objs);
    HashSet found_set = new HashSet(found);

    // precision
    int precision_count = 0;
    for (Iterator i = found_set.iterator(); i.hasNext(); ) {
      if (objs_set.contains(i.next()))
        precision_count++;
    }
    double precision = (double) precision_count / found_set.size();

    // recall
    int recall_count = 0;
    for (Iterator i = objs_set.iterator(); i.hasNext(); ) {
      if (found_set.contains(i.next()))
        recall_count++;
    }
    double recall = (double) recall_count / objs_set.size();

    return new ClassificationPerformance(precision, recall);
  }
}