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 pseudocounts to different matrices. They should be matrices of the appropriate size that contain numbers to add to each parameter matrix Definition at line 333 of file MarkovModel.py. : """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 pseudocounts to different matrices. They should be matrices of the appropriate size that contain numbers to add to each parameter matrix """ N, M = len(states), len(alphabet) pseudo_initial, pseudo_emission, pseudo_transition = map( _safe_asarray, (pseudo_initial, pseudo_emission, pseudo_transition)) if pseudo_initial and shape(pseudo_initial) != (N,): raise ValueError, "pseudo_initial not shape len(states)" if pseudo_transition and shape(pseudo_transition) != (N,N): raise ValueError, "pseudo_transition not shape " + \ "len(states) X len(states)" if pseudo_emission and shape(pseudo_emission) != (N,M): raise ValueError, "pseudo_emission not shape " + \ "len(states) X len(alphabet)" # Training data is given as a list of members of the alphabet. # Replace those with indexes into the alphabet list for easier # computation. training_states, training_outputs = [], [] states_indexes = listfns.itemindex(states) outputs_indexes = listfns.itemindex(alphabet) for toutputs, tstates in training_data: if len(tstates) != len(toutputs): raise ValueError, "states and outputs not aligned" training_states.append([states_indexes[x] for x in tstates]) training_outputs.append([outputs_indexes[x] for x in toutputs]) x = _mle(N, M, training_outputs, training_states, pseudo_initial, pseudo_transition, pseudo_emission) p_initial, p_transition, p_emission = x return MarkovModel(states, alphabet, p_initial, p_transition, p_emission) def _mle(N, M, training_outputs, training_states, pseudo_initial,
