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.modelBased
Class ModelBasedClassifier

    java.lang.Object
      de.jstacs.classifier.AbstractClassifier
          de.jstacs.classifier.AbstractScoreBasedClassifier
              de.jstacs.classifier.modelBased.ModelBasedClassifier

All Implemented Interfaces:
  Storable, Cloneable

Direct Known Subclasses:
  SharedStructureClassifier

    public class ModelBasedClassifier

extends AbstractScoreBasedClassifier

This class is the main class for all model based classifiers. The score for this class is the logarithm of the joint probability `p(x,c|\lambda)`.

Author:
  Jens Keilwagen
See Also:
  `Model`

Nested Class Summary

Nested classes/interfaces inherited from class de.jstacs.classifier.AbstractScoreBasedClassifier
`AbstractScoreBasedClassifier.DoubleTableResult`

Field Summary
`protected Model[]` | `models` The internal models.

Constructor Summary
`protected` | `ModelBasedClassifier(boolean cloneModels, Model... models)` This constructor creates a new instance with the given models and clones these if necessary.
`` | `ModelBasedClassifier(Model... models)` The default constructor.
`` | `ModelBasedClassifier(StringBuffer xml)` This is the constructor for the interface `Storable`.

Method Summary
`byte[]` | `classify(Sample s)` This method classifies all sequences of a sample and returns the index `i`, with `0 < i < getNumberOfClasses()`, of the class to which the sequence is assigned.
`ModelBasedClassifier` | `clone()`
`protected void` | `extractFurtherClassifierInfosFromXML(StringBuffer xml)` Extracts further information of a classifier from an XML representation.
`ResultSet` | `getCharacteristics()` Returns some information characterizing or describing the current instance of the model.
`CategoricalResult[]` | `getClassifierAnnotation()` Returns an array of `Result`s of dimension `AbstractClassifier.getNumberOfClasses()` that contains information about the classifier and for each class.
`protected StringBuffer` | `getFurtherClassifierInfos()` This method returns further information of a classifier as a `StringBuffer`.
`String` | `getInstanceName()` Returns a short description of the classifier.
`Model` | `getModel(int classIndex)` Returns a clone of the model for a specified class.
`NumericalResultSet` | `getNumericalCharacteristics()` Returns the subset of numerical values that are also returned by `AbstractClassifier.getCharacteristics()`.
`static int` | `getPossibleLength(Model... models)` This method returns the possible length of a classifier that would use the given models.
`protected double` | `getScore(Sequence seq, int i, boolean check)` This method returns the score for a given sequence and a given class.
`double[]` | `getScores(Sample s)` This method returns the scores of the classifier for any sequence in the sample.
`protected String` | `getXMLTag()` Returns the `String` that is used as tag for the XML representation.
`boolean` | `isTrained()` This method gives information about the state of the classifier.
`boolean` | `setNewAlphabetContainerInstance(AlphabetContainer abc)` This method tries to set a new instance of an `AlphabetContainer` for the current model.
`void` | `train(Sample[] s, 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, setClassWeights, setThresholdClassWeights, test`

Methods inherited from class de.jstacs.classifier.AbstractClassifier
`evaluate, evaluateAll, getAlphabetContainer, getClassificationRate, getLength, getMeasuresForEvaluate, getMeasuresForEvaluateAll, toXML, train`

Methods inherited from class java.lang.Object
`equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### models

    protected Model[] models

  The internal models. Model 0 handles class 0; Model 1 ...

Constructor Detail

### ModelBasedClassifier

    protected ModelBasedClassifier(boolean cloneModels,
                                   Model... models)
                            throws IllegalArgumentException,
                                   CloneNotSupportedException,
                                   ClassDimensionException

  This constructor creates a new instance with the given models and clones these if necessary.

  Parameters:
    `cloneModels` - a switch to decide whether to clone the model or not
    `models` - the models
  Throws:
    `IllegalArgumentException` - if the models do not describe a common domain of sequences
    `CloneNotSupportedException` - if at least one model could not be cloned
    `ClassDimensionException` - if the number of classes is below 2

### ModelBasedClassifier

    public ModelBasedClassifier(Model... models)
                         throws IllegalArgumentException,
                                CloneNotSupportedException,
                                ClassDimensionException

  The default constructor.

  Parameters:
    `models` - the models
  Throws:
    `IllegalArgumentException` - if the models do not describe a common domain of sequences
    `CloneNotSupportedException` - if at least one model could not be cloned
    `ClassDimensionException` - if the number of classes is below 2

### ModelBasedClassifier

    public ModelBasedClassifier(StringBuffer xml)
                         throws NonParsableException

  This is the constructor for the interface `Storable`.

  Parameters:
    `xml` - the XML representation
  Throws:
    `NonParsableException` - if the representation could not be parsed.

Method Detail

### getPossibleLength

    public static int getPossibleLength(Model... models)
                                 throws IllegalArgumentException

  This method returns the possible length of a classifier that would use the given models.

  Parameters:
    `models` - the models that will be tested
  Returns:
    the length of a classifier that would use the given models
  Throws:
    `IllegalArgumentException` - if no classifier could be created, since the models have incompatible lengths

### clone

    public ModelBasedClassifier clone()
                               throws CloneNotSupportedException

  Overrides:
    `clone` in class `AbstractScoreBasedClassifier`
  Throws:
    `CloneNotSupportedException`

### getCharacteristics

    public ResultSet getCharacteristics()
                                 throws Exception

  Description copied from class: `AbstractClassifier`
  Returns some information characterizing or describing the current instance of the model. This could be for instance the number of edges for a Bayesian network or an image showing some representation of the model of a class. The set of characteristics should always include the XML representation of the classifier. The corresponding result type is `ObjectResult`.

  Overrides:
    `getCharacteristics` in class `AbstractClassifier`
  Returns:
    the characteristics
  Throws:
    `Exception` - an `Exception` is thrown if some of the characteristics could not be defined
  See Also:
    `StorableResult`

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

### getModel

    public Model getModel(int classIndex)
                   throws CloneNotSupportedException

  Returns a clone of the model for a specified class.

  Parameters:
    `classIndex` - the index of the specified class
  Returns:
    a clone the model of the specified class
  Throws:
    `CloneNotSupportedException` - if the model could not be cloned

### 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` - an `Exception` is thrown 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 able to classify sequences, otherwise `false`

### setNewAlphabetContainerInstance

    public final boolean setNewAlphabetContainerInstance(AlphabetContainer abc)

  Description copied from class: `AbstractClassifier`
  This method tries to set a new instance of an `AlphabetContainer` for the current model. This instance has to be consistent with the underlying instance of an `AlphabetContainer`.
  This method can be very useful to save time.

  Overrides:
    `setNewAlphabetContainerInstance` in class `AbstractClassifier`
  Parameters:
    `abc` - the alphabets
  Returns:
    `true` if the new container could be set
  See Also:
    `AbstractClassifier.getAlphabetContainer()`, `AlphabetContainer.checkConsistency(AlphabetContainer)`

### train

    public void train(Sample[] s,
                      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 `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:
    `s` - an array of `Sample`s
    `weights` - the weights for `s`
  Throws:
    `Exception` - an `Exception` should be thrown if the weights are incorrect or the training did not succeed

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

### getScore

    protected double getScore(Sequence seq,
                              int i,
                              boolean check)
                       throws 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 for a given sequence and a given class
  Throws:
    `NotTrainedException` - if the classifier is not trained
    `IllegalArgumentException` - if something is wrong with `seq`
    `Exception` - if something went wrong

### getScores

    public double[] getScores(Sample s)
                       throws Exception

  Description copied from class: `AbstractScoreBasedClassifier`
  This method returns the scores of the classifier for any sequence in the sample. The scores are stored in the array according to the index of the sequence in the sample.
  Only for 2-class-classifiers.

  Overrides:
    `getScores` in class `AbstractScoreBasedClassifier`
  Parameters:
    `s` - the sample
  Returns:
    the array of scores
  Throws:
    `Exception` - if something went wrong

### classify

    public byte[] classify(Sample s)
                    throws Exception

  Description copied from class: `AbstractClassifier`
  This method classifies all sequences of a sample and returns the index `i`, with `0 < i < getNumberOfClasses()`, of the class to which the sequence is assigned.

  Overrides:
    `classify` in class `AbstractClassifier`
  Parameters:
    `s` - the sample to be classified
  Returns:
    an array of class assignments
  Throws:
    `Exception` - if something went wrong while classification

### getXMLTag

    protected 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 `AbstractClassifier.fromXML(StringBuffer)` and `AbstractClassifier.toXML()`.

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

### 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` - XML representation
  Throws:
    `NonParsableException` - if the information could not be parsed out of the `StringBuffer`

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