|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object de.jstacs.classifier.AbstractClassifier de.jstacs.classifier.AbstractScoreBasedClassifier de.jstacs.classifier.modelBased.ModelBasedClassifier
public class ModelBasedClassifier
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)
.
Model
Nested Class Summary |
---|
Nested classes/interfaces inherited from class de.jstacs.classifier.AbstractScoreBasedClassifier |
---|
AbstractScoreBasedClassifier.DoubleTableResult |
Field Summary | |
---|---|
protected Model[] |
models
The internal Model s. |
Constructor Summary | |
---|---|
protected |
ModelBasedClassifier(boolean cloneModels,
Model... models)
This constructor creates a new instance with the given Model s and
clones these if necessary. |
|
ModelBasedClassifier(Model... models)
The default constructor that creates a new instance with the given Model s. |
|
ModelBasedClassifier(StringBuffer xml)
The standard constructor for the interface Storable . |
Method Summary | |
---|---|
byte[] |
classify(Sample s)
This method classifies all sequences of a sample 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() . |
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 classifier. |
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 Model 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(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
of the classifier. |
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 classifier. |
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, 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 |
---|
protected Model[] models
Model
s. Model
0 handles class 0;
Model
1 handles class 1 ... etc.
Constructor Detail |
---|
protected ModelBasedClassifier(boolean cloneModels, Model... models) throws IllegalArgumentException, CloneNotSupportedException, ClassDimensionException
Model
s and
clones these if necessary.
cloneModels
- a switch to decide whether to clone the Model
or notmodels
- the Model
s
IllegalArgumentException
- if the Model
s 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 2AbstractScoreBasedClassifier.AbstractScoreBasedClassifier(AlphabetContainer,
int, int, double)
public ModelBasedClassifier(Model... models) throws IllegalArgumentException, CloneNotSupportedException, ClassDimensionException
Model
s.
models
- the Model
s
IllegalArgumentException
- if the Model
s 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 2ModelBasedClassifier(boolean, Model...)
public ModelBasedClassifier(StringBuffer xml) throws NonParsableException
Storable
.
Constructs a ModelBasedClassifier
out of its XML representation.
xml
- the XML representation as StringBuffer
NonParsableException
- if the ModelBasedClassifier
could not be
reconstructed out of the XML representation (the
StringBuffer
could not be parsed)AbstractScoreBasedClassifier.AbstractScoreBasedClassifier(StringBuffer)
,
Storable
Method Detail |
---|
public static int getPossibleLength(Model... models) throws IllegalArgumentException
Model
s.
models
- the Model
s that will be tested
IllegalArgumentException
- if no classifier could be created since the Model
s
have incompatible lengthspublic ModelBasedClassifier 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 Model getModel(int classIndex) throws CloneNotSupportedException
Model
for a specified class.
classIndex
- the index of the specified class
Model
of the specified class
CloneNotSupportedException
- if the Model
could not be clonedModel.clone()
public NumericalResultSet getNumericalCharacteristics() throws Exception
AbstractClassifier
AbstractClassifier.getCharacteristics()
.
getNumericalCharacteristics
in class AbstractClassifier
Exception
- if some of the characteristics could not be definedpublic boolean isTrained()
AbstractClassifier
isTrained
in class AbstractClassifier
true
if the classifier is trained and therefore able
to classify sequences, otherwise false
public final boolean setNewAlphabetContainerInstance(AlphabetContainer abc)
AbstractClassifier
AlphabetContainer
for the current classifier. AlphabetContainer
.
setNewAlphabetContainerInstance
in class AbstractClassifier
abc
- the alphabets
true
if the new AlphabetContainer
could be
set, false
otherwiseAbstractClassifier.getAlphabetContainer()
,
AlphabetContainer.checkConsistency(AlphabetContainer)
public void train(Sample[] s, double[][] weights) throws Exception
AbstractClassifier
Sample
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(Sample...)
.
Sample
s are defined over the
underlying alphabet and length.
train
in class AbstractClassifier
s
- an array of Sample
sweights
- the weights for the Sample
s
Exception
- if the weights are incorrect or the training did not succeedAbstractClassifier.train(Sample...)
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 not
Sequence
and a given class
NotTrainedException
- if the classifier is not trained
IllegalArgumentException
- if something is wrong with the Sequence
seq
Exception
- if something went wrongpublic double[] getScores(Sample s) throws Exception
AbstractScoreBasedClassifier
Sequence
in the Sample
. The scores are stored in the array according to
the index of the Sequence
in the Sample
.
getScores
in class AbstractScoreBasedClassifier
s
- the Sample
Exception
- if something went wrongpublic byte[] classify(Sample s) throws Exception
AbstractClassifier
i
in the array
0 < i < getNumberOfClasses()
.
classify
in class AbstractClassifier
s
- the sample to be classified
Exception
- 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
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |