plot_bo_benchmarks.py 3.29 KB
Newer Older
1
2
3
4
5
6
#!/bin/python
# plot the results of the Bayesian Optimization benchmarks
from glob import glob
from collections import defaultdict
import numpy as np
from pylab import *
Jean-Baptiste Mouret's avatar
Jean-Baptiste Mouret committed
7
8
import brewer2mpl
bmap = brewer2mpl.get_map('Set2', 'qualitative', 8)
9

Jean-Baptiste Mouret's avatar
Jean-Baptiste Mouret committed
10
11
colors = bmap.mpl_colors
print len(colors)
12

Jean-Baptiste Mouret's avatar
Jean-Baptiste Mouret committed
13
14
15


print colors
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
params = {
    'axes.labelsize' : 8,
    'text.fontsize' : 8,
    'axes.titlesize': 10,
    'legend.fontsize' : 10,
    'xtick.labelsize': 5,
    'ytick.labelsize' : 10,
    'figure.figsize' : [9, 2.5]
}
rcParams.update(params)

def load_data():
    files = glob("../benchmark_results/*/*/*.dat")
    data = defaultdict(lambda : defaultdict(dict))
    for f in files:
        fs = f.split("/")
        func, var, lib = fs[-1], fs[-2], fs[-3]
        data[func][lib][var] = np.loadtxt(f)
    return data

def custom_ax(ax):
    ax.spines['right'].set_visible(False)
    ax.spines['top'].set_visible(False)
    ax.spines['bottom'].set_visible(False)
    ax.get_xaxis().tick_bottom()
    ax.get_yaxis().tick_left()
Jean-Baptiste Mouret's avatar
Jean-Baptiste Mouret committed
42
    ax.set_axisbelow(True)
43
44
    ax.grid(axis='x', color="0.9", linestyle='-')

Jean-Baptiste Mouret's avatar
Jean-Baptiste Mouret committed
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
def custom_boxes(ax, bp):
    for i in range(len(bp['boxes'])):
        box = bp['boxes'][i]
        box.set_linewidth(0)
        boxX = []
        boxY = []
        for j in range(5):
            boxX.append(box.get_xdata()[j])
            boxY.append(box.get_ydata()[j])
            boxCoords = zip(boxX,boxY)
            boxPolygon = Polygon(boxCoords, facecolor = colors[i % len(colors)], linewidth=0)
            ax.add_patch(boxPolygon)

        for i in range(0, len(bp['boxes'])):
            bp['boxes'][i].set_color(colors[i])
            # we have two whiskers!
            bp['whiskers'][i*2].set_color(colors[i])
            bp['whiskers'][i*2 + 1].set_color(colors[i])
            bp['whiskers'][i*2].set_linewidth(2)
            bp['whiskers'][i*2 + 1].set_linewidth(2)
            # top and bottom fliers
            bp['fliers'][i * 2].set(markerfacecolor=colors[i],
                            marker='o', alpha=0.75, markersize=6,
                            markeredgecolor='none')
            bp['fliers'][i * 2 + 1].set(markerfacecolor=colors[i],
                            marker='o', alpha=0.75, markersize=6,
                            markeredgecolor='none')
            bp['medians'][i].set_color('black')
            bp['medians'][i].set_linewidth(2)
            # and 4 caps to remove
            for c in bp['caps']:
                c.set_linewidth(0)


79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# plot a single function
def plot(func_name, data):
    d = data[func_name]
    da_acc = []
    da_time = []
    labels = [] 
    for k in d.iterkeys():
        for k2 in d[k].iterkeys():
            da_acc.append(d[k][k2][:, 0])
            da_time.append(d[k][k2][:, 1] / 1000.0)
            labels.append(k + "/" + k2)
    fig = figure()
    fig.subplots_adjust(left=0.3)
    ax = fig.add_subplot(121)
    custom_ax(ax)
Jean-Baptiste Mouret's avatar
Jean-Baptiste Mouret committed
94
95
    bp = ax.boxplot(da_acc, 0, 'rs', 0)
    custom_boxes(ax, bp)
96
97
98
99
    ax.set_yticklabels(labels)
    ax.set_title("Accuracy")
    ax = fig.add_subplot(122)
    custom_ax(ax)
Jean-Baptiste Mouret's avatar
Jean-Baptiste Mouret committed
100
101
    bp = ax.boxplot(da_time, 0, 'rs', 0)
    custom_boxes(ax, bp)
102
103
104
105
106
107
108
109
110
111
112
113
    ax.set_yticklabels([])
    ax.set_title("Wall clock time")

    fig.savefig("../benchmark_results/" + func_name.split('.')[0] + ".png")    


def main():
    data = load_data()
    for k in data.keys():
        plot(k, data)

main()