-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.py
195 lines (170 loc) · 5.42 KB
/
config.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
import random
import numpy as np
import math
np.random.seed(1)
random.seed(1)
M = 5 # number of arms
N = 90 # number of episodes
B = 1400 # batch size
d = 40 # dimension of data
A = [0, 1, 2, 3, 4] # arm
data_size = 10000
data_buffer_counter = 0
D_kernel = 100
class Data_config():
def __init__(self, REWARD):
self.sigma_c = 0.01
self.sigma_d = 0.01
self.miu_c = 0
self.miu_d = 0
self.w_c = []
self.w_d = []
self.CLICK_prob = np.arange(0.3, 0.5, 0.2/M)
_d = d
# if reward fuction is kernel, must change dimension of theta
if REWARD == 'kernel':
_d = D_kernel
for i in range(M):
w_c_i = np.random.normal(self.miu_c, ((i + 1) * self.sigma_c) ** 2, (1, _d))
w_d_i = np.random.normal(self.miu_d, ((i + 1) * self.sigma_d) ** 2, (1, _d))
self.miu_c -= 0.2
self.miu_d += 0.2
self.w_c.append(w_c_i)
self.w_d.append(w_d_i)
class UCB_config():
def __init__(self, REWARD):
self.miu_ucb = 1.0
self.Theta = []
self.Fai = []
self.B_aj = []
# if reward fuction is kernel, must change dimension of theta
_d = d
if REWARD == 'kernel':
_d = D_kernel
for i in range(M):
theta = np.zeros((_d, 1))
self.Theta.append(theta)
fai = np.identity(_d)
self.Fai.append(fai)
b = np.zeros((_d, 1))
self.B_aj.append(b)
class DFM_config():
def __init__(self):
self.W_C = []
self.W_D = []
self.continuous = 1
for i in range(M):
self.W_C.append(np.zeros((d, 1)))
self.W_D.append(np.zeros((d, 1)))
class PR_UCB_config():
def __init__(self, REWARD):
self.alpha = 0.2
self.beta = 0
self.eta = 1.0
self.gamma = 0.1
self.Theta = []
self.Fai = []
self.B_aj = []
self.B_aj_hat = []
self.Fai_hat = []
self.psi = []
self.sketch_size = 200
# if reward fuction is kernel, must change dimension of theta
_d = d
if REWARD == 'kernel':
_d = D_kernel
for i in range(M):
theta = np.zeros((_d, 1))
self.Theta.append(theta)
b = np.zeros((_d, 1))
b_hat = np.zeros((_d, 1))
self.B_aj.append(b)
self.B_aj_hat.append(b_hat)
fai = np.zeros((_d, _d))
fai_hat = np.zeros((_d, _d))
self.Fai.append(fai)
self.Fai_hat.append(fai_hat)
psi = np.identity(_d)
self.psi.append(psi)
class EXP3S1_config():
def __init__(self):
self.Theta = []
self.Theta_capital = []
self.Fai = []
self.B_aj = []
for i in range(M):
theta = np.zeros((d, 1))
self.Theta.append(theta)
fai = np.identity(d)
self.Fai.append(fai)
b = np.zeros((d, 1))
self.B_aj.append(b)
self.Theta_capital.append([])
self.P = np.ones((M, 1))
self.Q = np.ones((M, 1))
self.delta = 0.001
self.eta = (2 * (1 - self.delta) * math.log(M) / (M * N * B)) ** 0.5
class BEXP3S1_IPW_config():
def __init__(self):
self.Theta = []
self.Theta_capital = []
self.Fai = []
self.B_aj = []
for i in range(M):
theta = np.zeros((d, 1))
self.Theta.append(theta)
fai = np.identity(d)
self.Fai.append(fai)
b = np.zeros((d, 1))
self.B_aj.append(b)
self.Theta_capital.append([])
self.P = np.ones((M, 1))
self.Q = np.ones((M, 1))
self.delta = 0.001
self.eta = (2 * (1 - self.delta) * math.log(M) / (M * N * B)) ** 0.5
self.pai = np.ones((M, 1))
class BLTS_B_config():
def __init__(self):
self.miu = 1.0
self.gamma = 0.2
self.Theta = []
self.Theta_line = []
self.Fai = []
self.B_aj = []
# if reward fuction is kernel, must change dimension of theta
_d = d
for i in range(M):
theta = np.zeros((_d, 1))
self.Theta.append(theta)
theta_line = np.zeros((_d, 1))
self.Theta_line.append(theta_line)
fai = np.identity(_d)
self.Fai.append(fai)
b = np.zeros((_d, 1))
self.B_aj.append(b)
# load data
# {a,s,r,e,y}
def load_data():
data_buffer = []
f = open('data/data_0120.txt', 'r')
lines = f.readlines()
for line in lines:
l1 = line.strip('[').strip(']').strip('\n')
l2 = l1.split('|')
# generate a and r
l2_1 = l2[1].strip('\', ').strip(']').split(', ')
a = int(eval(l2_1[0]))
r = eval(l2_1[1])
# generate s
l2_0 = l2[0].strip('], \'').split('], [')
s = []
for item in l2_0:
s.append(eval(item))
# these 2 lines used for DFM
# e = dataset[i][52]
# y = dataset[i][53]
# All algorihtms use these two lines except DFM
e = [0] * M # linear reward for pseudo-reward. At the beginning, Theta = 0, so LR=0
y = [np.sqrt(np.dot(np.array(s).T, np.array(s)))] * M # Upper confidence bound. At the beginning, Fai = identity, so UCB = <S.T, S>
data_buffer.append([a,s,r,e,y])
return np.array(data_buffer, dtype=object)