//  [python]
def compare_sparsity(df_all, df_iid, df_ood, args):

    values = df_all.sparsity.unique()

    stack_iid = list()
    stack_ood = list()
    for val in values:
        df_all_setting, df_iid_setting, df_ood_setting = extract_setting(df_all, df_iid, df_ood,
            args.bbox, args.ood, args.model, args.critic_action, args.critic_state, 
            args.finetune, args.translation, args.mask, args.amin, val)
        stack_iid.append(df_iid_setting[['epoch', 'iid', 'sparsity', 'seed']])
        stack_ood.append(df_ood_setting[['epoch', 'ood', 'sparsity', 'seed']])
    df_iid_setting = pd.concat(stack_iid)
    df_ood_setting = pd.concat(stack_ood)

    # stats
    pd.options.display.float_format = '{:,.3f}'.format
    print('--- avg ---')
    print(df_iid_setting.groupby('sparsity').mean())
    print(df_ood_setting.groupby('sparsity').mean())
    print('--- std ---')
    print(df_iid_setting.groupby('sparsity').std())
    print(df_ood_setting.groupby('sparsity').std())

    plt.figure(figsize=(4,3))

    # sparsity impact
    ax = sns.pointplot(x=df_iid_setting.groupby('sparsity').mean().index, y=df_iid_setting.groupby('sparsity').mean().iid)
    ax.set_xlabel('$\lambda_s$')
    ax.set_ylabel('accuracy')
    ax.set_xscale('log')
    plt.savefig(args.foldername+'/summary_iid_sparsity.png', bbox_inches='tight')

    plt.clf()

    ax = sns.pointplot(x=df_ood_setting.groupby('sparsity').mean().index, y=df_ood_setting.groupby('sparsity').mean().ood)
    ax.set_xlabel('$\lambda_s$')
    ax.set_ylabel('accuracy')
    ax.set_xscale('log')
    plt.savefig(args.foldername+'/summary_ood_sparsity.png', bbox_inches='tight')

    plt.clf()

    df_ood_group = df_ood_setting.groupby('sparsity').mean()
    best_sparsity = df_ood_group.index[df_ood_group.ood.argmax()]
    print('optimal sparsity:', best_sparsity)

    # fig
    df_comp = pd.DataFrame({'vanilla': df_iid_setting[df_iid_setting['sparsity']==0.0].iid.to_numpy(), 
                            'sparse': df_iid_setting[df_iid_setting['sparsity']==best_sparsity].iid.to_numpy()})
    print(df_comp)
    vmin = 0.9
    vmax = 1.0
    vbin = 0.025
    vtick = np.linspace(vmin, vmax, round((vmax-vmin)/vbin)+1)
    ax = sns.scatterplot(data=df_comp, x='vanilla', y='sparse')
    ax.set_aspect('equal')
    ax.set_xlim([vmin, vmax])
    ax.set_ylim([vmin, vmax])
    ax.plot([vmin, vmax], [vmin, vmax], '-r')
    ax.set_xticks(vtick)
    ax.set_yticks(vtick)
    plt.savefig(args.foldername+'/compare_iid_sparsity.png', bbox_inches='tight')

    plt.clf()

    df_comp = pd.DataFrame({'vanilla': df_ood_setting[df_ood_setting['sparsity']==0.0].ood.to_numpy(), 
                            'sparse': df_ood_setting[df_ood_setting['sparsity']==best_sparsity].ood.to_numpy()})
    print(df_comp)
    vmin = 0.0
    vmax = 1.0
    # vmin = 0.3
    # vmax = 0.7
    vbin = 0.1
    vtick = np.linspace(vmin, vmax, round((vmax-vmin)/vbin)+1)
    ax = sns.scatterplot(data=df_comp, x='vanilla', y='sparse')
    ax.set_aspect('equal')
    ax.set_xlim([vmin, vmax])
    ax.set_ylim([vmin, vmax])
    ax.plot([vmin, vmax], [vmin, vmax], '-r')
    ax.set_xticks(vtick)
    ax.set_yticks(vtick)
    plt.savefig(args.foldername+'/compare_ood_sparsity.png', bbox_inches='tight')