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.AbstractTransitionElement s. |
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.AbstractTransitionElement
s.protected boolean[] isSilent
protected int maximalMarkovOrder
protected int maxInDegree
protected int[][][] lookup
public BasicHigherOrderTransition(boolean[] isSilent, BasicHigherOrderTransition.AbstractTransitionElement... transitions) throws Exception
transitions
- the BasicHigherOrderTransition.AbstractTransitionElement
s for the internal useisSilent
- an array indicating for each state whether it is silent or notException
- if an error occurs during checking the BasicHigherOrderTransition.AbstractTransitionElement
s and creating internal fieldspublic BasicHigherOrderTransition(StringBuffer xml) throws NonParsableException
Storable
.
Constructs a BasicHigherOrderTransition
out of an XML representation.xml
- the XML representation as StringBuffer
NonParsableException
- if the BasicHigherOrderTransition
could not be reconstructed out of
the StringBuffer
xml
public StringBuffer toXML()
Storable
StringBuffer
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
xml
public BasicHigherOrderTransition clone() throws CloneNotSupportedException
Transition
clone
in interface Transition
clone
in class Object
CloneNotSupportedException
- if the instance could not be clonedpublic void resetStatistic()
TransitionWithSufficientStatistic
resetStatistic
in interface TransitionWithSufficientStatistic
public void joinStatistics(Transition... transitions)
TransitionWithSufficientStatistic
joinStatistics
in interface TransitionWithSufficientStatistic
transitions
- the transitions to be joinedpublic void addToStatistic(int layer, int index, int childIdx, double weight, Sequence sequence, int sequencePosition)
TransitionWithSufficientStatistic
weight
to the sufficient statistic of a specific transition.addToStatistic
in interface TransitionWithSufficientStatistic
layer
- 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()
TrainableTransition
estimateFromStatistic
in interface TrainableTransition
public 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()
Transition
getMaximalMarkovOrder
in interface Transition
public double getLogPriorTerm()
Transition
getLogPriorTerm
in interface Transition
StatisticalModel.getLogPriorTerm()
public int getNumberOfStates()
Transition
getNumberOfStates
in interface Transition
public void initializeRandomly()
Transition
initializeRandomly
in interface Transition
public String getGraphizNetworkRepresentation(NumberFormat nf, String arrowOption, boolean graphical)
Transition
String
representation of the structure that
can be used in Graphviz to create an image.getGraphizNetworkRepresentation
in interface Transition
nf
- 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)
Transition
fillTransitionInformation
in interface Transition
layer
- 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 transitions
public int getNumberOfChildren(int layer, int index)
Transition
getNumberOfChildren
in interface Transition
layer
- the layer of the matrixindex
- the index encoding the contextpublic double getLogScoreFor(int layer, int index, int childIdx, Sequence sequence, int sequencePosition)
Transition
getLogScoreFor
in interface Transition
layer
- 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)
Transition
getNumberOfIndexes
in interface Transition
layer
- the layer of the matrixpublic boolean hasAnySelfTransitions()
Transition
true
if the current instance has
any self transitions, otherwise false
hasAnySelfTransitions
in interface Transition
true
if the current instance has any self
transitions, otherwise false
public int getMaximalInDegree()
Transition
getMaximalInDegree
in interface Transition
public int getMaximalNumberOfChildren()
Transition
getMaximalNumberOfChildren
in interface Transition
public int getLastContextState(int layer, int index)
Transition
getLastContextState
in interface Transition
layer
- the layer in the matrixindex
- the index encoding the contextpublic int getChildIdx(int layer, int index, int state)
Transition
getChildIdx
in interface Transition
layer
- the layer in the matrixindex
- the index encoding the contextstate
- the index of the statepublic double getLogGammaScoreFromStatistic()
TransitionWithSufficientStatistic
getLogGammaScoreFromStatistic
in interface TransitionWithSufficientStatistic
public String toString(String[] stateNames, NumberFormat nf)
Transition
String
representation of the Transition
using the given names of the states.toString
in interface Transition
stateNames
- the names of the states, can be null
nf
- the NumberFormat
for the String
representation of probabilitiesString
representation of the Transition
using the given names of the statespublic boolean[] isAbsoring()
Transition
isAbsoring
in interface Transition
public void setParameters(Transition t) throws IllegalArgumentException
Transition
setParameters
in interface Transition
t
- the transition with the parameters to be setIllegalArgumentException
- if the assumption about the same class for given and current instance is wrong