de.jstacs.classifiers
Class MappingClassifier

java.lang.Object
  extended by de.jstacs.classifiers.AbstractClassifier
      extended by de.jstacs.classifiers.AbstractScoreBasedClassifier
          extended by de.jstacs.classifiers.MappingClassifier
All Implemented Interfaces:
Storable, Cloneable

public class MappingClassifier
extends AbstractScoreBasedClassifier

This class allows the user to train the classifier on a given number of classes and to evaluate the classifier on a smaller number of classes by mapping classes together. For instance the user has a classifier for 3 classes, but likes to evaluate whether the classifier is able to discriminate between class 1 and class 2 and 3. This is a good example where to use this class. The user has to create its 3-class-classifier, create an instance of this class using its classifier, map the test data sets together ( mapDataSet(DataSet[])) and invoke AbstractClassifier.evaluate(AbstractPerformanceMeasureParameterSet, boolean, DataSet...) with these mapped DataSet. Alternatively, the method AbstractClassifier.evaluate(AbstractPerformanceMeasureParameterSet, boolean, DataSet...) can be used directly and the DataSets will be mapped internally (i.e. inside the evaluate method).

Author:
Jens Keilwagen

Nested Class Summary
 
Nested classes/interfaces inherited from class de.jstacs.classifiers.AbstractScoreBasedClassifier
AbstractScoreBasedClassifier.DoubleTableResult
 
Constructor Summary
MappingClassifier(AbstractScoreBasedClassifier classifier, int... mapping)
          Creates a new MappingClassifier from a given classifier and a class mapping.
MappingClassifier(StringBuffer representation)
          The standard constructor for the interface Storable.
 
Method Summary
protected  void extractFurtherClassifierInfosFromXML(StringBuffer xml)
          Extracts further information of a classifier from an XML representation.
 CategoricalResult[] getClassifierAnnotation()
          Returns an array of Results of dimension AbstractClassifier.getNumberOfClasses() that contains information about the classifier and for each class.

res[0] = new CategoricalResult( "classifier", "the kind of classifier", getInstanceName() );
res[1] = new CategoricalResult( "class info 0", "some information about the class", "info0" );
res[2] = new CategoricalResult( "class info 1", "some information about the class", "info1" );
...
protected  StringBuffer getFurtherClassifierInfos()
          This method returns further information of a classifier as a StringBuffer.
 String getInstanceName()
          Returns a short description of the classifier.
 NumericalResultSet getNumericalCharacteristics()
          Returns the subset of numerical values that are also returned by AbstractClassifier.getCharacteristics().
protected  boolean getResults(LinkedList list, DataSet[] s, double[][] weights, AbstractPerformanceMeasureParameterSet<? extends PerformanceMeasure> params, boolean exceptionIfNotComputeable)
          This method computes the results for any evaluation of the classifier.
protected  double getScore(Sequence seq, int i, boolean check)
          This method returns the score for a given Sequence and a given class.
protected  String getXMLTag()
          Returns the String that is used as tag for the XML representation of the classifier.
 boolean isInitialized()
          This method gives information about the state of the classifier.
 DataSet[] mapDataSet(DataSet[] s)
          This method maps the given DataSets to the internal classes.
 double[][] mapWeights(double[][] w)
          This method maps the given Sequence weights to the internal classes.
 void train(DataSet[] s, double[][] weights)
          This method trains a classifier over an array of weighted DataSet s.
 
Methods inherited from class de.jstacs.classifiers.AbstractScoreBasedClassifier
check, check, classify, classify, clone, createDefaultClassWeights, getClassWeight, getClassWeights, getMultiClassScores, getNumberOfClasses, getPValue, getPValue, getScore, getScores, setClassWeights, setClassWeights, setThresholdClassWeights
 
Methods inherited from class de.jstacs.classifiers.AbstractClassifier
classify, evaluate, evaluate, getAlphabetContainer, getCharacteristics, getLength, toXML, train
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MappingClassifier

public MappingClassifier(AbstractScoreBasedClassifier classifier,
                         int... mapping)
                  throws CloneNotSupportedException
Creates a new MappingClassifier from a given classifier and a class mapping.

Parameters:
classifier - the internal used classifier
mapping - the mapping from the classes of the internal classifier to the classes of this classifier
Throws:
CloneNotSupportedException - if something went wrong while cloning the classifier

MappingClassifier

public MappingClassifier(StringBuffer representation)
                  throws NonParsableException
The standard constructor for the interface Storable. Creates a new MappingClassifier out of its XML representation.

Parameters:
representation - the XML representation as StringBuffer
Throws:
NonParsableException - if the MappingClassifier could not be reconstructed out of the XML representation (the StringBuffer representation could not be parsed)
See Also:
AbstractScoreBasedClassifier.AbstractScoreBasedClassifier(StringBuffer), Storable
Method Detail

extractFurtherClassifierInfosFromXML

protected void extractFurtherClassifierInfosFromXML(StringBuffer xml)
                                             throws NonParsableException
Description copied from class: AbstractClassifier
Extracts further information of a classifier from an XML representation. This method is used by the method AbstractClassifier.fromXML(StringBuffer) and should not be made public.

