-
Notifications
You must be signed in to change notification settings - Fork 0
/
gp.py
38 lines (29 loc) · 910 Bytes
/
gp.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
from math import exp
import numpy as np
try:
import matplotlib.pyplot as plt
except:
import matplotlib
matplotlib.use('TkAgg')
import matplotlib.pyplot as plt
def getTimeVector(duration=16, ts=0.02):
return np.arange(0, duration, ts)
def createRandomFunction(T, display=False):
def rbf_kernel(x1, x2, variance = 1, _lambda = 12):
return exp(-1 * (((x1-x2) ** 2 ) / (_lambda ** 2)) / (variance))
def gram_matrix(xs):
return [[rbf_kernel(x1,x2) for x2 in xs] for x1 in xs]
xs = T
mean = [0 for x in xs]
gram = gram_matrix(xs)
plt_vals = []
ys = abs(np.random.multivariate_normal(mean, gram))
plt_vals.extend([xs, ys, "k"])
if display == True:
plt.plot(*plt_vals)
plt.show()
return ys
if __name__ == '__main__':
ys = createRandomFunction(T=getTimeVector(),display=True)
print(ys)
print(ys.shape)