edu.stanford.nlp.stats
Class PrecisionRecallStats

java.lang.Object
  |
  +--edu.stanford.nlp.stats.PrecisionRecallStats

public class PrecisionRecallStats
extends Object

Utility class for aggregating counts of true positives, false positives, and false negatives and computing precision/recall/F1 stats. Can be used for a single collection of stats, or to aggregate stats from a bunch of runs.


Field Summary
protected  int fnCount
          Count of false negatives.
protected  int fpCount
          Count of false positives.
protected  int tpCount
          Count of true positives.
 
Constructor Summary
PrecisionRecallStats()
          Constructs a new PrecisionRecallStats with initially 0 counts.
PrecisionRecallStats(int tp, int fp, int fn)
          Constructs a new PrecisionRecallStats with the given initial counts.
 
Method Summary
 void addCounts(PrecisionRecallStats prs)
          Adds the counts from the given stats to the counts of this stats.
 void addFN(int count)
          Adds the given number to the count of false negatives.
 void addFP(int count)
          Adds the given number to the count of false positives.
 void addTP(int count)
          Adds the given number to the count of true positives.
 double getFMeasure()
          Returns the current F1 measure (alpha=0.5).
 double getFMeasure(double alpha)
          Returns the F-Measure with the given mixing parameter (must be between 0 and 1).
 int getFN()
          Returns the current count of false negatives.
 int getFP()
          Returns the current count of false positives.
 double getPrecision()
          Returns the current precision: tp/(tp+fp).
 double getRecall()
          Returns the current recall: tp/(tp+fn).
 int getTP()
          Returns the current count of true positives.
 void incrementFN()
          Adds one to the count of false negatives.
 void incrementFP()
          Adds one to the count of false positives.
 void incrementTP()
          Adds one to the count of true positives.
 String toString()
          Returns a String representation of this PrecisionRecallStats, indicating the number of tp, fp, fn counts.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

tpCount

protected int tpCount
Count of true positives.


fpCount

protected int fpCount
Count of false positives.


fnCount

protected int fnCount
Count of false negatives.

Constructor Detail

PrecisionRecallStats

public PrecisionRecallStats()
Constructs a new PrecisionRecallStats with initially 0 counts.


PrecisionRecallStats

public PrecisionRecallStats(int tp,
                            int fp,
                            int fn)
Constructs a new PrecisionRecallStats with the given initial counts.

Method Detail

getTP

public int getTP()
Returns the current count of true positives.


getFP

public int getFP()
Returns the current count of false positives.


getFN

public int getFN()
Returns the current count of false negatives.


addTP

public void addTP(int count)
Adds the given number to the count of true positives.


incrementTP

public void incrementTP()
Adds one to the count of true positives.


addFP

public void addFP(int count)
Adds the given number to the count of false positives.


incrementFP

public void incrementFP()
Adds one to the count of false positives.


addFN

public void addFN(int count)
Adds the given number to the count of false negatives.


incrementFN

public void incrementFN()
Adds one to the count of false negatives.


addCounts

public void addCounts(PrecisionRecallStats prs)
Adds the counts from the given stats to the counts of this stats.


getPrecision

public double getPrecision()
Returns the current precision: tp/(tp+fp).


getRecall

public double getRecall()
Returns the current recall: tp/(tp+fn).


getFMeasure

public double getFMeasure()
Returns the current F1 measure (alpha=0.5).


getFMeasure

public double getFMeasure(double alpha)
Returns the F-Measure with the given mixing parameter (must be between 0 and 1). If either precision or recall are 0, return 0.0. F(alpha) = 1/(alpha/precision + (1-aalpha)/recall)


toString

public String toString()
Returns a String representation of this PrecisionRecallStats, indicating the number of tp, fp, fn counts.

Overrides:
toString in class Object


Stanford NLP Group