-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIGPR_test.py
78 lines (63 loc) · 1.98 KB
/
IGPR_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
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
from IGPR import IGPR
import numpy as np
import csv
import matplotlib.pyplot as plt
from matplotlib.gridspec import GridSpec
def load_csv(file_name):
with open(file_name, "r") as f:
reader = csv.reader(f)
columns = [row for row in reader]
columns = np.array(columns)
m_x, n_x = columns.shape
data_set = np.zeros((m_x, n_x))
for i in range(m_x):
for j in range(n_x):
data_set[i][j] = float(columns[i][j])
return data_set
training_set = load_csv('training_set.csv')
training_target = load_csv('training_target.csv')
test_set = load_csv('test_set.csv')
test_target = load_csv('test_target.csv')
data_len = 5000
print('iter 0')
igpr = IGPR(training_set[0, :], training_target[0, :])
print(igpr.k_matrix)
print(igpr.inv_k_matrix)
print(" ")
for i in range(1, data_len):
print('iter', i)
igpr.learn(training_set[i, :], training_target[i, :])
print(" ")
pred = igpr.predict(training_set[0, :])
for i in range(1, data_len):
pred = np.vstack((pred, igpr.predict(training_set[i, :])))
fig = plt.figure(figsize=(5, 5))
gs = GridSpec(3, 2, figure=fig)
ax1 = fig.add_subplot(gs[0, 0])
ax2 = fig.add_subplot(gs[1, 0])
ax3 = fig.add_subplot(gs[2, 0])
ax4 = fig.add_subplot(gs[0, 1])
ax5 = fig.add_subplot(gs[1, 1])
ax6 = fig.add_subplot(gs[2, 1])
ax1.plot(training_target[0:data_len, 0])
ax2.plot(training_target[0:data_len, 1])
ax3.plot(training_target[0:data_len, 2])
ax4.plot(pred[0:data_len, 0])
ax5.plot(pred[0:data_len, 1])
ax6.plot(pred[0:data_len, 2])
plt.show()
fig = plt.figure(figsize=(5, 5))
gs = GridSpec(3, 2, figure=fig)
ax1 = fig.add_subplot(gs[0, 0])
ax2 = fig.add_subplot(gs[1, 0])
ax3 = fig.add_subplot(gs[2, 0])
ax4 = fig.add_subplot(gs[0, 1])
ax5 = fig.add_subplot(gs[1, 1])
ax6 = fig.add_subplot(gs[2, 1])
ax1.plot(training_target[0:data_len, 3])
ax2.plot(training_target[0:data_len, 4])
ax3.plot(training_target[0:data_len, 5])
ax4.plot(pred[0:data_len, 3])
ax5.plot(pred[0:data_len, 4])
ax6.plot(pred[0:data_len, 5])
plt.show()