# Path: experiments/exp_setup.py
# SDCIT_RESULT_DIR = SDCIT_WORKING_DIR + '/results'
# 
# SDCIT_FIGURE_DIR = SDCIT_WORKING_DIR + '/figures'
# 
# Path: sdcit/utils.py
# def AUPC(p_values: Union[List, np.ndarray]) -> float:
#     """Area Under Power Curve"""
#     p_values = np.array(p_values)
# 
#     # CDF of p-values
#     xys = [(uniq_v, np.mean(p_values <= uniq_v)) for uniq_v in np.unique(p_values)]
# 
#     area, prev_x, prev_y = 0, 0, 0
#     for x, y in xys:
#         area += (x - prev_x) * prev_y
#         prev_x, prev_y = x, y
# 
#     area += (1 - prev_x) * prev_y
#     return area


import collections
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import scipy
import scipy.stats
import seaborn as sns
from os.path import exists
from experiments.exp_setup import SDCIT_RESULT_DIR, SDCIT_FIGURE_DIR
from sdcit.utils import AUPC
                D, _ = scipy.stats.kstest(gdf[pvalue_column[algo]], 'uniform')
                calib_data.append([algo, float(k[1]), int(k[2]), D])

    print(draw_calib_chaotic.__name__)
    [print(xx) for xx in calib_data]

    df = pd.DataFrame(calib_data, columns=['algo', 'gamma', 'N', 'D'])
    df['gamma'] = df['gamma'].astype(float)
    df['N'] = df['N'].map(int)
    df['D'] = df['D'].astype(float)
    sns_setting()
    for k, gdf in df.groupby(['algo', 'N']):
        if k[1] == 400:
            plt.plot(gdf['gamma'], gdf['D'], markers[(k[0])], c=color_palettes[method_color_codes[k[0]]] if k[1] == 400 else color_palettes[-0 + method_color_codes[k[0]]],
                     ls='-' if k[1] == 400 else ':', label=algo_name(str(k[0])))
        else:
            plt.plot(gdf['gamma'], gdf['D'], markers[(k[0])], c=color_palettes[method_color_codes[k[0]]] if k[1] == 400 else color_palettes[-0 + method_color_codes[k[0]]],
                     ls='-' if k[1] == 400 else ':', label='_nolegend_')
    handles, labels = plt.axes().get_legend_handles_labels()
    plt.axes().legend(handles[::-1], labels[::-1], ncol=2)
    plt.axes().set_xlabel(r'$\gamma$')
    plt.axes().set_ylabel('KS test statistic')
    plt.axes().set_ylim([0.0, 0.5])
    plt.axes().invert_yaxis()
    plt.axes().set_yticks([0.0, 0.1, 0.2, 0.3, 0.4, 0.5])

    handles, labels = plt.axes().get_legend_handles_labels()
    # plt.axes().legend(handles[::-1], labels[::-1])

    sns.despine()

# Path: experiments/exp_setup.py
# SDCIT_RESULT_DIR = SDCIT_WORKING_DIR + '/results'
# 
# SDCIT_FIGURE_DIR = SDCIT_WORKING_DIR + '/figures'
# 
# Path: sdcit/utils.py
# def AUPC(p_values: Union[List, np.ndarray]) -> float:
#     """Area Under Power Curve"""
#     p_values = np.array(p_values)
# 
#     # CDF of p-values
#     xys = [(uniq_v, np.mean(p_values <= uniq_v)) for uniq_v in np.unique(p_values)]
# 
#     area, prev_x, prev_y = 0, 0, 0
#     for x, y in xys:
#         area += (x - prev_x) * prev_y
#         prev_x, prev_y = x, y
# 
#     area += (1 - prev_x) * prev_y
#     return area


# Path: experiments/draw_figures.py
import collections
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import scipy
import scipy.stats
import seaborn as sns
from os.path import exists
from experiments.exp_setup import SDCIT_RESULT_DIR, SDCIT_FIGURE_DIR
from sdcit.utils import AUPC

                D, _ = scipy.stats.kstest(gdf[pvalue_column[algo]], 'uniform')
                calib_data.append([algo, float(k[1]), int(k[2]), D])

    print(draw_calib_chaotic.__name__)
    [print(xx) for xx in calib_data]

    df = pd.DataFrame(calib_data, columns=['algo', 'gamma', 'N', 'D'])
    df['gamma'] = df['gamma'].astype(float)
    df['N'] = df['N'].map(int)
    df['D'] = df['D'].astype(float)
    sns_setting()
    for k, gdf in df.groupby(['algo', 'N']):
        if k[1] == 400:
            plt.plot(gdf['gamma'], gdf['D'], markers[(k[0])], c=color_palettes[method_color_codes[k[0]]] if k[1] == 400 else color_palettes[-0 + method_color_codes[k[0]]],
                     ls='-' if k[1] == 400 else ':', label=algo_name(str(k[0])))
        else:
            plt.plot(gdf['gamma'], gdf['D'], markers[(k[0])], c=color_palettes[method_color_codes[k[0]]] if k[1] == 400 else color_palettes[-0 + method_color_codes[k[0]]],
                     ls='-' if k[1] == 400 else ':', label='_nolegend_')
    handles, labels = plt.axes().get_legend_handles_labels()
    plt.axes().legend(handles[::-1], labels[::-1], ncol=2)
    plt.axes().set_xlabel(r'$\gamma$')
    plt.axes().set_ylabel('KS test statistic')
    plt.axes().set_ylim([0.0, 0.5])
    plt.axes().invert_yaxis()
    plt.axes().set_yticks([0.0, 0.1, 0.2, 0.3, 0.4, 0.5])

    handles, labels = plt.axes().get_legend_handles_labels()
    # plt.axes().legend(handles[::-1], labels[::-1])

    sns.despine()

    plt.savefig(SDCIT_FIGURE_DIR + '/chaotic_calib.pdf', transparent=True, bbox_inches='tight', pad_inches=0.02)