def create_plots(info_path):
    output_dir = os.path.join(os.path.dirname(info_path), 'plots')
    if not os.path.exists(output_dir):
        os.mkdir(output_dir)
    prior_prob_omega_less_than = 0.0887
    psi_results, omega_results, tau_results = parse_results(info_path)
    cfg_to_psi = {}
    cfg_to_psi_prob = {}
    for cfg, psi in psi_results.iteritems():
        cfg_to_psi[cfg] = psi.mode
        cfg_to_psi_prob[cfg] = psi.prob
    cfg_to_omega = {}
    cfg_to_omega_prob = {}
    cfg_to_omega_true_ests = {}
    cfg_to_omega_true_ests_glm = {}
    for cfg, omega in omega_results.iteritems():
        cfg_to_omega[cfg] = omega.median
        cfg_to_omega_prob[cfg] = omega.prob
        cfg_to_omega_true_ests[cfg] = {'x': omega.true, 'y': omega.median}
        cfg_to_omega_true_ests_glm[cfg] = {'x': omega.true, 'y': omega.mode_glm}

    cfg_to_num_excluded = {}
    cfg_to_num_excluded_glm = {}
    cfg_to_prob_of_exclusion = {}
    cfg_to_prob_of_exclusion_glm = {}
    cfg_to_prob_of_bf_ex = {}
    cfg_to_prob_of_bf_ex_glm = {}
    bf_10_exclusion_prob = None
    for cfg, tau in tau_results.iteritems():
        cfg_to_num_excluded[cfg] = tau.num_excluded
        cfg_to_num_excluded_glm[cfg] = tau.num_excluded_glm
        cfg_to_prob_of_exclusion[cfg] = tau.prob_of_exclusion
        cfg_to_prob_of_exclusion_glm[cfg] = tau.prob_of_exclusion_glm
        cfg_to_prob_of_bf_ex[cfg] = tau.prob_of_bf_exclusion
        cfg_to_prob_of_bf_ex_glm[cfg] = tau.prob_of_bf_exclusion_glm
        if not bf_10_exclusion_prob:
            bf_10_exclusion_prob = tau.bf_10_exclusion_prob

    psi_plot = PowerPlotGrid(observed_config_to_estimates = cfg_to_psi,
            variable = 'psi',
            num_columns = 2)
    fig = psi_plot.create_grid()
    fig.savefig(os.path.join(output_dir, 'power_psi_mode.pdf'))

    psi_prob_plot = ProbabilityPowerPlotGrid(
            observed_config_to_estimates = cfg_to_psi_prob,
            variable = 'psi',
            div_model_prior = 'psi',
            bayes_factor = 10,
            num_columns = 2)
    fig = psi_prob_plot.create_grid()
    fig.savefig(os.path.join(output_dir, 'power_psi_prob.pdf'))

    omega_plot = PowerPlotGrid(observed_config_to_estimates = cfg_to_omega,
            variable = 'omega',
            num_columns = 2)
    fig = omega_plot.create_grid()
    fig.savefig(os.path.join(output_dir, 'power_omega_median.pdf'))

    omega_prob_plot = ProbabilityPowerPlotGrid(
            observed_config_to_estimates = cfg_to_omega_prob,
            variable = 'omega',
            div_model_prior = 'psi',
            bayes_factor = 10,
            bayes_factor_prob = prior_prob_omega_less_than,
            num_columns = 2)
    fig = omega_prob_plot.create_grid()
    fig.savefig(os.path.join(output_dir, 'power_omega_prob.pdf'))
    
    omega_accuracy_plot = AccuracyPowerPlotGrid(
            observed_config_to_estimates = cfg_to_omega_true_ests,
            num_columns = 2)
    fig = omega_accuracy_plot.create_grid()
    fig.savefig(os.path.join(output_dir, 'power_accuracy_omega_median.pdf'))

    omega_accuracy_plot_glm = AccuracyPowerPlotGrid(
            observed_config_to_estimates = cfg_to_omega_true_ests_glm,
            num_columns = 2)
    fig = omega_accuracy_plot_glm.create_grid()
    fig.savefig(os.path.join(output_dir, 'power_accuracy_omega_mode_glm.pdf'))

    ex_prob_plot = ProbabilityPowerPlotGrid(
            observed_config_to_estimates = cfg_to_prob_of_exclusion,
            variable = 'tau_exclusion',
            div_model_prior = 'psi',
            bayes_factor = 10,
            bayes_factor_prob = bf_10_exclusion_prob,
            cfg_to_prob_of_bf_exclusion = cfg_to_prob_of_bf_ex,
            num_columns = 2)
    fig = ex_prob_plot.create_grid()
    fig.savefig(os.path.join(output_dir, 'power_prob_exclusion.pdf'))
    ex_prob_plot_glm = ProbabilityPowerPlotGrid(
            observed_config_to_estimates = cfg_to_prob_of_exclusion_glm,
            variable = 'tau_exclusion',
            div_model_prior = 'psi',
            bayes_factor = 10,
            bayes_factor_prob = bf_10_exclusion_prob,
            cfg_to_prob_of_bf_exclusion = cfg_to_prob_of_bf_ex_glm,
            num_columns = 2)
    fig = ex_prob_plot_glm.create_grid()
    fig.savefig(os.path.join(output_dir, 'power_prob_exclusion_glm.pdf'))

    ex_plot = PowerPlotGrid(
            observed_config_to_estimates = cfg_to_num_excluded,
            variable = 'tau_exclusion',
            num_columns = 2)
    fig = ex_plot.create_grid()
    fig.savefig(os.path.join(output_dir, 'power_num_excluded.pdf'))
    ex_plot_glm = PowerPlotGrid(
            observed_config_to_estimates = cfg_to_num_excluded_glm,
            variable = 'tau_exclusion',
            num_columns = 2)
    fig = ex_plot_glm.create_grid()
    fig.savefig(os.path.join(output_dir, 'power_num_excluded_glm.pdf'))
