|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectde.jstacs.models.hmm.AbstractHMM
de.jstacs.models.hmm.models.HigherOrderHMM
de.jstacs.models.hmm.models.DifferentiableHigherOrderHMM
public class DifferentiableHigherOrderHMM
This class combines an HigherOrderHMM and a NormalizableScoringFunction by implementing some of the declared methods.
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class de.jstacs.models.hmm.models.HigherOrderHMM |
|---|
HigherOrderHMM.Type |
| Field Summary | |
|---|---|
protected double |
ess
The equivalent sample size used for the prior |
protected double[][][] |
gradient
Help array for the gradient |
protected int[][] |
index
Index array used for computing the gradient |
protected IntList[] |
indicesState
Help array for the indexes of the parameters of the states |
protected IntList[] |
indicesTransition
Help array for the indexes of the parameters of the transition |
protected int |
numberOfParameters
The number of parameters of this HMM |
protected DoubleList[] |
partDerState
Help array for the derivatives of the parameters of the states |
protected DoubleList[] |
partDerTransition
Help array for the derivatives of the parameters of the transition |
protected HigherOrderHMM.Type |
score
The type of the score that is evaluated |
| Fields inherited from class de.jstacs.models.hmm.models.HigherOrderHMM |
|---|
backwardIntermediate, container, logEmission, numberOfSummands, stateList |
| Fields inherited from class de.jstacs.models.hmm.AbstractHMM |
|---|
bwdMatrix, con, emission, emissionIdx, finalState, forward, fwdMatrix, name, sostream, START_NODE, states, trainingParameter, transition |
| Fields inherited from interface de.jstacs.scoringFunctions.ScoringFunction |
|---|
UNKNOWN |
| Constructor Summary | |
|---|---|
DifferentiableHigherOrderHMM(MaxHMMTrainingParameterSet trainingParameterSet,
String[] name,
int[] emissionIdx,
boolean[] forward,
DifferentiableEmission[] emission,
boolean likelihood,
double ess,
TransitionElement... te)
This is the main constructor. |
|
DifferentiableHigherOrderHMM(StringBuffer xml)
The standard constructor for the interface Storable. |
|
| Method Summary | |
|---|---|
void |
addGradientOfLogPriorTerm(double[] grad,
int start)
This method computes the gradient of NormalizableScoringFunction.getLogPriorTerm() for each
parameter of this model. |
protected void |
appendFurtherInformation(StringBuffer xml)
This method appends further information to the XML representation. |
DifferentiableHigherOrderHMM |
clone()
Creates a clone (deep copy) of the current Model instance. |
protected void |
createHelperVariables()
This method instantiates all helper variables that are need inside the model for instance for filling forward and backward matrix, ... |
protected void |
createStates()
This method creates states for the internal usage. |
protected void |
extractFurtherInformation(StringBuffer xml)
This method extracts further information from the XML representation. |
double[] |
getCurrentParameterValues()
Returns a double array of dimension
ScoringFunction.getNumberOfParameters() containing the current parameter values. |
double |
getEss()
Returns the equivalent sample size (ess) of this model, i.e. the equivalent sample size for the class or component that is represented by this model. |
double |
getInitialClassParam(double classProb)
Returns the initial class parameter for the class this ScoringFunction is responsible for, based on the class
probability classProb. |
String |
getInstanceName()
Should return a short instance name such as iMM(0), BN(2), ... |
double |
getLogNormalizationConstant()
Returns the logarithm of the sum of the scores over all sequences of the event space. |
double |
getLogPartialNormalizationConstant(int parameterIndex)
Returns the logarithm of the partial normalization constant for the parameter with index parameterIndex. |
double |
getLogScore(Sequence seq)
Returns the logarithmic score for the Sequence seq. |
double |
getLogScore(Sequence seq,
int start)
Returns the logarithmic score for the Sequence seq
beginning at position start in the Sequence. |
double |
getLogScoreAndPartialDerivation(Sequence seq,
int startPos,
IntList indices,
DoubleList partialDer)
Returns the logarithmic score for a Sequence beginning at
position start in the Sequence and fills lists with
the indices and the partial derivations. |
double |
getLogScoreAndPartialDerivation(Sequence seq,
IntList indices,
DoubleList partialDer)
Returns the logarithmic score for a Sequence seq and
fills lists with the indices and the partial derivations. |
int |
getNumberOfParameters()
Returns the number of parameters in this ScoringFunction. |
int |
getNumberOfRecommendedStarts()
This method returns the number of recommended optimization starts. |
int[][] |
getSamplingGroups(int parameterOffset)
Returns groups of indexes of parameters that shall be drawn together in a sampling procedure |
int |
getSizeOfEventSpaceForRandomVariablesOfParameter(int index)
Returns the size of the event space of the random variables that are affected by parameter no. |
void |
initializeFunction(int index,
boolean freeParams,
Sample[] data,
double[][] weights)
This method creates the underlying structure of the ScoringFunction. |
void |
initializeFunctionRandomly(boolean freeParams)
This method initializes the ScoringFunction randomly. |
boolean |
isInitialized()
This method can be used to determine whether the model is initialized. |
boolean |
isNormalized()
This method indicates whether the implemented score is already normalized to 1 or not. |
void |
setParameters(double[] params,
int start)
This method sets the internal parameters to the values of params between start and
start + |
void |
train(Sample data,
double[] weights)
Trains the Model object given the data as Sample using
the specified weights. |
| Methods inherited from class de.jstacs.models.hmm.models.HigherOrderHMM |
|---|
baumWelch, emitSample, estimateFromStatistics, fillBwdMatrix, fillBwdOrViterbiMatrix, fillFwdMatrix, fillLogStatePosteriorMatrix, finalize, getCharacteristics, getLength, getLogPriorTerm, getLogProbFor, getLogProbFor, getLogProbForPath, getMaximalMarkovOrder, getNumericalCharacteristics, getViterbiPathFor, getXMLTag, initializeRandomly, isTrained, resetStatistics, samplePath, viterbi |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface de.jstacs.scoringFunctions.NormalizableScoringFunction |
|---|
getLogPriorTerm |
| Methods inherited from interface de.jstacs.scoringFunctions.ScoringFunction |
|---|
getAlphabetContainer, getLength |
| Methods inherited from interface de.jstacs.Storable |
|---|
toXML |
| Field Detail |
|---|
protected int numberOfParameters
protected double ess
protected HigherOrderHMM.Type score
protected int[][] index
protected double[][][] gradient
protected IntList[] indicesState
protected IntList[] indicesTransition
protected DoubleList[] partDerState
protected DoubleList[] partDerTransition
| Constructor Detail |
|---|
public DifferentiableHigherOrderHMM(MaxHMMTrainingParameterSet trainingParameterSet,
String[] name,
int[] emissionIdx,
boolean[] forward,
DifferentiableEmission[] emission,
boolean likelihood,
double ess,
TransitionElement... te)
throws Exception
trainingParameterSet - the ParameterSet that determines the training algorithm and contains the necessary Parametersname - the names of the statesemissionIdx - the indices of the emissions that should be used for each state, if null state i will use emission iforward - a boolean array that indicates whether the symbol on the forward or the reverse complementary strand should be used,
if null all states use the forward strandemission - the emissionslikelihood - if true the likelihood is return by getLogScore(Sequence) otherwise the viterbi scoreess - the ess of the modelte - the TransitionElements used for creating a Transition
Exception - if
name, emissionIdx, or forward is not equal to the number of statesAlphabetContainer
public DifferentiableHigherOrderHMM(StringBuffer xml)
throws NonParsableException
Storable.
Constructs an DifferentiableHigherOrderHMM out of an XML representation.
xml - the XML representation as StringBuffer
NonParsableException - if the DifferentiableHigherOrderHMM could not be reconstructed out of
the StringBuffer xml| Method Detail |
|---|
protected void appendFurtherInformation(StringBuffer xml)
AbstractHMM
appendFurtherInformation in class HigherOrderHMMxml - the XML representation
protected void extractFurtherInformation(StringBuffer xml)
throws NonParsableException
HigherOrderHMM
extractFurtherInformation in class HigherOrderHMMxml - the XML representation
NonParsableException - if the information could not be reconstructed out of the StringBuffer xmlprotected void createHelperVariables()
AbstractHMM
createHelperVariables in class HigherOrderHMMprotected void createStates()
AbstractHMM
createStates in class HigherOrderHMM
public DifferentiableHigherOrderHMM clone()
throws CloneNotSupportedException
ModelModel instance.
clone in interface Modelclone in interface ScoringFunctionclone in class HigherOrderHMMCloneNotSupportedException - if something went wrong while cloningpublic double getEss()
NormalizableScoringFunction
getEss in interface NormalizableScoringFunction
public void addGradientOfLogPriorTerm(double[] grad,
int start)
throws Exception
NormalizableScoringFunctionNormalizableScoringFunction.getLogPriorTerm() for each
parameter of this model. The results are added to the array
grad beginning at index start.
addGradientOfLogPriorTerm in interface NormalizableScoringFunctiongrad - the array of gradientsstart - the start index in the grad array, where the
partial derivations for the parameters of this models shall be
entered
Exception - if something went wrong with the computing of the gradientsNormalizableScoringFunction.getLogPriorTerm()public int getNumberOfParameters()
ScoringFunctionScoringFunction. If the
number of parameters is not known yet, the method returns
ScoringFunction.UNKNOWN.
getNumberOfParameters in interface ScoringFunctionScoringFunctionScoringFunction.UNKNOWNpublic int getNumberOfRecommendedStarts()
ScoringFunction
getNumberOfRecommendedStarts in interface ScoringFunction
public double[] getCurrentParameterValues()
throws Exception
ScoringFunctiondouble array of dimension
ScoringFunction.getNumberOfParameters() containing the current parameter values.
If one likes to use these parameters to start an optimization it is
highly recommended to invoke
ScoringFunction.initializeFunction(int, boolean, Sample[], double[][]) before.
After an optimization this method can be used to get the current
parameter values.
getCurrentParameterValues in interface ScoringFunctionException - if no parameters exist (yet)public boolean isInitialized()
ScoringFunctionScoringFunction.initializeFunction(int, boolean, Sample[], double[][]).
isInitialized in interface ScoringFunctiontrue if the model is initialized, false
otherwise
public void setParameters(double[] params,
int start)
ScoringFunctionparams between start and
start + ScoringFunction.getNumberOfParameters() - 1
setParameters in interface ScoringFunctionparams - the new parametersstart - the start index in params
public void initializeFunctionRandomly(boolean freeParams)
throws Exception
ScoringFunctionScoringFunction randomly. It has to
create the underlying structure of the ScoringFunction.
initializeFunctionRandomly in interface ScoringFunctionfreeParams - indicates whether the (reduced) parameterization is used
Exception - if something went wrong
public void initializeFunction(int index,
boolean freeParams,
Sample[] data,
double[][] weights)
throws Exception
ScoringFunctionScoringFunction.
initializeFunction in interface ScoringFunctionindex - the index of the class the ScoringFunction modelsfreeParams - indicates whether the (reduced) parameterization is useddata - the samplesweights - the weights of the sequences in the samples
Exception - if something went wrong
public void train(Sample data,
double[] weights)
throws Exception
ModelModel object given the data as Sample 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 Modeltrain in class HigherOrderHMMdata - the given sequences as Sampleweights - 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)Sample.getElementAt(int),
Sample.ElementEnumeratorpublic boolean isNormalized()
NormalizableScoringFunctionfalse.
isNormalized in interface NormalizableScoringFunctiontrue if the implemented score is already normalized
to 1, false otherwisepublic double getLogNormalizationConstant()
NormalizableScoringFunction
getLogNormalizationConstant in interface NormalizableScoringFunction
public double getLogPartialNormalizationConstant(int parameterIndex)
throws Exception
NormalizableScoringFunctionparameterIndex. This is the logarithm of the partial derivation of the
normalization constant for the parameter with index
parameterIndex,
![\[\log \frac{\partial Z(\underline{\lambda})}{\partial \lambda_{parameterindex}}\]](images/NormalizableScoringFunction_LaTeXilb8_1.png)
getLogPartialNormalizationConstant in interface NormalizableScoringFunctionparameterIndex - the index of the parameter
Exception - if something went wrong with the normalizationNormalizableScoringFunction.getLogNormalizationConstant()public double getInitialClassParam(double classProb)
ScoringFunctionScoringFunction is responsible for, based on the class
probability classProb.
getInitialClassParam in interface NormalizableScoringFunctiongetInitialClassParam in interface ScoringFunctionclassProb - the class probability
public double getLogScore(Sequence seq)
ScoringFunctionSequence seq.
getLogScore in interface ScoringFunctionseq - the sequence
public double getLogScore(Sequence seq,
int start)
ScoringFunctionSequence seq
beginning at position start in the Sequence.
getLogScore in interface ScoringFunctionseq - the Sequencestart - the start position in the Sequence
Sequence
public double getLogScoreAndPartialDerivation(Sequence seq,
IntList indices,
DoubleList partialDer)
ScoringFunctionSequence seq and
fills lists with the indices and the partial derivations.
getLogScoreAndPartialDerivation in interface ScoringFunctionseq - the Sequenceindices - an IntList of indices, after method invocation the
list should contain the indices i where
is not zeropartialDer - a DoubleList of partial derivations, after method
invocation the list should contain the corresponding
that are not zero
Sequence
public double getLogScoreAndPartialDerivation(Sequence seq,
int startPos,
IntList indices,
DoubleList partialDer)
ScoringFunctionSequence beginning at
position start in the Sequence and fills lists with
the indices and the partial derivations.
getLogScoreAndPartialDerivation in interface ScoringFunctionseq - the SequencestartPos - the start position in the Sequenceindices - an IntList of indices, after method invocation the
list should contain the indices i where
is not zeropartialDer - a DoubleList of partial derivations, after method
invocation the list should contain the corresponding
that are not zero
Sequencepublic int getSizeOfEventSpaceForRandomVariablesOfParameter(int index)
NormalizableScoringFunctionindex, i.e. the product of the
sizes of the alphabets at the position of each random variable affected
by parameter index. For DNA alphabets this corresponds to 4
for a PWM, 16 for a WAM except position 0, ...
getSizeOfEventSpaceForRandomVariablesOfParameter in interface NormalizableScoringFunctionindex - the index of the parameter
public int[][] getSamplingGroups(int parameterOffset)
SamplingScoringFunction
getSamplingGroups in interface SamplingScoringFunctionparameterOffset - a global offset on the parameter indexes
parameterOffset.public String getInstanceName()
Model
getInstanceName in interface ModelgetInstanceName in interface ScoringFunctiongetInstanceName in class HigherOrderHMM
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||