org.biojava.bio.dp
Interface MarkovModel

All Superinterfaces:
Changeable
All Known Implementing Classes:
SimpleMarkovModel, WMAsMM

public interface MarkovModel
extends Changeable

A markov model.

All probablities are in log space.

This interface models a subset of hidden markov models with an explicit start and end state. In principle, these can be combined together, so that a state within one model may be an entire model in its own right, wired via container->start and end->container. For the sample methods to work, the log scores must be probabilities (sum to 1).


Nested Class Summary
static class MarkovModel.DistributionForwarder
          Add this as a listener to each distribution in a model.
 
Field Summary
static ChangeType ARCHITECTURE
          Signals that the architecture of the model is changing.
static ChangeType PARAMETER
          Signals that one or more parameters have altered.
 
Method Summary
 void addState(State newState)
          Adds a state to the model.
 boolean containsTransition(State from, State to)
          Returns wether a transition exists or not.
 void createTransition(State from, State to)
          Makes a transition between two states legal.
 void destroyTransition(State from, State to)
          Breaks a transition between two states legal.
 Alphabet emissionAlphabet()
          Alphabet that is emitted by the emission states.
 Distribution getWeights(State source)
          Get a probability Distribution over the transition from 'source'.
 int heads()
          The number of heads on this model.
 MagicalState magicalState()
          The MagicalState for this model.
 void removeState(State toGo)
          Remove a state from the model.
 void setWeights(State source, Distribution dist)
          Set the probability distribution over the transitions from 'source'.
 FiniteAlphabet stateAlphabet()
          FiniteAlphabet of the states.
 FiniteAlphabet transitionsFrom(State source)
          Returns the FiniteAlphabet of all states that have a transition from 'source'.
 FiniteAlphabet transitionsTo(State dest)
          Returns the FiniteAlphabet of all states that have a transition to 'dest'.
 
Methods inherited from interface org.biojava.utils.Changeable
addChangeListener, addChangeListener, isUnchanging, removeChangeListener, removeChangeListener
 

Field Detail

ARCHITECTURE

public static final ChangeType ARCHITECTURE
Signals that the architecture of the model is changing.

For a transition creation, the changed field should be a two element array containing the source and destination states of the new transition, and the previous field should be null. Likewise for the removal of a transition, the previos should hold the array, and changed should be null.


PARAMETER

public static final ChangeType PARAMETER
Signals that one or more parameters have altered.

If it is clear which parameter has changed, then this should be in the current and/or previous field. Otherwise, these should be null.

Method Detail

emissionAlphabet

public Alphabet emissionAlphabet()
Alphabet that is emitted by the emission states.


stateAlphabet

public FiniteAlphabet stateAlphabet()
FiniteAlphabet of the states.

We are modeling a finite-state-machine, so there will be a finite set of states.

The MagicalState returned by getMagicalState is always contained within this as the start/end state.

Returns:
the alphabet over states

magicalState

public MagicalState magicalState()
The MagicalState for this model.


heads

public int heads()
The number of heads on this model.

Each head consumes a single SymbolList. A single-head model just consumes/ emits a single sequence. A two-head model performs alignment between two sequences (e.g. smith-waterman). Models with more heads do more interesting things.


getWeights

public Distribution getWeights(State source)
                        throws IllegalSymbolException
Get a probability Distribution over the transition from 'source'.

Parameters:
source - the State currently occupied
Returns:
the probability Distribution over the reachable states
Throws:
IllegalSymbolException - if from is not a legal state

setWeights

public void setWeights(State source,
                       Distribution dist)
                throws IllegalSymbolException,
                       IllegalAlphabetException,
                       ChangeVetoException
Set the probability distribution over the transitions from 'source'.

This should throw an IllegalAlphabetException if the source alphabet in 'dist' is not the same alphabet as returned by transitionsFrom(source).

Parameters:
source - the source State
dist - the new distribution over transitions from 'source'
Throws:
IllegalSymbolException - if source is not a state in this model
IllegalAlphabetException - if the distribution has the wrong source alphabet
ChangeVetoException - if for any reason the distribution can't be replaced at this time

transitionsFrom

public FiniteAlphabet transitionsFrom(State source)
                               throws IllegalSymbolException
Returns the FiniteAlphabet of all states that have a transition from 'source'.

Parameters:
source - the source State
Returns:
a FiniteAlphabet of State objects that can reach from 'source'
Throws:
IllegalSymbolException

transitionsTo

public FiniteAlphabet transitionsTo(State dest)
                             throws IllegalSymbolException
Returns the FiniteAlphabet of all states that have a transition to 'dest'.

Parameters:
dest - the destination state
Returns:
a FiniteAlphabet of State objects that can reach 'dest'
Throws:
IllegalSymbolException

containsTransition

public boolean containsTransition(State from,
                                  State to)
                           throws IllegalSymbolException
Returns wether a transition exists or not.

Parameters:
from - the transitin source
to - the transition destination
Returns:
true/false depending on wether this model has the transition
Throws:
IllegalSymbolException - if either from or to are not states in this model

createTransition

public void createTransition(State from,
                             State to)
                      throws IllegalSymbolException,
                             ChangeVetoException
Makes a transition between two states legal.

This should inform each TransitionListener that a transition is to be created using preCreateTransition, and if none of the listeners fire a ChangeVetoException, it should create the transition, and then inform each TransitionListener with postCreateTransition.

Parameters:
from - the State currently occupied
to - the State to move to
Throws:
IllegalSymbolException - if either from or to are not legal states
ChangeVetoException - if creating the transition is vetoed

destroyTransition

public void destroyTransition(State from,
                              State to)
                       throws IllegalSymbolException,
                              ChangeVetoException
Breaks a transition between two states legal.

This should inform each TransitionListener that a transition is to be broken using preDestroyTransition, and if none of the listeners fire a ChangeVetoException, it should break the transition, and then inform each TransitionListener with postDestroyTransition.

Parameters:
from - the State currently occupied
to - the State to move to
Throws:
IllegalSymbolException - if either from or to are not legal states
ChangeVetoException - if breaking the transition is vetoed

addState

public void addState(State newState)
              throws IllegalSymbolException,
                     ChangeVetoException
Adds a state to the model.

Parameters:
newState - the state to add
Throws:
IllegalSymbolException - if the state is not valid or is a MagicalState
ChangeVetoException - if either the model does not allow states to be added, or the change was vetoed

removeState

public void removeState(State toGo)
                 throws IllegalTransitionException,
                        IllegalSymbolException,
                        ChangeVetoException
Remove a state from the model.

States should not be removed untill they are involved in no transitions. This is to avoid producing corrupted models by accident.

Parameters:
toGo - the state to remove
Throws:
IllegalSymbolException - if the symbol is not part of this model or a MagicalState
IllegalTransitionException - if the state is currently involved in any transitions
ChangeVetoException - if either the model does not allow states to be removed, or the change was vetoed