Esempio n. 1
0
def experiment_VI_plots(
    paths,
    names,
    title,
    out_name,
    out_dir,
    cond_ent_over="GT | Output",
    cond_ent_under="Output | GT",
):
    groups = []
    ce0 = []
    ce1 = []
    for i, p in enumerate(paths):
        df = pd.read_csv(p)
        ce0.append(df[cond_ent_over].values)
        ce1.append(df[cond_ent_under].values)
        groups += [names[i]] * len(df)
    x = 'Experiment'
    data = {
        x: groups,
        cond_ent_over: np.concatenate(ce0),
        cond_ent_under: np.concatenate(ce1)
    }
    data = pd.DataFrame(data)
    f, axs = plt.subplots(1, 2, figsize=(12, 10))
    ax0 = axs[0, 0]
    ax1 = axs[0, 1]
    o = 'h'
    pal = 'Set2'
    sigma = .2
    pt.RainCloud(x=x,
                 y=cond_ent_over,
                 data=data,
                 palette=pal,
                 bw=sigma,
                 width_viol=.6,
                 ax=ax0,
                 orient=o)
    pt.RainCloud(x=x,
                 y=cond_ent_under,
                 data=data,
                 palette=pal,
                 bw=sigma,
                 width_viol=.6,
                 ax=ax1,
                 orient=o)
    plt.title(title)
    if save:
        save_path = os.path.join(out_dir, '_VI_rainclould_plots.png')
        plt.savefig(save_path, bbox_inches='tight')
    if show:
        plt.show()
Esempio n. 2
0
def task_cp_reg():
    sns.set(style="whitegrid", font_scale=2)
    legend_handles = []
    for task, color in zip(task_order(False), task_colors()):
        legend_handles.append(Patch(facecolor=color, edgecolor=color, label=task))
    fig, axs = plt.subplots(2, 3, figsize=(36, 24), sharex="col", sharey="row")
    for col, (tpt, h_name) in enumerate(template_meta_combination):
        for row, (lib, label, name) in enumerate(lib_details):
            df = lib.gen_long_data(tpt).groupby(["task", "region", "network"]).mean().reset_index() \
                .and_filter(NOTtask="Rest") \
                .convert_column(metric=lambda x: x * 1000) \
                .add_topo(topo_at[tpt.key]) \
                .add_net_meta(tpt.net_hierarchy(h_name)) \
                .groupby("task").apply(
                lambda x: pd.merge(x, pd.Series(sm.OLS(x.metric, x.coord_y).fit().resid, x.index, float, "resid"),
                                   left_index=True, right_index=True)).reset_index(drop=True) \
                .groupby(["task", "net_meta"]).apply(remove_outliers, of="metric").reset_index(drop=True)

            ax = axs[row, col]
            pt.RainCloud(data=df, hue="task", y="resid", x="net_meta", alpha=.65, hue_order=task_order(False),
                         order=h_name.keys, ax=ax, offset=0.1, dodge=True, bw=.2, width_viol=.7,
                         pointplot=True, palette=task_colors())
            ax.set(xlabel="", ylabel=f"{name} Residual" if col == 0 else "")
            ax.get_legend().remove()
            ax.set_xticklabels(h_name.labels if row == 1 else [])
            if row == 0:
                ax.legend(handles=legend_handles, loc=2)
    fig.subplots_adjust(wspace=0.1, hspace=0.1)
    print(savefig(fig, "task.cp.res", low=False))
Esempio n. 3
0
def my_rain_plot(path):
    results = pd.read_csv(path + '/results.csv', delimiter=';')
    del results['HDRFDST']
    new_results = results.melt(id_vars=["SUBJECT", "LABEL"],
                               var_name="metric",
                               value_name="Score")
    dx = "LABEL"
    dy = "Score"
    dhue = "metric"
    ort = "v"
    pal = "Set2"
    sigma = .2
    f, ax = plt.subplots(figsize=(12, 5))

    ax = pt.RainCloud(x=dx,
                      y=dy,
                      hue=dhue,
                      data=new_results,
                      palette=pal,
                      bw=sigma,
                      width_viol=1,
                      ax=ax,
                      orient=ort,
                      alpha=.65,
                      dodge=True,
                      pointplot=True,
                      move=.1)
    plt.show()
Esempio n. 4
0
def alpha():
    sns.set(style="whitegrid", font_scale=2)
    legend_handles = []
    for task, color in zip(task_order(), task_colors(True)):
        legend_handles.append(Patch(facecolor=color, edgecolor=color, label=task))
    fig, axs = plt.subplots(2, 3, figsize=(36, 24), sharex="col", sharey="row")
    for col, (tpt, h_name) in enumerate(template_meta_combination):
        for row, (lib, label) in enumerate(zip([acwb, aczb], ["ACW-50", "ACW-0"])):
            df = lib.gen_long_data(tpt) \
                .groupby(["task", "region", "network"]).mean().reset_index() \
                .convert_column(metric=lambda x: x * 1000) \
                .add_net_meta(tpt.net_hierarchy(h_name)).drop("network", 1) \
                .groupby(["task", "net_meta"]).apply(remove_outliers, of="metric").reset_index(drop=True)

            ax = axs[row, col]
            pt.RainCloud(data=df, hue="task", y="metric", x="net_meta", alpha=.65, hue_order=task_order(),
                         order=h_name.keys, ax=ax, offset=0.1, dodge=True, bw=.2, width_viol=.7,
                         pointplot=True, palette=task_colors(True))
            ax.set(xlabel="", ylabel=f"{label} (ms)" if col == 0 else "")
            ax.get_legend().remove()
            ax.set_xticklabels(h_name.labels if row == 1 else [])
            if row == 0:
                ax.legend(handles=legend_handles)

    fig.subplots_adjust(wspace=0.1, hspace=0.1)
    print(savefig(fig, "alpha.cp", low=False))
Esempio n. 5
0
def raincloud(col: str, target_col: str, data, **params):
    """
    Visualizes 2 columns using raincloud.
    
    Parameters
    ----------
    col : str
        Column name of general data

    target_col : str
        Column name of measurable data, numerical

    data : Dataframe
        Dataframe of the data

    params: dict
        Parameters for the RainCloud visualization
    """

    _, ax = plt.subplots(figsize=(12, 8))

    if not params:
        params = {
            "x": col,
            "y": target_col,
            "data": data.infer_objects(),
            "pointplot": True,
            "width_viol": 0.8,
            "width_box": 0.4,
            "orient": "h",
            "move": 0.0,
            "ax": ax,
        }

    ax = pt.RainCloud(**params)
