A notebook to process experimental results of ex1_vary_n.py. p(reject) as problem sample size increases.


In [ ]:
%load_ext autoreload
%autoreload 2
%matplotlib inline
#%config InlineBackend.figure_format = 'svg'
#%config InlineBackend.figure_format = 'pdf'

import numpy as np

import matplotlib
import matplotlib.pyplot as plt
import kgof.data as data
import kgof.glo as glo
import kgof.goftest as gof
import kgof.kernel as kernel
import kgof.plot as plot
import kgof.util as util

import scipy.stats as stats

In [ ]:
import kgof.plot
kgof.plot.set_default_matplotlib_options()

In [ ]:
def load_plot_vs_ns(fname, show_legend=True, xscale='linear', yscale='linear'):
    """
    ns = sample sizes
    """
    func_xvalues = lambda agg_results: agg_results['ns']
    ex = 1
    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,5))
    results = plot.plot_prob_reject(
        ex, fname, func_xvalues, '', func_title=func_title)
    
    plt.title('')
    
    if xscale is not None:
        plt.xscale(xscale)
    if yscale is not None:
        plt.yscale(yscale)
    
    plt.xlabel('Sample size $n$')
    plt.gca().legend(loc='best').set_visible(show_legend)
    if show_legend:
        plt.legend(bbox_to_anchor=(1.0, 1.05))
        
    plt.grid(False)
    return results


def load_runtime_vs_ns(fname, xlabel='Sample size $n$', 
                      show_legend=True, xscale='linear', yscale='linear'):
    func_xvalues = lambda agg_results: agg_results['ns']
    ex = 1
    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.0, 1.05))
    
    #plt.grid(True)
    if xscale is not None:
        plt.xscale(xscale)
    if yscale is not None:
        plt.yscale(yscale)
    return results

In [ ]:
# # GMD
# # gmd_fname = 'ex1-gmd_p05_d10_ns-me4_rs50_nmi1000_nma4000_a0.050_trp0.50.p'
# gmd_fname = 'ex1-gmd_p03_d10_ns-me4_rs30_nmi1000_nma7000_a0.050_trp0.50.p'
# gmd_results = load_plot_vs_ns(gmd_fname, show_legend=True)
# plt.figure()
# load_runtime_vs_ns(gmd_fname);
$$p(x)=\mathcal{N}([0, 0,\ldots, 0], I) \\ q(x)=\mathcal{N}([c,0,\ldots, 0], I)$$

In [ ]:
gbrbm_fname = 'ex1-gbrbm_dx50_dh10_vp1-me6_rs200_nmi1000_nma4000_a0.050_trp0.20.p'
# plt.ylim([0, 0.1])
gbrbm_results = load_plot_vs_ns(gbrbm_fname, show_legend=False)
plt.savefig(gbrbm_fname.replace('.p', '.pdf', 1), bbox_inches='tight')

In [ ]:
load_runtime_vs_ns(gbrbm_fname, show_legend=False);
plt.yticks([0, 100, 200, 300])
plt.savefig(gbrbm_fname.replace('.p', '_time.pdf', 1), bbox_inches='tight',
           show_legend=False)

In [ ]:
gbrbm_h0_fname = 'ex1-gbrbm_dx50_dh10_h0-me6_rs200_nmi1000_nma4000_a0.050_trp0.20.p'
gbrbm_h0_results = load_plot_vs_ns(gbrbm_h0_fname, show_legend=False)
# plt.ylim([0.01, 0.08])
plt.savefig(gbrbm_h0_fname.replace('.p', '.pdf', 1), bbox_inches='tight',
           show_legend=False)

In [ ]:
load_runtime_vs_ns(gbrbm_h0_fname, show_legend=False);
plt.yticks([0, 100, 200, 300])
plt.savefig(gbrbm_h0_fname.replace('.p', '_time.pdf', 1), bbox_inches='tight',
           show_legend=False)

In [ ]:
# gbrbm_highd_fname = 'ex1-gbrbm_dx50_dh40_vp1-me6_rs200_nmi1000_nma4000_a0.050_trp0.20.p'
# gbrbm_highd_fname = 'ex1-gbrbm_dx50_dh40_vp1-me1_rs200_nmi1000_nma4000_a0.050_trp0.20.p'
gbrbm_highd_fname = 'ex1-gbrbm_dx50_dh40_vp1-me2_rs200_nmi1000_nma4000_a0.050_trp0.20.p'
gbrbm_highd_results = load_plot_vs_ns(gbrbm_highd_fname, show_legend=False)
plt.yticks([0, 0.25, 0.5, 0.75])
plt.ylim([0, 0.75])
plt.ylabel('P(detect difference)', fontsize=26)

plt.savefig(gbrbm_highd_fname.replace('.p', '.pdf', 1), bbox_inches='tight',
           show_legend=False)

In [ ]:
load_runtime_vs_ns(gbrbm_highd_fname, show_legend=False);
plt.yticks([0, 100, 200, 300])
plt.ylim([0, 300])
plt.savefig(gbrbm_highd_fname.replace('.p', '_time.pdf', 1), bbox_inches='tight',
           show_legend=False)

In [ ]:
gbrbm_highd_h0_fname = 'ex1-gbrbm_dx50_dh40_h0-me6_rs200_nmi1000_nma4000_a0.050_trp0.20.p'
gbrbm_highd_h0_results = load_plot_vs_ns(gbrbm_highd_h0_fname, show_legend=False)
plt.savefig(gbrbm_h0_fname.replace('.p', '.pdf', 1), bbox_inches='tight',
           show_legend=False)

In [ ]:
# gbrbm_fname = 'ex1-gbrbm_dx50_dh10_vp1-me4_rs30_nmi1000_nma5000_a0.050_trp0.50.p'
# gbrbm_results = load_plot_vs_ns(gbrbm_fname)
# plt.figure()
# load_runtime_vs_ns(gbrbm_fname);

In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]: