|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectde.jstacs.classifiers.AbstractClassifier
de.jstacs.classifiers.AbstractScoreBasedClassifier
de.jstacs.classifiers.differentiableSequenceScoreBased.ScoreClassifier
public abstract class ScoreClassifier
This abstract class implements the main functionality of a DifferentiableSequenceScore
based classifier.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class de.jstacs.classifiers.AbstractScoreBasedClassifier |
---|
AbstractScoreBasedClassifier.DoubleTableResult |
Field Summary | |
---|---|
protected boolean |
hasBeenOptimized
This boolean indicates whether the classifier has been optimized with the method AbstractClassifier.train(DataSet[]) 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 DifferentiableSequenceScore[] |
score
The internally used scoring functions. |
protected SafeOutputStream |
sostream
This stream is used for comments, e.g. during the training, ... . |
protected History |
template
The default history |
Constructor Summary | |
---|---|
ScoreClassifier(ScoreClassifierParameterSet params,
double lastScore,
DifferentiableSequenceScore... score)
Creates a new ScoreClassifier from a given
ScoreClassifierParameterSet and DifferentiableSequenceScore s . |
|
ScoreClassifier(StringBuffer xml)
The standard constructor for the interface Storable . |
Method Summary | |
---|---|
ScoreClassifier |
clone()
|
protected void |
createStructure(DataSet[] data,
double[][] weights)
Creates the structure that will be used in the optimization. |
protected void |
createStructure(DataSet[] data,
double[][] weights,
boolean initRandomly)
Creates the structure that will be used in the optimization. |
protected double |
doOptimization(DataSet[] 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. |
ScoreClassifierParameterSet |
getCurrentParameterSet()
This method returns the current ParameterSet of the classifier. |
DifferentiableSequenceScore |
getDifferentiableSequenceScore(int i)
Returns the internally used DifferentiableSequenceScore with index
i . |
DifferentiableSequenceScore[] |
getDifferentiableSequenceScores()
Returns all internally used DifferentiableSequenceScore s in the internal
order. |
protected abstract DiffSSBasedOptimizableFunction |
getFunction(DataSet[] 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. |
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. |
void |
initUsingParameters(double[] parameters)
Sets the parameters of this classifier and the contained scoring functions to the supplied parameters. |
boolean |
isInitialized()
This method gives information about the state of the classifier. |
protected OptimizableFunction.KindOfParameter |
preoptimize(OptimizableFunction f)
This method allows to pre-optimize the parameter before the real optimization. |
void |
setOutputStream(OutputStream o)
Sets the OutputStream that is used e.g. for writing information
during training. |
void |
train(DataSet[] data,
double[][] weights)
This method trains a classifier over an array of weighted DataSet
s. |
Methods inherited from class de.jstacs.classifiers.AbstractScoreBasedClassifier |
---|
check, check, classify, classify, createDefaultClassWeights, getClassWeight, getClassWeights, getMultiClassScores, getNumberOfClasses, getPValue, getPValue, getResults, getScore, getScores, setClassWeights, setClassWeights, setThresholdClassWeights |
Methods inherited from class de.jstacs.classifiers.AbstractClassifier |
---|
classify, evaluate, getAlphabetContainer, getCharacteristics, getLength, toXML, train |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected DifferentiableSequenceScore[] score
protected ScoreClassifierParameterSet params
protected boolean hasBeenOptimized
AbstractClassifier.train(DataSet[])
or
the weighted version.
protected SafeOutputStream sostream
public static final double NOT_TRAINED_VALUE
getLastScore()
if the classifier is not trained.
protected History template
Constructor Detail |
---|
public ScoreClassifier(ScoreClassifierParameterSet params, double lastScore, DifferentiableSequenceScore... score) throws CloneNotSupportedException
ScoreClassifier
from a given
ScoreClassifierParameterSet
and DifferentiableSequenceScore
s .
params
- the parameter set for the classifierlastScore
- the score of the last optimization, if no such value exists the
programmer should use NOT_TRAINED_VALUE
score
- the DifferentiableSequenceScore
s for the classes
CloneNotSupportedException
- if at least one DifferentiableSequenceScore
could not be clonedAbstractScoreBasedClassifier.AbstractScoreBasedClassifier(AlphabetContainer,
int, int)
public ScoreClassifier(StringBuffer xml) throws NonParsableException
Storable
.
Creates a new ScoreClassifier
out of its XML representation.
xml
- the XML representation as StringBuffer
NonParsableException
- if the ScoreClassifier
could not be reconstructed out
of the XML representation (the StringBuffer
could not
be parsed)AbstractScoreBasedClassifier.AbstractScoreBasedClassifier(StringBuffer)
,
Storable
Method Detail |
---|
public ScoreClassifier clone() throws CloneNotSupportedException
clone
in class AbstractScoreBasedClassifier
CloneNotSupportedException
public String getInstanceName()
AbstractClassifier
getInstanceName
in class AbstractClassifier
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
classifierpublic 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 boolean hasBeenOptimized()
train
-method.
true
if the classifier has been optimized by a
train
-method, false
otherwisepublic void setOutputStream(OutputStream o)
OutputStream
that is used e.g. for writing information
during training. It is possible to set o=null
, then nothing
will be written.
o
- the OutputStream
public void train(DataSet[] data, 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
data
- an array of DataSet
sweights
- the weights for the DataSet
s
Exception
- if the weights are incorrect or the training did not succeedAbstractClassifier.train(DataSet...)
protected double doOptimization(DataSet[] reduced, double[][] newWeights) throws Exception
train
-method
reduced
- the samplesnewWeights
- the weights
Exception
- if something went wrong during the optimizationprotected OptimizableFunction.KindOfParameter preoptimize(OptimizableFunction f) throws Exception
f
- the function to be optimized
Exception
- if the pre-optimization failsprotected void createStructure(DataSet[] data, double[][] weights, boolean initRandomly) throws Exception
data
- the dataweights
- the weights of the datainitRandomly
- initialize the functions randomly
Exception
- if something went wrongpublic void initUsingParameters(double[] parameters) throws Exception
parameters
- the new parameters
Exception
- if the parameters could not be setprotected void createStructure(DataSet[] data, double[][] weights) throws Exception
data
- the dataweights
- the weights of the data *
Exception
- if something went wrongprotected 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)
protected abstract DiffSSBasedOptimizableFunction getFunction(DataSet[] data, double[][] weights) throws Exception
data
- the samplesweights
- the weights of the sequences of the samples
Exception
- if something went wrongprotected 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 IllegalArgumentException, NotTrainedException, 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
IllegalArgumentException
- if something is wrong with the Sequence
seq
NotTrainedException
- if the classifier is not trained
Exception
- if something went wrongpublic double getLastScore()
public DifferentiableSequenceScore getDifferentiableSequenceScore(int i) throws CloneNotSupportedException
DifferentiableSequenceScore
with index
i
.
i
- the internal index of the DifferentiableSequenceScore
DifferentiableSequenceScore
with index
i
CloneNotSupportedException
- if the DifferentiableSequenceScore
could not be clonedpublic DifferentiableSequenceScore[] getDifferentiableSequenceScores() throws CloneNotSupportedException
DifferentiableSequenceScore
s in the internal
order.
DifferentiableSequenceScore
s in the internal
order
CloneNotSupportedException
- if a DifferentiableSequenceScore
could not be clonedprotected abstract 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 classifierpublic ScoreClassifierParameterSet getCurrentParameterSet() throws CloneNotSupportedException
ParameterSet
of the classifier.
ParameterSet
of the classifier.
CloneNotSupportedException
- if the ParameterSet
could not be cloned
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |