public class TrainSMBasedClassifier extends AbstractScoreBasedClassifier
TrainableStatisticalModels for each of the different classes.
By calling the AbstractClassifier.train(DataSet...) method of this classifier,
all internal TrainableStatisticalModels are learned on the DataSet for the corresponding class
using their own TrainableStatisticalModel.train(DataSet) method. In addition, the a-priori class
probabilities are estimated.
After training, the method AbstractScoreBasedClassifier.getScore(Sequence, int) returns the joint
probability (likelihood) of the provided Sequence and the specified class.
For two-class problems, the method getScores(DataSet) returns the log-likelihood ratios for
all Sequences in the provided DataSet.
The methods AbstractScoreBasedClassifier.classify(Sequence) and classify(DataSet) use the likelihoods of Sequence
and class and report the class yielding the maximum likelihood.TrainableStatisticalModelAbstractScoreBasedClassifier.DoubleTableResult| Modifier and Type | Field and Description |
|---|---|
protected TrainableStatisticalModel[] |
models
The internal
TrainableStatisticalModels. |
| Modifier | Constructor and Description |
|---|---|
protected |
TrainSMBasedClassifier(boolean cloneModels,
TrainableStatisticalModel... models)
This constructor creates a new instance with the given
TrainableStatisticalModels and
clones these if necessary. |
|
TrainSMBasedClassifier(StringBuffer xml)
The standard constructor for the interface
Storable. |
|
TrainSMBasedClassifier(TrainableStatisticalModel... models)
The default constructor that creates a new instance with the given
TrainableStatisticalModels. |
| Modifier and Type | Method and Description |
|---|---|
byte[] |
classify(DataSet s)
This method classifies all sequences of a data set and returns an array of
indices of the classes to which the respective sequences are assigned
with for each index
i in the array
0 < i < getNumberOfClasses(). |
TrainSMBasedClassifier |
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 classifier.
|
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() ); |
protected StringBuffer |
getFurtherClassifierInfos()
This method returns further information of a classifier as a
StringBuffer. |
String |
getInstanceName()
Returns a short description of the classifier.
|
double[] |
getLogLikelihoodRatio(Sequence seq)
Returns the log likelihood ratios along the sequence
seq for all
sliding windows of length AbstractClassifier.getLength(). |
TrainableStatisticalModel |
getModel(int classIndex)
Returns a clone of the
TrainableStatisticalModel for a specified class. |
NumericalResultSet |
getNumericalCharacteristics()
Returns the subset of numerical values that are also returned by
AbstractClassifier.getCharacteristics(). |
static int |
getPossibleLength(TrainableStatisticalModel... models)
This method returns the possible length of a classifier that would use
the given
TrainableStatisticalModels. |
protected double |
getScore(Sequence seq,
int i,
boolean check)
This method returns the score for a given
Sequence and a given
class. |
double[] |
getScores(DataSet s)
|
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.
|
String |
toString() |
void |
train(DataSet[] s,
double[][] weights)
This method trains a classifier over an array of weighted
DataSet
s. |
check, check, classify, classify, createDefaultClassWeights, getClassWeight, getClassWeights, getMultiClassScores, getNumberOfClasses, getPValue, getPValue, getResults, getScore, setClassWeights, setClassWeights, setThresholdClassWeightsevaluate, evaluate, getAlphabetContainer, getLength, toXML, trainprotected TrainableStatisticalModel[] models
TrainableStatisticalModels. TrainableStatisticalModel 0 handles class 0;
TrainableStatisticalModel 1 handles class 1 ... etc.protected TrainSMBasedClassifier(boolean cloneModels,
TrainableStatisticalModel... models)
throws IllegalArgumentException,
CloneNotSupportedException,
ClassDimensionException
TrainableStatisticalModels and
clones these if necessary.cloneModels - a switch to decide whether to clone the TrainableStatisticalModel or notmodels - the TrainableStatisticalModelsIllegalArgumentException - if the TrainableStatisticalModels do not describe a common domain of
sequencesCloneNotSupportedException - if at least one TrainableStatisticalModel could not be clonedClassDimensionException - if the number of classes is below 2AbstractScoreBasedClassifier.AbstractScoreBasedClassifier(AlphabetContainer,
int, int, double)public TrainSMBasedClassifier(TrainableStatisticalModel... models) throws IllegalArgumentException, CloneNotSupportedException, ClassDimensionException
TrainableStatisticalModels.models - the TrainableStatisticalModelsIllegalArgumentException - if the TrainableStatisticalModels do not describe a common domain of
sequencesCloneNotSupportedException - if at least one TrainableStatisticalModel could not be clonedClassDimensionException - if the number of classes is below 2TrainSMBasedClassifier(boolean, TrainableStatisticalModel...)public TrainSMBasedClassifier(StringBuffer xml) throws NonParsableException
Storable.
Constructs a TrainSMBasedClassifier out of its XML representation.xml - the XML representation as StringBufferNonParsableException - if the TrainSMBasedClassifier could not be
reconstructed out of the XML representation (the
StringBuffer could not be parsed)AbstractScoreBasedClassifier.AbstractScoreBasedClassifier(StringBuffer),
Storablepublic static int getPossibleLength(TrainableStatisticalModel... models) throws IllegalArgumentException
TrainableStatisticalModels.models - the TrainableStatisticalModels that will be testedIllegalArgumentException - if no classifier could be created since the TrainableStatisticalModels
have incompatible lengthspublic TrainSMBasedClassifier clone() throws CloneNotSupportedException
clone in class AbstractScoreBasedClassifierCloneNotSupportedExceptionpublic ResultSet getCharacteristics() throws Exception
AbstractClassifierStorableResult.getCharacteristics in class AbstractClassifierException - if some of the characteristics could not be definedStorableResult,
AbstractClassifier.getNumericalCharacteristics(),
ResultSet.ResultSet(de.jstacs.results.Result[][])public String getInstanceName()
AbstractClassifiergetInstanceName in class AbstractClassifierpublic TrainableStatisticalModel getModel(int classIndex) throws CloneNotSupportedException
TrainableStatisticalModel for a specified class.classIndex - the index of the specified classTrainableStatisticalModel of the specified classCloneNotSupportedException - if the TrainableStatisticalModel could not be clonedTrainableStatisticalModel.clone()public NumericalResultSet getNumericalCharacteristics() throws Exception
AbstractClassifierAbstractClassifier.getCharacteristics().getNumericalCharacteristics in class AbstractClassifierException - if some of the characteristics could not be definedpublic boolean isInitialized()
AbstractClassifierisInitialized in class AbstractClassifiertrue if the classifier is initialized and therefore able
to classify sequences, otherwise falsepublic void train(DataSet[] s, double[][] weights) throws Exception
AbstractClassifierDataSet
s. That is why the following has to be fulfilled:
s.length == weights.length
weights[i] == null || s[i].getNumberOfElements() == weights[i].length.
AbstractClassifier.train(DataSet...).
DataSets are defined over the
underlying alphabet and length.train in class AbstractClassifiers - an array of DataSetsweights - the weights for the DataSetsException - if the weights are incorrect or the training did not succeedAbstractClassifier.train(DataSet...)protected StringBuffer getFurtherClassifierInfos()
AbstractClassifierStringBuffer. This method is used by the method AbstractClassifier.toXML()
and should not be made public.getFurtherClassifierInfos in class AbstractScoreBasedClassifierStringBufferAbstractClassifier.toXML()protected double getScore(Sequence seq, int i, boolean check) throws Exception
AbstractScoreBasedClassifierSequence and a given
class.getScore in class AbstractScoreBasedClassifierseq - the Sequencei - the index of the classcheck - the switch to decide whether to check
AlphabetContainer and the length of the
Sequence or notSequence and a given classNotTrainedException - if the classifier is not trainedIllegalArgumentException - if something is wrong with the Sequence
seqException - if something went wrongpublic double[] getLogLikelihoodRatio(Sequence seq) throws Exception
seq for all
sliding windows of length AbstractClassifier.getLength().seq - the sequenceException - if the classifier has not been trained, it is no binary classifier, or the AlphabetContainers of sequence and classifier do not matchpublic double[] getScores(DataSet s) throws Exception
AbstractScoreBasedClassifierSequence
in the DataSet. The scores are stored in the array according to
the index of the Sequence in the DataSet.
getScores in class AbstractScoreBasedClassifiers - the DataSetException - if something went wrongpublic byte[] classify(DataSet s) throws Exception
AbstractClassifieri in the array
0 < i < getNumberOfClasses().classify in class AbstractClassifiers - the data set to be classifiedException - if something went wrong during the classificationprotected String getXMLTag()
AbstractClassifierString 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().getXMLTag in class AbstractClassifierString that is used as tag for the XML representation
of the classifierprotected void extractFurtherClassifierInfosFromXML(StringBuffer xml) throws NonParsableException
AbstractClassifierAbstractClassifier.fromXML(StringBuffer) and
should not be made public.extractFurtherClassifierInfosFromXML in class AbstractScoreBasedClassifierxml - the XML representation as StringBufferNonParsableException - if the information could not be parsed out of the XML
representation (the StringBuffer could not be parsed)AbstractClassifier.fromXML(StringBuffer)public CategoricalResult[] getClassifierAnnotation()
AbstractClassifierResults 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" );
...
getClassifierAnnotation in class AbstractClassifierResults that contains information about the
classifier