<jupyter_start><jupyter_text>A notebook to process experimental results of ex2_prob_params.py.<jupyter_code>%load_ext autoreload
%autoreload 2
%matplotlib inline
#%config InlineBackend.figure_format = 'svg'
#%config InlineBackend.figure_format = 'pdf'

import autograd.numpy as np

import kmod.plot as plot
import matplotlib
import matplotlib.pyplot as plt

import scipy.stats as stats
plot.set_default_matplotlib_options()
def load_plot_vs_params(fname, xlabel='Problem parameter', show_legend=True, 
                        xscale='linear', yscale='linear'):
    func_xvalues = lambda agg_results: agg_results['prob_params']
    ex = 2
    def func_title(agg_results):
        repeats, _, n_methods = agg_results['job_results'].shape
        alpha = agg_results['alpha']
        sample_size = agg_results['sample_size']
#         title = r'%s. %d trials. Sample size: %d. $\alpha$ = %.2g.'%\
#             ( agg_results['prob_label'], repeats, sample_size, alpha)
        title = 'n = {}'.format(sample_size)
        return title
    #plt.figure(figsize=(10,5))
    results = plot.plot_prob_reject(
        ex, fname, func_xvalues, xlabel, func_title=func_title)
    
    plt.title('')
    plt.gca().legend(loc='upper right').set_visible(show_legend)
    if show_legend:
        plt.legend(bbox_to_anchor=(1.00, 1.08))
    
    plt.grid(False)
    
    #plt.grid(True)
    if xscale is not None:
        plt.xscale(xscale)
    if yscale is not None:
        plt.yscale(yscale)
    return results

def load_runtime_vs_params(fname, xlabel='Problem parameter', 
                      show_legend=True, xscale='linear', yscale='linear'):
    func_xvalues = lambda agg_results: agg_results['prob_params']
    ex = 2
    def func_title(agg_results):
        repeats, _, n_methods = agg_results['job_results'].shape
        alpha = agg_results['alpha']
        title = '%s. %d trials. $\\alpha$ = %.2g.'%\
            ( agg_results['prob_label'], repeats, alpha)
        return title
    
    #plt.figure(figsize=(10,6))
    
    results = plot.plot_runtime(ex, fname,  
                                func_xvalues, xlabel=xlabel, func_title=func_title)
    
    plt.title('')
    plt.gca().legend(loc='best').set_visible(show_legend)
    if show_legend:
        plt.legend(bbox_to_anchor=(1.80, 1.05))
    
    plt.grid(False)
    if xscale is not None:
        plt.xscale(xscale)
    if yscale is not None:
        plt.yscale(yscale)
        
    return results<jupyter_output><empty_output><jupyter_text>----------  1D Gaussian problem.  $$ p = \mathcal{N}(\mu_p, 1)$$$$ q = \mathcal{N}(0.5, 1)$$$$ r = \mathcal{N}(0, 1)$$<jupyter_code># gauss1d_fname = 'ex2-stdnorm_shift_d1-me4_n300_rs50_pmi0.4_pma0.7_a0.050.p'
# gauss1d_results = load_plot_vs_params(gauss1d_fname, show_legend=True, xlabel='$\mu_P$')
# # plt.yticks([0, 0.025, 0.05, 0.075, 0.1])
# plt.xticks([0.4, 0.5, 0.6, 0.7])
# plt.yticks([0, 0.05, 0.5, 1], ['0', '', '0.5', '1'])
# plt.grid()
# plt.savefig(gauss1d_fname.replace('.p', '.pdf', 1), bbox_inches='tight')
# load_runtime_vs_params(gauss1d_fname, show_legend=False);
# # plt.yticks([0, 100, 200, 300])
# plt.savefig(gauss1d_fname.replace('.p', '_time.pdf', 1), bbox_inches='tight',
#            show_legend=False)<jupyter_output><empty_output><jupyter_text>--------<jupyter_code># fname = 'ex2-stdnorm_shift_d10-me4_n300_rs50_pmi0.4_pma0.7_a0.050.p'
# results = load_plot_vs_params(fname, show_legend=True, xlabel='$\mu_P$')

