-
Notifications
You must be signed in to change notification settings - Fork 18
/
experiments.py
238 lines (198 loc) · 13.3 KB
/
experiments.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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
import REMBO
import count_sketch
import numpy as np
import pickle
import timeit
import sys
from random import sample
from pyDOE import lhs
def REMBO_experiments(start_rep=1, stop_rep=50, test_func='Rosenbrock', total_itr=100,
low_dim=2, high_dim=25, initial_n=20, opt_interval=20, ARD=False,
box_size=None, noise_var=0):
if box_size is None:
box_size=np.sqrt(low_dim)
all_A = np.random.normal(0, 1, [stop_rep, low_dim, high_dim])
all_s = np.empty((stop_rep, initial_n, low_dim))
for i in range(stop_rep):
all_s[i] = lhs(low_dim, initial_n) * 2 * box_size - box_size
result_x_obj = np.empty((0, total_itr+initial_n))
result_y_obj = np.empty((0, total_itr+initial_n))
result_psi_obj = np.empty((0, total_itr+initial_n))
elapsed_x = np.empty((0, total_itr + initial_n))
elapsed_y = np.empty((0, total_itr + initial_n))
elapsed_psi = np.empty((0, total_itr + initial_n))
result_x_s = np.empty((0, initial_n + total_itr, low_dim))
result_x_f_s = np.empty((0, initial_n + total_itr, 1))
result_y_s = np.empty((0, initial_n + total_itr, low_dim))
result_y_f_s = np.empty((0, initial_n + total_itr, 1))
result_psi_s = np.empty((0, initial_n + total_itr, low_dim))
result_psi_f_s = np.empty((0, initial_n + total_itr, 1))
for i in range(start_rep - 1, stop_rep):
start = timeit.default_timer()
active_var = sample(range(high_dim), low_dim)
# Running different algorithms to solve Hartmann6 function
temp_result, temp_elapsed, temp_s, temp_f_s, _, _ = REMBO.RunRembo(low_dim=low_dim, high_dim=high_dim, initial_n=initial_n,
total_itr=total_itr, func_type=test_func, A_input=all_A[i],
s=all_s[i], kern_inp_type='Y', matrix_type='simple',
hyper_opt_interval=opt_interval, ARD=ARD, box_size=box_size,
noise_var=noise_var)
result_y_obj = np.append(result_y_obj, temp_result, axis=0)
elapsed_y = np.append(elapsed_y, temp_elapsed, axis=0)
result_y_s = np.append(result_y_s, [temp_s], axis=0)
result_y_f_s = np.append(result_y_f_s, [temp_f_s], axis=0)
temp_result, temp_elapsed, temp_s, temp_f_s, _, _ = REMBO.RunRembo(low_dim=low_dim, high_dim=high_dim, initial_n=initial_n,
total_itr=total_itr, func_type=test_func, A_input=all_A[i],
s=all_s[i], kern_inp_type='X', matrix_type='simple',
hyper_opt_interval=opt_interval, ARD=ARD, box_size=box_size,
noise_var=noise_var)
result_x_obj = np.append(result_x_obj, temp_result, axis=0)
elapsed_x = np.append(elapsed_x, temp_elapsed, axis=0)
result_x_s = np.append(result_x_s, [temp_s], axis=0)
result_x_f_s = np.append(result_x_f_s, [temp_f_s], axis=0)
temp_result, temp_elapsed, temp_s, temp_f_s, _, _ = REMBO.RunRembo(low_dim=low_dim, high_dim=high_dim, initial_n=initial_n,
total_itr=total_itr, func_type=test_func, A_input=all_A[i],
s=all_s[i], kern_inp_type='psi', matrix_type='simple',
hyper_opt_interval=opt_interval, ARD=ARD, box_size=box_size,
noise_var=noise_var)
result_psi_obj = np.append(result_psi_obj, temp_result, axis=0)
elapsed_psi = np.append(elapsed_psi, temp_elapsed, axis=0)
result_psi_s = np.append(result_psi_s, [temp_s], axis=0)
result_psi_f_s = np.append(result_psi_f_s, [temp_f_s], axis=0)
stop = timeit.default_timer()
print(i)
print(stop - start)
# Saving the results for Hartmann6 in a pickle
if test_func=='Rosenbrock':
file_name = 'result/rosenbrock_results_d'+str(low_dim)+'_D'+str(high_dim)+'_n'+str(initial_n)+'_rep_' + str(start_rep) + '_' + str(stop_rep)
elif test_func=='Branin':
file_name = 'result/branin_results_d'+str(low_dim)+'_D'+str(high_dim)+'_n'+str(initial_n)+'_rep_' + str(start_rep) + '_' + str(stop_rep)
elif test_func == 'Hartmann6':
file_name = 'result/hartmann6_results_d'+str(low_dim)+'_D'+str(high_dim)+'_n'+str(initial_n)+'_rep_' + str(start_rep) + '_' + str(stop_rep)
elif test_func == 'StybTang':
file_name = 'result/stybtang_results_d'+str(low_dim)+'_D'+str(high_dim)+'_n'+str(initial_n)+'_rep_' + str(start_rep) + '_' + str(stop_rep)
elif test_func == 'WalkerSpeed':
file_name = 'result/walkerspeed_results_d'+str(low_dim)+'_D'+str(high_dim)+'_n'+str(initial_n)+'_rep_' + str(start_rep) + '_' + str(stop_rep)
elif test_func == 'MNIST':
file_name = 'result/mnist_results_d' + str(low_dim) + '_D' + str(high_dim) + '_n' + str(initial_n) + '_rep_' + str(start_rep) + '_' + str(stop_rep)
fileObject = open(file_name, 'wb')
pickle.dump(result_y_obj, fileObject)
pickle.dump(result_x_obj, fileObject)
pickle.dump(result_psi_obj, fileObject)
pickle.dump(elapsed_y, fileObject)
pickle.dump(elapsed_x, fileObject)
pickle.dump(elapsed_psi, fileObject)
pickle.dump(result_y_s, fileObject)
pickle.dump(result_x_s, fileObject)
pickle.dump(result_psi_s, fileObject)
pickle.dump(result_y_f_s, fileObject)
pickle.dump(result_x_f_s, fileObject)
pickle.dump(result_psi_f_s, fileObject)
fileObject.close()
def REMBO_separate(start_rep=1, stop_rep=50, test_func='Rosenbrock', total_itr=100, low_dim=2,
high_dim=25, initial_n=20, opt_interval=20, ARD=False, box_size=None,
kern_inp_type='Y', noise_var=0):
if box_size is None:
box_size=np.sqrt(low_dim)
all_A = np.random.normal(0, 1, [stop_rep, low_dim, high_dim])
all_s = np.empty((stop_rep, initial_n, low_dim))
for i in range(stop_rep):
all_s[i] = lhs(low_dim, initial_n) * 2 * box_size - box_size
result_x_obj = np.empty((0, total_itr+initial_n))
elapsed_x = np.empty((0, total_itr + initial_n))
result_x_s = np.empty((0, initial_n + total_itr, low_dim))
result_x_f_s = np.empty((0, initial_n + total_itr, 1))
result_high_s = np.empty((0, initial_n + total_itr, high_dim))
for i in range(start_rep - 1, stop_rep):
start = timeit.default_timer()
active_var = sample(range(high_dim), low_dim)
# Running different algorithms to solve Hartmann6 function
temp_result, temp_elapsed, temp_s, temp_f_s, _, temp_high_s = REMBO.RunRembo(low_dim=low_dim, high_dim=high_dim, initial_n=initial_n,
total_itr=total_itr, func_type=test_func, A_input=all_A[i],
s=all_s[i], kern_inp_type=kern_inp_type, matrix_type='simple',
hyper_opt_interval=opt_interval, ARD=ARD, box_size=box_size,
noise_var=noise_var)
result_x_obj = np.append(result_x_obj, temp_result, axis=0)
elapsed_x = np.append(elapsed_x, temp_elapsed, axis=0)
result_high_s = np.append(result_high_s, [temp_high_s], axis=0)
result_x_s = np.append(result_x_s, [temp_s], axis=0)
result_x_f_s = np.append(result_x_f_s, [temp_f_s], axis=0)
stop = timeit.default_timer()
print(i)
print(stop - start)
# Saving the results for Hartmann6 in a pickle
if test_func=='Rosenbrock':
file_name = 'result/rosenbrock_results_' + kern_inp_type + '_d'+str(low_dim)+'_D'+str(high_dim)+'_n'+str(initial_n)+'_rep_' + str(start_rep) + '_' + str(stop_rep)
elif test_func=='Branin':
file_name = 'result/branin_results_' + kern_inp_type + '_d'+str(low_dim)+'_D'+str(high_dim)+'_n'+str(initial_n)+'_rep_' + str(start_rep) + '_' + str(stop_rep)
elif test_func == 'Hartmann6':
file_name = 'result/hartmann6_results_' + kern_inp_type + '_d' + str(low_dim)+'_D'+str(high_dim)+'_n'+str(initial_n)+'_rep_' + str(start_rep) + '_' + str(stop_rep)
elif test_func == 'StybTang':
file_name = 'result/stybtang_results_' + kern_inp_type + '_d' + str(low_dim)+'_D'+str(high_dim)+'_n'+str(initial_n)+'_rep_' + str(start_rep) + '_' + str(stop_rep)
elif test_func == 'WalkerSpeed':
file_name = 'result/walkerspeed_results_' + kern_inp_type + '_d' + str(low_dim)+'_D'+str(high_dim)+'_n'+str(initial_n)+'_rep_' + str(start_rep) + '_' + str(stop_rep)
elif test_func == 'MNIST':
file_name = 'result/mnist_results_' + kern_inp_type + '_d' + str(low_dim) + '_D' + str(high_dim) + '_n' + str(initial_n) + '_rep_' + str(start_rep) + '_' + str(stop_rep)
fileObject = open(file_name, 'wb')
pickle.dump(result_x_obj, fileObject)
pickle.dump(elapsed_x, fileObject)
pickle.dump(result_high_s, fileObject)
pickle.dump(result_x_s, fileObject)
pickle.dump(result_x_f_s, fileObject)
fileObject.close()
def count_sketch_BO_experiments(start_rep=1, stop_rep=50, test_func='Rosenbrock', total_itr=100,
low_dim=2, high_dim=25, initial_n=20, ARD=False, box_size=None,
noise_var=0):
result_obj = np.empty((0, total_itr+initial_n))
elapsed = np.empty((0, total_itr + initial_n))
result_s = np.empty((0, initial_n + total_itr, low_dim))
result_f_s = np.empty((0, initial_n + total_itr, 1))
result_high_s = np.empty((0, initial_n + total_itr, high_dim))
for i in range(start_rep - 1, stop_rep):
start = timeit.default_timer()
temp_result, temp_elapsed, temp_s, temp_f_s, _, temp_high_s = count_sketch.RunMain(low_dim=low_dim, high_dim=high_dim, initial_n=initial_n,
total_itr=total_itr, func_type=test_func, s=None, ARD=ARD,
box_size=box_size, noise_var=noise_var)
result_obj = np.append(result_obj, temp_result, axis=0)
elapsed = np.append(elapsed, temp_elapsed, axis=0)
result_s = np.append(result_s, [temp_s], axis=0)
result_f_s = np.append(result_f_s, [temp_f_s], axis=0)
result_high_s = np.append(result_high_s, [temp_high_s], axis=0)
stop = timeit.default_timer()
print(i)
print(stop - start)
# Saving the results for Hartmann6 in a pickle
if test_func == 'Rosenbrock':
file_name = 'result/rosenbrock_results_CS_d' + str(low_dim) + '_D' + str(high_dim) + '_n' + str(initial_n) + '_rep_' + str(start_rep) + '_' + str(stop_rep)
elif test_func == 'Branin':
file_name = 'result/branin_results_CS_d' + str(low_dim) + '_D' + str(high_dim) + '_n' + str(initial_n) + '_rep_' + str(start_rep) + '_' + str(stop_rep)
elif test_func == 'Hartmann6':
file_name = 'result/hartmann6_results_CS_d' + str(low_dim) + '_D' + str(high_dim) + '_n' + str(initial_n) + '_rep_' + str(start_rep) + '_' + str(stop_rep)
elif test_func == 'StybTang':
file_name = 'result/stybtang_results_CS_d' + str(low_dim) + '_D' + str(high_dim) + '_n' + str(initial_n) + '_rep_' + str(start_rep) + '_' + str(stop_rep)
elif test_func == 'WalkerSpeed':
file_name = 'result/walkerspeed_results_CS_d' + str(low_dim) + '_D' + str(high_dim) + '_n' + str(initial_n) + '_rep_' + str(start_rep) + '_' + str(stop_rep)
elif test_func == 'MNIST':
file_name = 'result/mnist_results_CS_d' + str(low_dim) + '_D' + str(high_dim) + '_n' + str(initial_n) + '_rep_' + str(start_rep) + '_' + str(stop_rep)
fileObject = open(file_name, 'wb')
pickle.dump(result_obj, fileObject)
pickle.dump(elapsed, fileObject)
pickle.dump(result_s, fileObject)
pickle.dump(result_f_s, fileObject)
fileObject.close()
if __name__=='__main__':
start_rep = int(sys.argv[2])
stop_rep = int(sys.argv[3])
test_func = sys.argv[4]
total_iter = int(sys.argv[5])
low_dim = int(sys.argv[6])
high_dim = int(sys.argv[7])
initial_n = int(sys.argv[8])
variance = int(sys.argv[9])
if sys.argv[1]=='REMBO':
if len(sys.argv)<=10:
REMBO_experiments(start_rep=start_rep, stop_rep=stop_rep, test_func=test_func, total_itr=total_iter, low_dim=low_dim, high_dim=high_dim, initial_n=initial_n, ARD=True, noise_var=variance)
else:
kern_type = sys.argv[10]
REMBO_separate(start_rep=start_rep, stop_rep=stop_rep, test_func=test_func, total_itr=total_iter, low_dim=low_dim, high_dim=high_dim, initial_n=initial_n, ARD=True, kern_inp_type=kern_type, noise_var=variance)
elif sys.argv[1]=='HeSBO':
count_sketch_BO_experiments(start_rep=start_rep, stop_rep=stop_rep, test_func=test_func, total_itr=total_iter, low_dim=low_dim, high_dim=high_dim, initial_n=initial_n, ARD=True, box_size=1, noise_var=variance)