-
Notifications
You must be signed in to change notification settings - Fork 0
/
performance_plot.py
126 lines (102 loc) · 5.19 KB
/
performance_plot.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import numpy as np
import matplotlib.pyplot as plt
import os
from pathlib import Path
if __name__ == '__main__':
dataset = 'synthetic'
results_folder = 'results_performance'
# LinearUCB
filepath = Path(Path(__file__).parent, results_folder, dataset, 'LinearUCB')
cumul_regrets = []
for csv in os.listdir(filepath):
csv_path = Path(filepath, csv)
cumul_regret = np.genfromtxt(csv_path, delimiter=',')
cumul_regrets.append(cumul_regret)
cumul_regrets = np.array(cumul_regrets)
cumul_regrets_mean = np.mean(cumul_regrets, axis=0)
cumul_regrets_mean_with_std = cumul_regrets_mean + np.std(cumul_regrets, axis=0)
plt.plot(cumul_regrets_mean, label='LinearUCB ($\lambda$ = 1, $\\nu = 1$)')
plt.fill_between(np.arange(len(cumul_regrets_mean)), cumul_regrets_mean, cumul_regrets_mean_with_std, alpha=0.4)
plt.legend()
# LinearTS
filepath = Path(Path(__file__).parent, results_folder, dataset, 'LinearTS')
cumul_regrets = []
for csv in os.listdir(filepath):
csv_path = Path(filepath, csv)
cumul_regret = np.genfromtxt(csv_path, delimiter=',')
cumul_regrets.append(cumul_regret)
cumul_regrets = np.array(cumul_regrets)
cumul_regrets_mean = np.mean(cumul_regrets, axis=0)
cumul_regrets_mean_with_std = cumul_regrets_mean + np.std(cumul_regrets, axis=0)
plt.plot(cumul_regrets_mean, label='LinearTS ($\lambda$ = 1, $\\nu = 10^{-2}$)')
plt.fill_between(np.arange(len(cumul_regrets_mean)), cumul_regrets_mean, cumul_regrets_mean_with_std, alpha=0.4)
plt.legend()
# KernelUCB
filepath = Path(Path(__file__).parent, results_folder, dataset, 'KernelUCB')
cumul_regrets = []
for csv in os.listdir(filepath):
csv_path = Path(filepath, csv)
cumul_regret = np.genfromtxt(csv_path, delimiter=',')
cumul_regrets.append(cumul_regret)
cumul_regrets = np.array(cumul_regrets)
cumul_regrets_mean = np.mean(cumul_regrets, axis=0)
cumul_regrets_mean_with_std = cumul_regrets_mean + np.std(cumul_regrets, axis=0)
plt.plot(cumul_regrets_mean, label='KernelUCB ($\lambda$ = 1, $\\nu = 1$)')
plt.fill_between(np.arange(len(cumul_regrets_mean)), cumul_regrets_mean, cumul_regrets_mean_with_std, alpha=0.4)
plt.legend()
# KernelTS
filepath = Path(Path(__file__).parent, results_folder, dataset, 'KernelTS')
cumul_regrets = []
for csv in os.listdir(filepath):
csv_path = Path(filepath, csv)
cumul_regret = np.genfromtxt(csv_path, delimiter=',')
cumul_regrets.append(cumul_regret)
cumul_regrets = np.array(cumul_regrets)
cumul_regrets_mean = np.mean(cumul_regrets, axis=0)
cumul_regrets_mean_with_std = cumul_regrets_mean + np.std(cumul_regrets, axis=0)
plt.plot(cumul_regrets_mean, label='KernelTS ($\lambda$ = 1, $\\nu = 10^{-2}$)')
plt.fill_between(np.arange(len(cumul_regrets_mean)), cumul_regrets_mean, cumul_regrets_mean_with_std, alpha=0.4)
plt.legend()
# NeuralUCB
filepath = Path(Path(__file__).parent, results_folder, dataset, 'NeuralUCB')
cumul_regrets = []
for csv in os.listdir(filepath):
csv_path = Path(filepath, csv)
cumul_regret = np.genfromtxt(csv_path, delimiter=',')
cumul_regrets.append(cumul_regret)
cumul_regrets = np.array(cumul_regrets)
cumul_regrets_mean = np.mean(cumul_regrets, axis=0)
cumul_regrets_mean_with_std = cumul_regrets_mean + np.std(cumul_regrets, axis=0)
plt.plot(cumul_regrets_mean, label='NeuralUCB ($\lambda$ = 1, $\\nu = 10^{-1}$)')
plt.fill_between(np.arange(len(cumul_regrets_mean)), cumul_regrets_mean, cumul_regrets_mean_with_std, alpha=0.4)
plt.legend()
# NeuralTS
filepath = Path(Path(__file__).parent, results_folder, dataset, 'NeuralTS')
cumul_regrets = []
for csv in os.listdir(filepath):
csv_path = Path(filepath, csv)
cumul_regret = np.genfromtxt(csv_path, delimiter=',')
cumul_regrets.append(cumul_regret)
cumul_regrets = np.array(cumul_regrets)
cumul_regrets_mean = np.mean(cumul_regrets, axis=0)
cumul_regrets_mean_with_std = cumul_regrets_mean + np.std(cumul_regrets, axis=0)
plt.plot(cumul_regrets_mean, label='NeuralTS ($\lambda$ = 1, $\\nu = 10^{-2}$)')
plt.fill_between(np.arange(len(cumul_regrets_mean)), cumul_regrets_mean, cumul_regrets_mean_with_std, alpha=0.4)
plt.legend()
# NeuralRandUCB
filepath = Path(Path(__file__).parent, results_folder, dataset, 'NeuralRandUCB')
cumul_regrets = []
for csv in os.listdir(filepath):
csv_path = Path(filepath, csv)
cumul_regret = np.genfromtxt(csv_path, delimiter=',')
cumul_regrets.append(cumul_regret)
cumul_regrets = np.array(cumul_regrets)
cumul_regrets_mean = np.mean(cumul_regrets, axis=0)
cumul_regrets_mean_with_std = cumul_regrets_mean + np.std(cumul_regrets, axis=0)
plt.plot(cumul_regrets_mean, label='NeuralRandUCB')
plt.fill_between(np.arange(len(cumul_regrets_mean)), cumul_regrets_mean, cumul_regrets_mean_with_std, alpha=0.4)
plt.xlabel('# of rounds')
plt.ylabel('Cumulative regret')
#plt.title(f'Performance on {dataset}')
plt.legend()
plt.savefig(f"performance_{dataset}.png")