public class HigherOrderTransition extends BasicHigherOrderTransition implements DifferentiableTransition, SamplingTransition
AbstractHMM allowing to use gradient based or sampling training algorithm.BasicHigherOrderTransition.AbstractTransitionElement| Modifier and Type | Field and Description |
|---|---|
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. |
isSilent, lookup, maximalMarkovOrder, maxInDegree, transitions| Constructor and Description |
|---|
HigherOrderTransition(boolean[] isSilent,
TransitionElement... transitions)
The main constructor.
|
HigherOrderTransition(StringBuffer xml)
The standard constructor for the interface
Storable. |
| Modifier and Type | Method and Description |
|---|---|
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 |
TransitionElement[] |
getTransisionElements()
Returns a clone of the internal transition elements.
|
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.
|
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, toXMLequals, getClass, hashCode, notify, notifyAll, wait, wait, waitaddToStatistic, getLogGammaScoreFromStatistic, joinStatistics, resetStatisticfillTransitionInformation, getChildIdx, getGraphizNetworkRepresentation, getLastContextState, getLogPriorTerm, getLogScoreFor, getMaximalInDegree, getMaximalMarkovOrder, getMaximalNumberOfChildren, getNumberOfChildren, getNumberOfIndexes, getNumberOfStates, hasAnySelfTransitions, initializeRandomly, isAbsoring, setParameters, toStringdrawParametersFromStatisticprotected File[] paramsFile
protected int[] counter
protected int samplingIndex
protected BufferedWriter writer
paramsFile in a sampling.protected BufferedReader reader
paramsFile after a sampling.public HigherOrderTransition(boolean[] isSilent,
TransitionElement... transitions)
throws Exception
transitions - the TransitionElements for the internal useisSilent - an array indicating for each state whether it is silent or notException - if an error occurs during checking the TransitionElements and creating internal fieldspublic HigherOrderTransition(StringBuffer xml) throws NonParsableException
Storable.
Constructs a HigherOrderTransition out of an XML representation.xml - the XML representation as StringBufferNonParsableException - if the HigherOrderTransition could not be reconstructed out of
the StringBuffer xmlprotected String getXMLTag()
BasicHigherOrderTransitiongetXMLTag in class BasicHigherOrderTransitionprotected void appendFurtherInformation(StringBuffer xml)
BasicHigherOrderTransitionappendFurtherInformation in class BasicHigherOrderTransitionxml - the XML representationprotected void extractFurtherInformation(StringBuffer xml) throws NonParsableException
BasicHigherOrderTransitionextractFurtherInformation in class BasicHigherOrderTransitionxml - the XML representationNonParsableException - if the information could not be reconstructed out of the StringBuffer xmlpublic HigherOrderTransition clone() throws CloneNotSupportedException
Transitionclone in interface Transitionclone in class BasicHigherOrderTransitionCloneNotSupportedException - if the instance could not be clonedpublic void fillParameters(double[] params)
DifferentiableTransitionfillParameters in interface DifferentiableTransitionparams - 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)
DifferentiableTransitionsetParameterOffset in interface DifferentiableTransitionoffset - the offsetprotected int setParameterOffset()
TransitionElement.setParameterOffset(int),
TransitionElement.setParameterOffset(int)public void setParameters(double[] params,
int start)
DifferentiableTransitionsetParameters in interface DifferentiableTransitionparams - 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)
DifferentiableTransitionTransition.getLogPriorTerm() for each
parameter of this transition. The results are added to the array
gradient beginning at index start.addGradientForLogPriorTerm in interface DifferentiableTransitiongradient - 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)
DifferentiableTransitiongetLogScoreAndPartialDerivation in interface DifferentiableTransitionlayer - 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 sequenceTransition.getLogScoreFor(int, int, int, Sequence, int)public void initForSampling(int starts)
throws IOException
SamplingComponentinitForSampling in interface SamplingComponentstarts - the number of different sampling starts that will be doneIOException - if something went wrongFile.createTempFile(String, String, java.io.File )protected void finalize()
throws Throwable
public void extendSampling(int sampling,
boolean append)
throws IOException
SamplingComponentextendSampling in interface SamplingComponentsampling - the index of the samplingappend - whether to append the sampled parameters to an existing file
or to overwrite the fileIOException - if the file could not be handled correctlypublic boolean isInSamplingMode()
SamplingComponenttrue if the object is currently used in
a sampling, otherwise false.isInSamplingMode in interface SamplingComponenttrue if the object is currently used in a sampling,
otherwise falsepublic boolean parseNextParameterSet()
SamplingComponentparseNextParameterSet in interface SamplingComponenttrue if the parameters could be parsed, otherwise
falseSamplingComponent.parseParameterSet(int, int)public boolean parseParameterSet(int sampling,
int n)
throws IOException
SamplingComponentn 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 SamplingComponentsampling - the index of the samplingn - the index of the parameter settrue if the parameter set could be parsedIOExceptionSamplingComponent.parseNextParameterSet()public void samplingStopped()
throws IOException
SamplingComponentSamplingComponent.extendSampling(int, boolean). It can be
used for closing any streams of writer, ...samplingStopped in interface SamplingComponentIOException - if something went wrongSamplingComponent.extendSampling(int, boolean)public void acceptParameters()
throws IOException
SamplingComponentacceptParameters in interface SamplingComponentIOException - if the file could not be handled correctlypublic double getLogPosteriorFromStatistic()
SamplingFromStatisticgetLogPosteriorFromStatistic in interface SamplingFromStatisticpublic int getSizeOfEventSpace(int index)
DifferentiableTransitionindexgetSizeOfEventSpace in interface DifferentiableTransitionindex - the index of the parameterpublic void fillSamplingGroups(int parameterOffset,
LinkedList<int[]> list)
DifferentiableTransitionint[], 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 parameterOffsetfillSamplingGroups in interface DifferentiableTransitionparameterOffset - the external parameter offsetlist - the list of sampling groupspublic TransitionElement[] getTransisionElements() throws CloneNotSupportedException
CloneNotSupportedException - if the transition elements could not be cloned