def ppm_group_algo_contour_plot_helper(test_name, fnames, algos, granularity=config.PPM_CONTOUR_GRANULARITY, alpha_start=config.PPM_ALPHA_START, alpha_end=config.PPM_ALPHA_END, beta_start=config.PPM_BETA_START, beta_end=config.PPM_BETA_END): if type(fnames) == str: fnames = [fnames] alpha_range = (float(alpha_start), float(alpha_end)) beta_range = (float(beta_start), float(beta_end)) granularity = int(granularity) algos = algos.split(",") kwargs = contour_settings(config.PPM_GROUP_CONTOUR_DEFAULT_ARGS, config.PPM_GROUP_CONTOUR_OVERRIDES, test_name, fnames) fig = plot_contour_base(xlim=beta_range, ylim=alpha_range) colors = kwargs['colormap'](np.linspace(0, 1, len(algos))) del kwargs['colormap'] for algo, color in zip(algos, colors): prior, depth = algo.split("/") depth = int(depth) optimum, evals = benchmark.tasks.contour_data(prior, paranoia, depth, alpha_range, beta_range, granularity, fnames) label = short_name(config.SHORT_PRIOR_NAME, prior) plot_optimum(optimum, label=label, color=color) plot_contour_lines(optimum, evals, colors=color, **kwargs) return plot.save_figure(fig, general.sanitize_fname(test_name), fnames)
def save_figure(fig, output_dir, fnames): if len(fnames) == 1: fig_fname = general.sanitize_fname(fnames[0]) else: m = hashlib.md5() for fname in fnames: m.update(fname.encode('utf8')) fig_fname = "group-" + m.hexdigest() fig_fname += "_" + style_name + ".pdf" fig_dir = os.path.join(config.FIGURE_DIR, output_dir) os.makedirs(fig_dir, exist_ok=True) fig_path = os.path.join(fig_dir, fig_fname) with PdfPages(fig_path) as out: print("Writing figure to " + fig_path) out.savefig(fig) return fig_path
def ppm_optimal_alpha_beta_helper(test_name, fname, prior, depths=config.PPM_PARAMETER_DEPTHS, granularity=config.PPM_PARAMETER_GRANULARITY): depths = parse_depths(depths) granularity = int(granularity) csv_dir = os.path.join(config.TABLE_DIR, test_name) os.makedirs(csv_dir, exist_ok=True) csv_path = os.path.join(csv_dir, general.sanitize_fname(fname) + '.csv') with open(csv_path, 'w') as f: fieldnames = ['depth', 'alpha', 'beta', 'efficiency', 'status'] writer = csv.writer(f) writer.writerow(fieldnames) for d in depths: res = benchmark.tasks.ppm_find_optimal_alpha_beta([fname], paranoia, prior, d, granularity, config.PPM_ALPHA_RANGE, config.PPM_BETA_RANGE) if res: # optimisation succeeded (alpha, beta), efficiency, status = res writer.writerow([d, alpha, beta, efficiency, status]) return csv_path