Class SimpleMarkovModel
- java.lang.Object
-
- org.biojava.utils.AbstractChangeable
-
- org.biojava.bio.dp.SimpleMarkovModel
-
- All Implemented Interfaces:
Serializable,MarkovModel,Changeable
- Direct Known Subclasses:
FullHmmerProfileHMM,ProfileHMM
public class SimpleMarkovModel extends AbstractChangeable implements MarkovModel, Serializable
- Author:
- Matthew Pocock, Thomas Down, Samiul Hasan, Keith James
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static longserialVersionUID-
Fields inherited from interface org.biojava.bio.dp.MarkovModel
ARCHITECTURE, PARAMETER
-
-
Constructor Summary
Constructors Constructor Description SimpleMarkovModel(int heads, Alphabet emissionAlpha)Deprecated.SimpleMarkovModel(int heads, Alphabet emissionAlpha, String name)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddState(State toAdd)Adds a state to the model.int[]advance()The maximum advance for this model.booleancontainsTransition(State from, State to)Returns wether a transition exists or not.voidcreateTransition(State from, State to)Makes a transition between two states legal.voiddestroyTransition(State from, State to)Breaks a transition between two states legal.AlphabetemissionAlphabet()Alphabet that is emitted by the emission states.protected ChangeSupportgetChangeSupport(ChangeType ct)Called to retrieve the ChangeSupport for this object.DistributiongetWeights(State source)Get a probability Distribution over the transition from 'source'.intheads()The number of heads on this model.MagicalStatemagicalState()The MagicalState for this model.voidremoveState(State toGo)Remove a state from the model.voidsetWeights(State source, Distribution dist)Use this methods to customize the transition probabilities.FiniteAlphabetstateAlphabet()FiniteAlphabet of the states.StringtoString()FiniteAlphabettransitionsFrom(State from)Returns the FiniteAlphabet of all states that have a transition from 'source'.FiniteAlphabettransitionsTo(State to)Returns the FiniteAlphabet of all states that have a transition to 'dest'.-
Methods inherited from class org.biojava.utils.AbstractChangeable
addChangeListener, addChangeListener, generateChangeSupport, hasListeners, hasListeners, isUnchanging, removeChangeListener, removeChangeListener
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.biojava.utils.Changeable
addChangeListener, addChangeListener, isUnchanging, removeChangeListener, removeChangeListener
-
-
-
-
Field Detail
-
serialVersionUID
public static final long serialVersionUID
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
SimpleMarkovModel
public SimpleMarkovModel(int heads, Alphabet emissionAlpha, String name)
-
SimpleMarkovModel
public SimpleMarkovModel(int heads, Alphabet emissionAlpha)
Deprecated.
-
-
Method Detail
-
getChangeSupport
protected ChangeSupport getChangeSupport(ChangeType ct)
Description copied from class:AbstractChangeableCalled to retrieve the ChangeSupport for this object.Your implementation of this method should have the following structure:
It is usual for the forwarding listeners (someForwarder in this example) to be transient and lazily instantiated. Be sure to register & unregister the forwarder in the code that does the ChangeEvent handling in setter methods.ChangeSupport cs = super.getChangeSupport(ct); if(someForwarder == null && ct.isMatching(SomeInterface.SomeChangeType)) { someForwarder = new ChangeForwarder(... this.stateVariable.addChangeListener(someForwarder, VariableInterface.AChange); } return cs;- Overrides:
getChangeSupportin classAbstractChangeable
-
emissionAlphabet
public Alphabet emissionAlphabet()
Description copied from interface:MarkovModelAlphabet that is emitted by the emission states.- Specified by:
emissionAlphabetin interfaceMarkovModel
-
stateAlphabet
public FiniteAlphabet stateAlphabet()
Description copied from interface:MarkovModelFiniteAlphabet 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.
- Specified by:
stateAlphabetin interfaceMarkovModel- Returns:
- the alphabet over states
-
heads
public int heads()
Description copied from interface:MarkovModelThe 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.
heads()should equaladvance().length.- Specified by:
headsin interfaceMarkovModel- Returns:
- the number of heads in this model.
-
magicalState
public MagicalState magicalState()
Description copied from interface:MarkovModelThe MagicalState for this model.- Specified by:
magicalStatein interfaceMarkovModel
-
advance
public int[] advance()
Description copied from interface:MarkovModelThe maximum advance for this model.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 removed- Specified by:
advancein interfaceMarkovModel- Returns:
- the maximum advance of all states for all heads
-
getWeights
public Distribution getWeights(State source) throws IllegalSymbolException
Description copied from interface:MarkovModelGet a probability Distribution over the transition from 'source'.- Specified by:
getWeightsin interfaceMarkovModel- 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
Use this methods to customize the transition probabilities.By default, the distribution P(destination | source) is a totally free distribution. This allows the different probabilities to vary. If you wish to change this behaviour (for example, to make one set of transition probabilities equal to another), then use this method to replace the Distribution with one of your own.
- Specified by:
setWeightsin interfaceMarkovModel- Parameters:
source- source Statedist- the new Distribution over the transition probabilites from source- Throws:
IllegalSymbolException- if source is not a member of this modelIllegalAlphabetException- if dist is not a distribution over the states returned by model.transitionsFrom(source)ChangeVetoException- if a listener vetoed this change
-
createTransition
public void createTransition(State from, State to) throws IllegalSymbolException, ChangeVetoException
Description copied from interface:MarkovModelMakes 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.
- Specified by:
createTransitionin interfaceMarkovModel- Parameters:
from- the State currently occupiedto- the State to move to- Throws:
IllegalSymbolException- if either from or to are not legal statesChangeVetoException- if creating the transition is vetoed
-
destroyTransition
public void destroyTransition(State from, State to) throws IllegalSymbolException, ChangeVetoException
Description copied from interface:MarkovModelBreaks 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.
- Specified by:
destroyTransitionin interfaceMarkovModel- Parameters:
from- the State currently occupiedto- the State to move to- Throws:
IllegalSymbolException- if either from or to are not legal statesChangeVetoException- if breaking the transition is vetoed
-
containsTransition
public boolean containsTransition(State from, State to) throws IllegalSymbolException
Description copied from interface:MarkovModelReturns wether a transition exists or not.- Specified by:
containsTransitionin interfaceMarkovModel- Parameters:
from- the transitin sourceto- 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
-
transitionsFrom
public FiniteAlphabet transitionsFrom(State from) throws IllegalSymbolException
Description copied from interface:MarkovModelReturns the FiniteAlphabet of all states that have a transition from 'source'.- Specified by:
transitionsFromin interfaceMarkovModel- Parameters:
from- the source State- Returns:
- a FiniteAlphabet of State objects that can reach from 'source'
- Throws:
IllegalSymbolException
-
transitionsTo
public FiniteAlphabet transitionsTo(State to) throws IllegalSymbolException
Description copied from interface:MarkovModelReturns the FiniteAlphabet of all states that have a transition to 'dest'.- Specified by:
transitionsToin interfaceMarkovModel- Parameters:
to- the destination state- Returns:
- a FiniteAlphabet of State objects that can reach 'dest'
- Throws:
IllegalSymbolException
-
addState
public void addState(State toAdd) throws IllegalSymbolException, ChangeVetoException
Description copied from interface:MarkovModelAdds a state to the model.- Specified by:
addStatein interfaceMarkovModel- Parameters:
toAdd- the state to add- Throws:
IllegalSymbolException- 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 vetoed
-
removeState
public void removeState(State toGo) throws IllegalSymbolException, IllegalTransitionException, ChangeVetoException
Description copied from interface:MarkovModelRemove 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.
- Specified by:
removeStatein interfaceMarkovModel- Parameters:
toGo- the state to remove- Throws:
IllegalSymbolException- 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 vetoed
-
-