de.jstacs.sequenceScores.statisticalModels.trainable.hmm.transitions.elements
Class TransitionElement

java.lang.Object
  extended by de.jstacs.sequenceScores.statisticalModels.trainable.hmm.transitions.BasicHigherOrderTransition.AbstractTransitionElement
      extended by de.jstacs.sequenceScores.statisticalModels.trainable.hmm.transitions.elements.BasicTransitionElement
          extended by de.jstacs.sequenceScores.statisticalModels.trainable.hmm.transitions.elements.TransitionElement
All Implemented Interfaces:
Storable, Cloneable

public class TransitionElement
extends BasicTransitionElement

This class implements an transition element implements method used for training via sampling or gradient based optimization approach.

Author:
Jens Keilwagen

Field Summary
protected  int offset
          The internally used parameter offset.
protected  double[] probs
          The precomputed probabilities for each possible transition.
 
Fields inherited from class de.jstacs.sequenceScores.statisticalModels.trainable.hmm.transitions.BasicHigherOrderTransition.AbstractTransitionElement
context, descendants, hyperParameters, logNorm, parameters, states, statistic
 
Constructor Summary
TransitionElement(int[] context, int[] states, double[] hyperParameters)
          This is the main constructor creating a new instance with given context, descendant states, and hyper parameters.