# plt.xticks([0.4, 0.5, 0.6, 0.7])
# plt.yticks([0, 0.05, 0.5, 1], ['0', '', '0.5', '1'])
# plt.grid()
# plt.savefig(fname.replace('.p', '.pdf', 1), bbox_inches='tight')

# load_runtime_vs_params(fname, show_legend=False);
# plt.savefig(fname.replace('.p', '_time.pdf', 1), bbox_inches='tight',
#            show_legend=False)<jupyter_output><empty_output><jupyter_text>----------------<jupyter_code># fname = 'ex2-stdnorm_shift_d20-me4_n500_rs50_pmi0.4_pma0.7_a0.050.p'
# results = load_plot_vs_params(fname, show_legend=True, xlabel='$\mu_P$')

# plt.xticks([0.4, 0.5, 0.6, 0.7])
# plt.yticks([0, 0.05, 0.5, 1], ['0', '', '0.5', '1'])
# plt.grid()
# plt.savefig(fname.replace('.p', '.pdf', 1), bbox_inches='tight')

# load_runtime_vs_params(fname, show_legend=False);
# plt.savefig(fname.replace('.p', '_time.pdf', 1), bbox_inches='tight',
#            show_legend=False)<jupyter_output><empty_output><jupyter_text>--------------<jupyter_code># fname = 'ex2-gbrbm_dx10_dh5-me6_n600_rs200_pmi0.1_pma0.6_a0.050.p'
# results = load_plot_vs_params(fname, show_legend=True, xlabel='Perturbation')

# plt.xticks([0.2, 0.3, 0.4, 0.5])
# plt.yticks([0.05, 0.5, 1], ['0.05', '0.5', '1'])
# plt.grid()
# plt.savefig(fname.replace('.p', '.pdf', 1), bbox_inches='tight')

# load_runtime_vs_params(fname, show_legend=False);
# plt.savefig(fname.replace('.p', '_time.pdf', 1), bbox_inches='tight',
#            show_legend=False)<jupyter_output><empty_output><jupyter_text>--------------<jupyter_code>fname = 'ex2-gbrbm_dx20_dh5-me5_n2000_rs300_pmi0.2_pma0.7_a0.050.p'
results = load_plot_vs_params(fname, show_legend=False, xlabel='Perturbation $\epsilon$')

plt.xticks([0.2, 0.3, 0.4, 0.6])
# plt.yticks([0, 0.05, 0.5], ['0', '', '0.5'])
# plt.grid()
plt.savefig(fname.replace('.p', '.pdf', 1), bbox_inches='tight')

load_runtime_vs_params(fname, show_legend=False);

plt.xticks([0.2, 0.3, 0.4, 0.6])
plt.savefig(fname.replace('.p', '_time.pdf', 1), bbox_inches='tight',
           show_legend=False, xlabel='Perturbation')<jupyter_output><empty_output><jupyter_text>---------------<jupyter_code># fname = 'ex2-gbrbm_dx30_dh10-me6_n800_rs50_pmi0.1_pma0.5_a0.050.p'
# results = load_plot_vs_params(fname, show_legend=True, xlabel='Perturbation')

# plt.xticks([0.2, 0.3, 0.4, 0.5])
# plt.yticks([0, 0.05, 0.5], ['0', '', '0.5'])
# plt.grid()
# plt.savefig(fname.replace('.p', '.pdf', 1), bbox_inches='tight')

# load_runtime_vs_params(fname, show_legend=False);
# plt.savefig(fname.replace('.p', '_time.pdf', 1), bbox_inches='tight',
#            show_legend=False)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1913447189520809, 'fraction_numerical': 0.0497429945282706, 'mean_word_length': 3.9523809523809526, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '288519', 'license': 'MIT', 'n_tokens_mistral': 2645, 'n_tokens_neox': 2472, 'n_words': 363, 'path': 'ipynb/ex2_results.ipynb', 'repo_name': 'wittawatj/kernel-mod', 'size': '6031'}