def draw_plot(plot_data, ax, func_id, decorations=[], num_blendcurves=plotparams.GP_DEFAULT_NUM_BLENDCURVES, blendcurve_alpha=plotparams.GP_DEFAULT_BLENDCURVE_ALPHA): xp = np.linspace(-20, 20, 100) xp_fine = np.linspace(-20, 20, 2000) pmean, pcov = posterior_mean_and_cov(plot_data, xp) # This is a waste of memory, but we have enough memory and I'd rather # not rewrite the program yet again yps = [] for i in range(num_blendcurves): yp = np.random.multivariate_normal(pmean, pcov) yps.append(yp) ax.plot(xp, yp, c="red", alpha=blendcurve_alpha, linewidth=2) f_true = gpexample_plugin.get_ftrue(func_id) ax.plot(xp_fine, [f_true(x) for x in xp_fine], **plotparams.GP_FTRUE) ax.scatter(plot_data.Xseen, plot_data.Yseen, **plotparams.GP_PAST_PROBE) ax.axes.xaxis.set_ticklabels([]) ax.axes.yaxis.set_ticklabels([]) for artist in decorations: ax.add_artist(artist) ax.set_xlim(-20, 20) ax.set_ylim(-1.5, 1.5) # ax.legend() return xp, yps, pmean, pcov
def draw_optplot(plot_data_lists, ax, func_id): (xmin, xmax) = (1, len(plot_data_lists[0]) - 1) ax.set_xlim(xmin, xmax) ax.set_ylim(-1.0, 1.5) f_true = gpexample_plugin.get_ftrue(func_id) for plot_data_list in plot_data_lists: optima = [plotdata_optimum(plot_data) for plot_data in plot_data_list[1:]] optvals = [f_true(x) for (x,y) in optima] ax.plot(range(1, len(optvals) + 1), optvals, **plotparams.GP_OPTPLOT_SERIES) local_optval_lines = [ Line2D( [0, xmax], [local_optval, local_optval], **plotparams.GP_OPTPLOT_TRUE_LOCAL_OPT) for (_, local_optval) in gpexample_plugin.get_true_local_optima(func_id) ] for l in local_optval_lines: ax.add_artist(l) ax.set_title('Estimated Optimum Over Time', **plotparams.GP_OPTPLOT_TITLE) ax.set_xlabel('Iteration', **plotparams.GP_OPTPLOT_XLABEL) ax.set_ylabel('$f_{\\rm true}(\\widehat{x})$', **plotparams.GP_OPTPLOT_YLABEL) ax.legend(handles=local_optval_lines[:1])
(func_id, plot_data) = pickle.load(f) sns.set(font_scale=3) fig = plt.figure() fig.set_dpi(30) fig.set_figwidth(1.5 * plotparams.GP_PLOT_WIDTH) fig.set_figheight(plotparams.GP_PLOT_HEIGHT) gs = gridspec.GridSpec(1, 2, width_ratios=[2,1]) plot_ax = fig.add_subplot(gs[0]) legend_ax = fig.add_subplot(gs[1]) decorations = [] decorations.append(plotutils.centered_rectangle( create_bayesopt_gp_plots.plotdata_optimum(plot_data), **plotparams.GP_OPTIMUM)) f_true = gpexample_plugin.get_ftrue(func_id) def generate_candidate(): return np.random.uniform(-20, 20) if not ns.omit_candidates: proposed_xs = [generate_candidate() for _ in range(8)] plot_ax.scatter(proposed_xs, map(f_true, proposed_xs), **plotparams.GP_UNIFORM_XCANDIDATE) create_bayesopt_gp_plots.draw_plot(plot_data, plot_ax, func_id, decorations) make_legend(legend_ax) outfname = ns.outfile print "Saving figure %s" % (outfname,) fig.savefig(outfname, dpi=fig.dpi,bbox_inches='tight')