In [1]:
import matplotlib.pyplot as plt
%matplotlib inline

import seaborn as sns
sns.set_context('talk')

from matplotlib.ticker import FuncFormatter

In [2]:
labelsize = 15

In [3]:
def scientific_tex_formatter(x, pos):
    if x == 0.:
        return r'$0$'
    
    str_ = "%.1e" % x
    
    #str_ = str_.replace('1.0', '')
    str_ = str_.replace('e-0', '\,\,10^{-')
    str_ = str_.replace('e+0', '\,\,10^{')
    
    str_ = str_ + '}'
    str_ = r'$%s$' % str_
    
    return str_

f_scientific_tex_formatter = FuncFormatter(scientific_tex_formatter)

def scientific_tex_formatter2(x, pos):
    if x == 1.:
        return r'$1$'
    
    str_ = "%.1e" % x
    
    str_ = str_.replace('1.0', '')
    str_ = str_.replace('e-0', '\,\,10^{-')
    str_ = str_.replace('e+0', '\,\,10^{')
    
    str_ = str_ + '}'
    str_ = r'$%s$' % str_
    
    return str_

f_scientific_tex_formatter2 = FuncFormatter(scientific_tex_formatter2)

In [4]:
def tex_foramtter(x, pos):
    return r'$\rm{%s}$' % x

f_tex_foramtter = FuncFormatter(tex_foramtter)

def tex_transf(x):
    return r'$\rm{%s}$' % x

In [5]:
def tex_pct_formatter(x, pos):
    return r'$%.0f \%%$' % x

f_tex_pct_formatter = FuncFormatter(tex_pct_formatter)

In [6]:
import pandas as pd
import numpy as np

import os

In [7]:
dir_res_ = './results'

Loss $\ell_1$


In [8]:
l1_2 = pd.read_csv(os.path.join(dir_res_, 'l1_nu_eq_2.csv'), header=0, index_col=0)[r'$\nu = 2$ bounds']
l1_6 = pd.read_csv(os.path.join(dir_res_, 'l1_nu_eq_6.csv'), header=0, index_col=0)[r'$\nu = 6$ bounds']
l1_50 = pd.read_csv(os.path.join(dir_res_, 'l1_nu_eq_50.csv'), header=0, index_col=0)[r'$\nu = 50$ bounds']

In [9]:
l1 = pd.DataFrame()
l1[r'$\nu = 2$'] = l1_2
l1[r'$\nu = 6$'] = l1_6
l1[r'$\nu = 50$'] = l1_50

In [10]:
l1_weights = l1

for col in l1_weights.columns:
    l1_weights[col] = l1_weights[col] / l1_weights[col].sum() * 100.

l1_weights.head()


Out[10]:
$\nu = 2$ $\nu = 6$ $\nu = 50$
PB1 0.003754 0.003747 0.003709
PB2 0.001058 0.001029 0.001020
PB3 0.007419 0.007165 0.007096
PB4 1.456499 1.421488 1.413740
PB5 3.155080 3.177689 3.217428

In [11]:
f, ax = plt.subplots()

l1_weights.sort_values(r'$\nu = 2$')[::-1].plot.bar(ax=ax)

labels = ['' for item in ax.get_xticklabels()]
ax.set_xticklabels(labels)

ax.yaxis.set_major_formatter(f_tex_pct_formatter)

plt.tick_params(axis='both', which='major', labelsize=labelsize)
plt.legend(fontsize=labelsize)

plt.show()



In [12]:
f, ax = plt.subplots()

l1_weights.sort_values(r'$\nu = 2$')[::-1][:10].plot.bar(ax=ax)

labels = [tex_transf(item.get_text()) for item in ax.get_xticklabels()]
ax.set_xticklabels(labels)

for label in ax.get_xticklabels():
    label.set_rotation(0) 

ax.yaxis.set_major_formatter(f_tex_pct_formatter)

plt.tick_params(axis='both', which='major', labelsize=labelsize)
plt.legend(fontsize=labelsize)

plt.show()



In [13]:
f, ax = plt.subplots()

l1_weights[r'$\nu = 6$'].sort_values()[::-1].plot.bar(ax=ax, logy=True)

labels = ['' for item in ax.get_xticklabels()]
ax.set_xticklabels(labels)

ax.yaxis.set_major_formatter(f_scientific_tex_formatter2)

plt.tick_params(axis='both', which='major', labelsize=labelsize)
plt.legend(fontsize=labelsize)

plt.show()



In [22]:
f, ax = plt.subplots()

l1_weights[r'$\nu = 6$'].sort_values()[::-1][:12].plot.bar(ax=ax)

labels = [tex_transf(item.get_text()) for item in ax.get_xticklabels()]
ax.set_xticklabels(labels)

for label in ax.get_xticklabels():
    label.set_rotation(0) 

ax.yaxis.set_major_formatter(f_tex_pct_formatter)

plt.tick_params(axis='both', which='major', labelsize=labelsize)
plt.legend(fontsize=labelsize)

plt.show()


Loss $\ell_3$


In [15]:
l3_2 = pd.read_csv(os.path.join(dir_res_, 'l3_nu_eq_2.csv'), header=0, index_col=0)[r'$\nu = 2$ bounds']
l3_6 = pd.read_csv(os.path.join(dir_res_, 'l3_nu_eq_6.csv'), header=0, index_col=0)[r'$\nu = 6$ bounds']
l3_50 = pd.read_csv(os.path.join(dir_res_, 'l3_nu_eq_50.csv'), header=0, index_col=0)[r'$\nu = 50$ bounds']

In [16]:
l3 = pd.DataFrame()
l3[r'$\nu = 2$'] = l3_2
l3[r'$\nu = 6$'] = l3_6
l3[r'$\nu = 50$'] = l3_50

In [17]:
l3_weights = l3

for col in l3_weights.columns:
    l3_weights[col] = l3_weights[col] / l3_weights[col].sum() * 100.

l3_weights.head()


Out[17]:
$\nu = 2$ $\nu = 6$ $\nu = 50$
PB1 0.004589 0.004562 0.004513
PB2 0.002125 0.002084 0.002068
PB3 0.006878 0.006599 0.006478
PB4 1.339278 1.304330 1.299244
PB5 2.981591 2.987940 3.023878

In [18]:
f, ax = plt.subplots()

l3_weights.sort_values(r'$\nu = 2$')[::-1].plot.bar(ax=ax)

labels = ['' for item in ax.get_xticklabels()]
ax.set_xticklabels(labels)

ax.yaxis.set_major_formatter(f_tex_pct_formatter)

plt.tick_params(axis='both', which='major', labelsize=labelsize)
plt.legend(fontsize=labelsize)

plt.show()



In [19]:
f, ax = plt.subplots()

l3_weights.sort_values(r'$\nu = 2$')[::-1][:10].plot.bar(ax=ax)

labels = [tex_transf(item.get_text()) for item in ax.get_xticklabels()]
ax.set_xticklabels(labels)

for label in ax.get_xticklabels():
    label.set_rotation(0) 

ax.yaxis.set_major_formatter(f_tex_pct_formatter)

plt.tick_params(axis='both', which='major', labelsize=labelsize)
plt.legend(fontsize=labelsize)

plt.show()