|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectde.fu_berlin.ties.io.BaseStorable
de.fu_berlin.ties.eval.FMetrics
public class FMetrics
This class manages and updates evaluation results, calculating precision (P), recall (R) and F-measure (F). It counts true positives (tp), false negatives (tn) and false positives (fp).
The metrics are defines as follows (cf. Manning and Schütze (1999): Foundations of Statistical Natural Language Processing, p. 268f):
Instances of this class are not thread-safe and must be synchronized externally, if required.
Field Summary | |
---|---|
static String |
KEY_F1_MEASURE
Serialization key for the F1 measure. |
static String |
KEY_FALSE_NEG
Serialization key for false negatives. |
static String |
KEY_FALSE_POS
Serialization key for false positives. |
static String |
KEY_PRECISION
Serialization key for the precision. |
static String |
KEY_RECALL
Serialization key for the recall. |
static String |
KEY_TRUE_POS
Serialization key for true positives. |
Constructor Summary | |
---|---|
FMetrics()
Creates a new empty instance. |
|
FMetrics(EvalInput input)
Creates a new instance. |
|
FMetrics(FieldMap fieldMap)
Creates a new instance from a field map, fulfilling the Storable contract. |
|
FMetrics(long initTruePos,
long initFalseNeg,
long initFalsePos)
Creates a new instance. |
Method Summary | |
---|---|
double |
getF1Measure()
Returns the F-measure, setting alpha = 0.5 so P and R are weighted equal ("F1 measure"). |
long |
getFalseNeg()
Returns the number of false negatives (false rejections). |
long |
getFalsePos()
Returns the number of false positives (false acceptances). |
double |
getFMeasure(double alpha)
Returns the F-measure: F = 1 / (alpha * (1/P) + (1-alpha) * (1/R)). |
double |
getPrecision()
Returns the precision: P = tp / (tp + fp). |
double |
getRecall()
Returns the recall: R = tp / (tp + fn). |
long |
getTruePos()
Returns the number of true positives (correct recognitions). |
void |
incFalseNeg()
Increases the number of false negatives by 1. |
void |
incFalsePos()
Increases the number of false positives by 1. |
void |
incTruePos()
Increases the number of true positives by 1. |
FieldMap |
storeFields()
Stores all relevant fields of this object in a field map for serialization. |
void |
update(EvalInput input)
Updates the statistics, increasing the stored values as specified. |
void |
update(long addTruePos,
long addFalseNeg,
long addFalsePos)
Updates the statistics, increasing the stored values as specified. |
Methods inherited from class de.fu_berlin.ties.io.BaseStorable |
---|
toString, toString |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final String KEY_TRUE_POS
public static final String KEY_FALSE_NEG
public static final String KEY_FALSE_POS
public static final String KEY_PRECISION
public static final String KEY_RECALL
public static final String KEY_F1_MEASURE
Constructor Detail |
---|
public FMetrics()
public FMetrics(EvalInput input) throws IllegalArgumentException
input
- contains the initial number of true and false positives and
false negatives
IllegalArgumentException
- if at least one of the input value is
negativepublic FMetrics(FieldMap fieldMap) throws IllegalArgumentException
Storable
contract.
fieldMap
- map containing the serialized fields
IllegalArgumentException
- if at least one of the parameters is
negative or missingpublic FMetrics(long initTruePos, long initFalseNeg, long initFalsePos) throws IllegalArgumentException
initTruePos
- the initial number of true positivesinitFalseNeg
- the initial number of false negativesinitFalsePos
- the initial number of false positives
IllegalArgumentException
- if at least one of the parameters is
negativeMethod Detail |
---|
public final long getFalseNeg()
getFalseNeg
in interface EvalInput
public final long getFalsePos()
getFalsePos
in interface EvalInput
public final double getF1Measure()
getF1Measure
in interface FMetricsView
public final double getFMeasure(double alpha) throws IllegalArgumentException
getFMeasure
in interface FMetricsView
alpha
- a factor in the range from 0.0 to 1.0 defining the weighting
of precision and recall
IllegalArgumentException
- if alpha
is smaller than
0.0 or larger than 1.0public final double getPrecision()
getPrecision
in interface FMetricsView
public final double getRecall()
getRecall
in interface FMetricsView
public final long getTruePos()
getTruePos
in interface EvalInput
public final void incFalseNeg()
public final void incFalsePos()
public final void incTruePos()
public FieldMap storeFields()
FieldMap.createObject(Class)
on the created
field map. The calculated values precision, recall, and F-measure are
also stored (they are ignored when
deserializing a stored instance).
storeFields
in interface Storable
public final void update(EvalInput input) throws IllegalArgumentException
input
- contains the number of true and false positives and
false negatives to add
IllegalArgumentException
- if at least one of the input values is
negativepublic void update(long addTruePos, long addFalseNeg, long addFalsePos) throws IllegalArgumentException
addTruePos
- the number of new true positives to addaddFalseNeg
- the number of new false negatives to addaddFalsePos
- the number of new false positives to add
IllegalArgumentException
- if at least one of the parameters is
negative
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |