Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## de.jstacs.classifier.scoringFunctionBased
Class ScoreClassifier

    java.lang.Object
      de.jstacs.classifier.AbstractClassifier
          de.jstacs.classifier.AbstractScoreBasedClassifier
              de.jstacs.classifier.scoringFunctionBased.ScoreClassifier

All Implemented Interfaces:
  Storable, Cloneable

Direct Known Subclasses:
  GenDisMixClassifier

    public abstract class ScoreClassifier

extends AbstractScoreBasedClassifier

This abstract class implements the main functionality of a `ScoringFunction` based classifier.

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.
`static double` | `NOT_TRAINED_VALUE` This value should be used in `getLastScore()` if the classifier is not trained.
`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, e.g. during the training, ... .

Constructor Summary
`ScoreClassifier(ScoreClassifierParameterSet params, double lastScore, ScoringFunction... score)` Creates a new `ScoreClassifier` from a given `ScoreClassifierParameterSet` and `ScoringFunction`s .
`ScoreClassifier(StringBuffer xml)` The standard constructor for the interface `Storable`.

Method Summary
`ScoreClassifier` | `clone()`
`protected void` | `createStructure(Sample[] data, double[][] weights)` Creates the structure that will be used in the optimization.
`protected void` | `createStructure(Sample[] data, double[][] weights, boolean initRandomly)` 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 `Result`s of dimension `AbstractClassifier.getNumberOfClasses()` that contains information about the classifier and for each class.
`protected abstract Class<? extends ScoreClassifierParameterSet>` | `getClassOfParameterSet()` This method returns the class of the parameters that is used during restoring a classifier from XML.
`protected abstract SFBasedOptimizableFunction` | `getFunction(Sample[] data, double[][] weights)` Returns the function that 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()` Returns the score that was computed in the last optimization of the parameters.
`NumericalResultSet` | `getNumericalCharacteristics()` Returns the subset of numerical values that are also returned by `AbstractClassifier.getCharacteristics()`.
`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 `ScoringFunction`s in the internal order.
`protected abstract String` | `getXMLTag()` Returns the `String` that is used as tag for the XML representation of the classifier.
`boolean` | `hasBeenOptimized()` This method indicates if the classifier has been optimized by a `train`-method.
`boolean` | `isTrained()` This method gives information about the state of the classifier.
`void` | `setOutputStream(OutputStream o)` Sets the `OutputStream` that is used e.g. for writing information during training.
`void` | `train(Sample[] data, double[][] weights)` This method trains a classifier over an array of weighted `Sample` s.

Methods inherited from class de.jstacs.classifier.AbstractScoreBasedClassifier
`check, check, classify, classify, createDefaultClassWeights, getClassWeight, getClassWeights, getNumberOfClasses, getPValue, getPValue, getResults, getScore, getScores, setClassWeights, 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, e.g. during the training, ... .

### NOT_TRAINED_VALUE

    public static final double NOT_TRAINED_VALUE

  This value should be used in `getLastScore()` if the classifier is not trained.

  See Also:
    Constant Field Values

Constructor Detail

### ScoreClassifier

    public ScoreClassifier(ScoreClassifierParameterSet params,
                           double lastScore,
                           ScoringFunction... score)
                    throws CloneNotSupportedException

  Creates a new `ScoreClassifier` from a given `ScoreClassifierParameterSet` and `ScoringFunction`s .

  Parameters:
    `params` - the parameter set for the classifier
    `lastScore` - the score of the last optimization, if no such value exists the programmer should use `NOT_TRAINED_VALUE`
    `score` - the `ScoringFunction`s for the classes
  Throws:
    `CloneNotSupportedException` - if at least one `ScoringFunction` could not be cloned
  See Also:
    `AbstractScoreBasedClassifier.AbstractScoreBasedClassifier(AlphabetContainer, int, int)`

### ScoreClassifier

    public ScoreClassifier(StringBuffer xml)
                    throws NonParsableException

  The standard constructor for the interface `Storable`. Creates a new `ScoreClassifier` out of its XML representation.

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

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 `Result`s 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 `Result`s that contains information about 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

### isTrained

    public boolean isTrained()

  Description copied from class: `AbstractClassifier`
  This method gives information about the state of the classifier.

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

### hasBeenOptimized

    public boolean hasBeenOptimized()

  This method indicates if the classifier has been optimized by a `train`-method.

  Returns:
    `true` if the classifier has been optimized by a `train`-method, `false` otherwise

### setOutputStream

    public void setOutputStream(OutputStream o)

  Sets the `OutputStream` that is used e.g. for writing information during training. It is possible to set `o=null`, then 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 `Sample` s. That is why the following has to be fulfilled:
  - `s.length == weights.length`
  - and for all i: `weights[i] == null || s[i].getNumberOfElements() == weights[i].length`.
  This method should work non-incrementally as the method `AbstractClassifier.train(Sample...)`.
  This method should check that the `Sample`s are defined over the underlying alphabet and length.

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

### 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 during the optimization

### createStructure

    protected void createStructure(Sample[] data,
                                   double[][] weights,
                                   boolean initRandomly)
                            throws Exception

  Creates the structure that will be used in the optimization.

  Parameters:
    `data` - the data
    `weights` - the weights of the data
    `initRandomly` - initialize the functions randomly
  Throws:
    `Exception` - if something went wrong

### 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 `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)`

### getClassOfParameterSet

    protected abstract Class<? extends ScoreClassifierParameterSet> getClassOfParameterSet()

  This method returns the class of the parameters that is used during restoring a classifier from XML.

  Returns:
    the class of the parameters
  See Also:
    `extractFurtherClassifierInfosFromXML(StringBuffer)`

### getFunction

    protected abstract SFBasedOptimizableFunction getFunction(Sample[] data,
                                                              double[][] weights)
                                                       throws Exception

  Returns the function that should be optimized.

  Parameters:
    `data` - the samples
    `weights` - the weights of the sequences of the samples
  Returns:
    the function that 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 `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

### getLastScore

    public double getLastScore()

  Returns the 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 `ScoringFunction`s in the internal order.

  Returns:
    the internally used `ScoringFunction`s 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 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

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD