|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectde.jstacs.models.hmm.transitions.BasicHigherOrderTransition
de.jstacs.models.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.models.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.models.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 java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface de.jstacs.models.hmm.transitions.TransitionWithSufficientStatistic |
|---|
addToStatistic, getLogGammaScoreFromStatistic, resetStatistic |
| Methods inherited from interface de.jstacs.models.hmm.Transition |
|---|
fillTransitionInformation, getChildIdx, getGraphizNetworkRepresentation, getLastContextState, getLogPriorTerm, getLogScoreFor, getMaximalInDegree, getMaximalMarkovOrder, getMaximalNumberOfChildren, getNumberOfChildren, getNumberOfIndexes, getNumberOfStates, hasAnySelfTransitions, initializeRandomly, isAbsoring, 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 TransitionElements for the internal useisSilent - an array indicating for each state whether it is silent or not
Exception - if an error occurs during checking the TransitionElements and creating internal fields
public 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 BasicHigherOrderTransitionprotected void appendFurtherInformation(StringBuffer xml)
BasicHigherOrderTransition
appendFurtherInformation in class BasicHigherOrderTransitionxml - the XML representation
protected void extractFurtherInformation(StringBuffer xml)
throws NonParsableException
BasicHigherOrderTransition
extractFurtherInformation in class BasicHigherOrderTransitionxml - 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 Transitionclone in class BasicHigherOrderTransitionCloneNotSupportedException - if the instance could not be clonedpublic void fillParameters(double[] params)
DifferentiableTransition
fillParameters in interface DifferentiableTransitionparams - the parameters
protected 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 DifferentiableTransitionoffset - the offset
protected int setParameterOffset()
TransitionElement.
setParameterOffset(int),
TransitionElement.setParameterOffset(int)
public void setParameters(double[] params,
int start)
DifferentiableTransition
setParameters in interface DifferentiableTransitionparams - the parametersstart - the (global) start position
protected 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
entered
public double getLogScoreAndPartialDerivation(int layer,
int index,
int childIdx,
IntList indices,
DoubleList partDer,
Sequence sequence,
int sequencePosition)
DifferentiableTransition
getLogScoreAndPartialDerivation 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 sequence
Transition.getLogScoreFor(int, int, int, Sequence, int)
public void initForSampling(int starts)
throws IOException
SamplingComponent
initForSampling in interface SamplingComponentstarts - 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 ObjectThrowable
public void extendSampling(int sampling,
boolean append)
throws IOException
SamplingComponent
extendSampling in interface SamplingComponentsampling - 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()
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()
SamplingComponent
parseNextParameterSet 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++ )
{
while( b )
{
//do something
b = parseNextParameterSet();
}
parseParameterSet in interface SamplingComponentsampling - the index of the samplingn - the index of the parameter set
true if the parameter set could be parsed
IOExceptionSamplingComponent.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
SamplingComponent
acceptParameters in interface SamplingComponentIOException - if the file could not be handled correctlypublic double getLogPosteriorFromStatistic()
SamplingFromStatistic
getLogPosteriorFromStatistic in interface SamplingFromStatisticpublic int getSizeOfEventSpace(int index)
DifferentiableTransitionindex
getSizeOfEventSpace in interface DifferentiableTransitionindex - the index of the parameter
public 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 parameterOffset
fillSamplingGroups in interface DifferentiableTransitionparameterOffset - the external parameter offsetlist - the list of sampling groups
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||