-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.py
35 lines (28 loc) · 1.03 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import hmm as gmove
import numpy as np
from hmmlearn import hmm
# X_example = np.array([[40, -70, 42320, 0],
# [42, -71, 43989, 1],
# [38, -72, 32324, 2],
# [42, -70, 23222, 3],
# [37, -71, 81999, 3]])
length_example = [3, 2]
weight_example = [1/2, 1/2]
X_example = np.array([[0],
[0],
[0],
[1]])
# model = gmove.GroupLevelHMM(n_components=2, init_params='mce')
# model.set_weights(weight_example)
# model.fit(X_example, length_example)
model = hmm.MultinomialHMM(n_components=3)
model.fit(X_example, length_example)
print(model.score(X_example))
# model._init(X_example, length_example)
# obs = X_example[0:3]
# framelogprob = model._compute_log_likelihood(obs)
# logprob, fwdlattice = model._do_forward_pass(framelogprob)
# bwdlattice = model._do_backward_pass(framelogprob)
# posteriors = model._compute_posteriors(fwdlattice, bwdlattice)
# stats = model._initialize_sufficient_statistics()
# model._accumulate_sufficient_statistics(stats, obs, framelogprob, posteriors, fwdlattice, bwdlattice)