-
Notifications
You must be signed in to change notification settings - Fork 57
/
visualization.py
111 lines (77 loc) · 3.07 KB
/
visualization.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import cm
fgp = __import__('FaST-GP')
def ls_sample_2d(ls_list=[3, 10, 30, 100], xmin=5, xmax=30, ymin=5, ymax=26):
x = np.linspace(xmin, xmax)
y = np.linspace(ymin, ymax)
X1, X2 = np.meshgrid(x, y)
X = np.vstack((X1.flatten(), X2.flatten())).T
for i, ls in enumerate(ls_list):
K = fgp.SE_kernel(X, ls)
Y = np.random.multivariate_normal(0 * X[:, 0], K)
plt.subplot(1, len(ls_list), i + 1)
plt.pcolormesh(X1, X2, Y.reshape(X1.shape), cmap=cm.inferno)
plt.contour(X1, X2, Y.reshape(X1.shape), cmap=cm.inferno)
plt.axis('equal')
plt.title('$ \ell = {} $'.format(ls))
fig = plt.gcf()
fig.set_size_inches(9, 3)
plt.savefig('ls_guide.png')
def ls_sample_1d(ls_list=[3, 10, 30, 100], xmin=5, xmax=30):
X = np.linspace(xmin, xmax)[:, None]
for i, ls in enumerate(ls_list):
K = fgp.SE_kernel(X, ls)
Y = np.random.multivariate_normal(0 * X[:, 0], K)
plt.subplot(1, len(ls_list), i + 1)
plt.plot(X, Y)
plt.title('$ \ell = {} $'.format(ls))
fig = plt.gcf()
fig.set_size_inches(9, 3)
plt.savefig('1d_ls_guide_.png')
def linear_sample_2d(xmin=5, xmax=30, ymin=5, ymax=26):
x = np.linspace(xmin, xmax)
y = np.linspace(ymin, ymax)
X1, X2 = np.meshgrid(x, y)
X = np.vstack((X1.flatten(), X2.flatten())).T
K = fgp.linear_kernel(X)
Y = np.random.multivariate_normal(0 * X[:, 0], K)
plt.pcolormesh(X1, X2, Y.reshape(X1.shape), cmap=cm.inferno)
plt.contour(X1, X2, Y.reshape(X1.shape), cmap=cm.inferno)
plt.axis('equal')
fig = plt.gcf()
fig.set_size_inches(9, 3)
plt.savefig('linear_guide.png')
def period_sample_2d(p_list=[3, 10, 30, 100], xmin=5, xmax=30, ymin=5, ymax=26):
x = np.linspace(xmin, xmax)
y = np.linspace(ymin, ymax)
X1, X2 = np.meshgrid(x, y)
X = np.vstack((X1.flatten(), X2.flatten())).T
for i, p in enumerate(p_list):
K = fgp.cosine_kernel(X, p)
Y = np.random.multivariate_normal(0 * X[:, 0], K)
plt.subplot(1, len(p_list), i + 1)
plt.pcolormesh(X1, X2, Y.reshape(X1.shape), cmap=cm.inferno)
plt.contour(X1, X2, Y.reshape(X1.shape), cmap=cm.inferno)
plt.axis('equal')
plt.title('$ p = {} $'.format(p))
fig = plt.gcf()
fig.set_size_inches(9, 3)
plt.savefig('p_guide.png')
def period_sample_1d(p_list=[3, 10, 30, 100], xmin=5, xmax=30):
X = np.linspace(xmin, xmax, 50*50)[:, None]
for i, p in enumerate(p_list):
K = fgp.cosine_kernel(X, p)
Y = np.random.multivariate_normal(0 * X[:, 0], K)
plt.subplot(1, len(p_list), i + 1)
plt.plot(X, Y)
plt.title('$ p = {} $'.format(p))
fig = plt.gcf()
fig.set_size_inches(9, 3)
plt.savefig('1d_p_guide_.png')
if __name__ == '__main__':
# ls_sample_2d([1., 5., 10., 20.])
# linear_sample_2d()
period_sample_2d([3., 10., 30., 100.], xmin=0., xmax=200, ymin=0., ymax=250)
# ls_sample_1d([1., 5., 10., 20.])
# period_sample_1d([1., 5., 10., 20.])