gov.sandia.cognition.learning.performance.categorization
Class AbstractBinaryConfusionMatrix

java.lang.Object
  extended by gov.sandia.cognition.util.AbstractCloneableSerializable
      extended by gov.sandia.cognition.learning.performance.categorization.AbstractConfusionMatrix<Boolean>
          extended by gov.sandia.cognition.learning.performance.categorization.AbstractBinaryConfusionMatrix
All Implemented Interfaces:
BinaryConfusionMatrix, ConfusionMatrix<Boolean>, CloneableSerializable, Serializable, Cloneable
Direct Known Subclasses:
DefaultBinaryConfusionMatrix

public abstract class AbstractBinaryConfusionMatrix
extends AbstractConfusionMatrix<Boolean>
implements BinaryConfusionMatrix

An abstract implementation of the BinaryConfusionMatrix interface. Takes care of a lot of the general operations from the interface so that extending classes only need to focus on the data structure implementation.

Since:
3.1
Author:
Justin Basilico
See Also:
Serialized Form

Constructor Summary
AbstractBinaryConfusionMatrix()
          Creates a new AbstractBinaryConfusionMatrix.
 
Method Summary
 Set<Boolean> getActualCategories()
          Gets the set of all the actual categories.
 double getActualCount(Boolean target)
          Gets the total number of entries for the given actual category.
 Set<Boolean> getCategories()
          Gets the set of all categories in the confusion matrix.
 double getCount(Boolean target, Boolean estimate)
          Gets the entry in the matrix for the given actual and predicted categories, which is the count of the number of times the predicted category was given for the given actual category.
 double getFalseNegativesFraction()
          Gets the fraction of false negatives.
 double getFalsePositivesFraction()
          Gets the fraction of false positives.
 double getFScore()
          The F-score of the confusion matrix, which is also known as the F1-score or F-measure.
 double getFScore(double beta)
          The F-score for the confusion matrix with the given trade-off parameter (beta).
 double getPrecision()
          The precision value for the confusion matrix.
 Set<Boolean> getPredictedCategories()
          Gets the set of all the predicted categories.
 Set<Boolean> getPredictedCategories(Boolean target)
          Gets the predicted categories for a given actual category.
 double getRecall()
          The recall value for the confusion matrix.
 double getSensitivity()
          The sensitivity value for the confusion matrix.
 double getSpecificity()
          The specificity value for the confusion matrix.
 double getTrueNegativesFraction()
          Gets the fraction of true negatives.
 double getTruePositivesFraction()
          Gets the fraction of true positives.
 
Methods inherited from class gov.sandia.cognition.learning.performance.categorization.AbstractConfusionMatrix
add, addAll, getAccuracy, getAverageCategoryAccuracy, getAverageCategoryErrorRate, getCategoryAccuracy, getCategoryErrorRate, getErrorRate, getPredictedCount, getTotalCorrectCount, getTotalCount, getTotalIncorrectCount, isEmpty
 
Methods inherited from class gov.sandia.cognition.util.AbstractCloneableSerializable
clone
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface gov.sandia.cognition.learning.performance.categorization.BinaryConfusionMatrix
getFalseNegativesCount, getFalsePositivesCount, getTrueNegativesCount, getTruePositivesCount
 
Methods inherited from interface gov.sandia.cognition.learning.performance.categorization.ConfusionMatrix
add, add, addAll, clear, getAccuracy, getAverageCategoryAccuracy, getAverageCategoryErrorRate, getCategoryAccuracy, getCategoryErrorRate, getErrorRate, getPredictedCount, getTotalCorrectCount, getTotalCount, getTotalIncorrectCount, isEmpty
 
Methods inherited from interface gov.sandia.cognition.util.CloneableSerializable
clone
 

Constructor Detail

AbstractBinaryConfusionMatrix

public AbstractBinaryConfusionMatrix()
Creates a new AbstractBinaryConfusionMatrix.

Method Detail

getCategories

public Set<Boolean> getCategories()
Description copied from interface: ConfusionMatrix
Gets the set of all categories in the confusion matrix. It is the union of the predicted and actual categories.

Specified by:
getCategories in interface ConfusionMatrix<Boolean>
Returns:
The set of all categories.

getActualCategories

public Set<Boolean> getActualCategories()
Description copied from interface: ConfusionMatrix
Gets the set of all the actual categories.

Specified by:
getActualCategories in interface ConfusionMatrix<Boolean>
Returns:
The set of all actual categories.

getPredictedCategories

public Set<Boolean> getPredictedCategories()
Description copied from interface: ConfusionMatrix
Gets the set of all the predicted categories.

Specified by:
getPredictedCategories in interface ConfusionMatrix<Boolean>
Returns:
The set of all predicted categories.

getPredictedCategories