Overrides:
extractFurtherClassifierInfosFromXML in class AbstractScoreBasedClassifier
Parameters:
xml - the XML representation as StringBuffer
Throws:
NonParsableException - if the information could not be parsed out of the XML representation (the StringBuffer could not be parsed)
See Also:
AbstractClassifier.fromXML(StringBuffer)

getFurtherClassifierInfos

protected StringBuffer getFurtherClassifierInfos()
Description copied from class: AbstractClassifier
This method returns further information of a classifier as a StringBuffer. This method is used by the method AbstractClassifier.toXML() and should not be made public.

Overrides:
getFurtherClassifierInfos in class AbstractScoreBasedClassifier
Returns:
further information of a classifier as a StringBuffer
See Also:
AbstractClassifier.toXML()

getScore

protected double getScore(Sequence seq,
                          int i,
                          boolean check)
                   throws IllegalArgumentException,
                          NotTrainedException,
                          Exception
Description copied from class: AbstractScoreBasedClassifier
This method returns the score for a given Sequence and a given class.

Specified by:
getScore in class AbstractScoreBasedClassifier
Parameters:
seq - the Sequence
i - the index of the class
check - the switch to decide whether to check AlphabetContainer and the length of the Sequence or not
Returns:
the score for a given Sequence and a given class
Throws:
IllegalArgumentException - if something is wrong with the Sequence seq
NotTrainedException - if the classifier is not trained
Exception - if something went wrong

getClassifierAnnotation

public CategoricalResult[] getClassifierAnnotation()
Description copied from class: AbstractClassifier
Returns an array of Results of dimension AbstractClassifier.getNumberOfClasses() that contains information about the classifier and for each class.

res[0] = new CategoricalResult( "classifier", "the kind of classifier", getInstanceName() );
res[1] = new CategoricalResult( "class info 0", "some information about the class", "info0" );
res[2] = new CategoricalResult( "class info 1", "some information about the class", "info1" );
...

Specified by:
getClassifierAnnotation in class AbstractClassifier
Returns:
an array of Results that contains information about the classifier

getInstanceName

public String getInstanceName()
Description copied from class: AbstractClassifier
Returns a short description of the classifier.

Specified by:
getInstanceName in class AbstractClassifier
Returns:
a short description of the classifier

getNumericalCharacteristics

public NumericalResultSet getNumericalCharacteristics()
                                               throws Exception
Description copied from class: AbstractClassifier
Returns the subset of numerical values that are also returned by AbstractClassifier.getCharacteristics().

Specified by:
getNumericalCharacteristics in class AbstractClassifier
Returns:
the numerical characteristics
Throws:
Exception - if some of the characteristics could not be defined

getXMLTag

protected String getXMLTag()
Description copied from class: AbstractClassifier
Returns the String that is used as tag for the XML representation of the classifier. This method is used by the methods AbstractClassifier.fromXML(StringBuffer) and AbstractClassifier.toXML().

Specified by:
getXMLTag in class AbstractClassifier
Returns:
the String that is used as tag for the XML representation of the classifier

isInitialized

public boolean isInitialized()
Description copied from class: AbstractClassifier
This method gives information about the state of the classifier.

Specified by:
isInitialized in class AbstractClassifier
Returns:
true if the classifier is initialized and therefore able to classify sequences, otherwise false

train

public void train(DataSet[] s,
                  double[][] weights)
           throws Exception
Description copied from class: AbstractClassifier
This method trains a classifier over an array of weighted DataSet s. That is why the following has to be fulfilled: This method should work non-incrementally as the method AbstractClassifier.train(DataSet...).

This method should check that the DataSets are defined over the underlying alphabet and length.

Specified by:
train in class AbstractClassifier
Parameters:
s - an array of DataSets
weights - the weights for the DataSets
Throws:
Exception - if the weights are incorrect or the training did not succeed
See Also:
AbstractClassifier.train(DataSet...)

getResults

protected boolean getResults(LinkedList list,
                             DataSet[] s,
                             double[][] weights,
                             AbstractPerformanceMeasureParameterSet<? extends PerformanceMeasure> params,
                             boolean exceptionIfNotComputeable)
                      throws Exception
Description copied from class: AbstractClassifier
This method computes the results for any evaluation of the classifier.

Overrides:
getResults in class AbstractScoreBasedClassifier
Parameters:
list - a list adding the results
s - the array of DataSets
weights - the weights of the sequences for each data set
params - the current parameters
exceptionIfNotComputeable - indicates the method throws an Exception if a measure could not be computed
Returns:
a boolean indicating if all results are numerical
Throws:
Exception - if something went wrong
See Also:
AbstractClassifier.evaluate(AbstractPerformanceMeasureParameterSet, boolean, DataSet[], double[][]), NumericalResult, Result

mapDataSet

public DataSet[] mapDataSet(DataSet[] s)
This method maps the given DataSets to the internal classes.

Parameters:
s - the array of DataSets
Returns:
the array of data sets corresponding to the classes

mapWeights

public double[][] mapWeights(double[][] w)
This method maps the given Sequence weights to the internal classes.

Parameters:
w - the array of weights
Returns:
the array of weights corresponding to the classes