Esempio n. 6
0
def raincloud(par1, par2, df):
    """
    Same specifications and requirements as overlapping density plot

    Function takes package name, input variables(categories), and target variable as input.
    Returns a figure

    PARAMETERS

    :param package:        should only take sns or matplotlib as inputs, any other value should throw and error
    :param input_vars:     should take the x variables/categories you want to plot
    :param target_vars:    the y variable of your plot, what you are comparing
    :return:               fig to be enhanced in subsequent visualization functions
    """
    dx = par1
    dy = par2
    ort = "h"
    pal = "Set2"
    sigma = .2
    fig, ax = plt.subplots(figsize=(16, 10))

    pt.RainCloud(x=dx,
                 y=dy,
                 data=df,
                 palette=pal,
                 bw=sigma,
                 width_viol=.6,
                 ax=ax,
                 orient=ort,
                 move=0)
    plt.xlabel('Danceability')
    plt.title('20 year Comparison of Songs Danceability')

    return fig
Esempio n. 7
0
def pchange_net():
    sns.set(style="whitegrid", font_scale=2)
    fig, axs = plt.subplots(2, 2, figsize=(36, 20), sharey="row", sharex="col",
                            gridspec_kw={'width_ratios': [7 / 19, 12 / 19]})
    for col, tpt in enumerate([tpt_sh, tpt_cole]):
        for row, (lib, label, name) in enumerate(lib_details):
            df = lib.gen_long_data(tpt) \
                .and_filter(subject=lib.find_shared_subjects(tpt, task_order())) \
                .groupby(["task", "subject", "network", "region"]).mean().reset_index() \
                .groupby(["subject", "network", "region"]).apply(calc_percentage_change).reset_index() \
                .groupby(["task", "network", "region"]).mean().reset_index()

            ax = axs[row, col]
            pt.RainCloud(data=df, hue="task", y="pchange", x="network", alpha=.65, hue_order=task_order(False),
                         order=tpt.net_order, ax=ax, offset=0.1, dodge=True, bw=.2, width_viol=.7,
                         pointplot=True, palette=task_colors())
            ax.set(xlabel="", ylabel=f"{label} Change From Rest (%)" if col == 0 else "")
            ax.set_xticklabels(tpt.net_labels, rotation=90)
            ax.get_legend().remove()
    fig.subplots_adjust(wspace=0.1, hspace=0.1)
    legend_handles = []
    for task, color in zip(task_order(False), task_colors()):
        legend_handles.append(Patch(facecolor=color, edgecolor=color, label=task))
    lgn = fig.legend(handles=legend_handles, loc=2, ncol=3, mode="expand",
                     bbox_to_anchor=(0.12, -0.08, 0.785, 1))
    print(savefig(fig, "pchange.net", low=False, extra_artists=(lgn,)))
Esempio n. 8
0
def pchange_cp():
    sns.set(style="whitegrid", font_scale=2)
    legend_handles = []
    for task, color in zip(task_order(False), task_colors()):
        legend_handles.append(Patch(facecolor=color, edgecolor=color, label=task))
    fig, axs = plt.subplots(2, 3, figsize=(36, 24), sharex="col", sharey="row")
    for col, (tpt, h_name) in enumerate(template_meta_combination):
        for row, (lib, label, name) in enumerate(lib_details):
            df = lib.gen_long_data(tpt) \
                .and_filter(subject=lib.find_shared_subjects(tpt, task_order())) \
                .groupby(["task", "subject", "network", "region"]).mean().reset_index() \
                .groupby(["subject", "network", "region"]).apply(calc_percentage_change).reset_index() \
                .add_net_meta(tpt.net_hierarchy(h_name)) \
                .groupby(["task", "region", "net_meta"]).mean().reset_index()
            ax = axs[row, col]
            pt.RainCloud(data=df, hue="task", y="pchange", x="net_meta", alpha=.65, hue_order=task_order(False),
                         order=h_name.keys, ax=ax, offset=0.1, dodge=True, bw=.2, width_viol=.7,
                         pointplot=True, palette=task_colors())
            ax.set(xlabel="", ylabel=f"{label} Change From Rest (%)" if col == 0 else "")
            ax.get_legend().remove()
            ax.set_xticklabels(h_name.labels if row == 1 else [])
            if row == 0:
                ax.legend(handles=legend_handles, loc=2)
    fig.subplots_adjust(wspace=0.1, hspace=0.1)
    print(savefig(fig, "pchange.cp", low=False))
def hyperparameter_dendrites_wit_si_search_panel():
    """
    Plots a 3 panels figure on 1 rows x 3 columns
    Rows contains figures representing hyperparameters search for 10
    permutedMNIST tasks resulting from hyperparameter_search.py config file.
    Columns 1 is the number of dendritic segments, columns 2 the activation
    sparsity and column 3 the weight sparsity.
    """

    df_path1 = f"{experiment_folder}si_prototype_hp_10_lasttask.csv"
    df1 = pd.read_csv(df_path1)

    df_path2 = f"{experiment_folder}si_prototype_hp_10_control_lasttask.csv"
    df2 = pd.read_csv(df_path2)

    df1 = df1[[
        "Activation sparsity", "FF weight sparsity", "Num segments", "Accuracy"
    ]]
    df2 = df2[[
        "Activation sparsity", "FF weight sparsity", "Num segments", "Accuracy"
    ]]
    df1["condition"] = "dendrite_and_ff"
    df2["condition"] = "ff_only"
    df = pd.concat([df1, df2])

    gs = gridspec.GridSpec(1, 1)
    fig = plt.figure(figsize=(5, 5))

    ax1 = fig.add_subplot(gs[0, 0])

    x1 = "Num segments"
    dhue = "condition"
    y = "Accuracy"
    ort = "v"
    pal = sns.color_palette(n_colors=9)
    sigma = 0.2
    fig.suptitle("Impact of the number of segments with SI on performance",
                 fontsize=12)

    pt.RainCloud(x=x1,
                 y=y,
                 hue=dhue,
                 data=df,
                 palette=pal,
                 bw=sigma,
                 width_viol=0.6,
                 ax=ax1,
                 orient=ort,
                 move=0.2,
                 pointplot=True,
                 alpha=0.65)

    ax1.set_ylabel("Mean accuracy", fontsize=16)
    ax1.set_xlabel("Number of dendritic segments", fontsize=16)

    if savefigs:
        plt.savefig(
            f"{figs_dir}/hyperparameter_search_panel_with_si_dendrites.png",
            bbox_inches="tight")
Esempio n. 10
0
def display_raincloud(input_df, scaling=True):
    print(
        "==============================================================================================================="
    )
    print('# raincloud')
    print(
        "==============================================================================================================="
    )
    _df = input_df.copy()
    if scaling:
        _df = (_df - _df.mean()) / _df.std()

    cols = list(_df.select_dtypes('number'))
    fig, ax = plt.subplots(figsize=(18, 6))
    ptitprince.RainCloud(data=_df[cols], ax=ax, orient='v')
    fig.tight_layout()
    display(fig)
    plt.close()
Esempio n. 11
0
def plot_csv(
    filename: str,
    outpath: str,
    font: int = 14,
    width: int = 10,
    height: int = 4,
):
    csv = pd.read_csv(filename)

    f, ax = plt.subplots(figsize=(width, height))
    ax = pt.RainCloud(
        x="type",
        y="seconds",
        hue="source",
        data=csv,
        palette="Set2",
        order=("Overhead", "Zarr", "TIFF", "HDF5"),
        # bw = .2,
        width_viol=0.6,
        ax=ax,
        orient="h",
        alpha=0.65,
        # dodge = True,
        jitter=0.03,
        move=0.2,
        # pointplot = True,
    )

    # ax.set(ylim=(0.0002, 5))
    ax.set_xscale("log")
    ax.set_xlabel("seconds per chunk")
    for item in (
        [ax.title, ax.xaxis.label, ax.yaxis.label]
        + ax.get_xticklabels()
        + ax.get_yticklabels()
    ):
        item.set_fontsize(font)

    ax.axes.get_yaxis().get_label().set_visible(False)
    handles, labels = ax.get_legend_handles_labels()
    plt.legend(handles[0:3], labels[0:3], loc="lower left", prop={"size": font})
    plt.tight_layout()
    f.savefig(outpath)
Esempio n. 12
0
def raincloud(col: str,
              target_col: str,
              data: pd.DataFrame,
              output_file="",
              **params):
    """
    Visualizes 2 columns using raincloud.
    
    Parameters
    ----------
    col : str
        Column name of general data

    target_col : str
        Column name of measurable data, numerical

    data : Dataframe
        Dataframe of the data

    params: dict
        Parameters for the RainCloud visualization

    ouput_file : str
        Output file name for the image including extension (.jpg, .png, etc.)
    """

    fig, ax = plt.subplots(figsize=(12, 8))

    if not params:
        params = {
            "pointplot": True,
            "width_viol": 0.8,
            "width_box": 0.4,
            "orient": "h",
            "move": 0.0,
            "ax": ax,
        }

    ax = pt.RainCloud(x=col, y=target_col, data=data.infer_objects(), **params)

    if output_file:  # pragma: no cover
        fig.savefig(os.path.join(IMAGE_DIR, output_file))
Esempio n. 13
0
def rest_net():
    sns.set(style="whitegrid", font_scale=2)
    fig, axs = plt.subplots(
        2, 2, figsize=(36, 20), sharey="row", sharex="col", gridspec_kw={'width_ratios': [7 / 19, 12 / 19]})

    for col, tpt in enumerate([tpt_sh, tpt_cole]):
        for row, (lib, label, name) in enumerate(lib_details):
            df = lib.gen_long_data(tpt) \
                .groupby(["task", "region", "network"]).mean().reset_index() \
                .and_filter(task="Rest") \
                .convert_column(metric=lambda x: x * 1000) \
                .groupby("network").apply(remove_outliers, of="metric").reset_index(drop=True)

            ax = axs[row, col]
            pt.RainCloud(data=df, x="network", y="metric", order=tpt.net_order, ax=ax, offset=0.1,
                         pointplot=True, palette=tpt.net_colors, scale="width")
            ax.set(xlabel="", ylabel=f"{name} (ms)" if col == 0 else "")
            ax.set_xticklabels(tpt.net_labels, rotation=90)
    fig.subplots_adjust(wspace=0.1, hspace=0.1)
    print(savefig(fig, "rest.net", low=False))
Esempio n. 14
0
def plt_raincloud(ax, df, cmap):
    pt.RainCloud(
        x="type",
        y="seconds",
        hue="type",
        data=df,
        palette=cmap.name,
        width_viol=0.6,
        ax=ax,
        orient="h",
        alpha=0.65,
        jitter=0.03,
        move=0.2,
    )
    ax.legend().set_visible(False)
    ax.axes.get_yaxis().get_label().set_visible(False)
    ax.set_title(df["name"][0])
    ax.set_xscale("log")
    ax.set_xlabel("seconds per chunk")
    return ax
Esempio n. 15
0
def rest_cp():
    sns.set(style="whitegrid", font_scale=2)
    fig, axs = plt.subplots(2, 3, figsize=(24, 24), sharex="col", sharey="row")
    for col, (tpt, h_name) in enumerate(template_meta_combination):
        for row, (lib, label, name) in enumerate(lib_details):
            df = lib.gen_long_data(tpt) \
                .groupby(["task", "region", "network"]).mean().reset_index() \
                .and_filter(task="Rest") \
                .convert_column(metric=lambda x: x * 1000) \
                .add_net_meta(tpt.net_hierarchy(h_name)) \
                .drop("network", 1) \
                .groupby("net_meta").apply(remove_outliers, of="metric").reset_index(drop=True)

            ax = axs[row, col]
            pt.RainCloud(data=df, x="net_meta", y="metric", order=h_name.keys, ax=ax, offset=0.1,
                         pointplot=True, palette=PC_colors_tuple)
            ax.set(xlabel="", ylabel=f"{name} (ms)" if col == 0 else "")
            ax.set_xticklabels(h_name.labels)
    fig.subplots_adjust(wspace=0.1, hspace=0.1)
    print(savefig(fig, "rest.cp", low=False))
