-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathplotting.py
More file actions
269 lines (256 loc) · 10.2 KB
/
plotting.py
File metadata and controls
269 lines (256 loc) · 10.2 KB
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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
"""
Reads either pickle or mat files and plots the results.
-- syiblet@andrew.cmu.edu
-- kvysyara@andrew.cmu.edu
-- kandasamy@cs.cmu.edu
Usage:
python plotting.py --filelist <file containing list of pickle or mat file paths>
python plotting.py --file <pickle or mat file path>
"""
from __future__ import division
from __future__ import print_function
# pylint: disable=invalid-name
# pylint: disable=redefined-builtin
# pylint: disable=too-many-locals
# pylint: disable=too-many-branches
import os
import numpy as np
# Local
# from utils.plot_utils import COLOURS, plot_results, get_plot_options, \
# load_results, get_file_paths
from dragonfly.utils.plot_utils import COLOURS, plot_results, get_plot_options, \
load_results, get_file_paths
syn_funcs = {'hartmann3': (3.86278, 3),
'hartmann6': (3.322368, 6),
'currin_exp': (13.7986850, 2),
'branin': (-0.39788735773, 2),
'borehole': (309.523221, 8),
'park1': (25.5872304, 4),
'park2': (5.925698, 4)
}
def get_true_maxval(study_name):
''' Returns true max values for high dim synthetic functions. '''
name = study_name.split('-')[0]
if name not in syn_funcs:
return None
if len(study_name.split('-')) == 1:
return syn_funcs[name][0]
group_dim = int(study_name.split('-')[1])
max_val, domain_dim = syn_funcs[name]
num_groups = int(group_dim/domain_dim)
return max_val*num_groups
def main():
""" Main function. """
# plot_order = ['rand', 'ga', 'dragonfly']
# plot_order = ['rand', 'pdoo', 'dragonfly']
plot_order = ['rand', 'ga']
# # Cartesian product experiments
# plot_order = ['rand', 'ga', 'hyperopt', 'smac', 'gpyopt', 'dragonfly', 'dragonfly-mf']
# # Real experiments
# plot_order = ['rand', 'ga', 'smac', 'gpyopt', 'dragonfly', 'dragonfly-mf']
# # Euclidean Methods
# plot_order = ['rand', 'pdoo', 'hyperopt', 'smac', 'spearmint', 'gpyopt', 'dragonfly']
# plot_order = ['rand', 'pdoo', 'hyperopt', 'smac', 'gpyopt', 'dragonfly']
# plot_order = ['rand', 'pdoo', 'hyperopt', 'gpyopt', 'dragonfly']
# Load options and results
options = get_plot_options()
if options.filelist != '':
file_paths = get_file_paths(options.filelist)
elif options.file != '':
file_paths = [os.path.realpath(os.path.abspath(options.file))]
else:
raise ValueError('Missing Filelist.')
to_plot_legend = True
options.legend_location = 3
results = load_results(file_paths)
# Ancillary info for the plot
study_name = str(np.asscalar(results['study_name']))
# Check if noisy or not
if 'is_noisy' in results and results['is_noisy'].flatten()[0]:
is_noisy = True
else:
is_noisy = False
# GEt true max value
true_maxval = get_true_maxval(study_name)
y_bounds = None
if study_name in ['borehole_6', 'park1_3', 'park2_3', 'park2_4', 'hartmann6_4',
'syn_cnn_1', 'syn_cnn_2', 'park1_constrained',
'hartmann3_constrained', 'borehole_constrained']:
y_label = 'Maximum Value'
x_label = 'Expended Capital'
else:
y_label = 'Simple Regret'
x_label = 'Number of Evaluations'
# title
if not hasattr(options, 'title') or options.title is None:
if study_name == 'borehole':
plot_title = r'Borehole $(d=8)$'
if not len(results['methods']) == 7:
to_plot_legend = True
options.legend_location = 3
elif study_name == 'branin':
plot_title = r'Branin $(d=2)$'
to_plot_legend = True
options.legend_location = 3
elif study_name == 'branin-40':
plot_title = r'Branin$\times$20 $(d=40)$'
elif study_name == 'hartmann3':
plot_title = r'Hartmann3 $(d=3)$'
to_plot_legend = True
options.legend_location = 1
elif study_name == 'park1':
plot_title = r'Park1 $(d=4)$'
elif study_name == 'park2':
plot_title = r'Park2 $(d=4)$'
elif study_name == 'hartmann6':
plot_title = r'Hartmann6 $(d=6)$'
if 'ei' in plot_order:
to_plot_legend = True
options.legend_location = 3
elif study_name == 'hartmann-20':
plot_title = r'Hartmann6$\times$3 $(d=20)$'
true_maxval = syn_funcs['hartmann6'][0] * 3
elif study_name == 'branin-14':
plot_title = r'Branin$\times7$ $(d=14)$'
if not is_noisy:
y_bounds = [20, 800]
elif study_name == 'borehole-32':
plot_title = r'Borehole$\times4$ $(d=32)$'
elif study_name == 'hartmann6-42':
plot_title = r'Hartmann6$\times7$ $(d=42)$'
elif study_name == 'park2-20':
plot_title = r'Park2$\times$5 $(d=20)$'
elif study_name == 'park1-12':
plot_title = r'Park1$\times$3 $(d=12)$'
elif study_name == 'hartmann6':
plot_title = r'Hartmann6 $(d=6)$'
elif study_name == 'hartmann3-18':
plot_title = r'Hartmann3$\times$6 $(d=18)$'
to_plot_legend = True
options.legend_location = 3
elif study_name == 'park2-24':
plot_title = r'Park2$\times$6 $(d=24)$'
elif study_name == 'park2-40':
plot_title = r'Park2$\times$10 $(d=40)$'
elif study_name == 'branin-50':
plot_title = r'Branin$\times$25 $(d=50)$'
elif study_name == 'borehole-96':
plot_title = r'Borehole$\times$12 $(d=96)$'
elif study_name == 'park1-108':
plot_title = r'Park1$\times$27 $(d=108)$'
# Non-euclidean domains
elif study_name == 'borehole_6':
plot_title = r'Borehole_6 $(d=8)$'
to_plot_legend = True
options.legend_location = 4
y_bounds = [100, 295]
elif study_name == 'hartmann6_4':
plot_title = r'Hartmann6_4 $(d=6)$'
to_plot_legend = True
options.legend_location = 4
elif study_name == 'park1_3':
plot_title = r'Park1_3 $(d=4)$'
y_bounds = [17, 22.5]
elif study_name == 'park2_3':
plot_title = r'Park2_3 $(d=5)$'
elif study_name == 'park2_4':
plot_title = r'Park2_4 $(d=5)$'
elif study_name == 'syn_cnn_1':
plot_title = r'syn_cnn_1'
elif study_name == 'syn_cnn_2':
plot_title = r'syn_cnn_2'
elif study_name == 'park1_constrained':
plot_title = r'Park1-Constrained $(d=4)$'
to_plot_legend = True
options.legend_location = 4
elif study_name == 'hartmann3_constrained':
y_bounds = [1.3, 3.8]
plot_title = r'Hartmann3-Constrained $(d=3)$'
to_plot_legend = True
options.legend_location = 4
elif study_name == 'borehole_constrained':
plot_title = r'Borehole-Constrained $(d=6)$'
elif study_name == 'lrg':
plot_title = r'Luminous Red Galaxies $(d=9)$'
to_plot_legend = True
options.legend_location = 4
y_bounds = [-1400, -999]
elif study_name == 'supernova':
plot_title = r'Type Ia Supernova $(d=3)$'
x_label = 'Wall Clock Time (hours)'
to_plot_legend = True
options.legend_location = 4
y_bounds = [-0.25, 0.075]
x_label = 'Wall Clock Time (hours)'
elif study_name == 'salsa':
plot_title = r'SALSA, Energy Appliances $\,(d=30)$'
to_plot_legend = True
options.legend_location = 1
x_label = 'Wall Clock Time (hours)'
y_label = 'Validation Error'
elif study_name == 'rfrnews':
plot_title = r'Random Forest Regression, News $\,(d=6)$'
x_label = 'Wall Clock Time (hours)'
to_plot_legend = True
options.legend_location = 3
elif study_name == 'gbrnaval':
plot_title = r'Gradient Boosted Regression, Naval $\,(d=7)$'
y_bounds = [1e-5, 1e0]
x_label = 'Wall Clock Time (hours)'
to_plot_legend = False
options.legend_location = 3
elif study_name == 'gbrprotein':
plot_title = r'Gradient Boosted Regression, Protein $\,(d=7)$'
x_label = 'Wall Clock Time (hours)'
to_plot_legend = False
options.legend_location = 3
y_bounds = [0.5, 2e0]
elif study_name == 'infra':
plot_title = r'Real Time Stream Processing $\,(d=37)$'
x_label = 'Wall Clock Time (hours)'
y_label = 'Latency (ms)'
to_plot_legend = True
options.legend_location = 3
else:
plot_title = ''
# Method legend dictionary
method_legend_colour_marker_dict = {
# Packages
"rand": {'legend':'RAND', 'colour':COLOURS['black'], 'marker':'s', 'linestyle':'-'},
"ga": {'legend':'EA', 'colour':COLOURS['red'], 'marker':'*', 'linestyle':'-'},
"pdoo": {'legend':'PDOO', 'colour':COLOURS['red'], 'marker':'>', 'linestyle':'-'},
"hyperopt": {'legend':'HyperOpt', 'colour':COLOURS['orange'], 'marker':'1',
'linestyle':'-'},
"gpyopt": {'legend':'GPyOpt', 'colour':COLOURS['green'], 'marker':'+',
'linestyle':'-'},
"smac": {'legend':'SMAC', 'colour':COLOURS['magenta'], 'marker':'x',
'linestyle':'-'},
"spearmint": {'legend':'Spearmint', 'colour':COLOURS['yellow'], 'marker':'^',
'linestyle':'-'},
"dragonfly": {'legend':'Dragonfly', 'colour':COLOURS['blue'], 'marker':'o',
'linestyle':'-'},
"dragonfly-mf": {'legend':'Dragonfly+MF', 'colour':COLOURS['cyan'], 'marker':'d',
'linestyle':'-'},
# Custom methods
"ml": {'legend':'ML', 'colour':COLOURS['red'], 'marker':'>', 'linestyle':'-'},
"post_sampling": {'legend':'PS', 'colour':COLOURS['green'], 'marker':'s',
'linestyle':'-'},
"ml+post_sampling": {'legend':'ML+PS', 'colour':COLOURS['blue'], 'marker':'.',
'linestyle':'-'},
# Acquisition
"pi": {'legend':'GP-PI', 'colour':COLOURS['orange'], 'marker':'>', 'linestyle':'-'},
"ei": {'legend':'GP-EI', 'colour':COLOURS['green'], 'marker':'^',
'linestyle':'-'},
"ttei": {'legend':'TTEI', 'colour':COLOURS['magenta'], 'marker':'1',
'linestyle':'-'},
"ucb": {'legend':'GP-UCB', 'colour':COLOURS['red'], 'marker':'x', 'linestyle':'-'},
"add_ucb": {'legend':'Add-GP-UCB', 'colour':COLOURS['cyan'], 'marker':'s',
'linestyle':'-'},
"ts": {'legend':'TS', 'colour':COLOURS['blue'], 'marker':'+', 'linestyle':'-'},
}
print(results['methods'])
plot_results(results, plot_order, method_legend_colour_marker_dict, x_label, y_label,
to_plot_legend=to_plot_legend, true_maxval=true_maxval,
plot_title=plot_title, options=options, y_bounds=y_bounds)
if __name__ == '__main__':
main()