def plot_comp_sims(figure_path, figsize=(2.5, 2.5)): non_complexy_results = restore_results('../data/sim_comp_cost/non_complexy') con_complexy_results = restore_results('../data/sim_comp_cost/con_complexy') fig, axis = plt.subplots(1, 1, figsize=figsize) axis.plot(range(1,65), non_complexy_results.mean(axis=1), color=colors.categories[0], label='Random') axis.plot(range(1,65), con_complexy_results.mean(axis=1), color=colors.categories[2], label='Convex') axis.annotate ('', (16, non_complexy_results[15].mean()), (16, con_complexy_results[15].mean()), arrowprops={'arrowstyle':'<->', 'shrinkA':0, 'shrinkB':0}) axis.set_ylim(0-(700*0.025), 700+(700*0.025)) axis.set_xlim(0,65) axis.set_xticks([1, 16, 32, 48, 64]) axis.set_xlabel('Number of categories', fontsize=8) axis.set_yticks([0, 100, 200, 300, 400, 500, 600, 700]) axis.set_ylabel('Complexity (bits)', fontsize=8) for tick in axis.yaxis.get_major_ticks(): tick.label.set_fontsize(7) for tick in axis.xaxis.get_major_ticks(): tick.label.set_fontsize(7) handles, labels = axis.get_legend_handles_labels() fig.legend(handles, labels, loc='lower center', ncol=2, frameon=False, bbox_to_anchor=(0.5, -0.04), fontsize=8) fig.tight_layout(pad=0.1, h_pad=0.5, w_pad=0.5, rect=[0,0.08,1,1]) fig.savefig(figure_path, format='svg') tools.format_svg_labels(figure_path) if not figure_path.endswith('.svg'): tools.convert_svg(figure_path, figure_path)
def visualize(data, figure_path, figure_width=5, show_stimuli=True, rect_compress=False): if not isinstance(data, np.ndarray): raise ValueError('Input data should be numpy array') if len(data.shape) == 2 and (data.dtype == int or data.dtype == bool): height = 500 * data.shape[0] width = 500 * data.shape[1] figure_height = figure_width / width * height svg = '<svg width="%iin" height="%fin" viewBox="0 0 %i %i" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" version="1.1">\n\n' % ( figure_width, figure_height, width, height) if rect_compress: svg += create_production_svg_rect(data, show_stimuli) else: svg += create_production_svg(data, show_stimuli) elif len(data.shape) == 3 and data.dtype == float: height = 500 * data.shape[1] * 2 + 500 width = 500 * data.shape[2] * 2 + 500 figure_height = figure_width / width * height svg = '<svg width="%iin" height="%fin" viewBox="0 0 %i %i" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" version="1.1">\n\n' % ( figure_width, figure_height, width, height) svg += create_comprehension_svg(data) else: raise ValueError( 'Invalid input data. Should be 8x8 ints (production) or 4x8x8 floats (comprehension)' ) svg += '</svg>' with open(figure_path, mode='w', encoding='utf-8') as file: file.write(svg) if not figure_path.endswith('.svg'): tools.convert_svg(figure_path, figure_path)
def plot_all(figure_path): cost_rand = restore_results('../data/sim_comp_cost/non_commcost') comp_rand = restore_results('../data/sim_comp_cost/non_complexy') cost_conv = restore_results('../data/sim_comp_cost/con_commcost') comp_conv = restore_results('../data/sim_comp_cost/con_complexy') fig, axis = plt.subplots(1, 1, figsize=(2.5,2.5)) axis.scatter([comp_rand[0,0]], [cost_rand[0,0]], c='#E6CFDA', s=2.0) for i in range(1, 63): x, y = reduce_points(comp_rand[i], cost_rand[i]) axis.scatter(x, y, c=colors.fake_alpha(colors.categories[0], (i+32)/95.), s=2.0) for i in range(1, 63): x, y = reduce_points(comp_conv[i], cost_conv[i]) axis.scatter(x, y, c=colors.fake_alpha(colors.categories[2], (i+32)/95.), s=2.0) axis.scatter(comp_rand[63,0], cost_rand[63,0], c=colors.categories[0], s=2.0, label='Random') axis.scatter(comp_conv[63,0], cost_conv[63,0], c=colors.categories[2], s=2.0, label='Convex') axis.set_xlabel('Complexity (bits)', fontsize=8) axis.set_ylabel('Communicative cost (bits)', fontsize=8) for tick in axis.yaxis.get_major_ticks(): tick.label.set_fontsize(7) for tick in axis.xaxis.get_major_ticks(): tick.label.set_fontsize(7) handles, labels = axis.get_legend_handles_labels() fig.legend(handles, labels, loc='lower center', ncol=2, markerscale=3, frameon=False, bbox_to_anchor=(0.5, -0.04), fontsize=8) fig.tight_layout(pad=0.1, h_pad=0.5, w_pad=0.5, rect=[0,0.08,1,1]) fig.savefig(figure_path, format='svg') tools.format_svg_labels(figure_path) if not figure_path.endswith('.svg'): tools.convert_svg(figure_path, figure_path)
def make_figure(data, figure_path, start_gen=0, end_gen=100, n_columns=10, show_stimuli=False, method='productions', rect_compress=True, verbose=False): ''' Make a figure depeciting the evolution of a bunch of chains. ''' for chain in data['chains']: chain['generations'] = [ generation for gen_i, generation in enumerate(chain['generations']) if gen_i >= start_gen and gen_i <= end_gen ] svg = draw_all_chains(data['chains'], n_columns, show_stimuli, method, rect_compress, verbose) with open(figure_path, mode='w', encoding='utf-8') as file: file.write(svg) if not figure_path.endswith('.svg'): tools.convert_svg(figure_path, figure_path)
def plot(datasets, shape, nsims, maxcats, figure_path, figsize=(5, 4.8)): fig, axes = plt.subplots(len(datasets), 1, figsize=figsize, squeeze=False) for (dataset, xlim, ylim), axis in zip(datasets, axes.flatten()): plot_space(axis, dataset, shape, xlim, ylim, nsims, maxcats) fig.tight_layout(pad=0.1, h_pad=0.5, w_pad=0.5) fig.savefig(figure_path, format='svg') tools.format_svg_labels(figure_path) if not figure_path.endswith('.svg'): tools.convert_svg(figure_path, figure_path)
def plot_prop_correct(production_results, comprehension_results, figure_path): fig, axes = plt.subplots(1, 2, figsize=(5, 2.5)) plot_densities(axes[0], production_results) plot_densities(axes[1], comprehension_results) axes[0].set_title('Production', fontsize=10) axes[1].set_title('Comprehension', fontsize=10) fig.tight_layout(pad=0.1, h_pad=0.5, w_pad=0.5) fig.savefig(figure_path, format='svg') tools.format_svg_labels(figure_path) if not figure_path.endswith('.svg'): tools.convert_svg(figure_path, figure_path)
def visualize_all(data_by_participant, figure_path, figure_width=10, test_type='production', n_rows=5, n_cols=8, show_stimuli=True, label=None): if label: if test_type == 'production': y_offset_for_label = 2000 label = '<text text-anchor="left" dominant-baseline="central" x="500" y="1000" fill="black" style="font-size: 1000px; font-family:Helvetica">%s</text>\n\n' % label else: y_offset_for_label = 4000 label = '<text text-anchor="left" dominant-baseline="central" x="1000" y="2000" fill="black" style="font-size: 2000px; font-family:Helvetica">%s</text>\n\n' % label else: label = '' if test_type == 'production': height = 500 * data_by_participant[0].shape[0] * n_rows + ( 500 * (n_rows + 1)) + y_offset_for_label width = 500 * data_by_participant[0].shape[1] * n_cols + (500 * (n_cols + 1)) figure_height = figure_width / width * height elif test_type == 'comprehension': height = (500 * data_by_participant[0].shape[1] * n_rows + (500 * (n_rows + 1))) * 2 + 500 + y_offset_for_label width = (500 * data_by_participant[0].shape[2] * n_cols + (500 * (n_cols + 1))) * 2 + 500 figure_height = figure_width / width * height svg = '<svg width="%iin" height="%fin" viewBox="0 0 %i %i" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" version="1.1">\n\n%s' % ( figure_width, figure_height, width, height, label) arrangement_iterator = np.ndindex((n_rows, n_cols)) for partition in data_by_participant: position = arrangement_iterator.next() if test_type == 'production': offset_x, offset_y = position[1] * 4500 + 500, position[ 0] * 4500 + 500 + y_offset_for_label svg += create_production_svg(partition, show_stimuli=show_stimuli, offset_x=offset_x, offset_y=offset_y) elif test_type == 'comprehension': offset_x, offset_y = position[1] * 9000 + 1000, position[ 0] * 9000 + 1000 + y_offset_for_label svg += create_comprehension_svg(partition, show_stimuli=show_stimuli, offset_x=offset_x, offset_y=offset_y) svg += '</svg>' with open(figure_path, mode='w', encoding='utf-8') as file: file.write(svg) if not figure_path.endswith('.svg'): tools.convert_svg(figure_path, figure_path)
def plot_advantage(figure_path, figsize=(5, 2.5)): non_commcost = restore_results('../data/sim_comp_cost/non_commcost') con_commcost = restore_results('../data/sim_comp_cost/con_commcost') non_complexy = restore_results('../data/sim_comp_cost/non_complexy') con_complexy = restore_results('../data/sim_comp_cost/con_complexy') complexy_adv = non_complexy.mean(1) - con_complexy.mean(1) commcost_adv = non_commcost.mean(1) - con_commcost.mean(1) fig, axes = plt.subplots(1, 2, figsize=figsize) axes[0].plot(range(1,65), complexy_adv, color='k') axes[1].plot(range(1,65), commcost_adv, color='k') axes[0].set_ylim(0-(400*0.025), 400+(400*0.025)) axes[1].set_ylim(0-(0.7*0.025), 0.7+(0.7*0.025)) axes[0].set_xlim(0,65) axes[1].set_xlim(0,65) axes[0].set_xticks([1, 16, 32, 48, 64]) axes[1].set_xticks([1, 16, 32, 48, 64]) axes[0].set_xlabel('Number of categories', fontsize=8) axes[1].set_xlabel('Number of categories', fontsize=8) # axes[0].set_yticks([0, 1, 2, 3, 4, 5, 6]) axes[1].set_yticks([0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7]) axes[0].set_ylabel('Compactness advantage (bits)', fontsize=8) axes[0].set_title('Complexity', fontsize=8) axes[1].set_title('Communicative cost', fontsize=8) for tick in axes[0].yaxis.get_major_ticks(): tick.label.set_fontsize(7) for tick in axes[0].xaxis.get_major_ticks(): tick.label.set_fontsize(7) for tick in axes[1].yaxis.get_major_ticks(): tick.label.set_fontsize(7) for tick in axes[1].xaxis.get_major_ticks(): tick.label.set_fontsize(7) fig.tight_layout(pad=0.1, h_pad=0.5, w_pad=0.5) fig.savefig(figure_path, format='svg') tools.format_svg_labels(figure_path) if not figure_path.endswith('.svg'): tools.convert_svg(figure_path, figure_path) # run_sims(100) # plot_sims('../visuals/simulated_complexity_cost.svg') # plot_cost_sims('../visuals/simulated_cost.svg') # plot_comp_sims('../visuals/simulated_comp.svg') # plot_all('../visuals/simulated_complexity_cost.svg') # plot_advantage('../visuals/compactness_advantage.svg')
def make_gaussians_figure(figure_path): gammas = [0.001, 0.1, 10] metric = 'circle_euclidean' y_max = 0.07 N = commcost.Need((64, )) P = commcost.Partition([0] * 16 + [1] * 16 + [2] * 16 + [3] * 16) S = P.spawn_speaker() fig = plt.figure(figsize=(5.5, 2)) grid = gridspec.GridSpec(nrows=1, ncols=len(gammas)) for i in range(len(gammas)): sp = fig.add_subplot(grid[0, i]) sp.set_axisbelow(True) if gammas[i] == 'inf': L = P.spawn_listener(999999999) K = commcost.cost(P, N, S, L) plt.title('γ = ∞', fontsize=10) else: L = P.spawn_listener(gammas[i], metric) K = commcost.cost(P, N, S, L) plt.title('γ = ' + str(gammas[i]), fontsize=10) for j in range(len(P)): category_distribution = list(L[j].probabilities.flatten()) category_distribution = [ category_distribution[-1] ] + category_distribution + [category_distribution[0]] sp.plot(range(0, P.size + 2), category_distribution, linewidth=2.0, color=colors.categories[j]) plt.xticks(fontsize=7) plt.yticks(fontsize=7) if i == 0: plt.ylabel('Probability', fontsize=10) else: sp.set_yticklabels([]) if i == len(gammas) // 2: plt.xlabel('Universe', fontsize=10) plt.xlim(1, P.size) y_max = y_max * 1.05 y_min = 0 - (y_max * 0.05) plt.ylim(-0.005, 0.065) ticks = [1] + [(P.size // len(P)) * j for j in range(1, len(P) + 1)] sp.set_xticks(ticks) grid.tight_layout(fig, pad=0.1, h_pad=0.1, w_pad=0.5) fig.savefig(figure_path, format='svg') tools.format_svg_labels(figure_path) if not figure_path.endswith('.svg'): tools.convert_svg(figure_path, figure_path)
def plot_click_entropy_all_experiments(figure_path): exp1 = tools.read_json_lines('../data/experiments/exp1_participants.json') exp2 = tools.read_json_lines('../data/experiments/exp2_participants.json') res1p = click_entropy(exp1, 'production') res1c = click_entropy(exp1, 'comprehension') res2 = click_entropy(exp2) fig, axes = plt.subplots(1, 3, figsize=(5.5, 2)) y, c = zip(*res1p) axes[0].scatter(range(len(res1p)), y, c=c, marker='x') axes[0].set_ylim(-0.1, 2.1) axes[0].set_xlim(0, len(res1p)) axes[0].set_xticks([]) axes[0].set_xticklabels([]) axes[0].set_title('Experiment 1 (P)', fontsize=10) y, c = zip(*res1c) axes[1].scatter(range(len(res1c)), y, c=c, marker='x') axes[1].set_ylim(0, 6) axes[1].set_xlim(0, len(res1p)) axes[1].set_xticks([]) axes[1].set_xticklabels([]) axes[1].set_title('Experiment 1 (C)', fontsize=10) y, c = zip(*res2) axes[2].scatter(range(len(res2)), y, c=c, marker='x') axes[2].plot([0, len(res1p)], [1.75, 1.75], c='red', linestyle='--') axes[2].set_ylim(-0.1, 2.1) axes[2].set_xlim(0, len(res1p)) axes[2].set_xticks([]) axes[2].set_xticklabels([]) axes[2].set_title('Experiment 2', fontsize=10) axes[0].set_ylabel('Button-click entropy') axes[1].set_xlabel('Participant') fig.tight_layout(pad=0.1, h_pad=0.5, w_pad=0.5) fig.savefig(figure_path, format='svg') tools.format_svg_labels(figure_path) if not figure_path.endswith('.svg'): tools.convert_svg(figure_path, figure_path)
def plot_final_gen_distributions(datasets, figure_path): fig, axes = plt.subplots(1, len(datasets), figsize=(7.2, 1.75)) for i, (label, dataset) in enumerate(datasets): plot_final_gen_densities(axes[i], dataset) axes[i].set_title(label, fontsize=7) axes[0].set_xticks([25, 75, 125]) axes[1].set_xticks([25, 75, 125]) axes[2].set_xticks([25, 75, 125]) axes[0].set_xlim(0, 150) axes[1].set_xlim(0, 150) axes[2].set_xlim(0, 150) axes[1].set_xlabel('Complexity') axes[3].set_xticks([4.25, 4.3, 4.35]) axes[4].set_xticks([4.25, 4.3, 4.35]) axes[5].set_xticks([4.25, 4.3, 4.35]) axes[3].set_xlim(4.2, 4.4) axes[4].set_xlim(4.2, 4.4) axes[5].set_xlim(4.2, 4.4) axes[4].set_xlabel('Cost') fig.tight_layout(pad=0.01, h_pad=0.01, w_pad=0.01) fig.savefig(figure_path, format='svg') tools.format_svg_labels(figure_path) if not figure_path.endswith('.svg'): tools.convert_svg(figure_path, figure_path)
def make_fig(figure_path): comp_weights = np.linspace(0, 3, 100) cost_weights = np.linspace(0, 100, 100) comp_stripe = np.array([-35.90911969399966 * i for i in comp_weights]) comp_qudrnt = np.array([-39.25512476486815 * i for i in comp_weights]) comp_sum = np.logaddexp2(comp_stripe, comp_qudrnt) p_comp_stripe = 2**(comp_stripe - comp_sum) p_comp_qudrnt = 2**(comp_qudrnt - comp_sum) cost_stripe = np.array([-4.294113843380405 * i for i in cost_weights]) cost_qudrnt = np.array([-4.200174400715539 * i for i in cost_weights]) cost_sum = np.logaddexp2(cost_stripe, cost_qudrnt) p_cost_stripe = 2**(cost_stripe - cost_sum) p_cost_qudrnt = 2**(cost_qudrnt - cost_sum) fig, axes = plt.subplots(1, 2, figsize=(5.5, 2.1), sharey=True) axes[0].plot(comp_weights, p_comp_stripe, c=colors.blue, linewidth=2, linestyle='-') axes[0].plot(comp_weights, p_comp_qudrnt, c=colors.blue, linewidth=2, linestyle=':') axes[0].set_ylabel('Prior probability') axes[0].set_xlabel('Weight (w)') axes[0].set_title('Simplicity prior (πsim)', fontsize=10) axes[0].set_xlim(0, comp_weights[-1]) axes[0].text(comp_weights[-1] * 0.97, 0.9, 'stripes', horizontalalignment='right', verticalalignment='center') axes[0].text(comp_weights[-1] * 0.97, 0.1, 'quadrants', horizontalalignment='right', verticalalignment='center') axes[1].plot(cost_weights, p_cost_stripe, c=colors.red, linewidth=2, linestyle='-') axes[1].plot(cost_weights, p_cost_qudrnt, c=colors.red, linewidth=2, linestyle=':') axes[1].set_xlabel('Weight (w)') axes[1].set_title('Informativeness prior (πinf)', fontsize=10) axes[1].set_xlim(0, cost_weights[-1]) axes[1].text(cost_weights[-1] * 0.97, 0.9, 'quadrants', horizontalalignment='right', verticalalignment='center') axes[1].text(cost_weights[-1] * 0.97, 0.1, 'stripes', horizontalalignment='right', verticalalignment='center') fig.tight_layout(pad=0.1, h_pad=0.5, w_pad=0.5) fig.savefig(figure_path, format='svg') tools.format_svg_labels(figure_path) if not figure_path.endswith('.svg'): tools.convert_svg(figure_path, figure_path)
def save_figure(figure, figure_path): with open(figure_path, mode='w', encoding='utf-8') as file: file.write(figure) if not figure_path.endswith('.svg'): tools.convert_svg(figure_path, figure_path)
def make_figure(datasets, figure_path, title=None, show_legend=False, deep_legend=False, figsize=None): if show_legend: if deep_legend: if figsize is None: figsize = (5.5, 5.0) fig, axes = plt.subplots(len(figure_layout), len(figure_layout[0]), figsize=figsize, squeeze=False, sharex=True) else: if figsize is None: figsize = (7.2, 1.75) fig, axes = plt.subplots(len(figure_layout), len(figure_layout[0]), figsize=figsize, squeeze=False) else: if figsize is None: figsize = (7.2, 1.6) fig, axes = plt.subplots(len(figure_layout), len(figure_layout[0]), figsize=figsize, squeeze=False) for (i, j), axis in np.ndenumerate(axes): measure = figure_layout[i][j] for k, (dataset, label, color, color_conf, linestyle) in enumerate(datasets): mean, conf_pos, conf_neg, start_gen = dataset[measure] xvals = list(range(start_gen, start_gen + len(mean))) axis.plot(xvals, mean, c=color, label=label, linestyle=linestyle, dash_capstyle="round", linewidth=2) axis.fill_between(xvals, conf_neg, conf_pos, facecolor=color_conf, alpha=0.5) handles, labels = axis.get_legend_handles_labels() ylim = measure_bounds[measure] ypad = (ylim[1] - ylim[0]) * 0.05 axis.set_ylim(ylim[0] - ypad, ylim[1] + ypad) axis.set_ylabel(measures_names[measure]) x_max = len(dataset[figure_layout[i][j]][0]) - 1 if figure_layout[i][j] == 'error': x_max += 1 axis.set_xlim(0, x_max) axis.set_xticks(list(range(0, x_max + 1, x_max // 5))) if i == len(axes) - 1: axis.set_xlabel('Generation') if title: fig.suptitle(title) if show_legend: if deep_legend: fig.legend(handles, labels, loc='lower center', ncol=1, frameon=False) fig.tight_layout(pad=2, h_pad=0.5, w_pad=0.5, rect=(0, 0.1, 1, 1)) else: legend_offset = 1 / (figsize[1] / 0.15) if len(figure_layout) == 1: fig.legend(handles, labels, ncol=3, frameon=False, bbox_to_anchor=(0.5, -0.04), loc='lower center') else: fig.legend(handles, labels, ncol=3, frameon=False, bbox_to_anchor=(0.5, -0.02), loc='lower center') fig.tight_layout(pad=0.1, h_pad=0.5, w_pad=0.5, rect=(0.01, legend_offset, 1, 1)) else: fig.tight_layout(pad=0.1, h_pad=0.5, w_pad=0.5, rect=(0.01, 0, 1, 1)) fig.savefig(figure_path, format='svg') tools.format_svg_labels(figure_path) if not figure_path.endswith('.svg'): tools.convert_svg(figure_path, figure_path)
def make_carstensen_figure(datasets, figure_path, figsize): fig, axes = plt.subplots(1, 2, figsize=figsize, sharey=True) y_bounds = (4.6, 5) y_pad = (y_bounds[1] - y_bounds[0]) * 0.05 for k, (dataset, label, color, color_conf, linestyle) in enumerate(datasets): mean, conf_pos, conf_neg, start_gen = dataset['cost'] xvals = list(range(start_gen, start_gen + len(mean))) axes[0].plot(xvals, mean, c=color, label=label, linestyle=linestyle, dash_capstyle='round', linewidth=2) axes[0].fill_between(xvals, conf_neg, conf_pos, facecolor=color_conf, alpha=0.5) handles, labels = axes[0].get_legend_handles_labels() axes[0].set_ylim(y_bounds[0] - y_pad, y_bounds[1] + y_pad) axes[0].set_ylabel('Communicative cost (bits)') axes[0].set_xlim(0, 10) axes[0].set_xticks(list(range(0, 11, 2))) axes[0].set_xlabel('Generation') for k, (dataset, label, color, color_conf, linestyle) in enumerate(datasets): mean, conf_pos, conf_neg, start_gen = dataset['cost'] xvals = list(range(start_gen, start_gen + len(mean))) axes[1].plot(xvals, mean, c=color, label=label, linestyle=linestyle, dash_capstyle='round', linewidth=2) axes[1].fill_between(xvals, conf_neg, conf_pos, facecolor=color_conf, alpha=0.5) axes[1].set_ylim(y_bounds[0] - y_pad, y_bounds[1] + y_pad) axes[1].set_xlim(0, 100) axes[1].set_xticks(list(range(0, 101, 20))) axes[1].set_xlabel('Generation') legend_offset = 1 / (figsize[1] / 0.15) fig.legend(handles, labels, ncol=3, frameon=False, bbox_to_anchor=(0.5, -0.04), loc='lower center') fig.tight_layout(pad=0.1, h_pad=0.5, w_pad=0.5, rect=(0.01, legend_offset, 1, 1)) fig.savefig(figure_path, format='svg') tools.format_svg_labels(figure_path) if not figure_path.endswith('.svg'): tools.convert_svg(figure_path, figure_path)
def make_figure(datasets, opt, figure_path, n_levels=32): fig = plt.figure(figsize=(5.1, 1.9)) gs = gridspec.GridSpec(2, 4, width_ratios=[8, 8, 10, 1]) exp_axis = plt.subplot(gs[0, 0]) err_axis = plt.subplot(gs[0, 1]) com_axis = plt.subplot(gs[1, 0]) cst_axis = plt.subplot(gs[1, 1]) fit_axis = plt.subplot(gs[0:2, 2]) leg_axis = plt.subplot(gs[0:2, 3]) (dataset, label, color, color_conf, linestyle) = datasets for measure, axis in [('expressivity', exp_axis), ('error', err_axis), ('complexity', com_axis), ('cost', cst_axis)]: mean, conf_pos, conf_neg, start_gen = dataset[measure] xvals = list(range(start_gen, start_gen + len(mean))) axis.plot(xvals, mean, c=color, label=label, linestyle=linestyle, dash_capstyle="round", linewidth=2) axis.fill_between(xvals, conf_neg, conf_pos, facecolor=color_conf, alpha=0.5) ylim = measure_bounds[measure] ypad = (ylim[1] - ylim[0]) * 0.05 axis.set_ylim(ylim[0] - ypad, ylim[1] + ypad) axis.set_ylabel(measures_names[measure], fontsize=8) axis.set_yticklabels([]) axis.set_yticks([]) for tick in axis.xaxis.get_major_ticks(): tick.label.set_fontsize(7) axis.set_xlim(0, 10) if measure == 'expressivity' or measure == 'error': axis.set_xticks([]) else: axis.set_xticks([0, 2, 4, 6, 8, 10]) axis.set_xlabel('Generation', fontsize=8) (w_star, e_star), neg_log_p_sim = expected_minimum(opt) print('Simplicity:', len(opt.func_vals), 'iterations)') print('w* =', w_star) print('e* =', e_star) print('log(P) =', -neg_log_p_sim) space = opt.space samples = np.asarray(opt.x_iters) rvs_transformed = space.transform(space.rvs(n_samples=250)) xi, yi, zi = plots.partial_dependence(space, opt.models[-1], 1, 0, rvs_transformed, 250) zmin = zi.min() zmax = zi.max() levels = np.geomspace(zmin, zmax, n_levels + 1) cs = fit_axis.contourf(xi, yi, zi, levels, cmap='viridis_r') fit_axis.plot([0, w_star, w_star], [e_star, e_star, 0], c='k', linestyle=':') fit_axis.scatter(w_star, e_star, c='k', s=100, lw=0, marker='*') fit_axis.set_xlim(0, 2) fit_axis.set_ylim(0, 1) fit_axis.set_xticks([0, 0.5, 1.0, 1.5, 2.0]) for tick in fit_axis.xaxis.get_major_ticks(): tick.label.set_fontsize(7) fit_axis.set_yticklabels([]) fit_axis.set_yticks([]) fit_axis.set_xlabel('Weight (w)', fontsize=8) fit_axis.set_ylabel('Noise (ε)', fontsize=8) cb = plt.colorbar(cs, cax=leg_axis) cb.set_ticks([]) leg_axis.yaxis.set_label_position("left") leg_axis.set_ylabel('log likelihood', fontsize=8) leg_axis.invert_yaxis() fig.tight_layout(pad=0.1, h_pad=0.5, w_pad=0.5, rect=(0.01, 0, 1, 1)) fig.savefig(figure_path, format='svg') tools.format_svg_labels(figure_path) if not figure_path.endswith('.svg'): tools.convert_svg(figure_path, figure_path)