public class TrainSMBasedClassifier extends AbstractScoreBasedClassifier
TrainableStatisticalModel
s for each of the different classes.
By calling the AbstractClassifier.train(DataSet...)
method of this classifier,
all internal TrainableStatisticalModel
s 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 Sequence
s 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.TrainableStatisticalModel
AbstractScoreBasedClassifier.DoubleTableResult
Modifier and Type | Field and Description |
---|---|
protected TrainableStatisticalModel[] |
models
The internal
TrainableStatisticalModel s. |
Modifier | Constructor and Description |
---|---|
protected |
TrainSMBasedClassifier(boolean cloneModels,
TrainableStatisticalModel... models)
This constructor creates a new instance with the given
TrainableStatisticalModel s 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
TrainableStatisticalModel s. |
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 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() );
|
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
TrainableStatisticalModel s. |
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, setThresholdClassWeights
evaluate, evaluate, getAlphabetContainer, getLength, toXML, train
protected TrainableStatisticalModel[] models
TrainableStatisticalModel
s. TrainableStatisticalModel
0 handles class 0;
TrainableStatisticalModel
1 handles class 1 ... etc.protected TrainSMBasedClassifier(boolean cloneModels, TrainableStatisticalModel... models) throws IllegalArgumentException, CloneNotSupportedException, ClassDimensionException
TrainableStatisticalModel
s and
clones these if necessary.cloneModels
- a switch to decide whether to clone the TrainableStatisticalModel
or notmodels
- the TrainableStatisticalModel
sIllegalArgumentException
- if the TrainableStatisticalModel
s 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
TrainableStatisticalModel
s.models
- the TrainableStatisticalModel
sIllegalArgumentException
- if the TrainableStatisticalModel
s 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 StringBuffer
NonParsableException
- if the TrainSMBasedClassifier
could not be
reconstructed out of the XML representation (the
StringBuffer
could not be parsed)AbstractScoreBasedClassifier.AbstractScoreBasedClassifier(StringBuffer)
,
Storable
public static int getPossibleLength(TrainableStatisticalModel... models) throws IllegalArgumentException
TrainableStatisticalModel
s.models
- the TrainableStatisticalModel
s that will be testedIllegalArgumentException
- if no classifier could be created since the TrainableStatisticalModel
s
have incompatible lengthspublic TrainSMBasedClassifier clone() throws CloneNotSupportedException
clone
in class AbstractScoreBasedClassifier
CloneNotSupportedException
public ResultSet getCharacteristics() throws Exception
AbstractClassifier
StorableResult
.getCharacteristics
in class AbstractClassifier
Exception
- if some of the characteristics could not be definedStorableResult
,
AbstractClassifier.getNumericalCharacteristics()
,
ResultSet.ResultSet(de.jstacs.results.Result[][])
public String getInstanceName()
AbstractClassifier
getInstanceName
in class AbstractClassifier
public 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
AbstractClassifier
AbstractClassifier.getCharacteristics()
.getNumericalCharacteristics
in class AbstractClassifier
Exception
- if some of the characteristics could not be definedpublic boolean isInitialized()
AbstractClassifier
isInitialized
in class AbstractClassifier
true
if the classifier is initialized and therefore able
to classify sequences, otherwise false
public void train(DataSet[] s, double[][] weights) throws Exception
AbstractClassifier
DataSet
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...)
.
DataSet
s are defined over the
underlying alphabet and length.train
in class AbstractClassifier
s
- an array of DataSet
sweights
- the weights for the DataSet
sException
- if the weights are incorrect or the training did not succeedAbstractClassifier.train(DataSet...)
protected StringBuffer getFurtherClassifierInfos()
AbstractClassifier
StringBuffer
. This method is used by the method AbstractClassifier.toXML()
and should not be made public.getFurtherClassifierInfos
in class AbstractScoreBasedClassifier
StringBuffer
AbstractClassifier.toXML()
protected double getScore(Sequence seq, int i, boolean check) throws Exception
AbstractScoreBasedClassifier
Sequence
and a given
class.getScore
in class AbstractScoreBasedClassifier
seq
- the Sequence
i
- 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
seq
Exception
- 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 AlphabetContainer
s of sequence and classifier do not matchpublic double[] getScores(DataSet s) throws Exception
AbstractScoreBasedClassifier
Sequence
in the DataSet
. The scores are stored in the array according to
the index of the Sequence
in the DataSet
.
getScores
in class AbstractScoreBasedClassifier
s
- the DataSet
Exception
- if something went wrongpublic byte[] classify(DataSet s) throws Exception
AbstractClassifier
i
in the array
0 < i < getNumberOfClasses()
.classify
in class AbstractClassifier
s
- the data set to be classifiedException
- if something went wrong during the classificationprotected String getXMLTag()
AbstractClassifier
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()
.getXMLTag
in class AbstractClassifier
String
that is used as tag for the XML representation
of the classifierprotected void extractFurtherClassifierInfosFromXML(StringBuffer xml) throws NonParsableException
AbstractClassifier
AbstractClassifier.fromXML(StringBuffer)
and
should not be made public.extractFurtherClassifierInfosFromXML
in class AbstractScoreBasedClassifier
xml
- the XML representation as StringBuffer
NonParsableException
- if the information could not be parsed out of the XML
representation (the StringBuffer
could not be parsed)AbstractClassifier.fromXML(StringBuffer)
public CategoricalResult[] getClassifierAnnotation()
AbstractClassifier
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" );
...
getClassifierAnnotation
in class AbstractClassifier
Result
s that contains information about the
classifier