-
Notifications
You must be signed in to change notification settings - Fork 0
/
experiment-DSAR.py
48 lines (40 loc) · 1.07 KB
/
experiment-DSAR.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
import matplotlib.pyplot as plt
import numpy as np
from algorithms.dsar import DSAR
from environments.gaussian_jun import linear_bandit, linear_means
n=200
steps = 150000
m = 10
arms_n = 1000
variance = 0.25
linearmeans = linear_means(arms_n)
J_t_result = np.zeros((2,steps))
for i in range(n):
lin_bandits = linear_bandit(arms_n, variance)
J_t_n = np.zeros((2,steps))
algo = DSAR(lin_bandits, m)
for t in range(steps):
J_t = algo.step(t)
top_m = [linearmeans[int(k)] for k in J_t]
J_t_n[0][t] = np.min(top_m)
J_t_n[1][t] = np.sum(top_m)
J_t_result = J_t_result+J_t_n
result = J_t_result/n
plt.figure(1)
plt.title('DSAR m = 10', fontweight='bold')
plt.xlabel('t')
plt.ylabel('min')
plt.plot(result[0],'b-',color='r',label='DSAR')
plt.legend()
plt.xlim(0,steps)
plt.ylim(0.5,0.9)
plt.savefig('lin_DSAR_min.png')
plt.figure(2)
plt.title('DSAR m = 10', fontweight='bold')
plt.xlabel('t')
plt.ylabel('sum')
plt.plot(result[1],'b-',color='r',label='DSAR')
plt.legend()
plt.xlim(0,steps)
plt.ylim(7.8,9.0)
plt.savefig('lin_DSAR_sum.png')