In [ ]:
import sys, os
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
import pandas as pd
import seaborn as sns
import itertools as itt
from ipywidgets import widgets
import ConfigReader as cr

In [ ]:
#Styles
sns.set_style('whitegrid', {'axes.linewidth':1.25, 'axes.edgecolor':'0.15',
                            'grid.linewidth':1.5, 'grid.color':'gray'})
sns.set_color_codes()

In [ ]:
plt.rcParams['figure.figsize'] = (12.0, 9.0)

plt.rc('text', usetex=False)
plt.rc('font', size=20.0, family='serif')

In [ ]:
datasets =["1049", "1111", "1120", "1128", "179", "184", "293", "389", "38", "46", "554", "772", "917"]

In [ ]:
dataset = '38_bac'
experiments = ['ROAR']
preprocessor='DeepNetIterative'

In [ ]:
base_data_dir = '/mhome/mendozah/autonet_ROAR/results/fanova_merged_smac/'

In [ ]:
datasets_dirs = list(map(lambda X: X + '_bac', datasets))

Parameter importance evaluation


In [ ]:
import pyfanova.fanova

In [ ]:
state_run_dir = os.path.join(base_data_dir, dataset)

In [ ]:
fanova_set = pyfanova.fanova.Fanova(state_run_dir)

In [ ]:
max_marginals = 7
cols_imp_df = ['marginal', 'parameter']

In [ ]:
temp_df = pd.DataFrame(fanova_set.print_all_marginals(max_num=max_marginals, pairwise=True), columns=cols_imp_df)

In [ ]:
flatex = '%d_marginals_table_for_%s.tex' % (max_marginals, dataset)

In [ ]:
pd.set_option('display.max_colwidth', -1)
print(temp_df.to_latex())
pd.set_option('display.max_colwidth', 51)

In [ ]:
# From my opinion very sloppy way to do it
clear_name = lambda X: X.split(':')[-1] if X.split(':')[0] == 'classifier' else X.split(':')[0]

In [ ]:
for g in temp_df.parameter:
    print("ECA %s" % map(lambda X: X.split(':')[-1] if X.split(':')[0] == 'classifier' else X.split(':')[0], g))

Plot the marginals.


In [ ]:
import pyfanova.visualizer

In [ ]:
reload(pyfanova.visualizer)

In [ ]:
viz_set = pyfanova.visualizer.Visualizer(fanova_set)

In [ ]:
plt.rcdefaults()

In [ ]:
viz_set = pyfanova.visualizer.Visualizer(fanova_set)
categorical_params = fanova_set.get_config_space().get_categorical_parameters()
for p in temp_df.parameter:
    fig_hyper, ax_hyper = plt.subplots(1,1)
    print p
    if len(p) == 1:
        label = clear_name(p[0])
        if p[0] not in categorical_params:
            viz_set.plot_marginal(p[0], ax=ax_hyper)
        else:
            viz_set.plot_categorical_marginal(p[0], ax=ax_hyper)
        ax_hyper.set_xlabel(label)
    else:
        if(p[0] in categorical_params) and (p[1] not in categorical_params):
            viz_set.plot_categorical_pairwise(p[0], p[1], ax=ax_hyper)
            ax_hyper.set_xlabel(clear_name(p[1]))
        elif (p[0] not in categorical_params) and (p[1] not in categorical_params):
            viz_set.plot_contour_pairwise(p[0],p[1], ax=ax_hyper)
    fig_hyper.show()