示例#1
0
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)
plt.imshow(forwards, cmap = cm.gray)

backwards = my_proba_computer.compute_backward_probas([x['obs'] for x in data])

plt.subplot(312)
plt.imshow(backwards, cmap = cm.gray)
示例#2
0
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]))

for t in xrange(gammas_eps.shape[1]):
    gammas_eps[:, t] = np.sum(epsilons[:, :, t], axis=1)
示例#3
0
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
print 'Estimated'
print new_initial
示例#4
0
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)
plt.imshow(forwards, cmap=cm.gray)

backwards = my_proba_computer.compute_backward_probas([x['obs'] for x in data])

plt.subplot(312)
plt.imshow(backwards, cmap=cm.gray)

probas = my_proba_computer.compute_probas([x['obs'] for x in data])
示例#5
0
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 = [[1.0, 0.5, 0.5], [0.5, 1.0, 0.5], [0.5, 0.5, 1.0]]

my_markov_model = Markov_model(initial,
                               A,
                               B,
                               alphabet)

data = my_markov_model.generate_data(10)
      
my_forward_proba = Proba_computer(initial,
                                 A,
                                 B,
                                 alphabet)

print [x['state'] for x in data]
print [x['obs'] for x in data]

forward_probas = my_forward_proba.compute_forward_probas([x['obs'] for x in data])

for i in xrange(forward_probas.shape[1]):
    print forward_probas[:,i]

plt.imshow(forward_probas, cmap = cm.gray)
plt.clim()
plt.show()
示例#6
0
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]))

for t in xrange(gammas_eps.shape[1]):
    gammas_eps[:, t] = np.sum(epsilons[:, :, t], axis=1)
示例#7
0
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(100)
      
proba_cpter = Proba_computer(initial,
                             A,
                             B,
                             alphabet)

states = np.asarray([x['state'] for x in data])
observations = [x['obs'] for x in data]

actual_initial = proba_cpter.initial
actual_A = proba_cpter.A
actual_B = proba_cpter.B

for i in xrange(100):
    initial = proba_cpter.initial
    A = proba_cpter.A
    B = proba_cpter.B
    new_initial, new_A, new_B = proba_cpter.estimate_new_model(observations)
    print 'Initial'
示例#8
0
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 = [[1.0, 0.5, 0.5], [0.5, 1.0, 0.5], [0.5, 0.5, 1.0]]

my_markov_model = Markov_model(initial,
                               A,
                               B,
                               alphabet)

data = my_markov_model.generate_data(10)
      
my_forward_proba = Proba_computer(initial,
                                 A,
                                 B,
                                 alphabet)

print [x['state'] for x in data]
print [x['obs'] for x in data]

forward_probas = my_forward_proba.compute_forward_probas([x['obs'] for x in data])

for i in xrange(forward_probas.shape[1]):
    print forward_probas[:,i]

plt.imshow(forward_probas, cmap = cm.gray)
plt.clim()
plt.show()
示例#9
0
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
print 'Estimated'
print new_initial

print '\n'
示例#10
0
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(100)

proba_cpter = Proba_computer(initial, A, B, alphabet)

states = np.asarray([x["state"] for x in data])
observations = [x["obs"] for x in data]

actual_initial = proba_cpter.initial
actual_A = proba_cpter.A
actual_B = proba_cpter.B

for i in xrange(100):
    initial = proba_cpter.initial
    A = proba_cpter.A
    B = proba_cpter.B
    new_initial, new_A, new_B = proba_cpter.estimate_new_model(observations)
    print "Initial"
    print "Model:"