An abstract class to calculate forward and backward probabiliies.
This class should not be instantiated directly, but should be used
through a derived class which implements proper scaling of variables.
This class is just meant to encapsulate the basic foward and backward
algorithms, and allow derived classes to deal with the problems of
multiplying probabilities.
Derived class of this must implement:
_forward_recursion -- Calculate the forward values in the recursion
using some kind of technique for preventing underflow errors.
_backward_recursion -- Calculate the backward values in the recursion
step using some technique to prevent underflow errors.
Methods
|
|
__init__
_backward_recursion
_foward_recursion
backward_algorithm
forward_algorithm
|
|
__init__
|
__init__ (
self,
markov_model,
sequence,
)
Initialize to calculate foward and backward probabilities.
Arguments:
|
|
_backward_recursion
|
_backward_recursion (
self,
cur_state,
sequence_pos,
forward_vars,
)
Calculate the backward recursion value.
Exceptions
|
|
NotImplementedError( "Subclasses must implement" )
|
|
|
_foward_recursion
|
_foward_recursion (
self,
cur_state,
sequence_pos,
forward_vars,
)
Calculate the forward recursion value.
Exceptions
|
|
NotImplementedError( "Subclasses must implement" )
|
|
|
backward_algorithm
|
backward_algorithm ( self )
Calculate sequence probability using the backward algorithm.
This implements the backward algorithm, as described on p58-59 of
Durbin et al.
Returns:
|
|
forward_algorithm
|
forward_algorithm ( self )
Calculate sequence probability using the forward algorithm.
This implements the foward algorithm, as described on p57-58 of
Durbin et al.
Returns:
A dictionary containing the foward variables. This has keys of the
form (state letter, position in the training sequence), and values
containing the calculated forward variable.
The calculated probability of the sequence.
|
|