TransitionElement(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.
TransitionElement(StringBuffer xml)
          The standard constructor for the interface Storable.
 
Method Summary
 void addGradientForLogPriorTerm(double[] gradient, int start)
          This method computes the gradient of BasicHigherOrderTransition.AbstractTransitionElement.getLogPriorTerm() for each parameter of this transition element.
 TransitionElement clone()
           
 int fillParameters(double[] params, int offset)
          This method fills the current parameters of this TransitionElement into the given array params starting at position offset.
 double getLogPosteriorFromStatistic()
          This method computes the log posterior from the internal sufficient statistic.
 double getLogScoreAndPartialDerivation(int childIdx, IntList indices, DoubleList partialDer, Sequence sequence, int sequencePosition)
          Returns the logarithmic score and fills lists with the indices and the partial derivations.
 double getMinimalHyperparameter()
          This method returns the minimal hyper parameters of this TransitionElement.
protected  void init()
          This method initializes internal fields.
protected  void precompute()
          This method precomputes internal fields as for instance the normalization constant.
 int setParameterOffset(int o)
          This method sets the internal offset used for several methods (cf. see tags).
 int setParameters(double[] params, int start)
          This method sets the internal parameters to the values of params beginning at index start.
 
Methods inherited from class de.jstacs.sequenceScores.statisticalModels.trainable.hmm.transitions.elements.BasicTransitionElement
appendFurtherInformation, extractFurtherInformation
 
Methods inherited from class de.jstacs.sequenceScores.statisticalModels.trainable.hmm.transitions.BasicHigherOrderTransition.AbstractTransitionElement
addToStatistic, appendGraphvizDescription, appendTransitions, drawParametersFromStatistic, estimateFromStatistic, getArrowOption, getChild, getContext, getDescendant, getGraphvizEdgeWeight, getLabel, getLogGammaScoreFromStatistic, getLogPriorTerm, getLogScoreFor, getNextContext, getNumberOfChildren, getNumberOfParameters, getXMLTag, initializeRandomly, joinStatistics, resetStatistic, setIndexOfDescendantTransitionElement, setParameters, toString, toString, toXML
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

probs

protected double[] probs
The precomputed probabilities for each possible transition.

See Also:
getLogScoreAndPartialDerivation(int, IntList, DoubleList, Sequence, int), addGradientForLogPriorTerm(double[], int)

offset

protected int offset
The internally used parameter offset.

See Also:
setParameterOffset(int), getLogScoreAndPartialDerivation(int, IntList, DoubleList, Sequence, int), addGradientForLogPriorTerm(double[], int)
Constructor Detail

TransitionElement

public TransitionElement(int[] context,
                         int[] states,
                         double[] hyperParameters)
This is the main constructor creating a new instance with given context, descendant states, and hyper parameters.

Parameters:
context - the context (=previously visited state indices); last entry corresponds to the last state visited
states - the transitions to all possible states; if null than no transition allowed
hyperParameters - the hyper parameters for the transitions; if null than no prior is used
See Also:
TransitionElement(int[], int[], double[], double[])

TransitionElement

public TransitionElement(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.

Parameters:
context - the context (=previously visited state indices); last entry corresponds to the last state visited
states - the transitions to all possible states; if null than no transition allowed
hyperParameters - the hyper parameters for the transitions; if null than no prior is used
weight - the weight for plotting the edge in Graphviz, enables to modify the edge length, larger weights imply shorter edges (default: 1)

TransitionElement

public TransitionElement(StringBuffer xml)
                  throws NonParsableException
The standard constructor for the interface Storable. Constructs a TransitionElement out of an XML representation.

Parameters:
xml - the XML representation as StringBuffer
Throws:
NonParsableException - if the TransitionElement could not be reconstructed out of the StringBuffer xml
Method Detail

clone

public TransitionElement clone()
                        throws CloneNotSupportedException
Overrides:
clone in class BasicHigherOrderTransition.AbstractTransitionElement
Throws:
CloneNotSupportedException

init

protected void init()
Description copied from class: BasicHigherOrderTransition.AbstractTransitionElement
This method initializes internal fields.

Overrides:
init in class BasicHigherOrderTransition.AbstractTransitionElement

precompute

protected void precompute()
Description copied from class: BasicHigherOrderTransition.AbstractTransitionElement
This method precomputes internal fields as for instance the normalization constant.

Overrides:
precompute in class BasicHigherOrderTransition.AbstractTransitionElement
See Also:
BasicHigherOrderTransition.AbstractTransitionElement.logNorm

getLogScoreAndPartialDerivation

public double getLogScoreAndPartialDerivation(int childIdx,
                                              IntList indices,
                                              DoubleList partialDer,
                                              Sequence sequence,
                                              int sequencePosition)
Returns the logarithmic score and fills lists with the indices and the partial derivations.

Parameters:
childIdx - the index of the child to be visited
indices - an IntList of indices, after method invocation the list should contain the indices i where $\frac{\partial \log score(seq)}{\partial \lambda_i}$ is not zero
partialDer - a DoubleList of partial derivations, after method invocation the list should contain the corresponding $\frac{\partial \log score(seq)}{\partial \lambda_i}$ that are not zero
sequence - the Sequence that can be used to extract SequenceAnnotation
sequencePosition - the position within the sequence
Returns:
the logarithmic score

setParameterOffset

public int setParameterOffset(int o)
This method sets the internal offset used for several methods (cf. see tags).

Parameters:
o - the offset to be set
Returns:
the new offset that can be used for the next TransitionElement
See Also:
offset, getLogScoreAndPartialDerivation(int, IntList, DoubleList, Sequence, int), addGradientForLogPriorTerm(double[], int)

fillParameters

public int fillParameters(double[] params,
                          int offset)
This method fills the current parameters of this TransitionElement into the given array params starting at position offset.

Parameters:
params - the array for filling the parameters
offset - the start index
Returns:
the next start index for further parameter filling

setParameters

public int setParameters(double[] params,
                         int start)
This method sets the internal parameters to the values of params beginning at index start.

Parameters:
params - the new parameters
start - the start index in params
Returns:
the first index in params that has not been used

addGradientForLogPriorTerm

public void addGradientForLogPriorTerm(double[] gradient,
                                       int start)
This method computes the gradient of BasicHigherOrderTransition.AbstractTransitionElement.getLogPriorTerm() for each parameter of this transition element. The results are added to the array gradient using the index start.

Parameters:
gradient - the array of gradients
start - the start index in the gradient array used to add partial derivations for the parameters
See Also:
offset

getMinimalHyperparameter

public double getMinimalHyperparameter()
This method returns the minimal hyper parameters of this TransitionElement.

Returns:
the minimal hyper parameters of this TransitionElement

getLogPosteriorFromStatistic

public double getLogPosteriorFromStatistic()
This method computes the log posterior from the internal sufficient statistic.

Returns:
the log posterior from the internal sufficient statistic