public abstract static class BasicHigherOrderTransition.AbstractTransitionElement extends Object implements Cloneable, Storable
| Modifier and Type | Field and Description |
|---|---|
protected int[] |
context
The context, i.e.
|
protected int[] |
descendants
The indices for the descendant transition elements that can be visited following the states.
|
protected double[] |
hyperParameters
The hyperparameters of the prior over the parameters.
|
protected double |
logNorm
The log normalization constant based on the parameters.
|
protected double[] |
parameters
The parameters defining the distribution over all states that can be visited.
|
protected int[] |
states
The states that can be visited
|
protected double[] |
statistic
The sufficient statistic for determining the parameters during sampling, viterbi or Baum-Welch training.
|
| Constructor and Description |
|---|
AbstractTransitionElement(int[] context,
int[] states,
double[] hyperParameters)
This is the main constructor creating a new instance with given context, descendant states, and hyper parameters.
|
AbstractTransitionElement(int[] context,
int[] states,
double[] hyperParameters,
double[] weight)
This is the main constructor creating a new instance with given context, descendant states, and hyper parameters.
|
AbstractTransitionElement(StringBuffer xml)
The standard constructor for the interface
Storable. |
| Modifier and Type | Method and Description |
|---|---|
void |
addToStatistic(int childIdx,
double weight,
Sequence sequence,
int sequencePosition)
This method adds a given weight to the sufficient statistic for the parameters.
|
protected abstract void |
appendFurtherInformation(StringBuffer xml)
This method appends further information to the XML representation.
|
void |
appendGraphvizDescription(StringBuffer representation,
NumberFormat nf,
String arrowOption,
boolean graphical)
This method appends the current transition element to a Graphviz representation of the structure that
can be used to create an image.
|
protected void |
appendTransitions(StringBuffer representation,
String contextNodeRepresentation,
NumberFormat nf,
String arrowOption,
boolean graphical)
This method appends all edges of the transition element to a given Graphviz representation.
|
BasicHigherOrderTransition.AbstractTransitionElement |
clone() |
void |
drawParametersFromStatistic()
This method draws new parameters from the sufficient statistics.
|
void |
estimateFromStatistic()
This method estimates the parameters from the sufficient statistic.
|
protected abstract void |
extractFurtherInformation(StringBuffer xml)
This method extracts further information from the XML representation.
|
protected static String |
getArrowOption(NumberFormat nf,
double prob,
double weight,
String arrowOption,
boolean graphical)
This method returns the option for an edge in Graphviz.
|
int |
getChild(int index)
This method returns the state index encoded by the child index.
|
protected String |
getContext(String[] stateNames)
This method returns a
String representation of the context. |
int |
getDescendant(int index)
This method returns the index of the descendant transition element when following the child with index
index |
protected double |
getGraphvizEdgeWeight(int s)
This method returns the edge weight for plotting the edge with Graphviz.
|
protected String |
getLabel(String[] stateNames,
int stateIdx)
This method returns a label for the state.
|
int |
getLastContextState()
Returns the last state of the context
|
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 index,
Sequence sequence,
int sequencePosition)
This method returns the score for the transition from the current context to the state with index
index. |
int[] |
getNextContext(int index,
int maximalMarkovOrder)
This method returns the next context that will be visited when visiting the child with index
index. |
int |
getNumberOfChildren()
This method returns the number of states that can be visited.
|
int |
getNumberOfParameters()
This method returns the number of parameters in this transition element.
|
protected String |
getXMLTag()
This method returns the xml tag used in
toXML(). |
protected void |
init()
This method initializes internal fields.
|
void |
initializeRandomly()
This method draws new parameters from the prior.
|
void |
joinStatistics(BasicHigherOrderTransition.AbstractTransitionElement... te)
This method joins the statistics of different instances and sets this joined statistic as statistic of each instance.
|
protected void |
precompute()
This method precomputes internal fields as for instance the normalization constant.
|
void |
resetStatistic()
This method resets the sufficient statistic for the parameters.
|
void |
setIndexOfDescendantTransitionElement(int index,
int descendant)
This method sets the index of the descendant transition element for the child with index
index. |
void |
setParameters(BasicHigherOrderTransition.AbstractTransitionElement 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 element 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 int[] context
BasicHigherOrderTransition.AbstractTransitionElementprotected int[] states
protected double[] hyperParameters
getLogPriorTerm(),
parametersprotected double[] parameters
statesprotected double[] statistic
protected double logNorm
parametersprotected int[] descendants
statespublic AbstractTransitionElement(int[] context,
int[] states,
double[] hyperParameters)
context - the context (=previously visited state indices); last entry corresponds to the last state visitedstates - the transitions to all possible states; if null then no transition allowedhyperParameters - the hyper parameters for the transitions; if null then no prior is usedBasicHigherOrderTransition.AbstractTransitionElement(int[], int[], double[], double[])public AbstractTransitionElement(int[] context,
int[] states,
double[] hyperParameters,
double[] weight)
context - the context (=previously visited state indices); last entry corresponds to the last state visitedstates - the transitions to all possible states; if null then no transition allowedhyperParameters - the hyper parameters for the transitions; if null then no prior is usedweight - the weight for plotting the edges in Graphviz, enables to modify the edge length, larger weights imply shorter edges (default: 1)public AbstractTransitionElement(StringBuffer xml) throws NonParsableException
Storable.
Constructs a BasicHigherOrderTransition.AbstractTransitionElement out of an XML representation.xml - the XML representation as StringBufferNonParsableException - if the BasicHigherOrderTransition.AbstractTransitionElement could not be reconstructed out of
the StringBuffer xmlprotected abstract void appendFurtherInformation(StringBuffer xml)
xml - the XML representationprotected abstract void extractFurtherInformation(StringBuffer xml) throws NonParsableException
xml - the XML representationNonParsableException - if the information could not be reconstructed out of the StringBuffer xmlprotected String getXMLTag()
toXML().toXML()public StringBuffer toXML()
StorableStringBuffer of an
instance of the implementing class.protected void init()
public BasicHigherOrderTransition.AbstractTransitionElement clone() throws CloneNotSupportedException
clone in class ObjectCloneNotSupportedExceptionpublic int getLastContextState()
protected void precompute()
logNormpublic void appendGraphvizDescription(StringBuffer representation, NumberFormat nf, String arrowOption, boolean graphical)
representation - the current Graphviz representationnf - 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 outputTransition.getGraphizNetworkRepresentation(NumberFormat, String, boolean),
appendTransitions(StringBuffer, String, NumberFormat, String, boolean)protected void appendTransitions(StringBuffer representation, String contextNodeRepresentation, NumberFormat nf, String arrowOption, boolean graphical)
representation - the current Graphviz representationcontextNodeRepresentation - the String representation of the context node(s)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 outputappendGraphvizDescription(StringBuffer, NumberFormat, String, boolean),
getArrowOption(NumberFormat, double, double, String, boolean)protected final double getGraphvizEdgeWeight(int s)
s - the index of the states (child)protected static String getArrowOption(NumberFormat nf, double prob, double weight, String arrowOption, boolean graphical)
String that is used in the Graphviz notation to quantify a specific transition.nf - the NumberFormat for formating the probabilityprob - the probability of a certain transitionweight - the weight for plotting the edges in Graphviz, enables to modify the edge length, larger weights imply shorter edges (default: 1)arrowOption - further arrow options (e.g. color, ...)graphical - represent transition probabilities as thickness of edges instead of textual outputString that is used in the Graphviz notation to quantify a specific transitionTransition.getGraphizNetworkRepresentation(NumberFormat, String, boolean),
appendTransitions(StringBuffer, String, NumberFormat, String, boolean)public int getChild(int index)
index - the index of the childstatespublic int getDescendant(int index)
indexindex - the child indexdescendants,
setIndexOfDescendantTransitionElement(int, int)public void setIndexOfDescendantTransitionElement(int index,
int descendant)
index.index - the index of the childdescendant - the index of the descendant transition elementdescendants,
getDescendant(int)public int[] getNextContext(int index,
int maximalMarkovOrder)
index.index - the index of the childmaximalMarkovOrder - the maximal Markov order to be usedpublic double getLogScoreFor(int index,
Sequence sequence,
int sequencePosition)
index.index - the index of the childsequence - the sequence, which might be used to retrieve SequenceAnnotationsequencePosition - the position within the sequenceindexpublic double getLogPriorTerm()
Transition.getLogPriorTerm()public final int getNumberOfChildren()
statespublic void addToStatistic(int childIdx,
double weight,
Sequence sequence,
int sequencePosition)
childIdx - the index of the descendant stateweight - the weight to be addedsequence - the sequence, which might be used to retrieve SequenceAnnotationsequencePosition - the position within the sequenceTransitionWithSufficientStatistic.addToStatistic(int, int, int, double, Sequence, int),
statistic,
resetStatistic(),
estimateFromStatistic(),
drawParametersFromStatistic()public void joinStatistics(BasicHigherOrderTransition.AbstractTransitionElement... te)
te - the transition elements to be joinedpublic int getNumberOfParameters()
parameterspublic void drawParametersFromStatistic()
public void estimateFromStatistic()
public void resetStatistic()
public void initializeRandomly()
public double getLogGammaScoreFromStatistic()
public String toString(String[] stateNames, NumberFormat nf)
String representation of the transition element using the given names of the states.stateNames - the names of the states, can be nullnf - the NumberFormat for the String representation of probabilitiesString representation of the transition element using the given names of the statesprotected String getContext(String[] stateNames)
String representation of the context.stateNames - the names of the states, can be nullString representation of the contexttoString(),
toString(String[],NumberFormat)protected final String getLabel(String[] stateNames, int stateIdx)
stateNames - the names of the states, can be nullstateIdx - the index of the statestoString(String[], NumberFormat),
getContext(String[])public void setParameters(BasicHigherOrderTransition.AbstractTransitionElement t) throws IllegalArgumentException
t - the transition element with the parameters to be setIllegalArgumentException - if the assumption about the same class for given and current instance is wrong