-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
40 lines (34 loc) · 862 Bytes
/
test.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
from vppca import VPPCA
from utils.hinton import hinton
import matplotlib.pylab as plt
import numpy as np
def simulate():
N = 50
P = 10
K = 4
s = np.random.normal(0, 1, size=(N, K))
alpha = np.random.gamma(1, 1, size=(K))
A = np.empty((P, K))
for k in xrange(K):
A[:, k] = np.random.multivariate_normal(np.ones(P), (alpha[k]**-1) * np.eye(P))
y = np.empty((N, P))
mu = np.random.normal(0, 1, size=(P))
for i in xrange(N):
y[i] = np.random.multivariate_normal(A.dot(s[i])+mu, np.eye(P))
return y
def simulate2():
N = 100
P = 10
cov = np.diag([5,4,3,2,1,1,1,1,1,1])
y = np.random.multivariate_normal(np.zeros(P), cov, size=(N))
return y
def _main():
np.random.seed(0)
X = simulate2()
K = 9
model = VPPCA(K = K, n_iter = 1000, verbose = False, thresh=1e-3)
model.fit(X)
print(len(model.lbs))
hinton(model.mean_A)
plt.show()
_main()