-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot_results.py
203 lines (147 loc) · 8.76 KB
/
plot_results.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
'''
Name: plot_results.py
Authors: Julian Berk and Vu Nguyen
Publication date:08/04/2019
Inputs: #Pickle files produced by bayesianOptimizationMaster.py
#function_name: The name of the function used in the experiment as
defined in functions.py
#input_dim: The dimension of the function used
#iteration_factor: This is multiplied with input_dim to determine the
number of iterations the experiments were run for
#pickle_location: The location of the pickleStorage folder
Outputs: Plots the results contained in the input pickle files
Instructions:To suppress the results for an algorithm, comment the code bewteen
the "##ALGORITHM#NAME##" and "##ALGORITHM#NAME#END##" comments. The plot
settings eg. axis labels can be found at the end of the file, with the
exception of the figure size which is at the start
'''
###############################################################################
import sys
sys.path.insert(0,'../../')
import pickle
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
#from prada_bayes_opt import visualization
from prada_bayes_opt import auxiliary_functions
from prada_bayes_opt.utility import export_results
import matplotlib
class plot(object):
def __init__(self,function_name,input_dim,iteration_factor,pickle_location):
sns.set(style="ticks")
#change this to alter the figure size
fig=plt.figure(figsize=(10, 7))
##############
function_name=function_name
D=input_dim
y_optimal_value=0
step=2
mylinewidth=2
std_scale=0.4
T=iteration_factor*D+1
BatchSz_GPyOpt=[1]*T
BatchSz_GPyOpt[0]=D+1
BatchSz_BigBound=[1]*T
BatchSz_BigBound[0]=D+1
x_axis=np.array(range(0,T+1))
x_axis=x_axis[::step]
# is minimization problem
IsMin=1
#IsMin=-1
IsLog=0
######################################Fixed#Bound##############################
strFile=pickle_location+"\\{:s}_{:d}_Single_ei_fixed.pickle".format(function_name,D)
with open(strFile) as f:
EI = pickle.load(f)
myYbest,myStd,myYbestCum,myStdCum=auxiliary_functions.yBest_Iteration(EI[0],BatchSz_BigBound,IsPradaBO=1,Y_optimal=1,step=step)
ACSR_mean,ACSR_std=export_results.compute_average_cumulative_simple_regret(EI[0],BatchSz_GPyOpt,IsPradaBO=1,Y_optimal=y_optimal_value)
print "EI ACSR {:.4f}({:.4f})".format(ACSR_mean,ACSR_std)
myYbest=IsMin*np.asarray(myYbest)
if IsLog==1:
myYbest=np.log(myYbest)
myStd=np.log(myStd)
myStd=myStd*std_scale
plt.errorbar(x_axis,-myYbest,yerr=myStd/np.sqrt(10),linewidth=mylinewidth,color='b',linestyle='-',marker='h', label='Standard bound')
######################################Fixed#Bound#END##########################
######################################Regularised##############################
strFile=pickle_location+"\\{:s}_{:d}_Single_ei_regularizerH_fixed.pickle".format(function_name,D)
with open(strFile) as f:
EI = pickle.load(f)
myYbest,myStd,myYbestCum,myStdCum=auxiliary_functions.yBest_Iteration(EI[0],BatchSz_BigBound,IsPradaBO=1,Y_optimal=1,step=step)
ACSR_mean,ACSR_std=export_results.compute_average_cumulative_simple_regret(EI[0],BatchSz_GPyOpt,IsPradaBO=1,Y_optimal=y_optimal_value)
print "EI ACSR {:.4f}({:.4f})".format(ACSR_mean,ACSR_std)
myYbest=IsMin*np.asarray(myYbest)
if IsLog==1:
myYbest=np.log(myYbest)
myStd=np.log(myStd)
myStd=myStd*std_scale
plt.errorbar(x_axis,-myYbest,yerr=myStd/np.sqrt(10),linewidth=mylinewidth,color='green',linestyle=':',marker='h', label='Regularised')
######################################Regularised#END##########################
######################################Filtering################################
strFile=pickle_location+"\\{:s}_{:d}_Single_ei_expandBoundsFiltering.pickle".format(function_name,D)
with open(strFile) as f:
EI = pickle.load(f)
myYbest,myStd,myYbestCum,myStdCum=auxiliary_functions.yBest_Iteration(EI[0],BatchSz_BigBound,IsPradaBO=1,Y_optimal=1,step=step)
ACSR_mean,ACSR_std=export_results.compute_average_cumulative_simple_regret(EI[0],BatchSz_GPyOpt,IsPradaBO=1,Y_optimal=y_optimal_value)
print "EI ACSR {:.4f}({:.4f})".format(ACSR_mean,ACSR_std)
myYbest=IsMin*np.asarray(myYbest)
if IsLog==1:
myYbest=np.log(myYbest)
myStd=np.log(myStd)
myStd=myStd*std_scale
if myYbest.size==1:
myYbest=myYbest*np.ones(x_axis.shape)
plt.errorbar(x_axis,-myYbest,yerr=myStd/np.sqrt(10),linewidth=mylinewidth,color='black',linestyle=':',marker='h', label='FBO')
####################################Filtering#END##############################
#################################Volume#doubling###############################
strFile=pickle_location+"\\{:s}_{:d}_Single_ei_volumeDoubling.pickle".format(function_name,D)
with open(strFile) as f:
EI = pickle.load(f)
myYbest,myStd,myYbestCum,myStdCum=auxiliary_functions.yBest_Iteration(EI[0],BatchSz_BigBound,IsPradaBO=1,Y_optimal=1,step=step)
ACSR_mean,ACSR_std=export_results.compute_average_cumulative_simple_regret(EI[0],BatchSz_GPyOpt,IsPradaBO=1,Y_optimal=y_optimal_value)
print "EI ACSR {:.4f}({:.4f})".format(ACSR_mean,ACSR_std)
myYbest=IsMin*np.asarray(myYbest)
if IsLog==1:
myYbest=np.log(myYbest)
myStd=np.log(myStd)
myStd=myStd*std_scale
plt.errorbar(x_axis,-myYbest,yerr=myStd/np.sqrt(10),linewidth=mylinewidth,color='red',linestyle=':',marker='h', label='Volume doubling')
#################################Volume#doubling#END###########################
################################DDB#MAP########################################
strFile=pickle_location+"\\{:s}_{:d}_Single_ei_expandBoundsDDB_MAP.pickle".format(function_name,D)
with open(strFile) as f:
EI = pickle.load(f)
myYbest,myStd,myYbestCum,myStdCum=auxiliary_functions.yBest_Iteration(EI[0],BatchSz_BigBound,IsPradaBO=1,Y_optimal=1,step=step)
ACSR_mean,ACSR_std=export_results.compute_average_cumulative_simple_regret(EI[0],BatchSz_GPyOpt,IsPradaBO=1,Y_optimal=y_optimal_value)
print "EI ACSR {:.4f}({:.4f})".format(ACSR_mean,ACSR_std)
myYbest=IsMin*np.asarray(myYbest)
if IsLog==1:
myYbest=np.log(myYbest)
myStd=np.log(myStd)
myStd=myStd*std_scale
plt.errorbar(x_axis,-myYbest,yerr=myStd/np.sqrt(10),linewidth=mylinewidth,color='purple',linestyle='-',marker='h', label='DDB-MAP')
################################DDB#MAP#END####################################
################################DDB#FB#########################################
strFile=pickle_location+"\\{:s}_{:d}_Single_ei_expandBoundsDDB_FB.pickle".format(function_name,D)
with open(strFile) as f:
EI = pickle.load(f)
myYbest,myStd,myYbestCum,myStdCum=auxiliary_functions.yBest_Iteration(EI[0],BatchSz_BigBound,IsPradaBO=1,Y_optimal=1,step=step)
ACSR_mean,ACSR_std=export_results.compute_average_cumulative_simple_regret(EI[0],BatchSz_GPyOpt,IsPradaBO=1,Y_optimal=y_optimal_value)
print "EI ACSR {:.4f}({:.4f})".format(ACSR_mean,ACSR_std)
myYbest=IsMin*np.asarray(myYbest)
if IsLog==1:
myYbest=np.log(myYbest)
myStd=np.log(myStd)
myStd=myStd*std_scale
plt.errorbar(x_axis,-myYbest,yerr=myStd/np.sqrt(10),linewidth=mylinewidth,color='brown',linestyle='-',marker='h', label='DDB-FB')
################################DDB#FB#END#####################################
#The code below can be used to change the plot settings
plt.ylabel('Best Found Value',fontdict={'size':22})
plt.xlabel('Iteration',fontdict={'size':22})
plt.legend(loc='top right',prop={'size':20})
strTitle="{:s} D={:d}".format(function_name,D)
plt.title(strTitle,fontdict={'size':28})
plt.xticks(fontsize=18, rotation=0)
plt.yticks(fontsize=18, rotation=0)
strFile="plot/{:s}_{:d}_E3I.pdf".format(function_name,D)
plt.savefig(strFile, bbox_inches='tight')