def bokeh_quantiles(ticks, avgs, quantiles, color='#000055', alpha=1.0, **kwargs): plotting.line(ticks, avgs, color=color, line_alpha=alpha, title_text_font_size='6pt', **kwargs) plotting.hold(True) if quantiles is not None: print(quantiles) x_std = list(ticks) + list(reversed(ticks)) y_std = ([q_min for q_min, q_max in quantiles] + list(reversed([q_max for q_min, q_max in quantiles]))) plotting.patch(x_std, y_std, fill_color=color, fill_alpha=alpha * 0.25, line_color=None) plotting.grid().grid_line_color = 'white' plotting_axis() plotting.hold(False)
def coverage( s_channels, threshold, s_vectors=(), title="no title", swap_xy=True, x_range=None, y_range=None, color=C_COLOR, c_alpha=1.0, alpha=0.5, **kwargs ): x_range, y_range = ranges(s_channels, x_range=x_range, y_range=y_range) try: xv, yv = zip(*(s[:2] for s in s_vectors)) except ValueError: xv, yv = [], [] if swap_xy: x_range, y_range = y_range, x_range xv, yv = yv, xv plotting.circle( xv, yv, radius=threshold, x_range=x_range, y_range=y_range, fill_color=hexa(color, 0.35), fill_alpha=c_alpha, line_color=None, title=title, **kwargs ) plotting.hold(True) union = shapely.ops.unary_union([shapely.geometry.Point(*sv_i).buffer(threshold) for sv_i in s_vectors]) boundary = union.boundary if isinstance(boundary, shapely.geometry.LineString): boundary = [boundary] for b in boundary: x, y = b.xy x, y = list(x), list(y) if swap_xy: x, y = y, x plotting.patch(x, y, fill_color=None, line_color=hexa(color, 0.75)) plotting.hold(True) plotting_axis() plotting.hold(False)
def bokeh_quantiles(ticks, avgs, quantiles, color="#000055", alpha=1.0, **kwargs): plotting.line(ticks, avgs, color=color, line_alpha=alpha, title_text_font_size="6pt", **kwargs) plotting.hold(True) if quantiles is not None: print(quantiles) x_std = list(ticks) + list(reversed(ticks)) y_std = [q_min for q_min, q_max in quantiles] + list(reversed([q_max for q_min, q_max in quantiles])) plotting.patch(x_std, y_std, fill_color=color, fill_alpha=alpha * 0.25, line_color=None) plotting.grid().grid_line_color = "white" plotting_axis() plotting.hold(False)
def coverage(s_channels, threshold, s_vectors=(), title='no title', swap_xy=True, x_range=None, y_range=None, color=C_COLOR, c_alpha=1.0, alpha=0.5, **kwargs): x_range, y_range = ranges(s_channels, x_range=x_range, y_range=y_range) try: xv, yv = zip(*(s[:2] for s in s_vectors)) except ValueError: xv, yv = [], [] if swap_xy: x_range, y_range = y_range, x_range xv, yv = yv, xv plotting.circle(xv, yv, radius=threshold, x_range=x_range, y_range=y_range, fill_color=hexa(color, 0.35), fill_alpha=c_alpha, line_color=None, title=title, **kwargs) plotting.hold(True) union = shapely.ops.unary_union([ shapely.geometry.Point(*sv_i).buffer(threshold) for sv_i in s_vectors ]) boundary = union.boundary if isinstance(boundary, shapely.geometry.LineString): boundary = [boundary] for b in boundary: x, y = b.xy x, y = list(x), list(y) if swap_xy: x, y = y, x plotting.patch(x, y, fill_color=None, line_color=hexa(color, 0.75)) plotting.hold(True) plotting_axis() plotting.hold(False)
def perf_astd(ticks, avgs, astds, color=BLUE, alpha=1.0, sem=1.0, plot_width=1000, plot_height=500, **kwargs): plotting.line(ticks, avgs, color=color, line_alpha=alpha, title_text_font_size='6pt', plot_width=plot_width, plot_height=plot_height, **kwargs) plotting.hold(True) if astds is not None: x_std = list(ticks) + list(reversed(ticks)) y_std = ([ a - s_min / math.sqrt(sem) for a, (s_min, s_max) in zip(avgs, astds) ] + list( reversed([ a + s_max / math.sqrt(sem) for a, (s_min, s_max) in zip(avgs, astds) ]))) plotting.patch(x_std, y_std, fill_color=color, fill_alpha=alpha * 0.25, line_color=None) plotting.grid().grid_line_color = 'white' plotting_axis() plotting.hold(False)
def perf_astd(ticks, avgs, astds, color=BLUE, alpha=1.0, sem=1.0, plot_width=1000, plot_height=500, **kwargs): plotting.line( ticks, avgs, color=color, line_alpha=alpha, title_text_font_size="6pt", plot_width=plot_width, plot_height=plot_height, **kwargs ) plotting.hold(True) if astds is not None: x_std = list(ticks) + list(reversed(ticks)) y_std = [a - s_min / math.sqrt(sem) for a, (s_min, s_max) in zip(avgs, astds)] + list( reversed([a + s_max / math.sqrt(sem) for a, (s_min, s_max) in zip(avgs, astds)]) ) plotting.patch(x_std, y_std, fill_color=color, fill_alpha=alpha * 0.25, line_color=None) plotting.grid().grid_line_color = "white" plotting_axis() plotting.hold(False)
def adapt_graphs(ex_cfg, explorations, s_vectors, weight_history, mesh=None, title="no title"): s_channels = ex_cfg.s_channels tally_dict = {} for exploration, feedback in explorations: key = exploration["from"] + "_" + exploration["uuid"][:8] tally_dict.setdefault(key, 0) tally_dict[key] += 1 print(tally_dict) if ex_cfg.div_algorithm == "hyperball": coverage(s_channels, ex_cfg.threshold, s_vectors=s_vectors, title=title) else: assert ex_cfg.div_algorithm == "grid" if mesh is not None: mesh(mesh, title=title) hold(True) spread(s_channels, s_vectors=s_vectors, e_radius=1.25, e_alpha=0.75, grid=False) # interest measure colors = [BLUE, PINK, GREEN] weight_lists = zip(*weight_history["data"]) for i, weights in enumerate(weight_lists): perf_std( range(len(weights)), weights, [0.0 for _ in weights], legend=weight_history["ex_names"][i] + " ex_{}".format(i), color=colors[i], alpha=0.5, x_range=(0, len(weights)), plot_width=1000, plot_height=300, title="diversity: {}".format(title), ) hold(True) hold(False) # # usage with sliding window window = 100.0 uuid_history = tuple(e[0]["uuids"] for e in explorations) assert len(weight_lists) == 2 for i, weights in enumerate(weight_lists): ex_uuid = weight_history["ex_uuids"][0] ex_name = weight_history["ex_names"][0] usage = [t_usage(window, t, ex_uuid, uuid_history) for t in range(len(uuid_history))] x_p = tuple(range(1, len(usage) + 1)) + (len(usage), 0) y_p = tuple(usage) + (i, i) plotting.patch( x_p, y_p, fill_color=colors[i], fill_alpha=0.5, line_color=None, plot_width=1000, plot_height=300, title="usage: {}".format(title), y_range=(0.0, 1.0), x_range=(0, len(usage)), ) hold(True) perf_std( range(len(usage)), usage, [0.0 for _ in usage], color="black", alpha=0.05, plot_width=1000, plot_height=300, title="usage: {}".format(title), y_range=(0.0, 1.0), ) hold(True) hold(False) # print('{} {:.3f}'.format(env_name, np.average(errors))) return tally_dict
# Define Bollinger Bands. upperband = np.random.random_integers(100, 150, size=100) lowerband = upperband - 100 x_data = np.arange(1, 101) # Bollinger shading glyph: band_x = np.append(x_data, x_data[::-1]) band_y = np.append(lowerband, upperband[::-1]) pl.patch(band_x, band_y, color='#7570B3', fill_alpha=0.2) pl.show() # In[27]: import bokeh for ele in dir(bokeh): if 'version' in ele: print ele