In [ ]:
%load_ext autoreload
%autoreload 2
%matplotlib inline
#%config InlineBackend.figure_format = 'svg'
#%config InlineBackend.figure_format = 'svg'
#%config InlineBackend.figure_format = 'pdf'
import freqopttest.util as util
import freqopttest.data as data
import freqopttest.ex.exglobal as exglo
import freqopttest.kernel as kernel
import freqopttest.tst as tst
import freqopttest.glo as glo
import freqopttest.plot as plot
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
import scipy.stats as stats
import sys

Process ex1 results (test power vs n)


In [ ]:
def load_plot(fname, h1_true, show_legend=True, confidence=0.99):
    # to get the test sizes
    func_xvalues = lambda results: np.array(results['sample_sizes'])*(1.0 - results['tr_proportion'])
    results = plot.plot_prob_stat_above_thresh(1, fname, h1_true, func_xvalues, 'Test sample size')
    plt.title('')
    plt.gca().legend().set_visible(show_legend)
        
    return results


def load_runtime_vs_n(fname, h1_true=True, xlabel='Test sample size', 
                      show_legend=True, xscale='log', yscale='log'):
    func_xvalues = lambda results: np.array(results['sample_sizes'])*(1.0 - results['tr_proportion'])
    ex = 1
    def func_title(agg_results):
        repeats, _, n_methods = agg_results['test_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)
    #plt.grid(True)
    if xscale is not None:
        plt.xscale(xscale)
    if yscale is not None:
        plt.yscale(yscale)
    xvalues = func_xvalues(results)
    plt.xticks(xvalues)
    plt.autoscale(tight=True)
        
    return results

In [ ]:
# font options
font = {
    #'family' : 'normal',
    #'weight' : 'bold',
    'size'   : 18
}

plt.rc('font', **font)
plt.rc('lines', linewidth=2)
matplotlib.rcParams['pdf.fonttype'] = 42
matplotlib.rcParams['ps.fonttype'] = 42

In [ ]:
### H0 true. Same Gaussian
sg_fname = 'ex1-sg_d50-me7_J5_rs500_nmi2000_nma10000_a0.010_trp0.50.p'
#sg_fname = 'ex1-sg_d50-me7_J5_rs200_nmi2000_nma10000_a0.010_trp0.50.p'
sg_results = load_plot(sg_fname, False, False)
#plt.autoscale(tight=True)
plt.savefig(sg_fname.replace('.p', '.pdf', 1), bbox_inches='tight')

In [ ]:
load_runtime_vs_n(sg_fname, xscale='linear', yscale='log', show_legend=False);
#plt.legend(bbox_to_anchor=(1.7, 1))
#plt.ylim([0.08, 2000])
plt.savefig(sg_fname.replace('.p', '', 1) + '_time.pdf', bbox_inches='tight')

In [ ]:
### H1 true. Blobs
blobs_fname = 'ex1-SSBlobs-me7_J5_rs500_nmi2000_nma10000_a0.010_trp0.50.p'
#blobs_fname = 'ex1-SSBlobs-me7_J5_rs200_nmi2000_nma10000_a0.010_trp0.50.p'
blobs_results = load_plot(blobs_fname, True, False)
plt.legend(bbox_to_anchor=(1.70, 1.07))
plt.savefig(blobs_fname.replace('.p', '.pdf', 1), bbox_inches='tight')

In [ ]:
load_runtime_vs_n(blobs_fname, xscale='linear', yscale='log', show_legend=False);
plt.legend(bbox_to_anchor=(1.7, 1.05))
plt.savefig(blobs_fname.replace('.p', '', 1) + '_time.pdf', bbox_inches='tight')

In [ ]:
# H1 true. Gaussian mean diff. 
gmd_fname = 'ex1-gmd_d100-me7_J5_rs500_nmi2000_nma10000_a0.010_trp0.50.p'
#gmd_fname = 'ex1-gmd_d100-me7_J5_rs200_nmi2000_nma10000_a0.010_trp0.50.p'
gmd_results = load_plot(gmd_fname, True, False)
#plt.legend()

plt.savefig(gmd_fname.replace('.p', '.pdf', 1), bbox_inches='tight')

In [ ]:
load_runtime_vs_n(gmd_fname, xscale='linear', yscale='log', show_legend=False);
#plt.legend(bbox_to_anchor=(1.7, 1))
plt.savefig(gmd_fname.replace('.p', '', 1) + '_time.pdf', bbox_inches='tight')

In [ ]:
# H1 true. Gaussian variance diff. 
gvd_fname = 'ex1-gvd_d50-me7_J5_rs500_nmi2000_nma10000_a0.010_trp0.50.p'
#gvd_fname = 'ex1-gvd_d50-me7_J5_rs200_nmi2000_nma10000_a0.010_trp0.50.p'
gvd_results = load_plot(gvd_fname, True, False)
plt.savefig(gvd_fname.replace('.p', '.pdf', 1))

In [ ]:
load_runtime_vs_n(gvd_fname, xscale='linear', yscale='log', show_legend=False);
#plt.legend(bbox_to_anchor=(1.7, 1))
plt.savefig(gvd_fname.replace('.p', '', 1) + '_time.pdf', bbox_inches='tight')

In [ ]: