|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectde.jstacs.sequenceScores.statisticalModels.trainable.AbstractTrainableStatisticalModel
de.jstacs.sequenceScores.statisticalModels.trainable.hmm.AbstractHMM
de.jstacs.sequenceScores.statisticalModels.trainable.hmm.models.HigherOrderHMM
de.jstacs.sequenceScores.statisticalModels.trainable.hmm.models.SamplingHigherOrderHMM
public class SamplingHigherOrderHMM
Nested Class Summary | |
---|---|
static class |
SamplingHigherOrderHMM.ViterbiComputation
Emumeration of all possible Viterbi-Path methods |
Nested classes/interfaces inherited from class de.jstacs.sequenceScores.statisticalModels.trainable.hmm.models.HigherOrderHMM |
---|
HigherOrderHMM.Type |
Field Summary | |
---|---|
protected BurnInTest |
burnInTest
This variable holds the BurnInTest used for training the model |
protected boolean |
hasSampled
This boolean indicates if the parameters for the model were sampled |
Fields inherited from class de.jstacs.sequenceScores.statisticalModels.trainable.hmm.models.HigherOrderHMM |
---|
backwardIntermediate, container, logEmission, numberOfSummands, skipInit, stateList |
Fields inherited from class de.jstacs.sequenceScores.statisticalModels.trainable.hmm.AbstractHMM |
---|
bwdMatrix, emission, emissionIdx, finalState, forward, fwdMatrix, name, sostream, START_NODE, states, threads, trainingParameter, transition |
Fields inherited from class de.jstacs.sequenceScores.statisticalModels.trainable.AbstractTrainableStatisticalModel |
---|
alphabets, length |
Constructor Summary | |
---|---|
SamplingHigherOrderHMM(SamplingHMMTrainingParameterSet trainingParameterSet,
String[] name,
int[] emissionIdx,
boolean[] forward,
SamplingEmission[] emission,
TransitionElement... te)
This is the main constructor. |
|
SamplingHigherOrderHMM(StringBuffer xml)
The standard constructor for the interface Storable . |
Method Summary | |
---|---|
protected void |
acceptParameters()
This method can be used to accept the current parameters (and save them into a file) |
protected void |
appendFurtherInformation(StringBuffer xml)
This method appends further information to the XML representation. |
SamplingHigherOrderHMM |
clone()
Follows the conventions of Object 's clone() -method. |
protected void |
createStates()
This method creates states for the internal usage. |
protected void |
drawFromStatistics()
This method draws all parameters for the current statistics |
protected void |
extractFurtherInformation(StringBuffer xml)
This method extracts further information from the XML representation. |
protected void |
furtherInits(DataSet data,
double[] weights)
This method allows the implementation of further initialisations |
String |
getInstanceName()
Should return a short instance name such as iMM(0), BN(2), ... |
protected double |
getLogPosteriorFromStatistic()
This method calculates the a posteriori probability for the current statistics |
double |
getLogProbForPath(IntList path,
int startPos,
Sequence seq)
|
double[][] |
getLogStatePosteriorMatrixFor(int startPos,
int endPos,
Sequence seq)
This method returns the log state posterior of all states for a sequence. |
protected void |
getNewParameters()
This method set all parameters for the next sampling step |
Pair<IntList,Double> |
getViterbiPath(int startPos,
int endPos,
Sequence seq,
SamplingHigherOrderHMM.ViterbiComputation compute)
This method returns a viterbi path that is the optimum for the choosen ViterbiComputation method |
Pair<IntList,Double> |
getViterbiPathFor(int startPos,
int endPos,
Sequence seq)
|
protected String |
getXMLTag()
Returns the tag for the XML representation. |
protected double |
gibbsSampling(int startPos,
int endPos,
double weight,
Sequence seq)
This method implements a sampling step in the sampling procedure |
protected void |
gibbsSamplingStep(int sampling,
int steps,
boolean append,
DataSet data,
double[] weights)
This method implements the next step(s) in the sampling procedure |
protected void |
initTraining(DataSet data,
double[] weights)
This methods initialize the training procedure with the given training data |
boolean |
isInitialized()
This method can be used to determine whether the instance is initialized. |
protected double |
logProb(int startpos,
int endpos,
Sequence sequence)
This method computes the logarithm of the probability of the corresponding subsequences. |
protected boolean |
parseNextParameterSet()
This method parse a parameter set stored in file during sampling |
protected boolean |
parseParameterSet(int sampling,
int idx)
This method allows the user to parse the set of parameters with index idx of a certain sampling (from a file). |
void |
train(DataSet data,
double[] weights)
Trains the TrainableStatisticalModel object given the data as DataSet using
the specified weights. |
Methods inherited from class de.jstacs.sequenceScores.statisticalModels.trainable.hmm.models.HigherOrderHMM |
---|
baumWelch, createHelperVariables, estimateFromStatistics, fillBwdMatrix, fillBwdOrViterbiMatrix, fillFwdMatrix, fillLogStatePosteriorMatrix, finalize, getCharacteristics, getLogPriorTerm, getLogScoreFor, getLogScoreFor, getMaximalMarkovOrder, getNumericalCharacteristics, initialize, initializeRandomly, resetStatistics, samplePath, viterbi |
Methods inherited from class de.jstacs.sequenceScores.statisticalModels.trainable.hmm.AbstractHMM |
---|
createMatrixForStatePosterior, decodePath, decodeStatePosterior, determineFinalStates, fromXML, getFinalStatePosterioriMatrix, getGraphvizRepresentation, getGraphvizRepresentation, getGraphvizRepresentation, getGraphvizRepresentation, getLogProbFor, getLogStatePosteriorMatrixFor, getNumberOfStates, getNumberOfThreads, getRunTimeException, getStatePosteriorMatrixFor, getStatePosteriorMatrixFor, getViterbiPathFor, getViterbiPathsFor, initTransition, provideMatrix, setOutputStream, toString, toXML, train |
Methods inherited from class de.jstacs.sequenceScores.statisticalModels.trainable.AbstractTrainableStatisticalModel |
---|
check, emitDataSet, getAlphabetContainer, getLength, getLogProbFor, getLogProbFor, getLogScoreFor, getLogScoreFor, getLogScoreFor |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected BurnInTest burnInTest
protected boolean hasSampled
Constructor Detail |
---|
public SamplingHigherOrderHMM(SamplingHMMTrainingParameterSet trainingParameterSet, String[] name, int[] emissionIdx, boolean[] forward, SamplingEmission[] emission, TransitionElement... te) throws Exception
trainingParameterSet
- the ParameterSet
that determines the training algorithm and contains the necessary Parameter
sname
- the names of the statesemissionIdx
- the indices of the emissions that should be used for each stateforward
- a boolean array that indicates whether the symbol on the forward or the reverse complementary strand should be usedemission
- the emissionste
- the TransitionElement
s building a transition
Exception
- if
name, emissionIdx,
or forward
is not equal to the number of statesAlphabetContainer
public SamplingHigherOrderHMM(StringBuffer xml) throws NonParsableException
Storable
.
Constructs an SamplingHigherOrderHMM
out of an XML representation.
xml
- the XML representation as StringBuffer
NonParsableException
- if the SamplingHigherOrderHMM
could not be reconstructed out of
the StringBuffer
xml
Method Detail |
---|
public SamplingHigherOrderHMM clone() throws CloneNotSupportedException
AbstractTrainableStatisticalModel
Object
's clone()
-method.
clone
in interface SequenceScore
clone
in interface TrainableStatisticalModel
clone
in class HigherOrderHMM
AbstractTrainableStatisticalModel
(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
AbstractTrainableStatisticalModel
. 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 cloningprotected void createStates()
AbstractHMM
createStates
in class HigherOrderHMM
protected void acceptParameters() throws IOException
IOException
- if the parameters could not be writtenprotected void drawFromStatistics() throws Exception
Exception
- if the parameters could not be drawnprotected double gibbsSampling(int startPos, int endPos, double weight, Sequence seq) throws Exception
startPos
- the start position in the sequenceendPos
- the end position in the sequenceweight
- the weight for the sequenceseq
- the sequence
Exception
- if the sampling step did not succeedprotected void gibbsSamplingStep(int sampling, int steps, boolean append, DataSet data, double[] weights) throws Exception
sampling
- the index of the samplingsteps
- the number of sampling that should be executedappend
- whether to append the sampled parameters to an existing file
or to overwrite the filedata
- the data used for samplingweights
- the weight for each sequence
Exception
- if something wents wrongprotected void getNewParameters() throws Exception
Exception
- if something went wrongpublic void train(DataSet data, double[] weights) throws Exception
TrainableStatisticalModel
TrainableStatisticalModel
object given the data as DataSet
using
the specified weights. The weight at position i belongs to the element at
position i. So the array weight
should have the number of
sequences in the sample as dimension. (Optionally it is possible to use
weight == null
if all weights have the value one.)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 TrainableStatisticalModel
train
in class HigherOrderHMM
data
- the given sequences as DataSet
weights
- the weights of the elements, each weight should be
non-negative
Exception
- if the training did not succeed (e.g. the dimension of
weights
and the number of sequences in the
sample do not match)DataSet.getElementAt(int)
,
DataSet.ElementEnumerator
public String getInstanceName()
SequenceScore
getInstanceName
in interface SequenceScore
getInstanceName
in class HigherOrderHMM
public boolean isInitialized()
SequenceScore
SequenceScore.getLogScoreFor(Sequence)
.
isInitialized
in interface SequenceScore
isInitialized
in class HigherOrderHMM
true
if the instance is initialized, false
otherwiseprotected double logProb(int startpos, int endpos, Sequence sequence) throws Exception
AbstractHMM
AlphabetContainer
and possible further features
before starting the computation.
logProb
in class AbstractHMM
startpos
- the start position (inclusive)endpos
- the end position (inclusive)sequence
- the Sequence
(s)
Exception
- if the model has no parameters (for instance if it is not trained)protected boolean parseParameterSet(int sampling, int idx) throws Exception
idx
of a certain sampling
(from a file). The
internal numbering should start with 0.
sampling
- the index of the samplingidx
- the index of the parameter set
true
if the parameter set could be parsed
Exception
- if there is a problem with parsing the parametersprotected boolean parseNextParameterSet() throws Exception
Exception
- if the parameters could not be parsedprotected String getXMLTag()
AbstractHMM
getXMLTag
in class HigherOrderHMM
AbstractHMM.fromXML(StringBuffer)
,
AbstractHMM.toXML()
protected void appendFurtherInformation(StringBuffer xml)
AbstractHMM
appendFurtherInformation
in class HigherOrderHMM
xml
- the XML representationprotected void extractFurtherInformation(StringBuffer xml) throws NonParsableException
HigherOrderHMM
extractFurtherInformation
in class HigherOrderHMM
xml
- the XML representation
NonParsableException
- if the information could not be reconstructed out of the StringBuffer
xml
protected void initTraining(DataSet data, double[] weights) throws Exception
data
- the sample used for trainingweights
- the weight for each sequence
Exception
- if the transition or emissions could not be initializedprotected void furtherInits(DataSet data, double[] weights) throws Exception
data
- the current sampleweights
- the weight for each sequence
Exception
- if the init steps did not succeedpublic double[][] getLogStatePosteriorMatrixFor(int startPos, int endPos, Sequence seq) throws Exception
AbstractHMM
getLogStatePosteriorMatrixFor
in class AbstractHMM
startPos
- the start position within the sequenceendPos
- the end position within the sequenceseq
- the sequence
Exception
- if the state posterior could not be computed, for instance if the model is not trained, ...public double getLogProbForPath(IntList path, int startPos, Sequence seq) throws Exception
getLogProbForPath
in class HigherOrderHMM
path
- the given state pathstartPos
- the start position within the sequence(s) (inclusive)seq
- the sequence(s)
Exception
- if the probability for the sequence given path could not be computed, for instance if the model is not trained, ...public Pair<IntList,Double> getViterbiPathFor(int startPos, int endPos, Sequence seq) throws Exception
getViterbiPathFor
in class HigherOrderHMM
startPos
- the start position within the sequenceendPos
- the end position within the sequenceseq
- the sequence
Pair
containing the viterbi state path and the corresponding score
Exception
- if the viterbi path could not be computed, for instance if the model is not trained, ...public Pair<IntList,Double> getViterbiPath(int startPos, int endPos, Sequence seq, SamplingHigherOrderHMM.ViterbiComputation compute) throws Exception
startPos
- the start position in the sequenceendPos
- the end position in the sequenceseq
- the sequencecompute
- the ViterbiComputation method
Exception
- if the parameters could not be parsed from fileprotected double getLogPosteriorFromStatistic()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |