public class BasicHigherOrderTransition extends Object implements TrainableTransition
| Modifier and Type | Class and Description |
|---|---|
static class |
BasicHigherOrderTransition.AbstractTransitionElement
This class declares the probability distribution for a given context, i.e.
|
| Modifier and Type | Field and Description |
|---|---|
protected boolean[] |
isSilent
A vector indicating for each state whether it is silent or not.
|
protected int[][][] |
lookup
The lookup table for spare context en- and decoding.
|
protected int |
maximalMarkovOrder
The maximal Markov order of the transition.
|
protected int |
maxInDegree
The maximal in-degree of any state.
|
protected BasicHigherOrderTransition.AbstractTransitionElement[] |
transitions
The internally used
BasicHigherOrderTransition.AbstractTransitionElements. |
| Constructor and Description |
|---|
BasicHigherOrderTransition(boolean[] isSilent,
BasicHigherOrderTransition.AbstractTransitionElement... transitions)
The main constructor.
|
BasicHigherOrderTransition(StringBuffer xml)
The standard constructor for the interface
Storable. |
| Modifier and Type | Method and Description |
|---|---|
void |
addToStatistic(int layer,
int index,
int childIdx,
double weight,
Sequence sequence,
int sequencePosition)
This method allows to add a certain
weight to the sufficient statistic of a specific transition. |
protected void |
appendFurtherInformation(StringBuffer xml)
This method appends further information to the XML representation.
|
BasicHigherOrderTransition |
clone()
This method returns a deep clone of the current instance.
|
void |
drawParametersFromStatistic()
This method allows to draw parameters from the sufficient statistic, i.e., to draw from the posterior.
|
void |
estimateFromStatistic()
This method estimates the parameter of the transition using the internal sufficient statistic.
|
protected void |
extractFurtherInformation(StringBuffer xml)
This method extracts further information from the XML representation.
|
void |
fillTransitionInformation(int layer,
int index,
int childIdx,
int[] container)
This method fills all relevant information for a specific edge in a given container.
|
int |
getChildIdx(int layer,
int index,
int state)
This method returns the child index of the state, if this state is no child of the context -1 is returned
|
String |
getGraphizNetworkRepresentation(NumberFormat nf,
String arrowOption,
boolean graphical)
This method returns a
String representation of the structure that
can be used in Graphviz to create an image. |
int |
getLastContextState(int layer,
int index)
The method returns the index of the state of the context, if there is no context -1 is returned.
|
double |
getLogGammaScoreFromStatistic()
This method calculates a score for the current statistics, which is independent from the current parameters
In general the gamma-score is a product of gamma-functions parameterized with the current statistics
|
double |
getLogPriorTerm()
Returns a value that is proportional to the log of the prior.
|
double |
getLogScoreFor(int layer,
int index,
int childIdx,
Sequence sequence,
int sequencePosition)
This method returns the logarithm of the score for the transition.
|
int |
getMaximalInDegree()
This method returns the maximal out degree of any context used in this transition instance.
|
int |
getMaximalMarkovOrder()
This method returns the maximal used Markov order.
|
int |
getMaximalNumberOfChildren()
This method returns the maximal number of children for any context used in this transition instance.
|
int |
getNumberOfChildren(int layer,
int index)
This method returns the number of children states for given index, i.e.
|
int |
getNumberOfIndexes(int layer)
This method computes the number of different indexes for a given layer of the matrix.
|
int |
getNumberOfStates()
This method returns the number of states underlying this transition
instance.
|
protected int |
getTransitionElementIndex(int layer,
int index)
This method return the index of the
BasicHigherOrderTransition.AbstractTransitionElement using the lookup table. |
protected String |
getXMLTag()
The method returns the XML tag used during saving and loading the transition.
|
boolean |
hasAnySelfTransitions()
This method answers the question whether the instance models any self
transitions.
|
void |
initializeRandomly()
This method randomly initializes the parameters of the transition.
|
boolean[] |
isAbsoring()
This method returns for each state whether it is absorbing or not.
|
void |
joinStatistics(Transition... transitions)
This method joins the statistics of different instances and sets this joined statistic as statistic of each instance.
|
void |
resetStatistic()
This method reset the internal sufficient statistics that can be used for estimating the parameters.
|
void |
setParameters(Transition t)
Set values of parameters of the instance to the value of the parameters of the given instance.
|
String |
toString() |
String |
toString(String[] stateNames,
NumberFormat nf)
This method returns a
String representation of the Transition using the given names of the states. |
StringBuffer |
toXML()
This method returns an XML representation as
StringBuffer of an
instance of the implementing class. |
protected BasicHigherOrderTransition.AbstractTransitionElement[] transitions
BasicHigherOrderTransition.AbstractTransitionElements.protected boolean[] isSilent
protected int maximalMarkovOrder
protected int maxInDegree
protected int[][][] lookup
public BasicHigherOrderTransition(boolean[] isSilent,
BasicHigherOrderTransition.AbstractTransitionElement... transitions)
throws Exception
transitions - the BasicHigherOrderTransition.AbstractTransitionElements for the internal useisSilent - an array indicating for each state whether it is silent or notException - if an error occurs during checking the BasicHigherOrderTransition.AbstractTransitionElements and creating internal fieldspublic BasicHigherOrderTransition(StringBuffer xml) throws NonParsableException
Storable.
Constructs a BasicHigherOrderTransition out of an XML representation.xml - the XML representation as StringBufferNonParsableException - if the BasicHigherOrderTransition could not be reconstructed out of
the StringBuffer xmlpublic StringBuffer toXML()
StorableStringBuffer of an
instance of the implementing class.protected String getXMLTag()
protected void appendFurtherInformation(StringBuffer xml)
xml - the XML representationprotected void extractFurtherInformation(StringBuffer xml) throws NonParsableException
xml - the XML representationNonParsableException - if the information could not be reconstructed out of the StringBuffer xmlpublic BasicHigherOrderTransition clone() throws CloneNotSupportedException
Transitionclone in interface Transitionclone in class ObjectCloneNotSupportedException - if the instance could not be clonedpublic void resetStatistic()
TransitionWithSufficientStatisticresetStatistic in interface TransitionWithSufficientStatisticpublic void joinStatistics(Transition... transitions)
TransitionWithSufficientStatisticjoinStatistics in interface TransitionWithSufficientStatistictransitions - the transitions to be joinedpublic void addToStatistic(int layer,
int index,
int childIdx,
double weight,
Sequence sequence,
int sequencePosition)
TransitionWithSufficientStatisticweight to the sufficient statistic of a specific transition.addToStatistic in interface TransitionWithSufficientStatisticlayer - the layer of the matrixindex - the index encoding the contextchildIdx - the index of the childweight - the weight added to the sufficient statisticsequence - the sequencesequencePosition - the position within the sequencepublic void estimateFromStatistic()
TrainableTransitionestimateFromStatistic in interface TrainableTransitionpublic void drawParametersFromStatistic()
throws Exception
addToStatistic(int, int, int, double, Sequence, int), the method draws from the prior.Exception - if for instance the prior has some illegal hyper-parameters (e.g. 0)BasicHigherOrderTransition.AbstractTransitionElement.drawParametersFromStatistic()public int getMaximalMarkovOrder()
TransitiongetMaximalMarkovOrder in interface Transitionpublic double getLogPriorTerm()
TransitiongetLogPriorTerm in interface TransitionStatisticalModel.getLogPriorTerm()public int getNumberOfStates()
TransitiongetNumberOfStates in interface Transitionpublic void initializeRandomly()
TransitioninitializeRandomly in interface Transitionpublic String getGraphizNetworkRepresentation(NumberFormat nf, String arrowOption, boolean graphical)
TransitionString representation of the structure that
can be used in Graphviz to create an image.getGraphizNetworkRepresentation in interface Transitionnf - the NumberFormat used for the probabilities, if
null no probabilities will we writtenarrowOption - this parameter gives the possibility to set some arrow optiongraphical - represent transition probabilities as thickness of edges
instead of textual outputString representation of the statepublic void fillTransitionInformation(int layer,
int index,
int childIdx,
int[] container)
TransitionfillTransitionInformation in interface Transitionlayer - the layer in the matrixindex - the index encoding the contextchildIdx - the index of the child that will be visitedcontainer - container[0] the index of the state;
container[1] the index encoding the new context;
container[2] the distance for the new layer, i.e. 0 for the same layer (=silent state), and 1 for the next layer (=non-silent state)protected final int getTransitionElementIndex(int layer,
int index)
BasicHigherOrderTransition.AbstractTransitionElement using the lookup table.layer - the layer of the matrixindex - the index encoding the contextBasicHigherOrderTransition.AbstractTransitionElement with respect to transitionspublic int getNumberOfChildren(int layer,
int index)
TransitiongetNumberOfChildren in interface Transitionlayer - the layer of the matrixindex - the index encoding the contextpublic double getLogScoreFor(int layer,
int index,
int childIdx,
Sequence sequence,
int sequencePosition)
TransitiongetLogScoreFor in interface Transitionlayer - the layer in the matrixindex - the index encoding the contextchildIdx - the index of the child that will be visitedsequence - the sequencesequencePosition - the position within the sequencepublic int getNumberOfIndexes(int layer)
TransitiongetNumberOfIndexes in interface Transitionlayer - the layer of the matrixpublic boolean hasAnySelfTransitions()
Transitiontrue if the current instance has
any self transitions, otherwise falsehasAnySelfTransitions in interface Transitiontrue if the current instance has any self
transitions, otherwise falsepublic int getMaximalInDegree()
TransitiongetMaximalInDegree in interface Transitionpublic int getMaximalNumberOfChildren()
TransitiongetMaximalNumberOfChildren in interface Transitionpublic int getLastContextState(int layer,
int index)
TransitiongetLastContextState in interface Transitionlayer - the layer in the matrixindex - the index encoding the contextpublic int getChildIdx(int layer,
int index,
int state)
TransitiongetChildIdx in interface Transitionlayer - the layer in the matrixindex - the index encoding the contextstate - the index of the statepublic double getLogGammaScoreFromStatistic()
TransitionWithSufficientStatisticgetLogGammaScoreFromStatistic in interface TransitionWithSufficientStatisticpublic String toString(String[] stateNames, NumberFormat nf)
TransitionString representation of the Transition using the given names of the states.toString in interface TransitionstateNames - the names of the states, can be nullnf - the NumberFormat for the String representation of probabilitiesString representation of the Transition using the given names of the statespublic boolean[] isAbsoring()
TransitionisAbsoring in interface Transitionpublic void setParameters(Transition t) throws IllegalArgumentException
TransitionsetParameters in interface Transitiont - the transition with the parameters to be setIllegalArgumentException - if the assumption about the same class for given and current instance is wrong