Esempio n. 16
0
def VI_plot(path,
            cond_ent_over="GT | Output",
            cond_ent_under="Output | GT",
            lab="",
            save=False,
            show=True):
    df = pd.read_csv(path)
    overseg = df[cond_ent_over].values
    o_groups = [cond_ent_over] * len(overseg)
    underseg = df[cond_ent_under].values
    u_groups = [cond_ent_under] * len(underseg)
    groups = o_groups + u_groups
    x = 'Variation of information'
    y = 'Conditional entropy'
    data = {x: groups, y: np.concatenate([overseg, underseg])}
    data = pd.DataFrame(data)
    o = 'h'
    pal = 'Set2'
    sigma = .2
    f, ax = plt.subplots(figsize=(12, 10))
    pt.RainCloud(x=x,
                 y=y,
                 data=data,
                 palette=pal,
                 bw=sigma,
                 width_viol=.6,
                 ax=ax,
                 orient=o)
    p = Path(path)
    plt.title(p.stem)
    if save:
        save_path = os.path.join(p.parents[0],
                                 p.stem + lab + '_VI_rainclout_plot.png')
        plt.savefig(save_path, bbox_inches='tight')
    if show:
        plt.show()
Esempio n. 17
0
def raincloud_plot(folder_dir, file_name, x_data, title, y_label, x_label):

    sns.set(style="whitegrid")
    #ax = sns.boxplot(x=pauses, whis=np.inf)
    #ax = sns.swarmplot(x=pauses, color='black')

    #x = (3.5+2*np.random.randn(1000, 1))#); x1 = (-3.5+2*np.random.randn(1000, 2))
    #x=np.concatenate((x,x1),axis=0)
    #x_cat = np.random.randint(0,4,size=(2000, 1))
    #x=np.concatenate((x_cat,x),axis=1)
    #df_rand = pd.DataFrame(pauses, columns=['pauses','all pauses'])
    fig, ax = plt.subplots(figsize=(8, 3))
    ax = pt.RainCloud(x=np.array(x_data), orient='h', bw=.1, ax=ax)
    #sns.despine()

    #sns.despine()
    #ax.figure.set_size_inches(12,8)
    plt.title(title)
    plt.ylabel(y_label)
    plt.xlabel(x_label)
    #ax.xlabel(x_label)
    #fig.xlabel(x_label)
    plt.savefig('./output' + folder_dir + file_name + '/' +
                'raincloud_pause_groups_num_all.png')
Esempio n. 18
0
#%% Raincloud plots by brain area - mean tau

# ACC

dx = "species"
dy = "tau"
ort = "h"
sigma = .2

fig, ax = plt.subplots(figsize=(5, 5))

pt.RainCloud(x=dx,
             y=dy,
             data=acc_means,
             bw=sigma,
             width_viol=.6,
             ax=ax,
             orient=ort,
             point_size=1)

plt.title('ACC')
plt.show()
#%%
acc_mod = smf.ols('tau ~ species', data=acc_means)
acc_mod = acc_mod.fit()

print(acc_mod.summary())
#%%
acc_mod2 = smf.ols('tau ~ species + mean_fr', data=acc_means)
acc_mod2 = acc_mod2.fit()
Esempio n. 19
0
pal = "Set2"
sigma = .2

fig = plt.figure(figsize=[15, 15])
gs = gridspec.GridSpec(ncols=2, nrows=2)
plt.subplots_adjust(bottom=0.2, hspace=0.5)

ax1 = fig.add_subplot(gs[0])

dy = "SignalVEH.+"
ax1 = pt.RainCloud(x=dx,
                   y=dy,
                   hue=dhue,
                   data=capG,
                   palette=pal,
                   bw=sigma,
                   width_viol=.7,
                   ax=ax1,
                   orient=ort,
                   alpha=.65,
                   dodge=True,
                   move=.2)
ax1.get_legend().remove()
ax1.set(yscale="log")

ax2 = fig.add_subplot(gs[1])

dy = "SignalVEH.-"
ax2 = pt.RainCloud(x=dx,
                   y=dy,
                   hue=dhue,
                   data=capG,
Esempio n. 20
0
# load UKBB
ukbb_path = '/Users/hannah/SB/ukb_add1_holmes_merge_brain.csv'
if 'ukbb' not in locals():
    ukbb = pd.read_csv(ukbb_path)
else:
    print('Database is already in memory!')


keep = ['31-0.0', '21022-0.0', '2040-0.0']
ukbb_dem = ukbb.copy()[keep].dropna()
ukbb_dem = ukbb_dem[ukbb_dem['2040-0.0'] >= 0]     




sex='31-0.0'; age='21022-0.0'; risk='2040-0.0'
sex_colors = sns.set_palette(['#ff019c', '#F5D300'])

f, ax = plt.subplots(figsize=(8, 8))
pt.RainCloud(x = risk, y = age, data = ukbb_dem,
                ax = ax, hue=sex, palette=sex_colors, orient='h',
                dodge=True, point_size=1.0, linewidth=0.2,
                width_viol=1.3, width_box=0.25,
                alpha=0.60)
plt.tight_layout()    

plt.savefig('%s/raincloud.png' % (OUT_DIR), dpi=600)



pal = sns.color_palette(n_colors=3)
sigma = .3
fig, axes = plt.subplots(ncols=4, nrows=1, figsize=(
    23.38,
    8.27,
))
fig.suptitle('volume of thalamic subnuclei (corrected for ICV)')

for i, ax in zip(range(len(dfs)), axes.flat):

    data = dfs[i]
    ax_al = pt.RainCloud(x=dx,
                         y=dy,
                         data=data,
                         palette=pal,
                         bw=sigma,
                         width_viol=.3,
                         figsize=(7, 5),
                         orient=ort,
                         ax=ax)
    ax.set_title('')
    ax.set_ylabel('mm³')
    ax.set_xlabel('')
    plt.setp(ax.get_xticklabels(),
             rotation=20,
             ha="right",
             rotation_mode="anchor")

plt.subplots_adjust(left=0.125,
                    bottom=0.1,
                    right=0.9,
Esempio n. 22
0
sigma = .2

dx = "group"
dy = "score"
dhue = "gr2"
ort = "h"
pal = "Set2"
sigma = .2

#f, ax = plt.subplots(figsize=(5, 10))

ax = pt.RainCloud(x=dx,
                  y=dy,
                  hue=dhue,
                  data=df,
                  palette=pal,
                  bw=sigma,
                  width_viol=0.9,
                  figsize=(40, 10),
                  orient=ort,
                  alpha=.65)  # pointplot = True  # , move = .3

# orient = ort)

ax.set(xlim=(0.3, 0.9))
# ax.set(ylim=(0.2, 0.6))
sns.despine()
plt.show()

plt.tight_layout()
Esempio n. 23
0
                  ('female3'), ('female4'), ('female5'), ('female6')]

df_tpre = pd.DataFrame(tpre, columns=['sex', 'group', 'fatigue'])
df_ID = pd.DataFrame(participant_ID, columns=['ID'])
df_tpre['ID'] = participant_ID

df_tpre_male = pd.DataFrame(tpre_male, columns=['sex1', 'group1', 'fatigue1'])
df_tpre_female = pd.DataFrame(tpre_female,
                              columns=['sex2', 'group2', 'fatigue2'])

#make it rain
plt.subplot()
ax = pt.RainCloud(x='group',
                  y='fatigue',
                  data=df_tpre,
                  pointplot=True,
                  width_viol=2,
                  width_box=.1,
                  orient='h',
                  move=.0)
plt.subplot

ax1 = pt.RainCloud(x='group1',
                   y='fatigue1',
                   data=df_tpre_male,
                   pointplot=True,
                   width_viol=2,
                   width_box=.1,
                   orient='h',
                   move=.0)

ax2 = pt.RainCloud(x='group2',
Esempio n. 24
0
def genera_raincloud():

    # Plotting the clouds
    f, ax = plt.subplots(figsize=(7, 5))
    dy = "variety"
    dx = "sepal.length"
    ort = "h"
    pal = sns.color_palette(n_colors=1)
    ax = pt.half_violinplot(x=dx,
                            y=dy,
                            data=df,
                            palette=pal,
                            bw=.2,
                            cut=0.,
                            scale="area",
                            width=.6,
                            inner=None,
                            orient=ort)
    plt.title("Raincloud with Clouds")
    plt.savefig("img/Raincloud_Clouds.png")
    plt.close()

    # Adding the rain
    f, ax = plt.subplots(figsize=(7, 5))
    ax = pt.half_violinplot(x=dx,
                            y=dy,
                            data=df,
                            palette=pal,
                            bw=.2,
                            cut=0.,
                            scale="area",
                            width=.6,
                            inner=None,
                            orient=ort)
    ax = sns.stripplot(x=dx,
                       y=dy,
                       data=df,
                       palette=pal,
                       edgecolor="white",
                       size=3,
                       jitter=0,
                       zorder=0,
                       orient=ort)
    plt.title("Raincloud with Clouds and Rain")
    plt.savefig("img/Raincloud_Clouds_Rain.png")
    plt.close()

    # Adding jitter to the rain
    f, ax = plt.subplots(figsize=(7, 5))
    ax = pt.half_violinplot(x=dx,
                            y=dy,
                            data=df,
                            palette=pal,
                            bw=.2,
                            cut=0.,
                            scale="area",
                            width=.6,
                            inner=None,
                            orient=ort)
    ax = sns.stripplot(x=dx,
                       y=dy,
                       data=df,
                       palette=pal,
                       edgecolor="white",
                       size=3,
                       jitter=1,
                       zorder=0,
                       orient=ort)
    plt.title("Raincloud with Clouds and Jitter rain")
    plt.savefig("img/Raincloud_Clouds_Rain_Jitter.png")

    # Adding the boxplot with quartiles
    f, ax = plt.subplots(figsize=(7, 5))
    ax = pt.half_violinplot(x=dx,
                            y=dy,
                            data=df,
                            palette=pal,
                            bw=.2,
                            cut=0.,
                            scale="area",
                            width=.6,
                            inner=None,
                            orient=ort)
    ax = sns.stripplot(x=dx,
                       y=dy,
                       data=df,
                       palette=pal,
                       edgecolor="white",
                       size=3,
                       jitter=1,
                       zorder=0,
                       orient=ort)
    ax=sns.boxplot( x = dx, y = dy, data = df, color = "black", width = .15, zorder = 10,\
                showcaps = True, boxprops = {'facecolor':'none', "zorder":10},\
                showfliers=True, whiskerprops = {'linewidth':2, "zorder":10},\
                   saturation = 1, orient = ort)

    sns.boxplot( x = dx, y = dy, data = df, color = "black", width = .15, zorder = 10,\
                showcaps = True, boxprops = {'facecolor':'none', "zorder":10},\
                showfliers=True, whiskerprops = {'linewidth':2, "zorder":10},\
                   saturation = 1, orient = ort)
    plt.title("Raincloud with Boxplot")
    plt.savefig("img/Raincloud_Boxplot.png")
    plt.close()

    dx = "variety"
    dy = "sepal.length"
    ort = "h"
    pal = "Set2"
    sigma = .2
    f, ax = plt.subplots(figsize=(7, 5))
    ax = pt.RainCloud(x=dx,
                      y=dy,
                      data=df,
                      palette=pal,
                      bw=sigma,
                      width_viol=.6,
                      ax=ax,
                      orient=ort,
                      move=.2)
    plt.title("Raincloud with Boxplot and Shifted Rain")
    plt.savefig("img/Raincloud_Boxplot_Shifted_Rain.png")
    plt.close()
Esempio n. 25
0
def performance_across_tasks():
    """
    Similar representation as previous function (hyperparameter_search_panel)
    but in this case, it represents the performance along the number of tasks
    and we plot all the hyperparameters on the same figure for each figures.
    """

    df_path1 = f"{experiment_folder}segment_search_all.csv"
    df1 = pd.read_csv(df_path1)

    df_path2 = f"{experiment_folder}kw_sparsity_search_all.csv"
    df2 = pd.read_csv(df_path2)

    df_path3 = f"{experiment_folder}w_sparsity_search_all.csv"
    df3 = pd.read_csv(df_path3)

    df_path1_50 = f"{experiment_folder}segment_search_50_all.csv"
    df1_50 = pd.read_csv(df_path1_50)

    df_path2_50 = f"{experiment_folder}kw_sparsity_search_50_all.csv"
    df2_50 = pd.read_csv(df_path2_50)

    df_path3_50 = f"{experiment_folder}w_sparsity_search_50_all.csv"
    df3_50 = pd.read_csv(df_path3_50)

    gs = gridspec.GridSpec(2, 3)
    fig = plt.figure(figsize=(14, 10))

    ax1 = fig.add_subplot(gs[0, 0])
    ax2 = fig.add_subplot(gs[0, 1])
    ax3 = fig.add_subplot(gs[0, 2])
    ax1_50 = fig.add_subplot(gs[1, 0])
    ax2_50 = fig.add_subplot(gs[1, 1])
    ax3_50 = fig.add_subplot(gs[1, 2])

    x1 = "Iteration"
    hue1 = "Num segments"
    hue2 = "Activation sparsity"
    hue3 = "FF weight sparsity"
    y = "Accuracy"
    ort = "v"
    pal = sns.color_palette(n_colors=10)
    sigma = 0.2
    fig.suptitle(
        """Performance along number of tasks with different
        hyperpameter conditions""",
        fontsize=16,
    )

    pt.RainCloud(x=x1,
                 y=y,
                 hue=hue1,
                 data=df1,
                 palette=pal,
                 bw=sigma,
                 width_viol=0.6,
                 ax=ax1,
                 orient=ort,
                 move=0.2,
                 pointplot=True,
                 alpha=0.65)

    l, h = ax1.get_legend_handles_labels()
    ax1.legend(handles=l[0:10], labels=h[0:10], fontsize="8")

    pt.RainCloud(x=x1,
                 y=y,
                 hue=hue2,
                 data=df2,
                 palette=pal,
                 bw=sigma,
                 width_viol=0.6,
                 ax=ax2,
                 orient=ort,
                 move=0.2,
                 pointplot=True,
                 alpha=0.65)

    l, h = ax2.get_legend_handles_labels()
    ax2.legend(handles=l[0:9], labels=h[0:9], fontsize="8")

    pt.RainCloud(x=x1,
                 y=y,
                 hue=hue3,
                 data=df3,
                 palette=pal,
                 bw=sigma,
                 width_viol=0.6,
                 ax=ax3,
                 orient=ort,
                 move=0.2,
                 pointplot=True,
                 alpha=0.65)
    l, h = ax3.get_legend_handles_labels()
    ax3.legend(handles=l[0:8], labels=h[0:8], fontsize="8")

    pt.RainCloud(x=x1,
                 y=y,
                 hue=hue1,
                 data=df1_50,
                 palette=pal,
                 bw=sigma,
                 width_viol=0.6,
                 ax=ax1_50,
                 orient=ort,
                 move=0.2,
                 pointplot=True,
                 alpha=0.65)
    l, h = ax1_50.get_legend_handles_labels()
    labels = h[0:9]
    ax1_50.legend(
        handles=l[0:9],
        labels=labels,
        fontsize="8",
    )

    pt.RainCloud(x=x1,
                 y=y,
                 hue=hue2,
                 data=df2_50,
                 palette=pal,
                 bw=sigma,
                 width_viol=0.6,
                 ax=ax2_50,
                 orient=ort,
                 move=0.2,
                 pointplot=True,
                 alpha=0.65)
    l, h = ax2_50.get_legend_handles_labels()
    ax2_50.legend(handles=l[0:8], labels=h[0:8], fontsize="8")

    pt.RainCloud(x=x1,
                 y=y,
                 hue=hue3,
                 data=df3_50,
                 palette=pal,
                 bw=sigma,
                 width_viol=0.6,
                 ax=ax3_50,
                 orient=ort,
                 move=0.2,
                 pointplot=True,
                 alpha=0.65)
    l, h = ax3_50.get_legend_handles_labels()
    ax3_50.legend(handles=l[0:8], labels=h[0:8], fontsize="8")

    ax1.set_xlabel("")
    ax1.set_ylabel("Mean Accuracy")
    ax1.set_title("Number of segments")
    ax1_50.set_xlabel("Tasks", fontsize=16)
    ax1_50.set_ylabel("Mean Accuracy")
    ax1_50.xaxis.set_major_locator(ticker.MultipleLocator(10))
    ax1_50.xaxis.set_major_formatter(ticker.ScalarFormatter())
    ax2.set_title("Activation density")
    ax2.set_xlabel("")
    ax2.set_ylabel("")
    ax2_50.set_xlabel("Tasks", fontsize=16)
    ax2_50.set_ylabel("")
    ax2_50.xaxis.set_major_locator(ticker.MultipleLocator(10))
    ax2_50.xaxis.set_major_formatter(ticker.ScalarFormatter())
    ax3.set_xlabel("")
    ax3.set_ylabel("")
    ax3.set_title("FF weight density")
    ax3_50.set_xlabel("Tasks", fontsize=16)
    ax3_50.set_ylabel("")
    ax3_50.xaxis.set_major_locator(ticker.MultipleLocator(10))
    ax3_50.xaxis.set_major_formatter(ticker.ScalarFormatter())

    plt.figtext(-0.01, 0.7, "  10 TASKS", fontsize=14)
    plt.figtext(-0.01, 0.28, "  50 TASKS", fontsize=14)

    if savefigs:
        plt.savefig(f"{figs_dir}/hyperparameter_search_panel_along_tasks.png")
Esempio n. 26
0
def hyperparameter_search_panel():
    """
    Plots a 6 panels figure on 2 rows x 3 columns
    Rows contains figures representing hyperparameters search for 10 and 50
    permutedMNIST tasks resulting from hyperparameter_search.py config file.
    Columns 1 is the number of dendritic segments, columns 2 the activation
    sparsity and column 3 the weight sparsity.
    """

    df_path1 = f"{experiment_folder}segment_search_lasttask.csv"
    df1 = pd.read_csv(df_path1)

    df_path2 = f"{experiment_folder}kw_sparsity_search_lasttask.csv"
    df2 = pd.read_csv(df_path2)

    df_path3 = f"{experiment_folder}w_sparsity_search_lasttask.csv"
    df3 = pd.read_csv(df_path3)

    df_path1_50 = f"{experiment_folder}segment_search_50_lasttask.csv"
    df1_50 = pd.read_csv(df_path1_50)

    df_path2_50 = f"{experiment_folder}kw_sparsity_search_50_lasttask.csv"
    df2_50 = pd.read_csv(df_path2_50)

    df_path3_50 = f"{experiment_folder}w_sparsity_search_50_lasttask.csv"
    df3_50 = pd.read_csv(df_path3_50)

    relevant_columns = [
        "Activation sparsity", "FF weight sparsity", "Num segments", "Accuracy"
    ]

    df1 = df1[relevant_columns]
    df2 = df2[relevant_columns]
    df3 = df3[relevant_columns]
    df1_50 = df1_50[relevant_columns]
    df2_50 = df2_50[relevant_columns]
    df3_50 = df3_50[relevant_columns]

    # Figure 1 'Impact of the different hyperparameters on performance
    # full cross product of hyperparameters
    gs = gridspec.GridSpec(2, 3)
    fig = plt.figure(figsize=(14, 10))

    ax1 = fig.add_subplot(gs[0, 0])
    ax2 = fig.add_subplot(gs[0, 1])
    ax3 = fig.add_subplot(gs[0, 2])
    ax1_50 = fig.add_subplot(gs[1, 0])
    ax2_50 = fig.add_subplot(gs[1, 1])
    ax3_50 = fig.add_subplot(gs[1, 2])

    x1 = "Num segments"
    x2 = "Activation sparsity"
    x3 = "FF weight sparsity"

    y = "Accuracy"
    ort = "v"
    pal = sns.color_palette(n_colors=6)
    sigma = 0.2
    fig.suptitle("Impact of the different hyperparameters on performance",
                 fontsize=12)

    pt.RainCloud(x=x1,
                 y=y,
                 data=df1,
                 palette=pal,
                 bw=sigma,
                 width_viol=0.6,
                 ax=ax1,
                 orient=ort,
                 move=0.2,
                 pointplot=True,
                 alpha=0.65)
    pt.RainCloud(x=x1,
                 y=y,
                 data=df1_50,
                 palette=pal,
                 bw=sigma,
                 width_viol=0.6,
                 ax=ax1_50,
                 orient=ort,
                 move=0.2,
                 pointplot=True,
                 alpha=0.65)
    pt.RainCloud(x=x2,
                 y=y,
                 data=df2,
                 palette=pal,
                 bw=sigma,
                 width_viol=0.6,
                 ax=ax2,
                 orient=ort,
                 move=0.2,
                 pointplot=True,
                 alpha=0.65)
    pt.RainCloud(x=x2,
                 y=y,
                 data=df2_50,
                 palette=pal,
                 bw=sigma,
                 width_viol=0.6,
                 ax=ax2_50,
                 orient=ort,
                 move=0.2,
                 pointplot=True,
                 alpha=0.65)
    pt.RainCloud(x=x3,
                 y=y,
                 data=df3,
                 palette=pal,
                 bw=sigma,
                 width_viol=0.6,
                 ax=ax3,
                 orient=ort,
                 move=0.2,
                 pointplot=True,
                 alpha=0.65)
    pt.RainCloud(x=x3,
                 y=y,
                 data=df3_50,
                 palette=pal,
                 bw=sigma,
                 width_viol=0.6,
                 ax=ax3_50,
                 orient=ort,
                 move=0.2,
                 pointplot=True,
                 alpha=0.65)
    ax1.set_ylabel("Mean accuracy", fontsize=16)
    ax1.set_xlabel("Number of dendritic segments", fontsize=16)
    ax1_50.set_ylabel("Mean accuracy", fontsize=16)
    ax1_50.set_xlabel("Number of dendritic segments", fontsize=16)

    ax2.set(ylabel="")
    ax2.set_xlabel("Activation density", fontsize=16)

    ax2_50.set(ylabel="")
    ax2_50.set_xlabel("Activation density", fontsize=16)

    ax3.set(ylabel="")
    ax3.set_xlabel("FF Weight density", fontsize=16)
    ax3_50.set(ylabel="")
    ax3_50.set_xlabel("FF Weight density", fontsize=16)

    # Add 10 tasks and 50 tasks labels on the left
    plt.figtext(-0.02, 0.7, "10 TASKS", fontsize=16)
    plt.figtext(-0.02, 0.28, "50 TASKS", fontsize=16)

    fig.suptitle(
        """Impact of different hyperparameters on \n 10-tasks and 50-tasks
        permuted MNIST performance""",
        fontsize=16,
    )
    if savefigs:
        plt.savefig(f"{figs_dir}/hyperparameter_search_panel.png",
                    bbox_inches="tight")
Esempio n. 27
0
def cns_figure_1c():
    """
    CNS 2021 abstract figure 1C.
    """
    data_folder = "cns2021_figure1c_data/"
    savefigs = True

    df_path1 = f"{data_folder}nb_segment_search2.csv"
    df1 = pd.read_csv(df_path1)

    df_path1bis = f"{data_folder}nb_segment_search3.csv"
    df1bis = pd.read_csv(df_path1bis)

    df_path2 = f"{data_folder}kw_sparsity_search.csv"
    df2 = pd.read_csv(df_path2)

    relevant_columns = [
        "Activation sparsity", "FF weight sparsity", "Num segments", "Accuracy"
    ]

    df1 = df1[relevant_columns]
    df1bis = df1bis[relevant_columns]
    df2 = df2[relevant_columns]

    df1 = pd.concat([df1, df1bis])

    gs = gridspec.GridSpec(1, 2)
    fig = plt.figure(figsize=(10, 8))

    ax1 = fig.add_subplot(gs[:, 0])
    ax2 = fig.add_subplot(gs[:, 1])

    x1 = "Num segments"
    x2 = "Activation sparsity"

    y = "Accuracy"
    ort = "v"
    pal = "Set2"
    sigma = 0.2
    fig.suptitle(
        "Impact of the number of dendritic segments or the\n \
                 activation sparsity on 10-tasks permuted MNIST performance",
        fontsize=16,
    )

    pt.RainCloud(x=x1,
                 y=y,
                 data=df1,
                 palette=pal,
                 bw=sigma,
                 width_viol=0.6,
                 ax=ax1,
                 orient=ort,
                 move=0.2,
                 pointplot=True,
                 alpha=0.65)
    pt.RainCloud(x=x2,
                 y=y,
                 data=df2,
                 palette=pal,
                 bw=sigma,
                 width_viol=0.6,
                 ax=ax2,
                 orient=ort,
                 move=0.2,
                 pointplot=True,
                 alpha=0.65)
    ax1.set_ylim([0.9, 0.96])
    ax1.set_ylabel("Mean accuracy", fontsize=16)
    ax1.set_xlabel("Number of dendritic segments", fontsize=16)
    ax1.set_xticklabels(["2", "3", "5", "7", "10", "14", "20"], fontsize=14)
    ax1.set_yticklabels(
        ["0.90", "0.91", "0.92", "0.93", "0.94", "0.95", "0.96"], fontsize=14)
    ax2.set_ylim([0.60, 1])
    ax2.set_ylabel("")
    ax2.set_xticklabels(
        ["0.99", "0.95", "0.9", "0.8", "0.6", "0.4", "0.2", "0.1"],
        fontsize=14)
    ax2.set_yticklabels([
        "0.60", "0.65", "0.70", "0.75", "0.80", "0.85", "0.90", "0.95", "1.0"
    ],
                        fontsize=14)
    ax2.set_xlabel("Activation sparsity", fontsize=16)

    if savefigs:
        plt.savefig("cns2021_figure1c.png", bbox_inches="tight", dpi=1200)
Esempio n. 28
0
def dist_splits(key, data):
    data = data.assign(joiner=0)
    fig = plt.figure(figsize=[15, 5])
    gs = mpl.gridspec.GridSpec(2, 7, figure=fig)
    ax0 = fig.add_subplot(gs[:, 0:3])
    ax1 = fig.add_subplot(gs[:, 3:5])
    ax2 = fig.add_subplot(gs[0, 5:7])
    ax3 = fig.add_subplot(gs[1, 5:7])

    pt.RainCloud(x='strategy',
                 y=key,
                 data=data,
                 bw=.2,
                 width_viol=.6,
                 ax=ax0,
                 orient='v',
                 alpha=0.5,
                 palette='Set1',
                 hue='n_parties',
                 dodge=True)
    ax0.set_title('Split by n_parties')
    handles, labels = ax0.get_legend_handles_labels()
    ax0.legend().remove()
    fig.legend((handles[0], handles[1]), (labels[0], labels[1]),
               title='n_parties',
               loc=(0.9, 0.325))
    ax0.set_xlabel('')

    pt.RainCloud(x='n_parties',
                 y=key,
                 data=data,
                 bw=.2,
                 width_viol=.6,
                 ax=ax1,
                 orient='v',
                 alpha=0.5,
                 palette='Set2',
                 hue='strategy',
                 dodge=True)
    ax1.set_title('Split by strategy')
    ax1.axes.get_yaxis().set_visible(False)
    handles, labels = ax1.get_legend_handles_labels()
    ax1.legend().remove()
    fig.legend((handles[0], handles[1], handles[2]),
               (labels[0], labels[1], labels[2]),
               title='strategy',
               loc=(0.9, 0.71))
    ax1.set_xlabel('')

    pt.RainCloud(x='joiner',
                 y=key,
                 data=data,
                 bw=.2,
                 width_viol=.6,
                 ax=ax2,
                 orient='h',
                 alpha=0.5,
                 palette='Set2',
                 hue='strategy',
                 dodge=True)
    ax2.legend().remove()
    ax2.axes.get_yaxis().set_visible(False)
    ax2.axes.get_xaxis().set_visible(False)
    ax2.set_xlabel('')

    pt.RainCloud(x='joiner',
                 y=key,
                 data=data,
                 bw=.2,
                 width_viol=.6,
                 ax=ax3,
                 orient='h',
                 alpha=0.5,
                 palette='Set1',
                 hue='n_parties',
                 dodge=True)
    ax3.legend().remove()
    ax3.axes.get_yaxis().set_visible(False)
    ax3.set_xlabel('')

    fig.suptitle('{0} distributions'.format(key), fontsize=14)
    plt.subplots_adjust(wspace=0.08, hspace=0.08)
    return fig
Esempio n. 29
0
    '#FF9300', '#FF9300', '#FF9300', '#FF9C54', '#FF9C54', '#FFAA8A',
    '#FFAA8A', '#FFAA8A', '#FFBFBB', '#FFBFBB'
]

likableness_palette = [
    '#009FDA', '#009FDA', '#009FDA', '#418DD7', '#418DD7', '#6979CC',
    '#6979CC', '#6979CC', '#8862B6', '#8862B6'
]

dx = 'ROI'
dy = 'Classification accuracy'
ort = 'v'
pal = affect_palette
sigma = .2
#f, ax = plt.subplots(figsize=(5, 10))

ax = pt.RainCloud(x=dx,
                  y=dy,
                  data=clean_df,
                  palette=pal,
                  bw=sigma,
                  width_viol=0.7,
                  orient=ort,
                  move=.3,
                  alpha=.65)

ax.set(ylim=(0.40, 0.90))
# ax.set(ylim=(0.2, 0.6))
sns.despine()
plt.show()
Esempio n. 30
0
    print("{} Pearson R = ".format(region), pcorr)

    # create raincloud plots
    sns.set(style="ticks", context=("poster"), font_scale=1.25)
    fig, ax = plt.subplots()
    fig.set_size_inches(6, 10)
    dx = "Group"
    dy = region
    ort = "v"
    pal = "colorblind"
    sigma = .25
    ax = pt.RainCloud(x=dx,
                      y=dy,
                      data=df,
                      palette='colorblind',
                      width_viol=.5,
                      width_box=.25,
                      orient=ort,
                      move=.0,
                      bw=sigma,
                      showfliers=False)
    plt.title("{} Activity at Event Boundaries".format(region), y=1.02)
    plt.ylabel("% Signal Change\n(Boundary - Within-Event)")
    plt.xlabel("Group")
    sns.despine()
    plt.savefig(fig_dir + '{}_raincloud.pdf'.format(region),
                format='pdf',
                dpi=300,
                bbox_inches="tight")
    # run ANOVAs with posthoc Tukey HSD comparisons
    print("\n{} One-Way ANOVA:".format(region))
    mod = ols('{} ~ Group'.format(region), data=df).fit()