''' import numpy as np import matplotlib.pyplot as plt import matplotlib.cm as cm from surrogate.Markov_model import Markov_model from HMM_algos import Proba_computer initial = [0.1, 0.1, 0.1] A = [[0.1, 0.5, 0.1], [0.1, 0.1, 0.5], [0.5, 0.1, 0.1]] alphabet = ['a', 'b', 'c'] B = [[0.8, 0.1, 0.1], [0.1, 0.8, 0.1], [0.1, 0.1, 0.8]] my_markov_model = Markov_model(initial, A, B, alphabet) data = my_markov_model.generate_data(10) my_proba_computer = Proba_computer(initial, A, B, alphabet) print [x['state'] for x in data] print [x['obs'] for x in data] forwards = my_proba_computer.compute_forward_probas([x['obs'] for x in data]) plt.subplot(311)
@author: Francois Belletti ''' import numpy as np import matplotlib.pyplot as plt import matplotlib.cm as cm from surrogate.Markov_model import Markov_model from HMM_algos import Proba_computer initial = [0.1, 0.1, 0.1] A = [[0.3, 0.5, 0.3], [0.3, 0.3, 0.5], [0.5, 0.3, 0.3]] alphabet = ['o', '*', 'p', 'h'] B = [[1.0, 0.5, 0.5, 0.5], [0.5, 1.0, 0.5, 0.5], [0.5, 0.5, 1.0, 0.5]] my_markov_model = Markov_model(initial, A, B, alphabet) data = my_markov_model.generate_data(20) my_proba_computer = Proba_computer(initial, A, B, alphabet) states = np.asarray([x['state'] for x in data]) observations = [x['obs'] for x in data] gammas = my_proba_computer.compute_probas(observations) epsilons = my_proba_computer.compute_epsilons(observations) print epsilons gammas_eps = np.zeros((epsilons.shape[0], epsilons.shape[2]))
''' import numpy as np import matplotlib.pyplot as plt import matplotlib.cm as cm from surrogate.Markov_model import Markov_model from HMM_algos import Proba_computer initial = [0.1, 0.1, 0.1] A = [[0.3, 0.5, 0.3], [0.3, 0.3, 0.5], [0.5, 0.3, 0.3]] alphabet = ['o', '*', 'p', 'h'] B = [[1.0, 0.5, 0.5, 0.5], [0.5, 1.0, 0.5, 0.5], [0.5, 0.5, 1.0, 0.5]] my_markov_model = Markov_model(initial, A, B, alphabet) datas = [my_markov_model.generate_data(100) for i in xrange(100)] proba_cpter = Proba_computer(initial, A, B, alphabet) observations = [[x['obs'] for x in y] for y in datas] initial = proba_cpter.initial A = proba_cpter.A B = proba_cpter.B new_initial, new_A, new_B = proba_cpter.estimate_new_model_multi(observations)
@author: Francois Belletti ''' import numpy as np import matplotlib.pyplot as plt import matplotlib.cm as cm from surrogate.Markov_model import Markov_model from HMM_algos import Proba_computer initial = [0.1, 0.1, 0.1] A = [[0.3, 0.5, 0.3], [0.3, 0.3, 0.5], [0.5, 0.3, 0.3]] alphabet = ['o', '*', 'p', 'h'] B = [[1.0, 0.5, 0.5, 0.5], [0.5, 1.0, 0.5, 0.5], [0.5, 0.5, 1.0, 0.5]] my_markov_model = Markov_model(initial, A, B, alphabet) datas = [my_markov_model.generate_data(100) for i in xrange(100)] proba_cpter = Proba_computer(initial, A, B, alphabet) observations = [[x['obs'] for x in y] for y in datas] initial = proba_cpter.initial A = proba_cpter.A B = proba_cpter.B new_initial, new_A, new_B = proba_cpter.estimate_new_model_multi(observations) print 'Initial' print 'Model:' print initial