gov.sandia.cognition.learning.performance.categorization
Class AbstractConfusionMatrix<CategoryType>

java.lang.Object
  extended by gov.sandia.cognition.util.AbstractCloneableSerializable
      extended by gov.sandia.cognition.learning.performance.categorization.AbstractConfusionMatrix<CategoryType>
Type Parameters:
CategoryType - The type of category that the confusion matrix is under.
All Implemented Interfaces:
ConfusionMatrix<CategoryType>, CloneableSerializable, Serializable, Cloneable
Direct Known Subclasses:
AbstractBinaryConfusionMatrix, DefaultConfusionMatrix

public abstract class AbstractConfusionMatrix<CategoryType>
extends AbstractCloneableSerializable
implements ConfusionMatrix<CategoryType>

An abstract implementation of the ConfusionMatrix interface. Takes care of a lot of the support functions in the interface so that implementations can focus on the core data structures.

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

Constructor Summary
AbstractConfusionMatrix()
          Creates a new AbstractConfusionMatrix.
 
Method Summary
 void add(CategoryType target, CategoryType estimate)
          Adds a count of one to the matrix entry for the (actual, predicted) pair.
<OtherType extends CategoryType>
void
addAll(ConfusionMatrix<OtherType> other)
          Adds all of the values in the given confusion matrix to this confusion matrix.
 double getAccuracy()
          The accuracy value of the entire confusion matrix.
 double getActualCount(CategoryType target)
          Gets the total number of entries for the given actual category.
 double getAverageCategoryAccuracy()
          The average accuracy value for the categories in the confusion matrix.
 double getAverageCategoryErrorRate()
          The average error rate for the actual categories in the confusion matrix.
 double getCategoryAccuracy(CategoryType category)
          The category accuracy value for the confusion matrix.
 double getCategoryErrorRate(CategoryType category)
          The category error rate for the confusion matrix.
 double getErrorRate()
          The error rate of the entire confusion matrix.
 double getPredictedCount(CategoryType predicted)
          Gets the total number of entries for the given predicted category.
 double getTotalCorrectCount()
          Gets the total number of correct entries in the confusion matrix.
 double getTotalCount()
          Gets the total number of entries in the confusion matrix.
 double getTotalIncorrectCount()
          Gets the total number of incorrect entries in the confusion matrix.
 boolean isEmpty()
          Gets whether or not the matrix is empty.
 
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.ConfusionMatrix
add, clear, getActualCategories, getCategories, getCount, getPredictedCategories, getPredictedCategories
 
Methods inherited from interface gov.sandia.cognition.util.CloneableSerializable
clone
 

Constructor Detail

AbstractConfusionMatrix

public AbstractConfusionMatrix()
Creates a new AbstractConfusionMatrix.

Method Detail

add

public void add(CategoryType target,
                CategoryType estimate)
Description copied from interface: ConfusionMatrix
Adds a count of one to the matrix entry for the (actual, predicted) pair.

Specified by:
add in interface ConfusionMatrix<CategoryType>
Parameters:
target - The actual category.
estimate - The predicted category.

addAll

public <OtherType extends CategoryType> void addAll(ConfusionMatrix<OtherType> other)
Description copied from interface: ConfusionMatrix
Adds all of the values in the given confusion matrix to this confusion matrix.

Specified by:
addAll in interface ConfusionMatrix<CategoryType>
Type Parameters:
OtherType - The type of values in the other matrix, which must extend the type of value in this matrix. Typically these will be the same.
Parameters:
other - The other confusion matrix to add all of its values to this one.

isEmpty

public boolean isEmpty()
Description copied from interface: ConfusionMatrix
Gets whether or not the matrix is empty. This is equivalent to having a total count of zero.

Specified by:
isEmpty in interface ConfusionMatrix<CategoryType>
Returns:
True if the matrix is empty; otherwise, false.

getTotalCount

public double getTotalCount()
Description copied from interface: ConfusionMatrix
Gets the total number of entries in the confusion matrix. It is the sum of all counts.

Specified by:
getTotalCount in interface ConfusionMatrix<CategoryType>
Returns:
The total number of entries in the confusion matrix.

getTotalCorrectCount

public double getTotalCorrectCount()
Description copied from interface: ConfusionMatrix
Gets the total number of correct entries in the confusion matrix. It is the sum of the "diagonal" elements of the matrix. Must be greater than or equal to zero and less than or equal to the total count.

Specified by:
getTotalCorrectCount in interface ConfusionMatrix<CategoryType>
Returns:
The total number of correct predictions.

getTotalIncorrectCount

public double getTotalIncorrectCount()
Description copied from interface: ConfusionMatrix
Gets the total number of incorrect entries in the confusion matrix. It is the sum of all the "non-diagonal" elements of the matrix. Must be greater than or equal to zero and less than or equal to the total count. Equal to getTotalCount() - getTotalCorrectCount().

Specified by:
getTotalIncorrectCount in interface ConfusionMatrix<CategoryType>
Returns:
The total number of incorrect predictions.

getActualCount

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

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

getPredictedCount

public double getPredictedCount(CategoryType predicted)
Description copied from interface: ConfusionMatrix
Gets the total number of entries for the given predicted category.

Specified by:
getPredictedCount in interface ConfusionMatrix<CategoryType>
Parameters:
predicted - The predicted category.
Returns:
The total number of instances of the given predicted category.

getAccuracy

public double getAccuracy()
Description copied from interface: ConfusionMatrix
The accuracy value of the entire confusion matrix. It is the sum of counts where the actual and predicted value are the same, divided by the total number of entries in the matrix. It is equivalent to: 1 - errorRate.

Specified by:
getAccuracy in interface ConfusionMatrix<CategoryType>
Returns:
The accuracy value for the confusion matrix, which is between 0.0 and 1.0.

getCategoryAccuracy

public double getCategoryAccuracy(CategoryType category)
Description copied from interface: ConfusionMatrix
The category accuracy value for the confusion matrix. It is the number of predicted values that equal the actual values for the given category divided by the number of values for the category.

Specified by:
getCategoryAccuracy in interface ConfusionMatrix<CategoryType>
Parameters:
category - The category to get the accuracy for.
Returns:
The category accuracy, which is between 0.0 and 1.0.

getAverageCategoryAccuracy

public double getAverageCategoryAccuracy()
Description copied from interface: ConfusionMatrix
The average accuracy value for the categories in the confusion matrix. This is different than the accuracy in that each category is given equal weight in the accuracy calculation. Only actual categories that have a count greater than 0 are included.

Specified by:
getAverageCategoryAccuracy in interface ConfusionMatrix<CategoryType>
Returns:
The average category accuracy, which is between 0.0 and 1.0.

getErrorRate

public double getErrorRate()
Description copied from interface: ConfusionMatrix
The error rate of the entire confusion matrix. It sum of counts where the actual value is not equal to the predicted value, divided by the total number of entries in the matrix. It is equivalent to: 1 - accuracy.

Specified by:
getErrorRate in interface ConfusionMatrix<CategoryType>
Returns:
The error rate for the confusion matrix, which is between 0.0 and 1.0.

getCategoryErrorRate

public double getCategoryErrorRate(CategoryType category)
Description copied from interface: ConfusionMatrix
The category error rate for the confusion matrix. It is the number of predicted values that equal the actual values for the given category divided by the number of values for the category.

Specified by:
getCategoryErrorRate in interface ConfusionMatrix<CategoryType>
Parameters:
category - The category to get the error rate for.
Returns:
The category error rate, which is between 0.0 and 1.0.

getAverageCategoryErrorRate

public double getAverageCategoryErrorRate()
Description copied from interface: ConfusionMatrix
The average error rate for the actual categories in the confusion matrix. This is different than the error rate in that each category is given equal weight in the error rate calculation. Only actual categories that have a count greater than 0 are included.

Specified by:
getAverageCategoryErrorRate in interface ConfusionMatrix<CategoryType>
Returns:
The average category error rate, which is between 0.0 and 1.0.