|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||||
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)
, Storable.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)
The standard constructor for the interface Storable . |
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 a 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 sequences 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 (a part of) the given sequence given the model. |
double |
getLogProbFor(Sequence sequence,
int startpos,
int endpos)
Returns the logarithm of the probability of (a part 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 (a part 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 Model 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 |
Methods inherited from interface de.jstacs.Storable |
---|
toXML |
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 therefore both has to be checked before any
evaluation (e.g. getProbFor
)
alphabets
- the alphabets in an AlphabetContainer
length
- the length of the sequences a model can classify, 0 for
arbitrary lengthpublic AbstractModel(StringBuffer stringBuff) throws NonParsableException
Storable
.
Creates a new AbstractModel
out of a StringBuffer
.
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();
o
defined by
X
that are not of simple data-types like
int
, double
, ... have to be deeply
copied return o
CloneNotSupportedException
- if something went wrong while cloningpublic void train(Sample data) throws Exception
Model
Model
object given the data as Sample
. train(data1)
; train(data2)
should be a fully trained model over data2
and not over
data1+data2
. All parameters of the model were given by the
call of the constructor.
train
in interface Model
data
- the given sequences as Sample
Exception
- if the training did not succeedSample.getElementAt(int)
,
Sample.ElementEnumerator
public double getProbFor(Sequence sequence) throws NotTrainedException, Exception
Model
length
and the alphabets
define the type of
data that can be modeled and therefore both has to be checked.
getProbFor
in interface Model
sequence
- the given sequence for which the probability/the value of the
density function should be returned
NotTrainedException
- if the model is not trained yet
Exception
- if the sequence could not be handled by the modelpublic double getProbFor(Sequence sequence, int startpos) throws NotTrainedException, Exception
Model
startpos
. E.g. the fixed length is 12. The length
of the given sequence is 30 and the
startpos
=15 the probability
of the part from position 15 to 26 (inclusive) given the model should be returned.
length
and the alphabets
define the type of
data that can be modeled and therefore both has to be checked.
getProbFor
in interface Model
sequence
- the given sequencestartpos
- the start position within the given sequence
NotTrainedException
- if the model is not trained yet
Exception
- 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 given sequencestartpos
- the start position within the given sequenceendpos
- the last position to be taken into account
Exception
- if the sequence could not be handled (e.g.
startpos >
, endpos
> sequence.length
, ...) by the model
NotTrainedException
- if the model is not trained yetModel.getProbFor(Sequence, int, int)
public double getLogProbFor(Sequence sequence, int startpos) throws Exception
Model
Model.getProbFor(Sequence, int)
getLogProbFor
in interface Model
sequence
- the given sequencestartpos
- the start position within the given sequence
Exception
- if the sequence could not be handled by the model
NotTrainedException
- if the model is not trained yetModel.getProbFor(Sequence, int)
public double getLogProbFor(Sequence sequence) throws Exception
Model
Model.getProbFor(Sequence)
getLogProbFor
in interface Model
sequence
- the given sequence for which the logarithm of the
probability/the value of the density function should be
returned
Exception
- if the sequence could not be handled by the model
NotTrainedException
- if the model is not trained yetModel.getProbFor(Sequence)
public double[] getLogProbFor(Sample data) throws Exception
Model
Model.getLogProbFor(Sequence)
.
getLogProbFor
in interface Model
data
- the sample of sequences
Exception
- if something went wrongModel.getLogProbFor(Sequence)
public void getLogProbFor(Sample data, double[] res) throws Exception
Model
double
-array.
Model.getLogProbFor(Sequence)
.
getLogProbFor
in interface Model
data
- the sample of sequencesres
- the array for the results, has to have length
data.getNumberOfElements()
(which returns the
number of sequences in the sample)
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
Sample
object containing artificial
sequence(s).
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 given array l
.
emitSample( int n )
and
emitSample( int n, null )
should return a sample with
n
sequences of length of the model (
Model.getLength()
).
Exception
.
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.
Sample
containing the artificial sequence(s)
NotTrainedException
- if the model is not trained yet
Exception
- if the emission did not succeedSample
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
StorableResult
.
getCharacteristics
in interface Model
Exception
- if some of the characteristics could not be definedStorableResult
protected abstract void fromXML(StringBuffer xml) throws NonParsableException
StringBuffer
. It is the counter part of Storable.toXML()
.
xml
- the XML representation of the model
NonParsableException
- if the StringBuffer
is not parsable or the
representation is conflictingAbstractModel(StringBuffer)
public final boolean setNewAlphabetContainerInstance(AlphabetContainer abc)
Model
AlphabetContainer
for the current model. This instance has to be consistent with the
underlying instance of an AlphabetContainer
.
setNewAlphabetContainerInstance
in interface Model
abc
- the alphabets in an AlphabetContainer
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 All Classes | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |