A notebook to process experimental results of ex2_prob_params.py. p(reject) as problem parameters are varied.


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 [ ]:
# np.random.seed(0)
# x = np.linspace(-5., 5., 50)
# y = 3 * np.exp(-0.5 * (x - 1.3)**2 / 0.8**2)
# y += np.random.normal(0., 0.2, x.shape)
# f = plt.figure(0)
# plt.plot(x,y, 'b-')
# plt.xlabel(r'$\alpha$')
# plt.ylabel('Test power')
# f.savefig('test.pdf', bbox_inches='tight')

In [ ]:
def load_plot_vs_Js(fname, show_legend=True, xscale='log', yscale='linear'):
    """
    J = number of test locations.
    """
    func_xvalues = lambda agg_results: agg_results['Js']
    ex = 3
    def func_title(agg_results):
        repeats, _, n_methods = agg_results['job_results'].shape
        alpha = agg_results['alpha']
        test_size = (1.0 - agg_results['tr_proportion'])*agg_results['sample_size']
        title = '%s. %d trials. test size: %d. $\\alpha$ = %.2g.'%\
            ( agg_results['prob_label'], repeats, test_size, 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('$J$')
    plt.gca().legend(loc='best').set_visible(show_legend)
    if show_legend:
        plt.legend(bbox_to_anchor=(1.70, 1.05))
        
    plt.grid(False)
        
    return results


def load_runtime_vs_Js(fname, xlabel='$J$ parameter', 
                      show_legend=True, xscale='linear', yscale='linear'):
    func_xvalues = lambda agg_results: agg_results['Js']
    ex = 3
    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.70, 1.05))
    
    plt.grid(False)
    if xscale is not None:
        plt.xscale(xscale)
    if yscale is not None:
        plt.yscale(yscale)
        
    return results

In [ ]:
# GMD
# gmd_fname = 'ex3-gmd1-me2_n500_rs100_Jmi2_Jma32_a0.050_trp0.50.p'
# gmd_results = load_plot_vs_Js(gmd_fname, show_legend=True)

In [ ]:
# p: normal, q: Gaussian mixture
# g_vs_gmm_fname = 'ex3-g_vs_gmm_d5-me2_n500_rs50_Jmi2_Jma384_a0.050_trp0.50.p'
# g_vs_gmm_fname = 'ex3-g_vs_gmm_d5-me2_n500_rs100_Jmi2_Jma384_a0.050_trp0.50.p'
# g_vs_gmm_fname = 'ex3-g_vs_gmm_d2-me2_n500_rs50_Jmi2_Jma384_a0.050_trp0.50.p'
# g_vs_gmm_fname = 'ex3-g_vs_gmm_d1-me2_n500_rs50_Jmi2_Jma384_a0.050_trp0.50.p'
g_vs_gmm_fname = 'ex3-g_vs_gmm_d1-me2_n500_rs200_Jmi2_Jma384_a0.050_trp0.50.p'
# g_vs_gmm_fname = 'ex3-g_vs_gmm_d1-me2_n800_rs50_Jmi2_Jma384_a0.050_trp0.50.p'
g_vs_gmm_results = load_plot_vs_Js(g_vs_gmm_fname, show_legend=False)
plt.xticks([1, 10, 1e2, 1e3])
plt.savefig(g_vs_gmm_fname.replace('.p', '.pdf', 1), bbox_inches='tight')

In [ ]:
# Gaussian mixture
# gmm_fname = 'ex3-gmm_d1-me2_n500_rs100_Jmi2_Jma32_a0.050_trp0.50.p'
# gmm_results = load_plot_vs_Js(gmm_fname)

In [ ]:
# Same Gaussian
sg5_fname = "ex3-sg5-me2_n500_rs100_Jmi2_Jma384_a0.050_trp0.50.p"
sg5_results = load_plot_vs_Js(sg5_fname, show_legend=False)
plt.ylim([0, 0.05])
plt.xticks([1, 10, 1e2, 1e3])
plt.savefig(sg5_fname.replace('.p', '.pdf', 1), bbox_inches='tight')
$$p(x)=\mathcal{N}(0, I) \\ q(x)=\mathcal{N}(0, I)$$

In [ ]:
# Gaussian variance difference. 
gvd5_fname = 'ex3-gvd5-me2_n500_rs100_Jmi2_Jma384_a0.050_trp0.50.p'
gvd5_results = load_plot_vs_Js(gvd5_fname, show_legend=True)
plt.legend(bbox_to_anchor=(1.8, 1.05))
plt.xticks([1, 10, 1e2, 1e3])
plt.savefig(gvd5_fname.replace('.p', '.pdf', 1), bbox_inches='tight')
# plt.legend(ncol=2)
#plt.ylim([0.03, 0.1])
$$p(x)=\mathcal{N}(0, I) \\ q(x)=\mathcal{N}(0, \mathrm{diag}(2,1,1,\ldots))$$

In [ ]:
# Gauss-Bernoulli RBM. H1 case
# rbm_h1_fname = 'ex3-gbrbm_dx5_dh3_v5em3-me2_n500_rs100_Jmi2_Jma384_a0.050_trp0.50.p'
# rbm_h1_results = load_plot_vs_Js(rbm_h1_fname, show_legend=True)

In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]: