|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectde.jstacs.models.AbstractModel
de.jstacs.models.discrete.DiscreteGraphicalModel
de.jstacs.models.discrete.homogeneous.HomogeneousModel
public abstract class HomogeneousModel
This class implements homogeneous models.
HomogeneousModelParameterSet| Nested Class Summary | |
|---|---|
protected class |
HomogeneousModel.HomCondProb
This class handles the (conditional) homogeneous probabilities in a fast way. |
| Field Summary | |
|---|---|
protected byte |
order
The Markov 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)
Creates a homogeneous model from a StringBuffer. |
|
| Method Summary | |
|---|---|
protected void |
check(Sequence sequence,
int startpos,
int endpos)
Checks some constraints |
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 conditional probabilities. |
Sample |
emitSample(int no,
int... length)
Creates a sample of nosequences. |
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. |
NumericalResultSet |
getNumericalCharacteristics()
Returns the subset of numerical values that are also returned by getCharacteristsics. |
double |
getProbFor(Sequence sequence,
int startpos,
int endpos)
Returns the probability of the given sequence given the model. |
protected abstract Sequence |
getRandomSequence(Random r,
int length)
This method creates a sequence from a trained 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 model on all given samples. |
abstract void |
train(Sample[] data,
double[][] weights)
Trains the model using an array of weighted samples. |
| 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 parsable
public HomogeneousModel(StringBuffer stringBuff)
throws NonParsableException
stringBuff - the StringBuffer
NonParsableException - if the buffer is not parsable| Method Detail |
|---|
public final Sample emitSample(int no,
int... length)
throws NotTrainedException,
IllegalArgumentException,
EmptySampleException,
WrongAlphabetException,
WrongSequenceTypeException
nosequences.
emitSample in interface ModelemitSample in class AbstractModelno - the number of sequences in the samplelength - the length of all sequences or an array of length, than the sequence with index i has
length length[i]
NotTrainedException - if the model was not trained
IllegalArgumentException - if the dimension of length is neither 1 nor no
EmptySampleException - if no == 0
WrongSequenceTypeException
WrongAlphabetExceptionSample
protected abstract Sequence getRandomSequence(Random r,
int length)
throws WrongAlphabetException,
WrongSequenceTypeException
r - the random generatorlength - the length of the sequence
WrongSequenceTypeException
WrongAlphabetExceptionpublic byte getMaximalMarkovOrder()
Model
getMaximalMarkovOrder in interface ModelgetMaximalMarkovOrder in class AbstractModel
public NumericalResultSet getNumericalCharacteristics()
throws Exception
ModelgetCharacteristsics.
Exception - an Exception is thrown if some of the characteristics could not be defined
public final double getLogProbFor(Sequence sequence,
int startpos,
int endpos)
throws NotTrainedException,
Exception
ModelModel.getProbFor(Sequence, int, int)
getLogProbFor in interface ModelgetLogProbFor in class AbstractModelsequence - the sequencestartpos - the start positionendpos - the last position to be taken into account
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 (e.g. startpos > endpos, endpos
> sequence.length, ...) by the modelModel.getProbFor(Sequence, int, int)
public final double getProbFor(Sequence sequence,
int startpos,
int endpos)
throws NotTrainedException,
Exception
Modelstartpos to endpos (inclusive) should be returned.
length and alphabets define the type of data that can be modeled and therefore
both has to be checked.
sequence - the sequencestartpos - the start positionendpos - the last position to be taken into account
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 (e.g. startpos > endpos, endpos
> sequence.length, ...) by the model
public void train(Sample[] data)
throws Exception
data - the data
Exception - if something went wrong
public abstract void train(Sample[] data,
double[][] weights)
throws Exception
weights[i] are for data[i].
data - the samplesweights - 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
set in class DiscreteGraphicalModelparams - the new ParameterSettrained - the indicator for the model
CloneNotSupportedException - if the parmeterSet could not be cloned
NonParsableException - if the parameters of the model could not be parsed
protected void check(Sequence sequence,
int startpos,
int endpos)
throws NotTrainedException,
IllegalArgumentException
check in class DiscreteGraphicalModelsequence - the sequencestartpos - the start positionendpos - the end position
NotTrainedException - if the model is not trained
IllegalArgumentException - if some arguments are wrong
protected final int chooseFromDistr(Constraint distr,
int start,
int end,
double randNo)
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)
Model.getLogProbFor(Sequence, int, int) after the method
check(Sequence, int, int) has been invoked.
sequence - the sequencestartpos - the start positionendpos - the end position
check(Sequence, int, int),
Model.getLogProbFor(Sequence, int, int)
protected abstract double probFor(Sequence sequence,
int startpos,
int endpos)
Model.getProbFor(Sequence, int, int) after the method
check(Sequence, int, int) has been invoked.
sequence - the sequencestartpos - the start positionendpos - the end position
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 | |||||||||