de.jstacs.classifier.scoringFunctionBased
Class ScoreClassifier

java.lang.Object
  extended by de.jstacs.classifier.AbstractClassifier
      extended by de.jstacs.classifier.AbstractScoreBasedClassifier
          extended by de.jstacs.classifier.scoringFunctionBased.ScoreClassifier
All Implemented Interfaces:
Storable, Cloneable
Direct Known Subclasses:
CLLClassifier

public abstract class ScoreClassifier
extends AbstractScoreBasedClassifier

Author:
Jens Keilwagen, Jan Grau

Nested Class Summary
 
Nested classes/interfaces inherited from class de.jstacs.classifier.AbstractScoreBasedClassifier
AbstractScoreBasedClassifier.DoubleTableResult
 
Field Summary
protected  boolean hasBeenOptimized
          This boolean indicates whether the classifier has been optimized with the method AbstractClassifier.train(Sample...) or the weighted version.
protected  ScoreClassifierParameterSet params
          The parameter set for the classifier.
protected  ScoringFunction[] score
          The internally used scoring functions.
protected  SafeOutputStream sostream
          This stream is used for comments, ... while the training, ... .
 
Constructor Summary
ScoreClassifier(ScoreClassifierParameterSet params, ScoringFunction... score)
          The default constructor.
ScoreClassifier(StringBuffer xml)
          This is the constructor for Storable.
 
Method Summary
 ScoreClassifier clone()
           
protected  void createStructure(Sample[] data, double[][] weights)
          Creates the structure that will be used in the optimization.
protected  double doOptimization(Sample[] reduced, double[][] newWeights)
          This method does the optimization of the train-method
protected  void extractFurtherClassifierInfosFromXML(StringBuffer xml)
          Extracts further information of a classifier from an xml-representation.
 CategoricalResult[] getClassifierAnnotation()
          Returns an array of Results of dimension getNumberOfClasses that contains information the classifier and for each class.
protected abstract  OptimizableFunction getFunction(Sample[] data, double[][] weights)
          Returns the function the should be optimized
protected  StringBuffer getFurtherClassifierInfos()
          This method returns further information of a classifier as a StringBuffer.
 String getInstanceName()
          Returns a short description of the classifier.
 double getLastScore()
          Return score that was computed in the last optimization of the parameters.
 NumericalResultSet getNumericalCharacteristics()
          Returns the subset of numerical values that are also returned by getCharacteristsics.
protected  double getScore(Sequence seq, int i, boolean check)
          This method returns the score for a given sequence and a given class.
 ScoringFunction getScoringFunction(int i)
          Returns the internally used ScoringFunction with index i.
 ScoringFunction[] getScoringFunctions()
          Returns all internally used ScoringFunctions in the internal order.
protected abstract  String getXMLTag()
          Returns the String that is used as tag for the xml-representation.
 boolean hasBeenOptimized()
          This method returns true if the classifier has been optimized by a train-method.
 boolean isTrained()
          This method the state of the classifier.
 void setOutputStream(OutputStream o)
          Sets the OutputStream that is used e.g. for writing information while training.
 void train(Sample[] data, double[][] weights)
          This method trains a classifier over an array of weighted Samples.
 
Methods inherited from class de.jstacs.classifier.AbstractScoreBasedClassifier
check, check, classify, classify, createDefaultClassWeights, getClassWeight, getClassWeights, getNumberOfClasses, getPValue, getPValue, getResults, getScore, getScores, setClassWeights, setThresholdClassWeights, test
 
Methods inherited from class de.jstacs.classifier.AbstractClassifier
classify, evaluate, evaluateAll, getAlphabetContainer, getCharacteristics, getClassificationRate, getLength, getMeasuresForEvaluate, getMeasuresForEvaluateAll, setNewAlphabetContainerInstance, toXML, train
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

score

protected ScoringFunction[] score
The internally used scoring functions.


params

protected ScoreClassifierParameterSet params
The parameter set for the classifier.


hasBeenOptimized

protected boolean hasBeenOptimized
This boolean indicates whether the classifier has been optimized with the method AbstractClassifier.train(Sample...) or the weighted version.


sostream

