epidemioptim/analysis/plots.py
def beta_plot(folder):
    """
    Custom plotting function to plot the evolution of the two costs as a function of the mixing parameter beta.

    Parameters
    ----------
    folder:  str
        Directory of the algorithm (full of directories, one for each run).

    """
    all_data = dict()
    goals = []
    list_folds = sorted(os.listdir(folder))
    for f in list_folds:
        if 'res' not in f:
            with open(folder + f + '/res_eval.pk', 'rb') as f:
                data = pickle.load(f)
            if 'G_all' in data.keys():
                for g, f, f_std in zip(data['G_all'], data['F_all'], data['F_std_all']):
                    g = np.atleast_1d(g)
                    if str(g) not in all_data.keys():
                        all_data[str(g)] = dict(F_all=[],
                                                F_std_all=[])
                        goals.append(g)
                    all_data[str(g)]['F_all'].append(f)
                    all_data[str(g)]['F_std_all'].append(f_std)

    if len(goals) > 0:
        ind = np.argsort(np.array(goals)[:, 0])
        goals = np.array(goals)[ind]
        beta_y = goals[:, 0]
        keys = [str(g) for g in goals]
        data = np.swapaxes(np.array([all_data[k]['F_all'] / np.array([XLIM[1], 110]) for k in keys]), axis1=0, axis2=1)
        central = LINE(data)
        errors = ERR_MIN(data), ERR_MAX(data)
        artists, ax = setup_figure(r"$\beta$", 'costs (% max)', xlim=[0, 1], ylim=[0, 1], figsize=(15, 10))
        nb_costs = central.shape[1]
        for i_c in range(nb_costs):
            c = colors[i_c]
            plt.plot(beta_y, central[:, i_c], c=c, linewidth=8)
            plt.fill_between(beta_y, errors[0][:, i_c], errors[1][:, i_c], color=c, alpha=ALPHA)
        leg = plt.legend(COST_LABELS2,
                         loc='upper center',
                         bbox_to_anchor=(0.5, 1.08),
                         ncol=2,
                         fancybox=True,
                         shadow=True,
                         prop={'size': 32, 'weight': 'bold'},
                         markerscale=1)
        artists += (leg,)
        save_fig(folder + 'res/beta_study.pdf', artists)

    Custom plotting function to plot the evolution of the two costs as a function of the mixing parameter beta.

    Parameters
    ----------
    folder:  str
        Directory of the algorithm (full of directories, one for each run).

    
Custom plotting function to plot the evolution of the two costs as a function of the mixing parameter beta.
Parameters

str
Directory of the algorithm (full of directories, one for each run).
Custom plotting function to plot the evolution of the two costs as a function of the mixing parameter beta . Parameters str Directory of the algorithm ( full of directories one for each run ) .
def beta_plot(folder):
    all_data = dict()
    goals = []
    list_folds = sorted(os.listdir(folder))
    for f in list_folds:
        if 'res' not in f:
            with open(folder + f + '/res_eval.pk', 'rb') as f:
                data = pickle.load(f)
            if 'G_all' in data.keys():
                for g, f, f_std in zip(data['G_all'], data['F_all'], data['F_std_all']):
                    g = np.atleast_1d(g)
                    if str(g) not in all_data.keys():
                        all_data[str(g)] = dict(F_all=[],
                                                F_std_all=[])
                        goals.append(g)
                    all_data[str(g)]['F_all'].append(f)
                    all_data[str(g)]['F_std_all'].append(f_std)
    if len(goals) > 0:
        ind = np.argsort(np.array(goals)[:, 0])
        goals = np.array(goals)[ind]
        beta_y = goals[:, 0]
        keys = [str(g) for g in goals]
        data = np.swapaxes(np.array([all_data[k]['F_all'] / np.array([XLIM[1], 110]) for k in keys]), axis1=0, axis2=1)
        central = LINE(data)
        errors = ERR_MIN(data), ERR_MAX(data)
        artists, ax = setup_figure(r"$\beta$", 'costs (% max)', xlim=[0, 1], ylim=[0, 1], figsize=(15, 10))
        nb_costs = central.shape[1]
        for i_c in range(nb_costs):
            c = colors[i_c]
            plt.plot(beta_y, central[:, i_c], c=c, linewidth=8)
            plt.fill_between(beta_y, errors[0][:, i_c], errors[1][:, i_c], color=c, alpha=ALPHA)
        leg = plt.legend(COST_LABELS2,
                         loc='upper center',
                         bbox_to_anchor=(0.5, 1.08),
                         ncol=2,
                         fancybox=True,
                         shadow=True,
                         prop={'size': 32, 'weight': 'bold'},
                         markerscale=1)
        artists += (leg,)
        save_fig(folder + 'res/beta_study.pdf', artists)
def beta_plot ( folder ) : all_data = dict ( ) goals = [ ] list_folds = sorted ( os . listdir ( folder ) ) for f in list_folds : if 'res' not in f : with open ( folder + f + '/res_eval.pk' , 'rb' ) as f : data = pickle . load ( f ) if 'G_all' in data . keys ( ) : for g , f , f_std in zip ( data [ 'G_all' ] , data [ 'F_all' ] , data [ 'F_std_all' ] ) : g = np . atleast_1d ( g ) if str ( g ) not in all_data . keys ( ) : all_data [ str ( g ) ] = dict ( F_all = [ ] , F_std_all = [ ] ) goals . append ( g ) all_data [ str ( g ) ] [ 'F_all' ] . append ( f ) all_data [ str ( g ) ] [ 'F_std_all' ] . append ( f_std ) if len ( goals ) > 0 : ind = np . argsort ( np . array ( goals ) [ : , 0 ] ) goals = np . array ( goals ) [ ind ] beta_y = goals [ : , 0 ] keys = [ str ( g ) for g in goals ] data = np . swapaxes ( np . array ( [ all_data [ k ] [ 'F_all' ] / np . array ( [ XLIM [ 1 ] , 110 ] ) for k in keys ] ) , axis1 = 0 , axis2 = 1 ) central = LINE ( data ) errors = ERR_MIN ( data ) , ERR_MAX ( data ) artists , ax = setup_figure ( r"$\beta$" , 'costs (% max)' , xlim = [ 0 , 1 ] , ylim = [ 0 , 1 ] , figsize = ( 15 , 10 ) ) nb_costs = central . shape [ 1 ] for i_c in range ( nb_costs ) : c = colors [ i_c ] plt . plot ( beta_y , central [ : , i_c ] , c = c , linewidth = 8 ) plt . fill_between ( beta_y , errors [ 0 ] [ : , i_c ] , errors [ 1 ] [ : , i_c ] , color = c , alpha = ALPHA ) leg = plt . legend ( COST_LABELS2 , loc = 'upper center' , bbox_to_anchor = ( 0.5 , 1.08 ) , ncol = 2 , fancybox = True , shadow = True , prop = { 'size' : 32 , 'weight' : 'bold' } , markerscale = 1 ) artists += ( leg , ) save_fig ( folder + 'res/beta_study.pdf' , artists )
Custom plotting function to plot the evolution of the two costs as a function of the mixing parameter beta.
Custom plotting function to plot the evolution of the two costs as a function of the mixing parameter beta .
"""
    Custom plotting function to plot the evolution of the two costs as a function of the mixing parameter beta.

    Parameters
    ----------
    folder:  str
        Directory of the algorithm (full of directories, one for each run).

    """
folder