public Set<Boolean> getPredictedCategories(Boolean target)
Description copied from interface: ConfusionMatrix
Gets the predicted categories for a given actual category. This can be either a sparse set (non-zero values) or a dense set (zeros allowed). However, the sparse set will usually yield higher performance in most use cases.

Specified by:
getPredictedCategories in interface ConfusionMatrix<Boolean>
Parameters:
target - The actual category to get the set of prediction categories for.
Returns:
The set of predicted categories for the given actual categories.

getCount

public double getCount(Boolean target,
                       Boolean estimate)
Description copied from interface: ConfusionMatrix
Gets the entry in the matrix for the given actual and predicted categories, which is the count of the number of times the predicted category was given for the given actual category.

Specified by:
getCount in interface ConfusionMatrix<Boolean>
Parameters:
target - The actual category.
estimate - The predicted category.
Returns:
The count for (actual, predicted).

getActualCount

public double getActualCount(Boolean target)
Description copied from interface: ConfusionMatrix
Gets the total number of entries for the given actual category.

Specified by:
getActualCount in interface ConfusionMatrix<Boolean>
Overrides:
getActualCount in class AbstractConfusionMatrix<Boolean>
Parameters:
target - The actual category.
Returns:
The total number of instances of the given actual category.

getTruePositivesFraction

public double getTruePositivesFraction()
Description copied from interface: BinaryConfusionMatrix
Gets the fraction of true positives. This is the (true, true) fraction.

Specified by:
getTruePositivesFraction in interface BinaryConfusionMatrix
Returns:
The fraction of true positives.

getFalsePositivesFraction

public double getFalsePositivesFraction()
Description copied from interface: BinaryConfusionMatrix
Gets the fraction of false positives. This is the (false, true) fraction.

Specified by:
getFalsePositivesFraction in interface BinaryConfusionMatrix
Returns:
The fraction of false positives.

getTrueNegativesFraction

public double getTrueNegativesFraction()
Description copied from interface: BinaryConfusionMatrix
Gets the fraction of true negatives. This is the (false, false) fraction.

Specified by:
getTrueNegativesFraction in interface BinaryConfusionMatrix
Returns:
The fraction of true negatives.

getFalseNegativesFraction

public double getFalseNegativesFraction()
Description copied from interface: BinaryConfusionMatrix
Gets the fraction of false negatives. This is the (true, false) fraction.

Specified by:
getFalseNegativesFraction in interface BinaryConfusionMatrix
Returns:
The fraction of false negatives.

getSensitivity

public double getSensitivity()
Description copied from interface: BinaryConfusionMatrix
The sensitivity value for the confusion matrix. The sensitivity is the number of true positives divided by the number of true positives plus the number of false negatives: TP / (TP + FN). It is equivalent to recall.

Specified by:
getSensitivity in interface BinaryConfusionMatrix
Returns:
The sensitivity, which is between 0.0 and 1.0.

getSpecificity

public double getSpecificity()
Description copied from interface: BinaryConfusionMatrix
The specificity value for the confusion matrix. The specificity is the number of true negatives divided by the number of true negatives plus the number of false positives: TN / (TN + FP).

Specified by:
getSpecificity in interface BinaryConfusionMatrix
Returns:
The specificity value, which is between 0.0 and 1.0.

getPrecision

public double getPrecision()
Description copied from interface: BinaryConfusionMatrix
The precision value for the confusion matrix. The precision is the number of true positives divided by the number of true positives plus the number of false positives: TP / (TP + FP).

Specified by:
getPrecision in interface BinaryConfusionMatrix
Returns:
The precision value, which is between 0.0 and 1.0.

getRecall

public double getRecall()
Description copied from interface: BinaryConfusionMatrix
The recall value for the confusion matrix. The recall is the number of true positives divided by the number of true positives plus the number of false negatives: TP / (TP + FN). It is equivalent to sensitivity.

Specified by:
getRecall in interface BinaryConfusionMatrix
Returns:
The recall value, which is be between 0.0 and 1.0.

getFScore

public double getFScore()
Description copied from interface: BinaryConfusionMatrix
The F-score of the confusion matrix, which is also known as the F1-score or F-measure. It is calculated as: 2 * (precision * recall) / (precision + recall) It is equivalent to the F-score with beta = 1.

Specified by:
getFScore in interface BinaryConfusionMatrix
Returns:
The F-score, which is between 0.0 and 1.0.

getFScore

public double getFScore(double beta)
Description copied from interface: BinaryConfusionMatrix
The F-score for the confusion matrix with the given trade-off parameter (beta). It is calculated as: (1 + beta^2) * (precision * recall) / ((beta^2 * precision) + recall)

Specified by:
getFScore in interface BinaryConfusionMatrix
Parameters:
beta - The beta value of the score. It is the importance assigned to precision as compared to recall.
Returns:
The F-score for the matrix, which is greater than zero.