-
Notifications
You must be signed in to change notification settings - Fork 11
/
sc_beam.py
77 lines (63 loc) · 1.29 KB
/
sc_beam.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
from emission_new import Gaussian
from duration_new import Poisson
from transition_new import Transition
from initial import Initial
from edhmm import EDHMM
import pylab as pb
import numpy as np
import logging
import sys
logging.basicConfig(
stream=sys.stdout,
#filename="EDHMM.log",
#filemode="w",
level=logging.DEBUG
)
A = Transition(
K=3,
A=pb.array([[0, 0.3, 0.7], [0.6, 0, 0.4], [0.3, 0.7, 0]])
)
O = Gaussian(
nu = 1,
Lambda = np.array([1]),
mu_0 = [0, 0, 0],
kappa = 0.01,
mu = [-3, 0, 3],
tau = [
np.array([[1]]),
np.array([[1]]),
np.array([[1]])
]
)
D = Poisson(
mu = [5,15,20],
alpha=[1, 1, 1],
beta=[0.0001, 0.0001, 0.0001],
support_step = 20
)
pi = Initial(K=3,beta=0.001)
m = EDHMM(A,O,D,pi)
T = 500
X,Y,Dseq = m.sim(T)
Z = zip(X,Dseq)
L_prior = m.loglikelihood([Z], [Y])
print L_prior
np.save("X.npy", X)
np.save("D.npy", Dseq)
np.save("Y.npy", Y)
np.save("Z.npy", zip(X,Dseq))
if True:
m.A.A = pb.array(
[[0, 0.5, 0.5],
[0.5, 0, 0.5],
[0.5, 0.5, 0]]
)
m.O.mu = [-1,0,1]
m.D.mu = [1,1,1]
L = m.beam(
[Y], min_u = 0, its=11, burnin=1, name="test", online=True,
sample_U=True
)
pb.figure()
pb.plot(L)
pb.savefig("L.pdf")