protected SafeOutputStream sostream
This stream is used for comments, ... while the training, ... .

Constructor Detail

ScoreClassifier

public ScoreClassifier(ScoreClassifierParameterSet params,
                       ScoringFunction... score)
                throws CloneNotSupportedException
The default constructor.

Parameters:
params - the parameter set for the classifier
score - the ScoringFunctions for the classes
Throws:
CloneNotSupportedException - if at least one ScoringFunction could not be cloned

ScoreClassifier

public ScoreClassifier(StringBuffer xml)
                throws NonParsableException
This is the constructor for Storable.

Parameters:
xml - the xml representation
Throws:
NonParsableException - if the representation could not be parsed.
Method Detail

clone

public ScoreClassifier clone()
                      throws CloneNotSupportedException
Overrides:
clone in class AbstractScoreBasedClassifier
Throws:
CloneNotSupportedException

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

getClassifierAnnotation

public CategoricalResult[] getClassifierAnnotation()
Description copied from class: AbstractClassifier
Returns an array of Results of dimension getNumberOfClasses that contains information 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 the classifier

getNumericalCharacteristics

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

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

isTrained

public boolean isTrained()
Description copied from class: AbstractClassifier
This method the state of the classifier.

Specified by:
isTrained in class AbstractClassifier
Returns:
true if the classifier is able to classify sequences, otherwise false

hasBeenOptimized

public boolean hasBeenOptimized()
This method returns true if the classifier has been optimized by a train-method.

Returns:
true if the classifier has been optimized by a train-method

setOutputStream

public void setOutputStream(OutputStream o)
Sets the OutputStream that is used e.g. for writing information while training. It is possible to set o=null, than nothing will be written.

Parameters:
o - the OutputStream

train

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

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

Specified by:
train in class AbstractClassifier
Parameters:
data - an array of Samples
weights - the weights for s
Throws:
Exception - an Exception should be thrown if the weights are incorrect or the training did not succeed

doOptimization

protected double doOptimization(Sample[] reduced,
                                double[][] newWeights)
                         throws Exception
This method does the optimization of the train-method

Parameters:
reduced - the samples
newWeights - the weights
Returns:
the value of the optimization
Throws:
Exception - if something went wrong while the optimization

createStructure

protected void createStructure(Sample[] data,
                               double[][] weights)
                        throws Exception
Creates the structure that will be used in the optimization.

Parameters:
data - the data
weights - the weights of the data
Throws:
Exception - if something went wrong

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 fromXML( StringBuffer ) and should not be made public.

Overrides:
extractFurtherClassifierInfosFromXML in class AbstractScoreBasedClassifier
Parameters:
xml - the xml-representation
Throws:
NonParsableException

getFunction

protected abstract OptimizableFunction getFunction(Sample[] data,
                                                   double[][] weights)
                                            throws Exception
Returns the function the should be optimized

Parameters:
data - the samples
weights - the weights of the sequences of the samples
Returns:
the function the should be optimized
Throws:
Exception - if something went wrong

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 toXML() and should not be made public.

Overrides:
getFurtherClassifierInfos in class AbstractScoreBasedClassifier
Returns:
further information of a classifier as a StringBuffer

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 length of the sequence or not
Returns:
the score
Throws:
IllegalArgumentException
NotTrainedException
Exception

getLastScore

public double getLastScore()
Return score that was computed in the last optimization of the parameters.

Returns:
score from the last parameter optimization

getScoringFunction

public ScoringFunction getScoringFunction(int i)
                                   throws CloneNotSupportedException
Returns the internally used ScoringFunction with index i.

Parameters:
i - the internal index of the ScoringFunction
Returns:
the internally used ScoringFunction with index i.
Throws:
CloneNotSupportedException - if the ScoringFunction could not be cloned

getScoringFunctions

public ScoringFunction[] getScoringFunctions()
                                      throws CloneNotSupportedException
Returns all internally used ScoringFunctions in the internal order.

Returns:
the internally used ScoringFunctions in the internal order.
Throws:
CloneNotSupportedException - if a ScoringFunction could not be cloned

getXMLTag

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

Specified by:
getXMLTag in class AbstractClassifier
Returns:
the String that is used as tag for the xml-representation