|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectde.jstacs.models.AbstractModel
public abstract class AbstractModel
Abstract class for a model for pattern recognition.
For writing or reading a StringBuffer to or from a file (fromXML(StringBuffer)
, toXML()
)
you can use the class FileManager
.
FileManager
Field Summary | |
---|---|
protected AlphabetContainer |
alphabets
The underlying alphabets |
protected int |
length
the length of the sequences the model can classify. |
Constructor Summary | |
---|---|
AbstractModel(AlphabetContainer alphabets,
int length)
Constructor that sets the length of the model to length and the AlphabetContainer to
alphabets . |
|
AbstractModel(StringBuffer stringBuff)
Constructor for parsing a AbstractModel out of a StringBuffer. |
Method Summary | |
---|---|
AbstractModel |
clone()
Follows the conventions of Object 's clone-method. |
Sample |
emitSample(int numberOfSequences,
int... seqLength)
This method returns a Sample object containing artificial sequence(s). |
protected abstract void |
fromXML(StringBuffer xml)
This method should only be used by the constructor that works on StringBuffer. |
AlphabetContainer |
getAlphabetContainer()
Returns the container of alphabets that were used when constructing the model. |
ResultSet |
getCharacteristics()
Returns some information characterizing or describing the current instance of the model. |
int |
getLength()
Returns the length of sequence this model can classify. |
double[] |
getLogProbFor(Sample data)
This method computes the logarithm of the probabilities of all sequences in the given sample. |
void |
getLogProbFor(Sample data,
double[] res)
This method computes and stores the logarithm of the probabilities for any sequence in the sample in the given double array. |
double |
getLogProbFor(Sequence sequence)
Returns the logarithm of the probability of the given sequence given the model. |
double |
getLogProbFor(Sequence sequence,
int startpos)
Returns the logarithm of the probability of the given sequence given the model. |
double |
getLogProbFor(Sequence sequence,
int startpos,
int endpos)
Returns the logarithm of the probability of the given sequence given the model. |
byte |
getMaximalMarkovOrder()
This method returns the maximal used markov order if possible. |
double |
getPriorTerm()
Returns a value that is proportional to the prior. |
double |
getProbFor(Sequence sequence)
Returns the probability of the given sequence given the model. |
double |
getProbFor(Sequence sequence,
int startpos)
Returns the probability of the given sequence given the model. |
protected void |
set(AlphabetContainer abc)
This method should only be invoked by the method setNewAlphabetContainerInstance( AlphabetContainer ) and not be made public. |
boolean |
setNewAlphabetContainerInstance(AlphabetContainer abc)
This method tries to set a new instance of an AlphabetContainer for the current model. |
void |
train(Sample data)
Trains the AbstractModel object given the data as Sample . |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface de.jstacs.models.Model |
---|
getInstanceName, getLogPriorTerm, getNumericalCharacteristics, getProbFor, isTrained, toString, train |
Field Detail |
---|
protected int length
protected AlphabetContainer alphabets
Constructor Detail |
---|
public AbstractModel(AlphabetContainer alphabets, int length)
length
and the AlphabetContainer to
alphabets
.
length
gives the length of the sequences the model can classify. Models that can
only classify sequences of defined length are e.g. PWM or inhomogeneous Markov models. If the model can classify
sequences of arbitrary length, e.g. homogeneous Markov models, this parameter must be set to 0 (zero).
length
and alphabets
define the type of data that can be modeled and therefor
both has to be checked before any evaluation (e.g. getProbFor
)
alphabets
- the alphabetslength
- the length of the sequences a model can classify, 0 for arbitrary lengthpublic AbstractModel(StringBuffer stringBuff) throws NonParsableException
stringBuff
- the StringBuffer to be parsed
NonParsableException
- is thrown if the StringBuffer could not be parsedMethod Detail |
---|
public AbstractModel clone() throws CloneNotSupportedException
Object
's clone-method.
clone
in interface Model
clone
in class Object
AbstractModel
(the member-AlphabetContainer
isn't deeply cloned since it is assumed to be immutable). The type of the returned object is defined by
the class X
directly inherited from AbstractModel
. Hence X
's
clone-method should work as:Object o = (X)super.clone();
2. all additional member variables of o
defined by X
that are not of simple data-types like int, double, ... , have to be deeply
copied 3. return o
CloneNotSupportedException
public void train(Sample data) throws Exception
Model
Sample
.
train
in interface Model
data
- the given sequences as Sample
Exception
- an Exception should be thrown if the training did not succeed.Sample.getElementAt(int)
,
Sample.ElementEnumerator
public double getProbFor(Sequence sequence) throws NotTrainedException, Exception
Model
length
and alphabets
define the type of data that can be modeled and therefore
both has to be checked.
getProbFor
in interface Model
sequence
- the sequence
NotTrainedException
- a NotTrainedException should be thrown if the model is not trained yet.
Exception
- an Exception should be thrown if the sequence could not be handled by the modelpublic double getProbFor(Sequence sequence, int startpos) throws NotTrainedException, Exception
Model
length
and alphabets
define the type of data that can be modeled and therefore
both has to be checked.
getProbFor
in interface Model
sequence
- the sequencestartpos
- the start position
NotTrainedException
- a NotTrainedException should be thrown if the model is not trained yet.
Exception
- an Exception should be thrown if the sequence could not be handled by the modelpublic double getLogProbFor(Sequence sequence, int startpos, int endpos) throws Exception
Model
Model.getProbFor(Sequence, int, int)
getLogProbFor
in interface Model
sequence
- the sequencestartpos
- the start positionendpos
- the last position to be taken into account
Exception
- an Exception should be thrown if the sequence could not be handled (e.g. startpos > endpos, endpos
> sequence.length, ...) by the model
NotTrainedException
- a NotTrainedException should be thrown if the model is not trained yet.Model.getProbFor(Sequence, int, int)
public double getLogProbFor(Sequence sequence, int startpos) throws Exception
Model
Model.getProbFor(Sequence, int)
getLogProbFor
in interface Model
sequence
- the sequencestartpos
- the start position
Exception
- an Exception should be thrown if the sequence could not be handled by the model
NotTrainedException
- a NotTrainedException should be thrown if the model is not trained yet.Model.getProbFor(Sequence, int)
public double getLogProbFor(Sequence sequence) throws Exception
Model
Model.getProbFor(Sequence)
getLogProbFor
in interface Model
sequence
- the sequence
Exception
- an Exception should be thrown if the sequence could not be handled by the model
NotTrainedException
- a NotTrainedException should be thrown if the model is not trained yet.Model.getProbFor(Sequence)
public double[] getLogProbFor(Sample data) throws Exception
Model
getLogProbFor(Sequence)
getLogProbFor
in interface Model
data
- the sample
Exception
- if something went wrongModel.getLogProbFor(Sequence)
public void getLogProbFor(Sample data, double[] res) throws Exception
Model
double
array.
getLogProbFor(Sequence)
getLogProbFor
in interface Model
data
- the sampleres
- the array for the results, has to have length data.getNumberOfElements()
Exception
- if something went wrongModel.getLogProbFor(Sample)
public double getPriorTerm() throws Exception
Model
getPriorTerm
in interface Model
Exception
- if something went wrongpublic Sample emitSample(int numberOfSequences, int... seqLength) throws NotTrainedException, Exception
Model
emitSample( int n, int l )
should return a sample with n
sequences of length l
.
emitSample( int n, int[] l )
should return a sample with n
sequences which have a sequence length corresponding to the entry in the array
emitSample( int n )
and emitSample( int n, null )
should return a sample with
n
sequences of length of the model (Model.getLength()
)
emitSample
in interface Model
numberOfSequences
- the number of sequences that should be contained in the returned sampleseqLength
- the length of the sequences for a homogeneous model; for an inhomogeneous model this parameter should be
null
or an array of size 0.
NotTrainedException
- a NotTrainedException should be thrown if the model is not trained yet.
Exception
- an Exception should be thrown if the emission did not succeed.Sample
public final AlphabetContainer getAlphabetContainer()
Model
getAlphabetContainer
in interface Model
public final int getLength()
Model
getLength
in interface Model
public byte getMaximalMarkovOrder() throws UnsupportedOperationException
Model
getMaximalMarkovOrder
in interface Model
UnsupportedOperationException
- if the model can't give a proper answerpublic ResultSet getCharacteristics() throws Exception
Model
ObjectResult
getCharacteristics
in interface Model
Exception
- an Exception
is thrown if some of the characteristics could not be definedStorableResult
protected abstract void fromXML(StringBuffer xml) throws NonParsableException
toXML()
.
xml
- the representation
NonParsableException
- if the StringBuffer is not parsable or the representation is conflictingAbstractModel(StringBuffer)
public final boolean setNewAlphabetContainerInstance(AlphabetContainer abc)
Model
setNewAlphabetContainerInstance
in interface Model
abc
- the alphabets
true
if the new instance could be setModel.getAlphabetContainer()
,
AlphabetContainer.checkConsistency(AlphabetContainer)
protected void set(AlphabetContainer abc)
setNewAlphabetContainerInstance( AlphabetContainer )
and not be made public.
setNewAlphabetContainerInstance( AlphabetContainer )
,
e.g. setting a new AlphabetContainer instance for subcomponents.
abc
- the new instance
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |