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]
 
_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
 
_safe_copy_and_check(matrix, desired_shape) source code
 
_safe_log(n) source code
 
_safe_asarray(a, typecode=None) source code
 
_logadd(logx, logy) source code
 
_logsum(matrix) source code
 
_logvecadd(logvec1, logvec2) source code
 
_exp_logsum(numbers) source code
Variables [hide private]
  VERY_SMALL_NUMBER = 1e-300
  LOG0 = -690.775527898
  MATCODE = 'd'
  MAX_ITERATIONS = 1000
  this_module = sys.modules [__name__]
  Complex0 = 'F'
  Complex16 = 'F'
  Complex32 = 'F'
  Complex64 = 'D'
  Complex8 = 'F'
  Float0 = 'f'
  Float16 = 'f'
  Float32 = 'f'
  Float64 = 'd'
  Float8 = 'f'
  Int0 = '1'
  Int16 = 's'
  Int32 = 'i'
  Int64 = 'l'
  Int8 = '1'
  __warningregistry__ = {('Not importing directory \'/usr/lib64/...
  absolute = <ufunc 'absolute'>
  add = <ufunc 'add'>
  arccos = <ufunc 'arccos'>
  arccosh = <ufunc 'arccosh'>
  arcsin = <ufunc 'arcsin'>
  arcsinh = <ufunc 'arcsinh'>
  arctan = <ufunc 'arctan'>
  arctan2 = <ufunc 'arctan2'>
  arctanh = <ufunc 'arctanh'>
  bitwise_and = <ufunc 'bitwise_and'>
  bitwise_or = <ufunc 'bitwise_or'>
  bitwise_xor = <ufunc 'bitwise_xor'>
  ceil = <ufunc 'ceil'>
  conjugate = <ufunc 'conjugate'>
  cos = <ufunc 'cos'>
  cosh = <ufunc 'cosh'>
  divide = <ufunc 'divide'>
  divide_safe = <ufunc 'divide_safe'>
  e = 2.71828182846
  equal = <ufunc 'equal'>
  exp = <ufunc 'exp'>
  fabs = <ufunc 'fabs'>
  floor = <ufunc 'floor'>
  floor_divide = <ufunc 'floor_divide'>
  fmod = <ufunc 'fmod'>
  greater = <ufunc 'greater'>
  greater_equal = <ufunc 'greater_equal'>
  hypot = <ufunc 'hypot'>
  invert = <ufunc 'invert'>
  left_shift = <ufunc 'left_shift'>
  less = <ufunc 'less'>
  less_equal = <ufunc 'less_equal'>
  log = <ufunc 'log'>
  log10 = <ufunc 'log10'>
  logical_and = <ufunc 'logical_and'>
  logical_not = <ufunc 'logical_not'>
  logical_or = <ufunc 'logical_or'>
  logical_xor = <ufunc 'logical_xor'>
  maximum = <ufunc 'maximum'>
  minimum = <ufunc 'minimum'>
  multiply = <ufunc 'multiply'>
  negative = <ufunc 'negative'>
  not_equal = <ufunc 'not_equal'>
  pi = 3.14159265359
  power = <ufunc 'power'>
  remainder = <ufunc 'remainder'>
  right_shift = <ufunc 'right_shift'>
  sin = <ufunc 'sin'>
  sinh = <ufunc 'sinh'>
  sqrt = <ufunc 'sqrt'>
  subtract = <ufunc 'subtract'>
  tan = <ufunc 'tan'>
  tanh = <ufunc 'tanh'>
  true_divide = <ufunc 'true_divide'>
  x = ImportError('No module named cMarkovModel',)
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


Variables Details [hide private]

__warningregistry__

Value:
{('Not importing directory \'/usr/lib64/python2.5/site-packages/Numeri\
c\': missing __init__.py',
  <type 'exceptions.ImportWarning'>,
  20): 1}