def compareTimes(table_names = ['FinalEstimate_4x100_N=100','FinalEstimate_4x100_N=1000']): regime_labels = {'subT': 'Sub-threshold', 'superT': 'Supra-threshold', 'superSin': 'Supra-sinusoidal', 'crit': 'Critical'} for table_name, N in zip(table_names, [100, 1000]): analyzer = DataAnalyzer(table_name); print table_name for regime in analyzer.getAllRegimes(): print regime_labels[regime] for mthd in [ 'Fortet', 'FP']: walltimes = analyzer.getWallTimes(regime, mthd) mu, sigma = mean(walltimes), std(walltimes) print '& %.2f'%mu, r'$\pm$ %.2f'%sigma print r'\\'
def tabulateEstimates(table_file_names, methods): for table_file_name in table_file_names: print table_file_name analyzer = DataAnalyzer(table_file_name) regimeNames = analyzer.getAllRegimes() param_names = [r'\a',r'\b',r'\g'] for regime in regimeNames: print r'\subfloat[%s]{\begin{tabular}{|c|ccc|} '%regime_labels[regime] abg_true = analyzer.getTrueParamValues(regime) print 'Parameter' for mthd in methods: print r'&', mthd print r'\\ \hline' for idx in xrange(3): print r'$%s=%.2f$' %(param_names[idx],abg_true[idx]) for mthd in methods: abg_est = array(analyzer.getAllEstimates(regime, mthd)) est = sort(abg_est[:, idx]) print r'& $%.2f : [%.2f, %.2f]$' %(mean(est), est[2], est[-3]) print r'\\' print r' \end{tabular}}\\' print 64*'#'
def crossAnalyze(table_file_name, fig_id = '', Method1 = 'Fortet', Method2 = 'FP', regimeNames = None): analyzer = DataAnalyzer(table_file_name) mpl.rcParams['figure.figsize'] = 17, 5*4 mpl.rcParams['figure.subplot.left'] = .15 mpl.rcParams['figure.subplot.right'] = .975 mpl.rcParams['figure.subplot.bottom'] = .05 mpl.rcParams['figure.subplot.top'] = .95 mpl.rcParams['figure.subplot.wspace'] = .25 mpl.rcParams['figure.subplot.hspace'] = .375 fig = figure(); if None==regimeNames: regimeNames = analyzer.getAllRegimes() plot_scale = 1.05; regime_tags = {'superT':'Supra-Threshold', 'crit':'Critical', 'subT':'Sub-Threshold', 'superSin':'Super-Sinusoidal', 'theta1':r'$\Omega=1$', 'theta5':r'$\Omega=5$', 'theta10':r'$\Omega=10$', 'theta20':r'$\Omega=20$'} xlabel_font_size = 32 for regime_idx,regime in enumerate(regimeNames): abg_true = analyzer.getTrueParamValues(regime) print regime, abg_true abgs = {}; abgs[Method1] = array( analyzer.getAllEstimates(regime, Method1) ) abgs[Method2] = array( analyzer.getAllEstimates(regime, Method2) ) for param_idx, pname in zip(arange(3), [r'\alpha', r'\beta', r'\gamma']): axu_lim = amax( r_[ abgs[Method1][:, param_idx], abgs[Method2][:, param_idx]]) axl_lim = amin( r_[ abgs[Method1][:, param_idx], abgs[Method2][:, param_idx]]) plot_buffer = (plot_scale -1.)*(axu_lim - axl_lim); axu_lim += plot_buffer axl_lim -= plot_buffer ax = subplot(len(regimeNames),3, regime_idx*3 + param_idx+1, aspect='equal') plot(abgs[Method1][:, param_idx], abgs[Method2][:, param_idx], linestyle='None', color= 'k', marker= 'o', markersize = 7 ) if 0 == param_idx: text(-.4, 0.5, regime_tags[regime], horizontalalignment='center', verticalalignment='center', transform = ax.transAxes, rotation='vertical', size = xlabel_font_size) # axu_lim, axl_lim = xlim() hlines(abg_true[param_idx], axl_lim, axu_lim, linestyles = 'dashed' ) # axu_lim, axl_lim = ylim() vlines(abg_true[param_idx], axl_lim, axu_lim, linestyles = 'dashed' ) ax.xaxis.set_major_locator(MaxNLocator(6)) ax.yaxis.set_major_locator(MaxNLocator(6)) xlim((axl_lim, axu_lim)); ylim((axl_lim, axu_lim)); xlabel(Method1,fontsize = xlabel_font_size); ylabel(Method2,fontsize = xlabel_font_size); title('$'+ pname + ' = %.2f$'%abg_true[param_idx], fontsize = 32) t = add_inner_title(ax, chr(ord('A') + regime_idx*3 + param_idx), loc=2, size=dict(size=ABCD_LABEL_SIZE)) t.patch.set_ec("none") t.patch.set_alpha(0.5) if '' != fig_id: file_name = os.path.join(FIGS_DIR, fig_id + '_cross_compare_joint.pdf') print 'saving to ', file_name savefig(file_name)
def postProcessThetaBoxPlots(table_file_name, fig_id = '', Methods = ['Initializer', 'FP', 'Fortet'], regimeNames = ['theta1', 'theta5', 'theta10', 'theta20'] ): analyzer = DataAnalyzer(table_file_name) if None==regimeNames: regimeNames = analyzer.getAllRegimes() mpl.rcParams['figure.figsize'] = 17, 12 figure() subplots_adjust(left=0.1, right=0.975, top=0.9, bottom=0.15, wspace = 0.3, hspace = 0.01) lgs = GridSpec(4,3) method_labels = ['Initializer', 'Numerical FP', 'Fortet'] xlabel_font_size = 24 sample_size_texts = ['N=100', 'N=1000'] yupper = 3*[-inf]; ylower = 3*[inf] for params_idx in xrange(3): for mthd in Methods: for regime in regimeNames: Omega = int(regime[5:]) ests = array(analyzer.getAllEstimates(regime, mthd))[:,params_idx] if (2 == params_idx): ests /= sqrt( 1. + Omega*Omega) ylower[params_idx] = amin([ylower[params_idx], amin(ests)]) yupper[params_idx] = amax([yupper[params_idx], amax(ests)]) for regime_idx, regime in enumerate(regimeNames): abg_true = analyzer.getTrueParamValues(regime) Omega = int(regime[5:]) print regime, abg_true, Omega abgs = {} param_tags = [r' \alpha ', r' \beta ', r' \gamma / \sqrt{1+ \Omega}'] for mthd in Methods: abgs[mthd] = array(analyzer.getAllEstimates(regime, mthd)) for params_idx, param_tag in enumerate(param_tags): print params_idx, param_tag subplot_idx = regime_idx*3 + params_idx; ax = subplot(lgs[subplot_idx]); hold(True) # for mthd in Methods: param_ests = [ abgs[mthd][:,params_idx] for mthd in Methods] param_true = abg_true[params_idx] if params_idx == 2: param_true /= sqrt(1. + Omega*Omega) for idx in xrange(len(param_ests)): param_ests[idx] /= sqrt(1. + Omega*Omega) boxplot(param_ests, positions = [1,3,5]) hlines(param_true, 0,5, linestyles='dashed') ylabel(r'$\hat{%s}$'%param_tag, fontsize = xlabel_font_size) if (regime_idx ==0): title(r'$%s = %.1f$'%(param_tag, param_true), fontsize = 32) if (params_idx == 2): title(r'$\gamma = .5\cdot \sqrt{1+ \Omega}$', fontsize = 32) if(regime_idx == 3): xtickNames = setp(ax, xticklabels = method_labels) setp(xtickNames, rotation=30, fontsize=xlabel_font_size) ylim((ylower[params_idx], yupper[params_idx])) ymin, ymax = ylim() activeticks = linspace(ymin, ymax, 7)[1:-1] yticks(activeticks, ['%.2f'%tick for tick in activeticks]) if 0 == params_idx: text(-.25, 0.5, r'$\Omega = %s$' %regime[5:], horizontalalignment='center', verticalalignment='center', transform = ax.transAxes, rotation='vertical', size = xlabel_font_size) tag_loc = 3; # if (median(param_ests[0]) > param_true): # tag_loc = 3; xlim((.0,5.5 )) t = add_inner_title(ax, chr(ord('A') + subplot_idx), loc=tag_loc, size=dict(size=ABCD_LABEL_SIZE)) t.patch.set_ec("none") t.patch.set_alpha(0.5) file_name = os.path.join(FIGS_DIR, fig_id + 'thetas_est_rel_errors' +'.pdf') get_current_fig_manager().window.showMaximized() print 'saving to ', file_name savefig(file_name)
def postProcessJointBoxPlot(table_file_names, fig_id = '', Methods = ['Initializer', 'Nelder-Mead', 'Fortet'], regimeNames = ['superT', 'subT', 'crit', 'superSin']): analyzers = []; for table_file_name in table_file_names: analyzer = DataAnalyzer(table_file_name) analyzers.append(analyzer) analyzer = analyzers[0] if None==regimeNames: regimeNames = analyzer.getAllRegimes() for regime in regimeNames: abg_true = analyzer.getTrueParamValues(regime) print regime, abg_true mpl.rcParams['figure.figsize'] = 17, 6 method_labels = ['Initializer', 'Numerical FP', 'Fortet'] xlabel_font_size = 24 sample_size_texts = ['N=100', 'N=1000'] for regime in regimeNames: yupper = 3*[-inf]; ylower = 3*[inf] for params_idx in xrange(3): for mthd in Methods: for analyzer in analyzers: ests = array(analyzer.getAllEstimates(regime, mthd))[:,params_idx] ylower[params_idx] = amin([ylower[params_idx], amin(ests)]) yupper[params_idx] = amax([yupper[params_idx], amax(ests)]) abg_true = analyzer.getTrueParamValues(regime) print regime, abg_true figure() subplots_adjust(left=0.1, right=0.975, top=0.9, bottom=0.25, wspace = 0.25, hspace = 0.01) lgs = GridSpec(2, 3) for sample_size_idx, analyzer in enumerate(analyzers): abgs = {} for mthd in Methods: abgs[mthd] = array(analyzer.getAllEstimates(regime, mthd)) # method_xpos = dict.fromkeys(Methods, [1,2,3]) param_tags = [r' \alpha ', r' \beta ', r' \gamma '] for params_idx, param_tag in enumerate(param_tags): print params_idx, param_tag subplot_idx = sample_size_idx*3 + params_idx; ax = subplot(lgs[subplot_idx]); hold(True) # for mthd in Methods: param_ests = [ abgs[mthd][:,params_idx] for mthd in Methods] param_true = abg_true[params_idx] boxplot(param_ests, positions = [1,3,5]) hlines(param_true, 0,5, linestyles='dashed') ylabel(r'$\hat{%s}$'%param_tag, fontsize = xlabel_font_size) if (sample_size_idx ==0): title(r'$%s = %.2f$'%(param_tag, param_true), fontsize = 32) if(sample_size_idx ==1): xtickNames = setp(ax, xticklabels = method_labels) setp(xtickNames, rotation=30, fontsize=xlabel_font_size) ylim((ylower[params_idx], yupper[params_idx])) ymin, ymax = ylim() activeticks = linspace(ymin, ymax, 7)[1:-1] yticks(activeticks, ['%.2f'%tick for tick in activeticks]) if 0 == params_idx: text(-.25, 0.5, sample_size_texts[sample_size_idx], horizontalalignment='center', verticalalignment='center', transform = ax.transAxes, rotation='vertical', size = xlabel_font_size) tag_loc = 3; # if (median(param_ests[0]) > param_true): # tag_loc = 3; xlim((.0, 5.5)) t = add_inner_title(ax, chr(ord('A') + subplot_idx), loc=tag_loc, size=dict(size=ABCD_LABEL_SIZE)) t.patch.set_ec("none") t.patch.set_alpha(0.5) file_name = os.path.join(FIGS_DIR, fig_id + regime+'_est_rel_errors_joint' +'.pdf') get_current_fig_manager().window.showMaximized() print 'saving to ', file_name savefig(file_name)
def alphaVsGamma(table_file_name, fig_id='', Methods=['Initializer', 'FP', 'Fortet']): analyzer = DataAnalyzer(table_file_name) mpl.rcParams['figure.figsize'] = 17, 5*4 mpl.rcParams['figure.subplot.left'] = .1 mpl.rcParams['figure.subplot.right'] = .975 mpl.rcParams['figure.subplot.bottom'] = .025 mpl.rcParams['figure.subplot.top'] = .95 mpl.rcParams['figure.subplot.wspace'] = .25 mpl.rcParams['figure.subplot.hspace'] = .375 fig = figure(); plot_scale = 1.05; regimeNames = analyzer.getAllRegimes() regime_tags = {'superT':'Supra-Threshold', 'crit':'Critical', 'subT':'Sub-Threshold', 'superSin':'Super-Sinusoidal', 'theta1':r'$\Omega=1$', 'theta5':r'$\Omega=5$', 'theta10':r'$\Omega=10$', 'theta20':r'$\Omega=20$'} xlabel_font_size = 32 for regime_idx,regime in enumerate(regimeNames): abg_true = analyzer.getTrueParamValues(regime) print regime, abg_true for method_idx, method in enumerate(Methods): abgs = array( analyzer.getAllEstimates(regime, method) ) axu_lim = amax( r_[ abgs[:, 0], abg_true[0]]) axl_lim = amin( r_[ abgs[:, 0], abg_true[0]]) plot_buffer = 5*(plot_scale -1.)*(axu_lim - axl_lim); axu_lim += plot_buffer axl_lim -= plot_buffer ayu_lim = amax( r_[ abgs[:, 2], abg_true[2]]) ayl_lim = amin( r_[ abgs[:, 2], abg_true[2]]) plot_buffer = (plot_scale -1.)*(ayu_lim - ayl_lim); ayu_lim += plot_buffer ayl_lim -= plot_buffer ax = subplot(len(regimeNames),3, regime_idx*len(Methods) + method_idx+1) plot(abgs[:, 0], abgs[:, 2], linestyle='None', color= 'k', marker= 'o', markersize = 7 ) if 0 == method_idx: text(-.3, 0.5, regime_tags[regime], horizontalalignment='center', verticalalignment='center', transform = ax.transAxes, rotation='vertical', size = xlabel_font_size) # axu_lim, axl_lim = xlim() hlines(abg_true[2], axl_lim, axu_lim, linestyles = 'dashed' ) # axu_lim, axl_lim = ylim() vlines(abg_true[0], ayl_lim, ayu_lim, linestyles = 'dashed' ) xlim((axl_lim, axu_lim)); ylim((ayl_lim, ayu_lim)); xlabel(r'$\alpha$',fontsize = xlabel_font_size); ylabel(r'$\gamma$',fontsize = xlabel_font_size); title(method , fontsize = 32) #+ ' : $\\Omega= %.1f$' %sqrt((2.0*abg_true[2])**2 -1.) t = add_inner_title(ax, chr(ord('A') + regime_idx*len(Methods) + method_idx), loc=2, size=dict(size=ABCD_LABEL_SIZE)) t.patch.set_ec("none") t.patch.set_alpha(0.5) if '' != fig_id: file_name = os.path.join(FIGS_DIR, fig_id + '_alphagamma_compare_joint.pdf') print 'saving to ', file_name savefig(file_name)
def crossAnalyzeJoint(table_file_name1, table_file_name2, fig_id = '', Method1 = 'Fortet', Method2 = 'FP', regimeNames = None): analyzer = DataAnalyzer(table_file_name1) analyzer2 = DataAnalyzer(table_file_name2) mpl.rcParams['figure.figsize'] = 17, 5*4 mpl.rcParams['figure.subplot.left'] = .05 mpl.rcParams['figure.subplot.right'] = .975 mpl.rcParams['figure.subplot.bottom'] = .025 mpl.rcParams['figure.subplot.top'] = .95 mpl.rcParams['figure.subplot.wspace'] = .1 mpl.rcParams['figure.subplot.hspace'] = .375 fig = figure(); if None==regimeNames: regimeNames = analyzer.getAllRegimes() for regime_idx,regime in enumerate(regimeNames): abg_true = analyzer.getTrueParamValues(regime) print regime, abg_true abgs = {}; abgs[Method1] = array( analyzer.getAllEstimates(regime, Method1) ) abgs[Method2] = array( analyzer.getAllEstimates(regime, Method2) ) abgs2 = {} abgs2[Method1] = array( analyzer2.getAllEstimates(regime, Method1) ) abgs2[Method2] = array( analyzer2.getAllEstimates(regime, Method2) ) plot_scale = 1.05; for param_idx, pname in zip(arange(3), [r'\alpha', r'\beta', r'\gamma']): axu_lim = amax( r_[ abgs[Method1][:, param_idx], abgs[Method2][:, param_idx]]) axl_lim = amin( r_[ abgs[Method1][:, param_idx], abgs[Method2][:, param_idx]]) plot_buffer = (plot_scale -1.)*(axu_lim - axl_lim); axu_lim += plot_buffer axl_lim -= plot_buffer ax = subplot(len(regimeNames),3, regime_idx*3 + param_idx+1, aspect='equal') plot(abgs[Method1][:, param_idx], abgs[Method2][:, param_idx], linestyle='None', color= 'k', marker= 'x', markersize = 7, label='$N=100$' ) plot(abgs2[Method1][:, param_idx], abgs2[Method2][:, param_idx], linestyle='None', color= 'k', marker= 'd', markersize = 7, label='$N=1000$' ) if param_idx == 0: legend(loc='lower left') # axu_lim, axl_lim = xlim() hlines(abg_true[param_idx], axl_lim, axu_lim, linestyles = 'dashed' ) # axu_lim, axl_lim = ylim() vlines(abg_true[param_idx], axl_lim, axu_lim, linestyles = 'dashed' ) ax.xaxis.set_major_locator(MaxNLocator(6)) ax.yaxis.set_major_locator(MaxNLocator(6)) xlim((axl_lim, axu_lim)); ylim((axl_lim, axu_lim)); xlabel(Method1,fontsize = 24); ylabel(Method2,fontsize = 24); title('$'+ pname + ' = %.2f$'%abg_true[param_idx], fontsize = 32) t = add_inner_title(ax, chr(ord('A') + regime_idx*3 + param_idx), loc=2, size=dict(size=20)) t.patch.set_ec("none") t.patch.set_alpha(0.5) # markers = ['x', '+', '^']: # for marker_idx, table_file_name in table_file_names[1:]: # analyzer = DataAnalyzer(table_file_name) if '' != fig_id: file_name = os.path.join(FIGS_DIR, fig_id + '_cross_compare_joint.pdf') print 'saving to ', file_name savefig(file_name)