def create_plots(info_path,
        observed_prefixes_to_include = None,
        observed_suffixes_to_include = None,
        prior_suffixes_to_include = None):
    dmc_sim = DMCSimulationResults(info_path)
    prior_configs = {}
    for k, v in dmc_sim.prior_index_to_config.iteritems():
        prior_configs[k] = MsBayesConfig(v)
    # output_dir = os.path.join(os.path.dirname(info_path), 'plots')
    output_dir = project_util.IMAGE_DIR
    if not os.path.exists(output_dir):
        os.mkdir(output_dir)
    prior_prob_omega_less_than = {
            1: 0.0025575,
            2: 0.049283,
            3: 0.002171,
            4: 0.049191}
    psi_res, omega_res, prior_index_to_name = parse_results(dmc_sim,
            observed_prefixes_to_include = observed_prefixes_to_include,
            observed_suffixes_to_include = observed_suffixes_to_include,
            prior_suffixes_to_include = prior_suffixes_to_include)
    for observed_name in psi_res.iterkeys():
        for prior_index in psi_res[observed_name].iterkeys():
            prior_name = prior_index_to_name[prior_index]
            div_model_prior = prior_name
            if prior_name in ['old', 'u-shaped']:
                div_model_prior = 'psi'
            dpp_concentration_mean = None
            if div_model_prior == 'dpp':
                dpp_concentration_mean = prior_configs[
                        prior_index].dpp_concentration.mean
            prior_prob_omega = prior_prob_omega_less_than[prior_index]
            psi_results = psi_res[observed_name][prior_index]
            omega_results = omega_res[observed_name][prior_index]
            prefix = '_'.join([observed_name, prior_name])
            cfg_to_psi = {}
            cfg_to_psi_prob = {}
            cfg_to_psi_glm = {}
            cfg_to_psi_prob_glm = {}
            for cfg, psi in psi_results.iteritems():
                cfg_to_psi[cfg] = psi.mode
                cfg_to_psi_prob[cfg] = psi.prob
                cfg_to_psi_glm[cfg] = psi.mode_glm
                cfg_to_psi_prob_glm[cfg] = psi.prob_glm
            cfg_to_omega = {}
            cfg_to_omega_prob = {}
            cfg_to_omega_glm = {}
            cfg_to_omega_prob_glm = {}
            cfg_to_omega_true_ests = {}
            cfg_to_omega_true_ests_glm = {}
            for cfg, omega in omega_results.iteritems():
                cfg_to_omega[cfg] = omega.median
                cfg_to_omega_prob[cfg] = omega.prob
                cfg_to_omega_glm[cfg] = omega.mode_glm
                cfg_to_omega_prob_glm[cfg] = omega.prob_glm
                cfg_to_omega_true_ests[cfg] = {'x': omega.true, 'y': omega.median}
                cfg_to_omega_true_ests_glm[cfg] = {'x': omega.true, 'y': omega.mode_glm}

            num_columns = len(observed_suffixes_to_include)
            width = 15
            height = 3.5
            column_label_offset = 0.14
            margin_top = 0.83
            margin_bottom = 0.1
            margin_left = 0.025
            margin_right = 0.95
            column_label_size = 26.0
            title_size = 22.0
            y_title_size = 20.0
            right_text_size = 14.0
            row_labels = []
            if prior_name == 'old':
                row_labels.append(r'$M_{msBayes}$')
            elif prior_name == 'u-shaped':
                row_labels.append(r'$M_{Ushaped}$')
            elif prior_name == 'uniform':
                row_labels.append(r'$M_{Uniform}$')
            elif prior_name == 'dpp':
                row_labels.append(r'$M_{DPP}$')
            else:
                row_labels.append('')
            row_label_size = 32.0
            row_label_offset = 0.08


            psi_plot = PowerPlotGrid(
                    observed_config_to_estimates = cfg_to_psi,
                    variable = 'psi',
                    variable_symbol = r'|\mathbf{\tau}|',
                    num_columns = num_columns,
                    width = width,
                    height = height,
                    x_title = r'Estimated number of divergence events (mode)',
                    y_title_size = y_title_size,
                    include_right_text = False,
                    text_size = right_text_size,
                    xtick_label_size = 14.0)
            pg = psi_plot.create_grid()
            pg.label_schema = None
            column_labels = []
            for cfg, sp in psi_plot.cfg_to_subplot.iteritems():
                column_labels.append((cfg.tau.maximum, tau_prior_in_generations(cfg)))
                sp.set_left_text('')
            pg.column_labels = [t for (c, t) in sorted(column_labels, key = lambda x : x[0])]
            pg.margin_bottom = margin_bottom
            pg.margin_top = margin_top
            pg.margin_left = margin_left
            pg.margin_right = margin_right
            pg.padding_between_horizontal = 2.0
            pg.column_label_offset = column_label_offset
            pg.column_label_size = column_label_size
            pg.title_size = title_size
            pg.row_labels = row_labels
            pg.row_label_size = row_label_size
            pg.row_label_offset = row_label_offset
            pg.reset_figure()
            pg.set_shared_x_limits()
            pg.set_shared_y_limits()
            pg.reset_figure()
            pg.savefig(os.path.join(output_dir,
                    prefix + '_power_psi_mode.pdf'))
            pg.column_labels = ['' for x in column_labels]
            pg.reset_figure()
            pg.savefig(os.path.join(output_dir,
                    prefix + '_power_psi_mode_headless.pdf'))

            psi_plot.width = 5.0
            psi_plot.height = 4.0
            pg = psi_plot.create_column_grid(
                subplot_indices_to_exclude = [0,1,2],
                x_title_size = 16.0,
                y_title_size = 15.0,
                add_column_labels = True,
                column_label_size = 18.0,
                column_label_offset = 0.14,
                plot_label_size = 12.0,
                right_text_size = 10.0,
                x_tick_label_size = 14.0,
                share_x = False,
                share_y = False)
            pg.label_schema = None
            pg.column_labels = [[t for (c, t) in sorted(column_labels, key = lambda x : x[0])][-1]]
            pg.margin_bottom = 0.07
            pg.margin_top = 0.88
            pg.margin_left = 0.07
            pg.margin_right = 0.99
            pg.column_label_offset = 0.04
            pg.column_label_size = column_label_size
            # pg.title_size = title_size
            pg.row_labels = None
            pg.reset_figure()
            pg.savefig(os.path.join(output_dir,
                    prefix + '_power_psi_mode_last.pdf'))

            psi_prob_plot = ProbabilityPowerPlotGrid(
                    observed_config_to_estimates = cfg_to_psi_prob,
                    variable = 'psi',
                    variable_symbol = r'|\mathbf{\tau}|',
                    div_model_prior = div_model_prior,
                    dpp_concentration_mean = dpp_concentration_mean,
                    bayes_factor = 10,
                    draw_bayes_factor_line = False,
                    x_title = r'Posterior probability of one divergence',
                    y_title_size = y_title_size,
                    width = width,
                    height = height,
                    num_columns = num_columns,
                    text_size = right_text_size,
                    xtick_label_size = 14.0,
                    pretty_xtick_labels = True)
            pg = psi_prob_plot.create_grid()
            pg.label_schema = None
            column_labels = []
            for cfg, sp in psi_prob_plot.cfg_to_subplot.iteritems():
                column_labels.append((cfg.tau.maximum, tau_prior_in_generations(cfg)))
                sp.set_left_text('')
                sp.set_right_text('')
            pg.column_labels = [t for (c, t) in sorted(column_labels, key = lambda x : x[0])]
            pg.margin_bottom = margin_bottom
            pg.margin_top = margin_top
            pg.margin_left = margin_left
            pg.margin_right = margin_right
            pg.column_label_offset = column_label_offset
            pg.column_label_size = column_label_size
            pg.padding_between_horizontal = 1.0
            pg.title_size = title_size
            pg.row_labels = row_labels
            pg.row_label_size = row_label_size
            pg.row_label_offset = row_label_offset
            pg.reset_figure()
            pg.set_shared_x_limits()
            pg.set_shared_y_limits()
            pg.reset_figure()
            pg.savefig(os.path.join(output_dir,
                    prefix + '_power_psi_prob.pdf'))
            pg.column_labels = ['' for x in column_labels]
            pg.reset_figure()
            pg.savefig(os.path.join(output_dir,
                    prefix + '_power_psi_prob_headless.pdf'))

            # psi_prob_plot_glm = ProbabilityPowerPlotGrid(
            #         observed_config_to_estimates = cfg_to_psi_prob_glm,
            #         variable = 'psi',
            #         variable_symbol = r'|\mathbf{\tau}|',
            #         div_model_prior = div_model_prior,
            #         dpp_concentration_mean = dpp_concentration_mean,
            #         bayes_factor = 10,
            #         num_columns = 2)
            # fig = psi_prob_plot_glm.create_grid()
            # fig.savefig(os.path.join(output_dir,
            #         prefix + '_power_psi_prob_glm.pdf'))

            omega_plot = PowerPlotGrid(
                    observed_config_to_estimates = cfg_to_omega,
                    variable = 'omega',
                    variable_symbol = r'D_T',
                    num_columns = num_columns,
                    width = width,
                    height = height,
                    x_title = r'Estimated variance in divergence times (median)',
                    y_title_size = y_title_size,
                    text_size = right_text_size)
            pg = omega_plot.create_grid()
            pg.label_schema = None
            column_labels = []
            for cfg, sp in omega_plot.cfg_to_subplot.iteritems():
                column_labels.append((cfg.tau.maximum, tau_prior_in_generations(cfg)))
                sp.set_left_text('')
            pg.column_labels = [t for (c, t) in sorted(column_labels, key = lambda x : x[0])]
            pg.margin_bottom = margin_bottom
            pg.margin_top = margin_top
            pg.margin_left = margin_left
            pg.margin_right = margin_right
            pg.column_label_offset = column_label_offset
            pg.column_label_size = column_label_size
            pg.title_size = title_size
            pg.row_labels = row_labels
            pg.row_label_size = row_label_size
            pg.row_label_offset = row_label_offset
            pg.reset_figure()
            pg.savefig(os.path.join(output_dir,
                    prefix + '_power_omega_median.pdf'))
            pg.column_labels = ['' for x in column_labels]
            pg.reset_figure()
            pg.savefig(os.path.join(output_dir,
                    prefix + '_power_omega_median_headless.pdf'))
예제 #3
0
def create_plots(info_path):
    dmc_sim = DMCSimulationResults(info_path)
    prior_configs = {}
    for k, v in dmc_sim.prior_index_to_config.iteritems():
        prior_configs[k] = MsBayesConfig(v)
    output_dir = os.path.join(os.path.dirname(info_path), 'plots')
    if not os.path.exists(output_dir):
        os.mkdir(output_dir)
    (psi_res, cv_res, prior_index_to_name,
     prior_index_to_model_type) = parse_results(dmc_sim)
    for prior_index, prior_name in prior_index_to_name.iteritems():
        cfg_to_psi = {}
        cfg_to_psi_prob = {}
        cfg_to_cv = {}
        cfg_to_cv_prob = {}
        cfg_to_cv_true_ests = {}
        prefix = prior_name
        for observed_name in psi_res.iterkeys():
            div_model_prior = prior_index_to_model_type[prior_index]
            dpp_concentration_mean = None
            if div_model_prior == 'dpp':
                dpp_concentration_mean = prior_configs[
                    prior_index].dpp_concentration.mean
            psi_results = psi_res[observed_name][prior_index]
            cv_results = cv_res[observed_name][prior_index]
            for cfg, psi in psi_results.iteritems():
                cfg_to_psi[cfg] = psi.mode
                cfg_to_psi_prob[cfg] = psi.prob
            for cfg, cv in cv_results.iteritems():
                cfg_to_cv[cfg] = cv.median
                cfg_to_cv_prob[cfg] = cv.prob
                cfg_to_cv_true_ests[cfg] = {'x': cv.true, 'y': cv.median}

        psi_plot = PowerPlotGrid(observed_config_to_estimates=cfg_to_psi,
                                 variable='psi',
                                 variable_symbol=r'|\mathbf{\tau}|',
                                 num_columns=2,
                                 margin_top=0.975)
        fig = psi_plot.create_grid()
        fig.savefig(os.path.join(output_dir, prefix + '_power_psi_mode.pdf'))

        psi_prob_plot = ProbabilityPowerPlotGrid(
            observed_config_to_estimates=cfg_to_psi_prob,
            variable='psi',
            variable_symbol=r'|\mathbf{\tau}|',
            div_model_prior=div_model_prior,
            dpp_concentration_mean=dpp_concentration_mean,
            bayes_factor=10,
            num_columns=2)
        fig = psi_prob_plot.create_grid()
        fig.savefig(os.path.join(output_dir, prefix + '_power_psi_prob.pdf'))

        cv_accuracy_plot = AccuracyPowerPlotGrid(
            observed_config_to_estimates=cfg_to_cv_true_ests,
            variable_symbol=r'CV_T',
            num_columns=2,
            padding_between_vertical=2.0,
            margin_left=0.04,
            margin_bottom=0.03)
        fig = cv_accuracy_plot.create_grid()
        fig.savefig(
            os.path.join(output_dir, prefix + '_accuracy_cv_median.pdf'))
def create_plots(info_path):
    output_dir = os.path.join(os.path.dirname(info_path), 'plots')
    if not os.path.exists(output_dir):
        os.mkdir(output_dir)
    prior_prob_omega_less_than = 0.0887
    psi_results, omega_results, tau_results = parse_results(info_path)
    cfg_to_psi = {}
    cfg_to_psi_prob = {}
    for cfg, psi in psi_results.iteritems():
        cfg_to_psi[cfg] = psi.mode
        cfg_to_psi_prob[cfg] = psi.prob
    cfg_to_omega = {}
    cfg_to_omega_prob = {}
    cfg_to_omega_true_ests = {}
    cfg_to_omega_true_ests_glm = {}
    for cfg, omega in omega_results.iteritems():
        cfg_to_omega[cfg] = omega.median
        cfg_to_omega_prob[cfg] = omega.prob
        cfg_to_omega_true_ests[cfg] = {'x': omega.true, 'y': omega.median}
        cfg_to_omega_true_ests_glm[cfg] = {'x': omega.true, 'y': omega.mode_glm}

    cfg_to_num_excluded = {}
    cfg_to_num_excluded_glm = {}
    cfg_to_prob_of_exclusion = {}
    cfg_to_prob_of_exclusion_glm = {}
    cfg_to_prob_of_bf_ex = {}
    cfg_to_prob_of_bf_ex_glm = {}
    bf_10_exclusion_prob = None
    for cfg, tau in tau_results.iteritems():
        cfg_to_num_excluded[cfg] = tau.num_excluded
        cfg_to_num_excluded_glm[cfg] = tau.num_excluded_glm
        cfg_to_prob_of_exclusion[cfg] = tau.prob_of_exclusion
        cfg_to_prob_of_exclusion_glm[cfg] = tau.prob_of_exclusion_glm
        cfg_to_prob_of_bf_ex[cfg] = tau.prob_of_bf_exclusion
        cfg_to_prob_of_bf_ex_glm[cfg] = tau.prob_of_bf_exclusion_glm
        if not bf_10_exclusion_prob:
            bf_10_exclusion_prob = tau.bf_10_exclusion_prob

    psi_plot = PowerPlotGrid(observed_config_to_estimates = cfg_to_psi,
            variable = 'psi',
            num_columns = 2,
            x_title = r'Estimated number of divergence events, $\hat{\Psi}$',
            y_title = 'Density',
            width = 14.0,
            height = 2.8,
            auto_height = False,
            auto_adjust_margins = False,
            margin_left = 0.025,
            margin_bottom = 0.1,
            margin_right = 1,
            margin_top = 0.835,
            padding_between_horizontal = 0.5)

    fig = psi_plot.create_column_grid(
            subplot_indices_to_exclude = [],
            x_title_size = 14.0,
            y_title_size = 14.0,
            column_label_size = 16.0,
            column_label_offset = 0.14,
            x_tick_label_size = 8.0,
            share_x = True,
            share_y = True)
    fig.savefig(os.path.join(output_dir, 'power-psi-mode-6.pdf'))

    psi_plot.width = 10.0
    fig = psi_plot.create_column_grid(
            subplot_indices_to_exclude = [1,3],
            x_title_size = 14.0,
            y_title_size = 14.0,
            column_label_size = 16.0,
            column_label_offset = 0.14,
            right_text_size = 12.0,
            x_tick_label_size = 8.0,
            share_x = True,
            share_y = True)
    fig.savefig(os.path.join(output_dir, 'power-psi-mode-4.pdf'))


    omega_prob_plot = ProbabilityPowerPlotGrid(
            observed_config_to_estimates = cfg_to_omega_prob,
            variable = 'omega',
            div_model_prior = 'psi',
            bayes_factor = 10,
            bayes_factor_prob = prior_prob_omega_less_than,
            num_columns = 2,
            x_title = (r'Posterior probability of one divergence, '
                    r'$p(\Omega < 0.01 \, | \, B_{{\epsilon}}(S*))$'),
            y_title = 'Density',
            width = 14.0,
            height = 2.8,
            auto_height = False,
            auto_adjust_margins = False,
            margin_left = 0.025,
            margin_bottom = 0.1,
            margin_right = 1,
            margin_top = 0.835,
            padding_between_horizontal = 0.5)
    fig = omega_prob_plot.create_column_grid(
            subplot_indices_to_exclude = [],
            x_title_size = 14.0,
            y_title_size = 14.0,
            column_label_size = 16.0,
            column_label_offset = 0.14,
            x_tick_label_size = 10.0,
            share_x = True,
            share_y = True)
    fig.savefig(os.path.join(output_dir, 'power-omega-prob-6.pdf'))
    omega_prob_plot.width = 10.0
    fig = omega_prob_plot.create_column_grid(
            subplot_indices_to_exclude = [1,3],
            x_title_size = 14.0,
            y_title_size = 14.0,
            column_label_size = 16.0,
            column_label_offset = 0.14,
            right_text_size = 10.0,
            x_tick_label_size = 10.0,
            share_x = True,
            share_y = True)
    fig.savefig(os.path.join(output_dir, 'power-omega-prob-4.pdf'))
    omega_prob_plot.label_offset = 6
    omega_prob_plot.width = 14.0
    fig = omega_prob_plot.create_column_grid(
            subplot_indices_to_exclude = [],
            x_title_size = 14.0,
            y_title_size = 14.0,
            add_column_labels = False,
            column_label_size = 16.0,
            column_label_offset = 0.14,
            x_tick_label_size = 10.0,
            share_x = True,
            share_y = True)
    fig.savefig(os.path.join(output_dir, 'power-omega-prob-6-panel.pdf'))
    omega_prob_plot.label_offset = 4
    omega_prob_plot.width = 10.0
    fig = omega_prob_plot.create_column_grid(
            subplot_indices_to_exclude = [1,3],
            x_title_size = 14.0,
            y_title_size = 14.0,
            add_column_labels = False,
            column_label_size = 16.0,
            column_label_offset = 0.14,
            right_text_size = 10.0,
            x_tick_label_size = 10.0,
            share_x = True,
            share_y = True)
    fig.savefig(os.path.join(output_dir, 'power-omega-prob-4-panel.pdf'))
    
    omega_accuracy_plot = AccuracyPowerPlotGrid(
            observed_config_to_estimates = cfg_to_omega_true_ests,
            num_columns = 2,
            x_title = r'True variance of divergence times, $\Omega$',
            y_title = r'$\hat{\Omega}$',
            width = 14.0,
            height = 2.8,
            auto_height = False,
            auto_adjust_margins = False,
            margin_left = 0.025,
            margin_bottom = 0.1,
            margin_right = 1,
            margin_top = 0.825,
            padding_between_horizontal = 0.5)
    fig = omega_accuracy_plot.create_column_grid(
            subplot_indices_to_exclude = [],
            x_title_size = 14.0,
            y_title_size = 14.0,
            column_label_size = 16.0,
            column_label_offset = 0.14,
            x_tick_label_size = 10.0,
            share_x = False,
            share_y = False)
    fig.savefig(os.path.join(output_dir, 'power-accuracy-omega-median-6.pdf'))
    omega_accuracy_plot.width = 10.0
    fig = omega_accuracy_plot.create_column_grid(
            subplot_indices_to_exclude = [1,3],
            x_title_size = 14.0,
            y_title_size = 14.0,
            column_label_size = 16.0,
            column_label_offset = 0.14,
            right_text_size = 10.0,
            x_tick_label_size = 10.0,
            share_x = False,
            share_y = False)
    fig.savefig(os.path.join(output_dir, 'power-accuracy-omega-median-4.pdf'))

    omega_accuracy_plot_glm = AccuracyPowerPlotGrid(
            observed_config_to_estimates = cfg_to_omega_true_ests_glm,
            num_columns = 2,
            x_title = r'True variance of divergence times, $\Omega$',
            y_title = r'$\hat{\Omega}$',
            width = 14.0,
            height = 2.8,
            auto_height = False,
            auto_adjust_margins = False,
            margin_left = 0.025,
            margin_bottom = 0.1,
            margin_right = 1,
            margin_top = 0.825,
            padding_between_horizontal = 0.5)
    fig = omega_accuracy_plot_glm.create_column_grid(
            subplot_indices_to_exclude = [],
            x_title_size = 14.0,
            y_title_size = 14.0,
            column_label_size = 16.0,
            column_label_offset = 0.14,
            x_tick_label_size = 10.0,
            share_x = False,
            share_y = False)
    fig.savefig(os.path.join(output_dir, 'power-accuracy-omega-mode-glm-6.pdf'))
    omega_accuracy_plot_glm.width = 10.0
    fig = omega_accuracy_plot_glm.create_column_grid(
            subplot_indices_to_exclude = [1,3],
            x_title_size = 14.0,
            y_title_size = 14.0,
            column_label_size = 16.0,
            column_label_offset = 0.14,
            right_text_size = 10.0,
            x_tick_label_size = 10.0,
            share_x = False,
            share_y = False)
    fig.savefig(os.path.join(output_dir, 'power-accuracy-omega-mode-glm-4.pdf'))
    omega_accuracy_plot_glm.label_offset = 6
    omega_accuracy_plot_glm.width = 14.0
    fig = omega_accuracy_plot_glm.create_column_grid(
            subplot_indices_to_exclude = [],
            x_title_size = 14.0,
            y_title_size = 14.0,
            add_column_labels = False,
            column_label_size = 16.0,
            column_label_offset = 0.14,
            x_tick_label_size = 10.0,
            share_x = False,
            share_y = False)
    fig.savefig(os.path.join(output_dir, 'power-accuracy-omega-mode-glm-6-panel.pdf'))
    omega_accuracy_plot_glm.label_offset = 4
    omega_accuracy_plot_glm.width = 10.0
    fig = omega_accuracy_plot_glm.create_column_grid(
            subplot_indices_to_exclude = [1,3],
            x_title_size = 14.0,
            y_title_size = 14.0,
            add_column_labels = False,
            column_label_size = 16.0,
            column_label_offset = 0.14,
            right_text_size = 10.0,
            x_tick_label_size = 10.0,
            share_x = False,
            share_y = False)
    fig.savefig(os.path.join(output_dir, 'power-accuracy-omega-mode-glm-4-panel.pdf'))

    ex_prob_plot = ProbabilityPowerPlotGrid(
            observed_config_to_estimates = cfg_to_prob_of_exclusion,
            variable = 'tau_exclusion',
            div_model_prior = 'psi',
            bayes_factor = 10,
            bayes_factor_prob = bf_10_exclusion_prob,
            draw_bayes_factor_line = False,
            cfg_to_prob_of_bf_exclusion = cfg_to_prob_of_bf_ex,
            num_columns = 2,
            x_title = (r'Posterior probability of excluding true parameters, $p(\mathbf{\tau} \, \notin \, '
                        r'M \, | \, B_{\epsilon}(S*))$'),
            y_title = 'Density',
            width = 14.0,
            height = 2.8,
            auto_height = False,
            auto_adjust_margins = False,
            margin_left = 0.025,
            margin_bottom = 0.1,
            margin_right = 1,
            margin_top = 0.835,
            padding_between_horizontal = 0.5)
    fig = ex_prob_plot.create_column_grid(
            subplot_indices_to_exclude = [],
            x_title_size = 14.0,
            y_title_size = 14.0,
            column_label_size = 16.0,
            column_label_offset = 0.14,
            x_tick_label_size = 10.0,
            share_x = True,
            share_y = True)
    fig.savefig(os.path.join(output_dir, 'power-prob-exclusion-6.pdf'))
    ex_prob_plot.width = 10.0
    fig = ex_prob_plot.create_column_grid(
            subplot_indices_to_exclude = [1,3],
            x_title_size = 14.0,
            y_title_size = 14.0,
            column_label_size = 16.0,
            column_label_offset = 0.14,
            right_text_size = 10.0,
            x_tick_label_size = 10.0,
            share_x = True,
            share_y = True)
    fig.savefig(os.path.join(output_dir, 'power-prob-exclusion-4.pdf'))
    ex_prob_plot.label_offset = 6
    ex_prob_plot.width = 14.0
    fig = ex_prob_plot.create_column_grid(
            subplot_indices_to_exclude = [],
            x_title_size = 14.0,
            y_title_size = 14.0,
            add_column_labels = False,
            column_label_size = 16.0,
            column_label_offset = 0.14,
            x_tick_label_size = 10.0,
            share_x = True,
            share_y = True)
    fig.savefig(os.path.join(output_dir, 'power-prob-exclusion-6-panel.pdf'))
    ex_prob_plot.label_offset = 4
    ex_prob_plot.width = 10.0
    fig = ex_prob_plot.create_column_grid(
            subplot_indices_to_exclude = [1,3],
            x_title_size = 14.0,
            y_title_size = 14.0,
            add_column_labels = False,
            column_label_size = 16.0,
            column_label_offset = 0.14,
            right_text_size = 10.0,
            x_tick_label_size = 10.0,
            share_x = True,
            share_y = True)
    fig.savefig(os.path.join(output_dir, 'power-prob-exclusion-4-panel.pdf'))


    ex_plot = PowerPlotGrid(
            observed_config_to_estimates = cfg_to_num_excluded,
            variable = 'tau_exclusion',
            num_columns = 2,
            x_title = r'Number of true $\tau$ excluded',
            y_title = 'Density',
            width = 14.0,
            height = 2.8,
            auto_height = False,
            auto_adjust_margins = False,
            margin_left = 0.025,
            margin_bottom = 0.1,
            margin_right = 1,
            margin_top = 0.835,
            padding_between_horizontal = 0.5)

    fig = ex_plot.create_column_grid(
            subplot_indices_to_exclude = [],
            x_title_size = 14.0,
            y_title_size = 14.0,
            column_label_size = 16.0,
            column_label_offset = 0.14,
            x_tick_label_size = 8.0,
            share_x = True,
            share_y = True)
    fig.savefig(os.path.join(output_dir, 'power-num-excluded-6.pdf'))
    ex_plot.width = 10.0
    fig = ex_plot.create_column_grid(
            subplot_indices_to_exclude = [1,3],
            x_title_size = 14.0,
            y_title_size = 14.0,
            column_label_size = 16.0,
            column_label_offset = 0.14,
            right_text_size = 12.0,
            x_tick_label_size = 8.0,
            share_x = True,
            share_y = True)
    fig.savefig(os.path.join(output_dir, 'power-num-excluded-4.pdf'))
예제 #5
0
def create_plots(info_path):
    dmc_sim = DMCSimulationResults(info_path)
    prior_configs = {}
    for k, v in dmc_sim.prior_index_to_config.iteritems():
        prior_configs[k] = MsBayesConfig(v)
    output_dir = os.path.join(os.path.dirname(info_path), 'plots')
    if not os.path.exists(output_dir):
        os.mkdir(output_dir)
    (psi_res, cv_res, prior_index_to_name,
            prior_index_to_model_type) = parse_results(dmc_sim)
    for prior_index, prior_name in prior_index_to_name.iteritems():
        cfg_to_psi = {}
        cfg_to_psi_prob = {}
        cfg_to_cv = {}
        cfg_to_cv_prob = {}
        cfg_to_cv_true_ests = {}
        prefix = prior_name
        for observed_name in psi_res.iterkeys():
            div_model_prior = prior_index_to_model_type[prior_index]
            dpp_concentration_mean = None
            if div_model_prior == 'dpp':
                dpp_concentration_mean = prior_configs[
                        prior_index].dpp_concentration.mean
            psi_results = psi_res[observed_name][prior_index]
            cv_results = cv_res[observed_name][prior_index]
            for cfg, psi in psi_results.iteritems():
                cfg_to_psi[cfg] = psi.mode
                cfg_to_psi_prob[cfg] = psi.prob
            for cfg, cv in cv_results.iteritems():
                cfg_to_cv[cfg] = cv.median
                cfg_to_cv_prob[cfg] = cv.prob
                cfg_to_cv_true_ests[cfg] = {'x': cv.true, 'y': cv.median}

        psi_plot = PowerPlotGrid(
                observed_config_to_estimates = cfg_to_psi,
                variable = 'psi',
                variable_symbol = r'|\mathbf{\tau}|',
                num_columns = 2,
                margin_top = 0.975)
        fig = psi_plot.create_grid()
        fig.savefig(os.path.join(output_dir,
                prefix + '_power_psi_mode.pdf'))

        psi_prob_plot = ProbabilityPowerPlotGrid(
                observed_config_to_estimates = cfg_to_psi_prob,
                variable = 'psi',
                variable_symbol = r'|\mathbf{\tau}|',
                div_model_prior = div_model_prior,
                dpp_concentration_mean = dpp_concentration_mean,
                bayes_factor = 10,
                num_columns = 2)
        fig = psi_prob_plot.create_grid()
        fig.savefig(os.path.join(output_dir,
                prefix + '_power_psi_prob.pdf'))

        cv_accuracy_plot = AccuracyPowerPlotGrid(
                observed_config_to_estimates = cfg_to_cv_true_ests,
                variable_symbol = r'CV_T',
                num_columns = 2,
                padding_between_vertical = 2.0,
                margin_left = 0.04,
                margin_bottom = 0.03)
        fig = cv_accuracy_plot.create_grid()
        fig.savefig(os.path.join(output_dir,
                prefix + '_accuracy_cv_median.pdf'))
def create_plots(info_path):
    dmc_sim = DMCSimulationResults(info_path)
    prior_configs = {}
    for k, v in dmc_sim.prior_index_to_config.iteritems():
        prior_configs[k] = MsBayesConfig(v)
    output_dir = os.path.join(os.path.dirname(info_path), 'plots')
    if not os.path.exists(output_dir):
        os.mkdir(output_dir)
    prior_prob_omega_less_than = {
            1: 0.0025575,
            2: 0.049283,
            3: 0.002171,
            4: 0.049191}
    psi_res, omega_res, prior_index_to_name = parse_results(dmc_sim)
    for observed_name in psi_res.iterkeys():
        for prior_index in psi_res[observed_name].iterkeys():
            prior_name = prior_index_to_name[prior_index]
            div_model_prior = prior_name
            if prior_name in ['old', 'u-shaped']:
                div_model_prior = 'psi'
            dpp_concentration_mean = None
            if div_model_prior == 'dpp':
                dpp_concentration_mean = prior_configs[
                        prior_index].dpp_concentration.mean
            prior_prob_omega = prior_prob_omega_less_than[prior_index]
            psi_results = psi_res[observed_name][prior_index]
            omega_results = omega_res[observed_name][prior_index]
            prefix = '_'.join([observed_name, prior_name])
            cfg_to_psi = {}
            cfg_to_psi_prob = {}
            cfg_to_psi_glm = {}
            cfg_to_psi_prob_glm = {}
            for cfg, psi in psi_results.iteritems():
                cfg_to_psi[cfg] = psi.mode
                cfg_to_psi_prob[cfg] = psi.prob
                cfg_to_psi_glm[cfg] = psi.mode_glm
                cfg_to_psi_prob_glm[cfg] = psi.prob_glm
            cfg_to_omega = {}
            cfg_to_omega_prob = {}
            cfg_to_omega_glm = {}
            cfg_to_omega_prob_glm = {}
            cfg_to_omega_true_ests = {}
            cfg_to_omega_true_ests_glm = {}
            for cfg, omega in omega_results.iteritems():
                cfg_to_omega[cfg] = omega.median
                cfg_to_omega_prob[cfg] = omega.prob
                cfg_to_omega_glm[cfg] = omega.mode_glm
                cfg_to_omega_prob_glm[cfg] = omega.prob_glm
                cfg_to_omega_true_ests[cfg] = {'x': omega.true, 'y': omega.median}
                cfg_to_omega_true_ests_glm[cfg] = {'x': omega.true, 'y': omega.mode_glm}

            psi_plot = PowerPlotGrid(
                    observed_config_to_estimates = cfg_to_psi,
                    variable = 'psi',
                    variable_symbol = r'|\mathbf{\tau}|',
                    num_columns = 2,
                    margin_top = 0.975)
            fig = psi_plot.create_grid()
            fig.savefig(os.path.join(output_dir,
                    prefix + '_power_psi_mode.pdf'))

            psi_plot_glm = PowerPlotGrid(
                    observed_config_to_estimates = cfg_to_psi_glm,
                    variable = 'psi',
                    variable_symbol = r'|\mathbf{\tau}|',
                    num_columns = 2,
                    margin_top = 0.975)
            fig = psi_plot_glm.create_grid()
            fig.savefig(os.path.join(output_dir,
                    prefix + '_power_psi_mode_glm.pdf'))

            psi_prob_plot = ProbabilityPowerPlotGrid(
                    observed_config_to_estimates = cfg_to_psi_prob,
                    variable = 'psi',
                    variable_symbol = r'|\mathbf{\tau}|',
                    div_model_prior = div_model_prior,
                    dpp_concentration_mean = dpp_concentration_mean,
                    bayes_factor = 10,
                    num_columns = 2)
            fig = psi_prob_plot.create_grid()
            fig.savefig(os.path.join(output_dir,
                    prefix + '_power_psi_prob.pdf'))

            psi_prob_plot_glm = ProbabilityPowerPlotGrid(
                    observed_config_to_estimates = cfg_to_psi_prob_glm,
                    variable = 'psi',
                    variable_symbol = r'|\mathbf{\tau}|',
                    div_model_prior = div_model_prior,
                    dpp_concentration_mean = dpp_concentration_mean,
                    bayes_factor = 10,
                    num_columns = 2)
            fig = psi_prob_plot_glm.create_grid()
            fig.savefig(os.path.join(output_dir,
                    prefix + '_power_psi_prob_glm.pdf'))

            omega_plot = PowerPlotGrid(
                    observed_config_to_estimates = cfg_to_omega,
                    variable = 'omega',
                    variable_symbol = r'D_T',
                    num_columns = 2)
            fig = omega_plot.create_grid()
            fig.savefig(os.path.join(output_dir,
                    prefix + '_power_omega_median.pdf'))

            omega_plot_glm = PowerPlotGrid(
                    observed_config_to_estimates = cfg_to_omega_glm,
                    variable = 'omega',
                    variable_symbol = r'D_T',
                    num_columns = 2)
            fig = omega_plot_glm.create_grid()
            fig.savefig(os.path.join(output_dir,
                    prefix + '_power_omega_mode_glm.pdf'))

            omega_prob_plot = ProbabilityPowerPlotGrid(
                    observed_config_to_estimates = cfg_to_omega_prob,
                    variable = 'omega',
                    variable_symbol = r'D_T',
                    div_model_prior = div_model_prior,
                    dpp_concentration_mean = dpp_concentration_mean,
                    bayes_factor = 10,
                    bayes_factor_prob = prior_prob_omega,
                    num_columns = 2,
                    text_size = 10.0)
            fig = omega_prob_plot.create_grid()
            fig.savefig(os.path.join(output_dir,
                    prefix + '_power_omega_prob.pdf'))

            omega_prob_plot_glm = ProbabilityPowerPlotGrid(
                    observed_config_to_estimates = cfg_to_omega_prob_glm,
                    variable = 'omega',
                    variable_symbol = r'D_T',
                    div_model_prior = div_model_prior,
                    dpp_concentration_mean = dpp_concentration_mean,
                    bayes_factor = 10,
                    bayes_factor_prob = prior_prob_omega,
                    num_columns = 2,
                    text_size = 10.0)
            fig = omega_prob_plot_glm.create_grid()
            fig.savefig(os.path.join(output_dir,
                    prefix + '_power_omega_prob_glm.pdf'))
            
            omega_accuracy_plot = AccuracyPowerPlotGrid(
                    observed_config_to_estimates = cfg_to_omega_true_ests,
                    variable_symbol = r'D_T',
                    num_columns = 2,
                    padding_between_vertical = 2.0,
                    margin_left = 0.04,
                    margin_bottom = 0.03)
            fig = omega_accuracy_plot.create_grid()
            fig.savefig(os.path.join(output_dir,
                    prefix + '_power_accuracy_omega_median.pdf'))

            omega_accuracy_plot_glm = AccuracyPowerPlotGrid(
                    observed_config_to_estimates = cfg_to_omega_true_ests_glm,
                    variable_symbol = r'D_T',
                    num_columns = 2,
                    padding_between_vertical = 2.0,
                    margin_left = 0.04,
                    margin_bottom = 0.03)
            fig = omega_accuracy_plot_glm.create_grid()
            fig.savefig(os.path.join(output_dir,
                    prefix + '_power_accuracy_omega_mode_glm.pdf'))