|
||||||||||
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.hmm.transitions.BasicHigherOrderTransition
de.jstacs.sequenceScores.statisticalModels.trainable.hmm.transitions.HigherOrderTransition
public class HigherOrderTransition
This class can be used in any AbstractHMM
allowing to use gradient based or sampling training algorithm.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class de.jstacs.sequenceScores.statisticalModels.trainable.hmm.transitions.BasicHigherOrderTransition |
---|
BasicHigherOrderTransition.AbstractTransitionElement |
Field Summary | |
---|---|
protected int[] |
counter
The counter for the sampling steps of each sampling. |
protected File[] |
paramsFile
The files for saving the parameters during the sampling. |
protected BufferedReader |
reader
The reader for the paramsFile after a sampling. |
protected int |
samplingIndex
The index of the current sampling. |
protected BufferedWriter |
writer
The writer for the paramsFile in a sampling. |
Fields inherited from class de.jstacs.sequenceScores.statisticalModels.trainable.hmm.transitions.BasicHigherOrderTransition |
---|
isSilent, lookup, maximalMarkovOrder, maxInDegree, transitions |
Constructor Summary | |
---|---|
HigherOrderTransition(boolean[] isSilent,
TransitionElement... transitions)
The main constructor. |
|
HigherOrderTransition(StringBuffer xml)
The standard constructor for the interface Storable . |
Method Summary | |
---|---|
void |
acceptParameters()
This methods accepts the drawn parameters. |
void |
addGradientForLogPriorTerm(double[] gradient,
int start)
This method computes the gradient of Transition.getLogPriorTerm() for each
parameter of this transition. |
protected void |
appendFurtherInformation(StringBuffer xml)
This method appends further information to the XML representation. |
HigherOrderTransition |
clone()
This method returns a deep clone of the current instance. |
void |
extendSampling(int sampling,
boolean append)
This method allows to extend a sampling. |
protected void |
extractFurtherInformation(StringBuffer xml)
This method extracts further information from the XML representation. |
void |
fillParameters(double[] params)
This method allows to fill the parameters of the transition in a given array. |
protected void |
fillParameters(double[] params,
int offset)
This method allows to fill the current parameters using a specific offset. |
void |
fillSamplingGroups(int parameterOffset,
LinkedList<int[]> list)
Adds the groups of indexes of those parameters of this transition that should be sampled together in one step of a grouped sampling procedure, each as an int[] , into list . |
protected void |
finalize()
|
double |
getLogPosteriorFromStatistic()
This method calculates the a-posteriori probability for the current statistics |
double |
getLogScoreAndPartialDerivation(int layer,
int index,
int childIdx,
IntList indices,
DoubleList partDer,
Sequence sequence,
int sequencePosition)
This method allows to compute the logarithm of the score and the gradient for a specific transition. |
int |
getSizeOfEventSpace(int index)
Returns the size of the event space, i.e., the number of possible outcomes, for the random variable of parameter index |
protected String |
getXMLTag()
The method returns the XML tag used during saving and loading the transition. |
void |
initForSampling(int starts)
This method initializes the instance for the sampling. |
boolean |
isInSamplingMode()
This method returns true if the object is currently used in
a sampling, otherwise false . |
boolean |
parseNextParameterSet()
This method allows the user to parse the next set of parameters (from a file). |
boolean |
parseParameterSet(int sampling,
int n)
This method allows the user to parse the set of parameters with index n of a certain sampling (from a file). |
void |
samplingStopped()
This method is the opposite of the method SamplingComponent.extendSampling(int, boolean) . |
protected int |
setParameterOffset()
This method allows to set the parameter offset in each internally used TransitionElement . |
int |
setParameterOffset(int offset)
This method sets the internal offset of the parameter index. |
void |
setParameters(double[] params,
int start)
This method allows to set the parameters of the transition. |
protected void |
setParams(double[] params,
int start)
This method allows to set the new parameters using a specific offset. |
Methods inherited from class de.jstacs.sequenceScores.statisticalModels.trainable.hmm.transitions.BasicHigherOrderTransition |
---|
addToStatistic, drawParametersFromStatistic, estimateFromStatistic, fillTransitionInformation, getChildIdx, getGraphizNetworkRepresentation, getLastContextState, getLogGammaScoreFromStatistic, getLogPriorTerm, getLogScoreFor, getMaximalInDegree, getMaximalMarkovOrder, getMaximalNumberOfChildren, getNumberOfChildren, getNumberOfIndexes, getNumberOfStates, getTransitionElementIndex, hasAnySelfTransitions, initializeRandomly, isAbsoring, joinStatistics, resetStatistic, setParameters, toString, toString, toXML |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface de.jstacs.sequenceScores.statisticalModels.trainable.hmm.transitions.TransitionWithSufficientStatistic |
---|
addToStatistic, getLogGammaScoreFromStatistic, joinStatistics, resetStatistic |
Methods inherited from interface de.jstacs.sequenceScores.statisticalModels.trainable.hmm.transitions.Transition |
---|
fillTransitionInformation, getChildIdx, getGraphizNetworkRepresentation, getLastContextState, getLogPriorTerm, getLogScoreFor, getMaximalInDegree, getMaximalMarkovOrder, getMaximalNumberOfChildren, getNumberOfChildren, getNumberOfIndexes, getNumberOfStates, hasAnySelfTransitions, initializeRandomly, isAbsoring, setParameters, toString |
Methods inherited from interface de.jstacs.Storable |
---|
toXML |
Methods inherited from interface de.jstacs.sampling.SamplingFromStatistic |
---|
drawParametersFromStatistic |
Field Detail |
---|
protected File[] paramsFile
protected int[] counter
protected int samplingIndex
protected BufferedWriter writer
paramsFile
in a sampling.
protected BufferedReader reader
paramsFile
after a sampling.
Constructor Detail |
---|
public HigherOrderTransition(boolean[] isSilent, TransitionElement... transitions) throws Exception
transitions
- the TransitionElement
s for the internal useisSilent
- an array indicating for each state whether it is silent or not
Exception
- if an error occurs during checking the TransitionElement
s and creating internal fieldspublic HigherOrderTransition(StringBuffer xml) throws NonParsableException
Storable
.
Constructs a HigherOrderTransition
out of an XML representation.
xml
- the XML representation as StringBuffer
NonParsableException
- if the HigherOrderTransition
could not be reconstructed out of
the StringBuffer
xml
Method Detail |
---|
protected String getXMLTag()
BasicHigherOrderTransition
getXMLTag
in class BasicHigherOrderTransition
protected void appendFurtherInformation(StringBuffer xml)
BasicHigherOrderTransition
appendFurtherInformation
in class BasicHigherOrderTransition
xml
- the XML representationprotected void extractFurtherInformation(StringBuffer xml) throws NonParsableException
BasicHigherOrderTransition
extractFurtherInformation
in class BasicHigherOrderTransition
xml
- the XML representation
NonParsableException
- if the information could not be reconstructed out of the StringBuffer
xml
public HigherOrderTransition clone() throws CloneNotSupportedException
Transition
clone
in interface Transition
clone
in class BasicHigherOrderTransition
CloneNotSupportedException
- if the instance could not be clonedpublic void fillParameters(double[] params)
DifferentiableTransition
fillParameters
in interface DifferentiableTransition
params
- the parametersprotected void fillParameters(double[] params, int offset)
params
- the parametersoffset
- the offset indicating the start positionfillParameters(double[])
,
TransitionElement.fillParameters(double[], int)
public int setParameterOffset(int offset)
DifferentiableTransition
setParameterOffset
in interface DifferentiableTransition
offset
- the offset
protected int setParameterOffset()
TransitionElement
.
setParameterOffset(int)
,
TransitionElement.setParameterOffset(int)
public void setParameters(double[] params, int start)
DifferentiableTransition
setParameters
in interface DifferentiableTransition
params
- the parametersstart
- the (global) start positionprotected void setParams(double[] params, int start)
params
- the parametersstart
- the offset indicating the start positionsetParameters(double[], int)
,
TransitionElement.setParameters(double[], int)
public void addGradientForLogPriorTerm(double[] gradient, int start)
DifferentiableTransition
Transition.getLogPriorTerm()
for each
parameter of this transition. The results are added to the array
gradient
beginning at index start
.
addGradientForLogPriorTerm
in interface DifferentiableTransition
gradient
- the array of gradientsstart
- the start index in the gradient
array, where the
partial derivations for the parameters of this Transition
shall be
enteredpublic double getLogScoreAndPartialDerivation(int layer, int index, int childIdx, IntList indices, DoubleList partDer, Sequence sequence, int sequencePosition)
DifferentiableTransition
getLogScoreAndPartialDerivation
in interface DifferentiableTransition
layer
- the layer of the matrixindex
- the index encoding the contextchildIdx
- the index of the childindices
- a list for the parameter indicespartDer
- a list for the partial derivationssequence
- the sequencesequencePosition
- the position within the sequence
Transition.getLogScoreFor(int, int, int, Sequence, int)
public void initForSampling(int starts) throws IOException
SamplingComponent
initForSampling
in interface SamplingComponent
starts
- the number of different sampling starts that will be done
IOException
- if something went wrongFile.createTempFile(String, String, java.io.File )
protected void finalize() throws Throwable
finalize
in class Object
Throwable
public void extendSampling(int sampling, boolean append) throws IOException
SamplingComponent
extendSampling
in interface SamplingComponent
sampling
- the index of the samplingappend
- whether to append the sampled parameters to an existing file
or to overwrite the file
IOException
- if the file could not be handled correctlypublic boolean isInSamplingMode()
SamplingComponent
true
if the object is currently used in
a sampling, otherwise false
.
isInSamplingMode
in interface SamplingComponent
true
if the object is currently used in a sampling,
otherwise false
public boolean parseNextParameterSet()
SamplingComponent
parseNextParameterSet
in interface SamplingComponent
true
if the parameters could be parsed, otherwise
false
SamplingComponent.parseParameterSet(int, int)
public boolean parseParameterSet(int sampling, int n) throws IOException
SamplingComponent
n
of a certain sampling
(from a file). The
internal numbering should start with 0. The parameter set with index 0 is
the initial (random) parameter set. It is recommended that a series of
parameter sets is accessed by the following lines:
for( sampling = 0; sampling < numSampling; sampling++ )
{
boolean b = parseParameterSet( sampling, n );
while( b )
{
//do something
b = parseNextParameterSet();
}
}
parseParameterSet
in interface SamplingComponent
sampling
- the index of the samplingn
- the index of the parameter set
true
if the parameter set could be parsed
IOException
SamplingComponent.parseNextParameterSet()
public void samplingStopped() throws IOException
SamplingComponent
SamplingComponent.extendSampling(int, boolean)
. It can be
used for closing any streams of writer, ...
samplingStopped
in interface SamplingComponent
IOException
- if something went wrongSamplingComponent.extendSampling(int, boolean)
public void acceptParameters() throws IOException
SamplingComponent
acceptParameters
in interface SamplingComponent
IOException
- if the file could not be handled correctlypublic double getLogPosteriorFromStatistic()
SamplingFromStatistic
getLogPosteriorFromStatistic
in interface SamplingFromStatistic
public int getSizeOfEventSpace(int index)
DifferentiableTransition
index
getSizeOfEventSpace
in interface DifferentiableTransition
index
- the index of the parameter
public void fillSamplingGroups(int parameterOffset, LinkedList<int[]> list)
DifferentiableTransition
int[]
, into list
.
In most cases, one group should contain the
parameters that are living on a common simplex, e.g. the parameters of one TransitionElement
of this transition. The internal indexes of the parameters are incremeneted by an external parameterOffset
fillSamplingGroups
in interface DifferentiableTransition
parameterOffset
- the external parameter offsetlist
- the list of sampling groups
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |