Class CostMatrix
- java.lang.Object
-
- org.processmining.plugins.workshop.Yaguang.WekaDiscriminationTree.Matrix
-
- org.processmining.plugins.workshop.Yaguang.WekaDiscriminationTree.CostMatrix
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable
public class CostMatrix extends Matrix
Class for storing and manipulating a misclassification cost matrix. The element at position i,j in the matrix is the penalty for classifying an instance of class j as class i.- Version:
- $Revision: 1.9.2.1 $
- Author:
- Richard Kirkby (rkirkby@cs.waikato.ac.nz)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringFILE_EXTENSIONThe deafult file extension for cost matrix files
-
Constructor Summary
Constructors Constructor Description CostMatrix(int numOfClasses)Creates a default cost matrix of a particular size.CostMatrix(java.io.Reader reader)Creates a cost matrix from a reader.CostMatrix(CostMatrix toCopy)Creates a cost matrix that is a copy of another.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description InstancesapplyCostMatrix(Instances data, java.util.Random random)Applies the cost matrix to a set of instances.double[]expectedCosts(double[] classProbs)Calculates the expected misclassification cost for each possible class value, given class probability estimates.doublegetMaxCost(int classVal)Gets the maximum cost for a particular class value.voidinitialize()Sets the cost of all correct classifications to 0, and all misclassifications to 1.voidnormalize()Normalizes the matrix so that the diagonal contains zeros.voidreadOldFormat(java.io.Reader reader)Loads a cost matrix in the old format from a reader.intsize()Gets the size of the matrix.-
Methods inherited from class org.processmining.plugins.workshop.Yaguang.WekaDiscriminationTree.Matrix
add, addElement, clone, eigenvalueDecomposition, getColumn, getElement, getL, getMatrix, getRow, getU, hypot, isSymmetric, LUDecomposition, main, multiply, numColumns, numRows, parseMatlab, regression, regression, setColumn, setElement, setRow, solve, toMatlab, toString, transpose, write
-
-
-
-
Constructor Detail
-
CostMatrix
public CostMatrix(CostMatrix toCopy)
Creates a cost matrix that is a copy of another.- Parameters:
toCopy- the matrix to copy.
-
CostMatrix
public CostMatrix(int numOfClasses)
Creates a default cost matrix of a particular size. All values will be 0.- Parameters:
numOfClasses- the number of classes that the cost matrix holds.
-
CostMatrix
public CostMatrix(java.io.Reader reader) throws java.lang.ExceptionCreates a cost matrix from a reader.- Parameters:
reader- the reader to get the values from.- Throws:
java.lang.Exception- if the matrix is invalid.
-
-
Method Detail
-
initialize
public void initialize()
Sets the cost of all correct classifications to 0, and all misclassifications to 1.
-
size
public int size()
Gets the size of the matrix.- Returns:
- the size.
-
applyCostMatrix
public Instances applyCostMatrix(Instances data, java.util.Random random) throws java.lang.Exception
Applies the cost matrix to a set of instances. If a random number generator is supplied the instances will be resampled, otherwise they will be rewighted. Adapted from code once sitting in Instances.java- Parameters:
data- the instances to reweight.random- a random number generator for resampling, if null then instances are rewighted.- Returns:
- a new dataset reflecting the cost of misclassification.
- Throws:
java.lang.Exception- if the data has no class or the matrix in inappropriate.
-
expectedCosts
public double[] expectedCosts(double[] classProbs) throws java.lang.ExceptionCalculates the expected misclassification cost for each possible class value, given class probability estimates.- Parameters:
classProbs- the class probability estimates.- Returns:
- the expected costs.
- Throws:
java.lang.Exception- if the wrong number of class probabilities is supplied.
-
getMaxCost
public double getMaxCost(int classVal)
Gets the maximum cost for a particular class value.- Parameters:
classVal- the class value.- Returns:
- the maximum cost.
-
normalize
public void normalize()
Normalizes the matrix so that the diagonal contains zeros.
-
readOldFormat
public void readOldFormat(java.io.Reader reader) throws java.lang.ExceptionLoads a cost matrix in the old format from a reader. Adapted from code once sitting in Instances.java- Parameters:
reader- the reader to get the values from.- Throws:
java.lang.Exception- if the matrix cannot be read correctly.
-
-