Package Bio :: Module MarkovModel
[hide private]
[frames] | no frames]

Module MarkovModel

source code


This is an implementation of a state-emitting MarkovModel.  I am using
terminology similar to Manning and Schutze.



Functions:
train_bw        Train a markov model using the Baum-Welch algorithm.
train_visible   Train a visible markov model using MLE.
find_states     Find the a state sequence that explains some observations.

load            Load a MarkovModel.
save            Save a MarkovModel.

Classes:
MarkovModel     Holds the description of a markov model

Classes [hide private]
  MarkovModel
Functions [hide private]
 
itemindex(values) source code
 
_readline_and_check_start(handle, start) source code
MarkovModel()

load(handle) source code
 
save(mm, handle) source code
 
train_bw(states, alphabet, training_data, pseudo_initial=None, pseudo_transition=None, pseudo_emission=None, update_fn=None)
train_bw(states, alphabet, training_data[, pseudo_initial] [, pseudo_transition][, pseudo_emission][, update_fn]) -> MarkovModel
source code
 
_baum_welch(N, M, training_outputs, p_initial=None, p_transition=None, p_emission=None, pseudo_initial=None, pseudo_transition=None, pseudo_emission=None, update_fn=None) source code
 
_baum_welch_one(N, M, outputs, lp_initial, lp_transition, lp_emission, lpseudo_initial, lpseudo_transition, lpseudo_emission) source code
 
_forward(N, T, lp_initial, lp_transition, lp_emission, outputs) source code
 
_backward(N, T, lp_transition, lp_emission, outputs) source code
 
train_visible(states, alphabet, training_data, pseudo_initial=None, pseudo_transition=None, pseudo_emission=None)
train_visible(states, alphabet, training_data[, pseudo_initial] [, pseudo_transition][, pseudo_emission]) -> MarkovModel
source code
 
_mle(N, M, training_outputs, training_states, pseudo_initial, pseudo_transition, pseudo_emission) source code
 
_argmaxes(vector, allowance=None) source code
list of (states, score)

find_states(markov_model, output) source code
 
_viterbi(N, lp_initial, lp_transition, lp_emission, output) source code
 
_normalize(matrix) source code
 
_uniform_norm(shape) source code
 
_random_norm(shape) source code
 
_copy_and_check(matrix, desired_shape) source code
 
_logsum(matrix) source code
 
_logvecadd(logvec1, logvec2) source code
 
_exp_logsum(numbers) source code
Variables [hide private]
  logaddexp = <ufunc 'logaddexp'>
  VERY_SMALL_NUMBER = 1e-300
  LOG0 = -690.77552789821368
  MAX_ITERATIONS = 1000
  __package__ = 'Bio'
Function Details [hide private]

train_bw(states, alphabet, training_data, pseudo_initial=None, pseudo_transition=None, pseudo_emission=None, update_fn=None)

source code 
train_bw(states, alphabet, training_data[, pseudo_initial]
[, pseudo_transition][, pseudo_emission][, update_fn]) -> MarkovModel

Train a MarkovModel using the Baum-Welch algorithm.  states is a list
of strings that describe the names of each state.  alphabet is a
list of objects that indicate the allowed outputs.  training_data
is a list of observations.  Each observation is a list of objects
from the alphabet.

pseudo_initial, pseudo_transition, and pseudo_emission are
optional parameters that you can use to assign pseudo-counts to
different matrices.  They should be matrices of the appropriate
size that contain numbers to add to each parameter matrix, before
normalization.

update_fn is an optional callback that takes parameters
(iteration, log_likelihood).  It is called once per iteration.

train_visible(states, alphabet, training_data, pseudo_initial=None, pseudo_transition=None, pseudo_emission=None)

source code 
train_visible(states, alphabet, training_data[, pseudo_initial]
[, pseudo_transition][, pseudo_emission]) -> MarkovModel

Train a visible MarkovModel using maximum likelihoood estimates
for each of the parameters.  states is a list of strings that
describe the names of each state.  alphabet is a list of objects
that indicate the allowed outputs.  training_data is a list of
(outputs, observed states) where outputs is a list of the emission
from the alphabet, and observed states is a list of states from
states.

pseudo_initial, pseudo_transition, and pseudo_emission are
optional parameters that you can use to assign pseudo-counts to
different matrices.  They should be matrices of the appropriate
size that contain numbers to add to each parameter matrix