|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object de.jstacs.models.AbstractModel de.jstacs.models.discrete.DiscreteGraphicalModel de.jstacs.models.discrete.homogeneous.HomogeneousModel
public abstract class HomogeneousModel
This class implements homogeneous models of arbitrary order.
HomogeneousModelParameterSet
Nested Class Summary | |
---|---|
protected class |
HomogeneousModel.HomCondProb
This class handles the (conditional) probabilities of a homogeneous model in a fast way. |
Field Summary | |
---|---|
protected byte |
order
The order of the model. |
protected int[] |
powers
The powers of the alphabet length. |
Fields inherited from class de.jstacs.models.discrete.DiscreteGraphicalModel |
---|
params, trained |
Fields inherited from class de.jstacs.models.AbstractModel |
---|
alphabets, length |
Constructor Summary | |
---|---|
HomogeneousModel(HomogeneousModelParameterSet params)
Creates a homogeneous model from a parameter set. |
|
HomogeneousModel(StringBuffer stringBuff)
The standard constructor for the interface Storable . |
Method Summary | |
---|---|
protected void |
check(Sequence sequence,
int startpos,
int endpos)
Checks some constraints, these are in general conditions on the AlphabetContainer of a (sub)Sequence
between startpos und endpos . |
protected int |
chooseFromDistr(Constraint distr,
int start,
int end,
double randNo)
Chooses a value in [0,end-start] according to the
distribution encoded in the frequencies of distr between the
indices start and end . |
protected HomogeneousModel.HomCondProb[] |
cloneHomProb(HomogeneousModel.HomCondProb[] p)
Clones the given array of conditional probabilities. |
Sample |
emitSample(int no,
int... length)
Creates a Sample of a given number of Sequence s from a
trained homogeneous 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. |
NumericalResultSet |
getNumericalCharacteristics()
Returns the subset of numerical values that are also returned by Model.getCharacteristics() . |
double |
getProbFor(Sequence sequence,
int startpos,
int endpos)
Returns the probability of (a part of) the given sequence given the model. |
protected abstract Sequence |
getRandomSequence(Random r,
int length)
This method creates a random Sequence from a trained homogeneous
model. |
protected abstract double |
logProbFor(Sequence sequence,
int startpos,
int endpos)
This method computes the logarithm of the probability of the given Sequence in the given interval. |
protected abstract double |
probFor(Sequence sequence,
int startpos,
int endpos)
This method computes the probability of the given Sequence in the
given interval. |
protected void |
set(DGMParameterSet params,
boolean trained)
Sets the parameters as internal parameters and does some essential computations. |
void |
train(Sample[] data)
Trains the homogeneous model on all given Sample s. |
abstract void |
train(Sample[] data,
double[][] weights)
Trains the homogeneous model using an array of weighted Sample s. |
Methods inherited from class de.jstacs.models.discrete.DiscreteGraphicalModel |
---|
clone, fromXML, getCurrentParameterSet, getDescription, getESS, getFurtherModelInfos, getXMLTag, isTrained, setFurtherModelInfos, toString, toXML |
Methods inherited from class de.jstacs.models.AbstractModel |
---|
getAlphabetContainer, getCharacteristics, getLength, getLogProbFor, getLogProbFor, getLogProbFor, getLogProbFor, getPriorTerm, getProbFor, getProbFor, set, setNewAlphabetContainerInstance, train |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface de.jstacs.models.Model |
---|
getInstanceName, getLogPriorTerm, train |
Field Detail |
---|
protected int[] powers
protected byte order
Constructor Detail |
---|
public HomogeneousModel(HomogeneousModelParameterSet params) throws CloneNotSupportedException, IllegalArgumentException, NonParsableException
params
- the parameter set
CloneNotSupportedException
- if the parameter set could not be cloned
IllegalArgumentException
- if the parameter set is not instantiated
NonParsableException
- if the parameter set is not parsableHomogeneousModelParameterSet
,
DiscreteGraphicalModel.DiscreteGraphicalModel(DGMParameterSet)
public HomogeneousModel(StringBuffer stringBuff) throws NonParsableException
Storable
.
Creates a new HomogeneousModel
out of its XML representation.
stringBuff
- the XML representation as StringBuffer
NonParsableException
- if the HomogeneousModel
could not be reconstructed
out of the XML representation (the StringBuffer
could
not be parsed)Storable
,
DiscreteGraphicalModel.DiscreteGraphicalModel(StringBuffer)
Method Detail |
---|
public final Sample emitSample(int no, int... length) throws NotTrainedException, IllegalArgumentException, EmptySampleException, WrongAlphabetException, WrongSequenceTypeException
Sample
of a given number of Sequence
s from a
trained homogeneous model.
emitSample
in interface Model
emitSample
in class AbstractModel
no
- the number of Sequence
s that should be in the
Sample
length
- the length of all Sequence
s or an array of lengths
with the Sequence
with index i
having
length length[i]
Sample
NotTrainedException
- if the model was not trained
IllegalArgumentException
- if the dimension of length
is neither 1 nor
no
EmptySampleException
- if no == 0
WrongSequenceTypeException
- if the Sequence
type is not suitable (for the
AlphabetContainer
)
WrongAlphabetException
- if something is wrong with the alphabetSample.Sample(String, Sequence...)
protected abstract Sequence getRandomSequence(Random r, int length) throws WrongAlphabetException, WrongSequenceTypeException
Sequence
from a trained homogeneous
model.
r
- the random generatorlength
- the length of the Sequence
Sequence
WrongSequenceTypeException
- if the Sequence
type is not suitable (for the
AlphabetContainer
)
WrongAlphabetException
- if something is wrong with the alphabetpublic byte getMaximalMarkovOrder()
Model
getMaximalMarkovOrder
in interface Model
getMaximalMarkovOrder
in class AbstractModel
public NumericalResultSet getNumericalCharacteristics() throws Exception
Model
Model.getCharacteristics()
.
Exception
- if some of the characteristics could not be definedpublic final double getLogProbFor(Sequence sequence, int startpos, int endpos) throws NotTrainedException, Exception
Model
Model.getProbFor(Sequence, int, int)
getLogProbFor
in interface Model
getLogProbFor
in class AbstractModel
sequence
- the given sequencestartpos
- the start position within the given sequenceendpos
- the last position to be taken into account
NotTrainedException
- if the model is not trained yet
Exception
- if the sequence could not be handled (e.g.
startpos >
, endpos
> sequence.length
, ...) by the modelModel.getProbFor(Sequence, int, int)
public final double getProbFor(Sequence sequence, int startpos, int endpos) throws NotTrainedException, Exception
Model
Model.getProbFor(Sequence, int)
by the fact, that the model could be
e.g. homogeneous and therefore the length of the sequences, whose
probability should be returned, is not fixed. Additionally the end
position of the part of the given sequence is given and the probability
of the part from position startpos
to endpos
(inclusive) should be returned.
length
and the alphabets
define the type of
data that can be modeled and therefore both has to be checked.
sequence
- the given sequencestartpos
- the start position within the given sequenceendpos
- the last position to be taken into account
NotTrainedException
- if the model is not trained yet
Exception
- if the sequence could not be handled (e.g.
startpos > endpos
, endpos
> sequence.length
, ...) by the modelpublic void train(Sample[] data) throws Exception
Sample
s.
data
- the given Sample
s
Exception
- if something went wrongtrain(Sample[], double[][])
public abstract void train(Sample[] data, double[][] weights) throws Exception
Sample
s.
The Sequence
weights in weights[i]
are for the
Sample
in data[i]
.
data
- the given Sample
sweights
- the weights
Exception
- if something went wrong, furthermore data.length
has to be weights.length
protected void set(DGMParameterSet params, boolean trained) throws CloneNotSupportedException, NonParsableException
DiscreteGraphicalModel
fromParameterSet
-methods.
set
in class DiscreteGraphicalModel
params
- the new ParameterSet
trained
- indicates if the model is trained or not
CloneNotSupportedException
- if the parameter set could not be cloned
NonParsableException
- if the parameters of the model could not be parsedprotected void check(Sequence sequence, int startpos, int endpos) throws NotTrainedException, IllegalArgumentException
AlphabetContainer
of a (sub)Sequence
between startpos
und endpos
.
check
in class DiscreteGraphicalModel
sequence
- the Sequence
startpos
- the start position within the Sequence
endpos
- the end position within the Sequence
NotTrainedException
- if the model is not trained
IllegalArgumentException
- if some arguments are wrongDiscreteGraphicalModel.check(Sequence, int, int)
protected final int chooseFromDistr(Constraint distr, int start, int end, double randNo)
[0,end-start]
according to the
distribution encoded in the frequencies of distr
between the
indices start
and end
.
distr
is not changed in the process.
distr
- the distributionstart
- the start indexend
- the end indexrandNo
- a random number in [0,1]
Constraint.getFreq(int)
protected abstract double logProbFor(Sequence sequence, int startpos, int endpos)
Sequence
in the given interval. The method is only used in
Model.getLogProbFor(Sequence, int, int)
after
the method check(Sequence, int, int)
has been
invoked.
sequence
- the Sequence
startpos
- the start position within the Sequence
endpos
- the end position within the Sequence
check(Sequence, int, int)
,
Model.getLogProbFor(Sequence, int, int)
protected abstract double probFor(Sequence sequence, int startpos, int endpos)
Sequence
in the
given interval. The method is only used in
Model.getProbFor(Sequence, int, int)
after the
method check(Sequence, int, int)
has been
invoked.
sequence
- the Sequence
startpos
- the start position within the Sequence
endpos
- the end position within the Sequence
check(Sequence, int, int)
,
Model.getProbFor(Sequence, int, int)
protected HomogeneousModel.HomCondProb[] cloneHomProb(HomogeneousModel.HomCondProb[] p)
p
- the original conditional probabilities
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |