public abstract class ScoreClassifier extends AbstractScoreBasedClassifier
DifferentiableSequenceScore
based classifier.AbstractScoreBasedClassifier.DoubleTableResult
Modifier and Type | Field and Description |
---|---|
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.
|
protected History |
template
The default history
|
Constructor and Description |
---|
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 . |
Modifier and Type | Method and Description |
---|---|
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.
res[0] = new CategoricalResult( "classifier", "the kind of classifier", getInstanceName() );
|
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.
|
protected int |
getIterations()
Returns the number of independent re-starts in the training.
|
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. |
void |
train(DataSet[] data,
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, getScores, setClassWeights, setClassWeights, setThresholdClassWeights
classify, evaluate, evaluate, getAlphabetContainer, getCharacteristics, getLength, toXML, train
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
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 classesCloneNotSupportedException
- 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
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
sException
- if the weights are incorrect or the training did not succeedAbstractClassifier.train(DataSet...)
protected int getIterations()
AbstractDifferentiableSequenceScore.getNumberOfStarts(DifferentiableSequenceScore[])
for the internal DifferentiableSequenceScore
s.doOptimization(DataSet[], double[][])
,
AbstractClassifier.train(DataSet...)
,
train(DataSet[], double[][])
protected double doOptimization(DataSet[] reduced, double[][] newWeights) throws Exception
train
-methodreduced
- the data setsnewWeights
- the weightsException
- if something went wrong during the optimizationprotected OptimizableFunction.KindOfParameter preoptimize(OptimizableFunction f) throws Exception
f
- the function to be optimizedException
- 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 randomlyException
- if something went wrongpublic void initUsingParameters(double[] parameters) throws Exception
parameters
- the new parametersException
- 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 data setsweights
- the weights of the sequences of the data setsException
- 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 notSequence
and a given classIllegalArgumentException
- if something is wrong with the Sequence
seq
NotTrainedException
- if the classifier is not trainedException
- 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
orderCloneNotSupportedException
- 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