Represent a hidden markov model that can be used for state estimation.
Methods
|
|
__init__
_calculate_from_transitions
_log_transform
get_blank_emissions
get_blank_transitions
transitions_from
viterbi
|
|
__init__
|
__init__ (
self,
transition_prob,
emission_prob,
transition_pseudo,
emission_pseudo,
)
Initialize a Markov Model.
Note: You should use the MarkovModelBuilder class instead of
initiating this class directly.
Arguments:
transition_prob -- A dictionary of transition probabilities for all
possible transitions in the sequence.
emission_prob -- A dictionary of emissions probabilities for all
possible emissions from the sequence states.
transition_pseudo -- Pseudo-counts to be used for the transitions,
when counting for purposes of estimating transition probabilities.
emission_pseduo -- Pseudo-counts fo tbe used for the emissions,
when counting for purposes of estimating emission probabilities.
|
|
_calculate_from_transitions
|
_calculate_from_transitions ( self, trans_probs )
Calculate which from transitions are allowed for each letter.
This looks through all of the trans_probs, and uses this dictionary
to determine allowed transitions. It converts this information into
a dictionary, whose keys are the transition letters and whose
values are a list of allowed letters to transition to.
|
|
_log_transform
|
_log_transform ( self, probability )
Return log transform of the given probability dictionary.
When calculating the Viterbi equation, we need to deal with things
as sums of logs instead of products of probabilities, so that we
don't get underflow errors.. This copies the given probability
dictionary and returns the same dictionary with everything
transformed with a log.
|
|
get_blank_emissions
|
get_blank_emissions ( self )
Get the starting default emmissions for each sequence.
This returns a dictionary of the default emmissions for each
letter. The dictionary is structured with keys as
(seq_letter, emmission_letter) and values as the starting number
of emmissions.
|
|
get_blank_transitions
|
get_blank_transitions ( self )
Get the default transitions for the model.
Returns a dictionary of all of the default transitions between any
two letters in the sequence alphabet. The dictionary is structured
with keys as (letter1, letter2) and values as the starting number
of transitions.
|
|
transitions_from
|
transitions_from ( self, state_letter )
Get all transitions which can happen from the given state.
This returns all letters which the given state_letter is allowed
to transition to. An empty list is returned if no letters are possible.
|
|
viterbi
|
viterbi (
self,
sequence,
state_alphabet,
)
Calculate the most probable state path using the Viterbi algorithm.
This implements the Viterbi algorithm (see pgs 55-57 in Durbin et
al for a full explanation -- this is where I took my implementation
ideas from), to allow decoding of the state path, given a sequence
of emissions.
Arguments:
|