public interface MarkovModel extends Changeable
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).
Modifier and Type | Field and Description |
---|---|
static ChangeType |
ARCHITECTURE
Signals that the architecture of the model is changing.
|
static ChangeType |
PARAMETER
Signals that one or more parameters have altered.
|
Modifier and Type | Method and Description |
---|---|
void |
addState(State newState)
Adds a state to the model.
|
int[] |
advance()
The maximum advance for this 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()
Deprecated.
use
advance().length |
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'.
|
addChangeListener, addChangeListener, isUnchanging, removeChangeListener, removeChangeListener
static final ChangeType ARCHITECTURE
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.
static final ChangeType PARAMETER
If it is clear which parameter has changed, then this should be in the current and/or previous field. Otherwise, these should be null.
Alphabet emissionAlphabet()
FiniteAlphabet stateAlphabet()
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.
MagicalState magicalState()
int heads()
advance().length
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.
heads()
should equal advance().length
.
int[] advance()
Each head consumes a single SymbolList. However, the states that advance through that SymbolList may emit more than one symbol at a time. This array give the maximum advance in each direction.
Be sure to return a new array each time this is called. This protects the internal state of the object from someone modifying the advance array. Be sure to update this as/when states modify their advance arrays and as/when states are added or removedDistribution getWeights(State source) throws IllegalSymbolException
source
- the State currently occupiedIllegalSymbolException
- if from is not a legal statevoid setWeights(State source, Distribution dist) throws IllegalSymbolException, IllegalAlphabetException, ChangeVetoException
This should throw an IllegalAlphabetException if the source alphabet in 'dist' is not the same alphabet as returned by transitionsFrom(source).
source
- the source Statedist
- the new distribution over transitions from 'source'IllegalSymbolException
- if source is not a state in this modelIllegalAlphabetException
- if the distribution has the wrong source
alphabetChangeVetoException
- if for any reason the distribution can't be
replaced at this timeFiniteAlphabet transitionsFrom(State source) throws IllegalSymbolException
source
- the source StateIllegalSymbolException
FiniteAlphabet transitionsTo(State dest) throws IllegalSymbolException
dest
- the destination stateIllegalSymbolException
boolean containsTransition(State from, State to) throws IllegalSymbolException
from
- the transitin sourceto
- the transition destinationIllegalSymbolException
- if either from or to are not states in this
modelvoid createTransition(State from, State to) throws IllegalSymbolException, ChangeVetoException
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.
from
- the State currently occupiedto
- the State to move toIllegalSymbolException
- if either from or to are not legal statesChangeVetoException
- if creating the transition is vetoedvoid destroyTransition(State from, State to) throws IllegalSymbolException, ChangeVetoException
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.
from
- the State currently occupiedto
- the State to move toIllegalSymbolException
- if either from or to are not legal statesChangeVetoException
- if breaking the transition is vetoedvoid addState(State newState) throws IllegalSymbolException, ChangeVetoException
newState
- the state to addIllegalSymbolException
- if the state is not valid or is a MagicalStateChangeVetoException
- if either the model does not allow states to
be added, or the change was vetoedvoid removeState(State toGo) throws IllegalTransitionException, IllegalSymbolException, ChangeVetoException
States should not be removed untill they are involved in no transitions. This is to avoid producing corrupted models by accident.
toGo
- the state to removeIllegalSymbolException
- if the symbol is not part of this model
or a MagicalStateIllegalTransitionException
- if the state is currently involved in
any transitionsChangeVetoException
- if either the model does not allow states to
be removed, or the change was vetoedCopyright © 2014 BioJava. All rights reserved.