<jupyter_start><jupyter_text>Generating Plots for the Paper<jupyter_code>import pandas as pd
import numpy as np
from matplotlib import pyplot as plt
import os

plt.style.use(['classic', 'ggplot'])
kwargs = {
    'sym' : '',
    'whis' : [5,95]
}

figures_dir = './'

labels = ['Edit', 'Resistance', 'DeltaCon', 'NetSimile', '$\lambda^\mathbf{A}$',
          '$\lambda^\mathbf{L}$', '$\lambda^\mathbf{\cal L}$']

k_list = [1,2,10,100,300,999]

SIZE = 14
def plot(path,title='',save=False,filename=None):
    """Plots data contained in data dictionary, for matrix and spectral distances.
    
    If save = True, then a filename must be provided
    
    Data unpacking is based on particular data format, see scripts in data_scripts 
    directory for examples.
    """

    data_dict = pd.read_pickle(path)

    adj_null = data_dict['results_df_null']['Adjacency Distances'].T
    adj_not = data_dict['results_df_not_null']['Adjacency Distances'].T

    for item in [adj_null,adj_not]:
        item.index = range(item.shape[0])

    adj_scaled = (adj_not - adj_null.mean())/adj_null.std()

    plt.figure(figsize=(6,4))
    adj_scaled.boxplot(**kwargs);
    plt.ylabel('Scaled Distance $\widehat{D}_1$',color='k',size=SIZE);
    plt.yticks(color='k');
    plt.xticks(range(1,len(labels)+1),labels,rotation=90,color='k',size=SIZE);
    plt.title(title,size=SIZE);

    if save:
        fig = plt.gcf();
        fig.savefig(os.path.join(figures_dir,filename),dpi=300,bbox_inches='tight');

def plot_lambda_k(path,k_list,title='',scale=1,shift=-0.07,figsize=(6,4),
                  save=False,filename=None,y_lim=None):

    data_dict = pd.read_pickle(path)

    adj_null = data_dict['results_df_null']['Adjacency Distances'].T
    adj_not = data_dict['results_df_not_null']['Adjacency Distances'].T

    for item in [adj_null,adj_not]:
        item.index = range(item.shape[0])

    adj_scaled = (adj_not - adj_null.mean())/adj_null.std()

    N = len(adj_scaled.columns)

    indices = list(range(0,N,3)) + list(range(1,N,3)) + list(range(2,N,3))
    adj_scaled = adj_scaled.iloc[:,indices]

    # we don't need k = 1 for Laplacian distances
    del adj_scaled['Lambda (Laplacian, k=1)']
    del adj_scaled['Lambda (Normalized Laplacian, k=1)']

    m = len(k_list)

    # we don't need k = 1 for Laplacian distances
    num_labels = k_list + k_list[1:] * 2

    plt.figure(figsize=figsize);
    adj_scaled.boxplot(**kwargs);
    plt.ylabel('Scaled Distance $\widehat{D}_1$',color='k',size=SIZE);
    plt.xlabel('Number of Eigenvalues $k$',color='k',size=SIZE)
    plt.xticks(range(1,len(num_labels)+1),num_labels,color='k');
    plt.yticks(color='k')
    plt.title(title,size=SIZE);
    plt.axvline(m + 0.5);
    plt.axvline(2*m - 0.5);

    axes = plt.gca()
    y_min,y_max = axes.get_ylim()
    scale = 1.1
    y_max = y_max*scale
    if y_lim is not None:
        y_min,y_max = y_lim
    y_ran = y_max - y_min
    shift = -0.1
    plt.ylim([y_min,y_max])

    plt.text(m/2 + 1, y_max + shift*y_ran, '$\lambda^\mathbf{A}$', horizontalalignment='center',size=SIZE+2)
    plt.text(3/2*m, y_max + shift*y_ran, '$\lambda^\mathbf{L}$', horizontalalignment='center',size=SIZE+2)
    plt.text(5/2*m - 1, y_max + shift*y_ran, '$\lambda^\mathbf{\cal{L}}$', horizontalalignment='center',size=SIZE+2)

    if save:
        fig = plt.gcf();
        fig.savefig(os.path.join(figures_dir,filename),dpi=300,bbox_inches='tight');<jupyter_output><empty_output><jupyter_text>Stochastic Blockmodel<jupyter_code>plot('pickled_data/SBM_vs_uncorr.p',title = 'Stochastic Blockmodel',save = True,filename = 'sbm.pdf')<jupyter_output><empty_output><jupyter_text>SBM 2-community<jupyter_code>path = 'pickled_data/SBM_vs_uncorr_lambda_k_l2.p'
title = 'Stochastic Blockmodel $\lambda_k$ Distances'
filename = 'sbm_k.pdf'

plot_lambda_k(path,k_list,title=title,scale=1.1,save=True,filename=filename, figsize=(10,4))<jupyter_output><empty_output><jupyter_text>Preferential Attachment<jupyter_code>plot('pickled_data/PA_vs_uncorr.p',
     title = 'Preferential Attachment',
     save = True,
     filename = 'pref_att.pdf')
path = 'pickled_data/PA_vs_uncorr_lambdak.p'
title = 'Preferential Attachment $\lambda_k$ Distances'
filename = 'pref_att_k.pdf'
figsize = [10,4]

plot_lambda_k(path,k_list,title=title,scale=1.1,save=True,filename=filename,
             figsize=figsize)<jupyter_output><empty_output><jupyter_text>Pref Attachment vs Random Degree Distribution<jupyter_code>plot('pickled_data/PA_vs_randDS.p',
     title = 'Pref. Att. vs. RDS',
     save = True,
     filename = 'degmatched_pa.pdf')<jupyter_output><empty_output><jupyter_text>Small World<jupyter_code>plot('pickled_data/watts_vs_uncorr.p',
     title = 'Watts-Strogatz',
     save = True,
     filename = 'small_world.pdf')
path = 'pickled_data/watts_vs_uncorr_lambda_k.p'
title = 'Watts-Strogatz $\lambda_k$ Distances'
filename = 'small_world_k.pdf'
figsize = [10,4]

plot_lambda_k(path,k_list,title=title,scale=1.1,save=True,filename=filename,
             figsize=figsize)<jupyter_output><empty_output><jupyter_text>Lattics vs Random Degree-Distr Graph<jupyter_code>plot('pickled_data/lattice_vs_randDS_100x10.p',
     title = '100x10 Lattice Graph',
     save = True,
     filename = 'lattice.pdf')
path = 'pickled_data/lattice_vs_randDS_lambda_k_100x10.p'
title = '100x10 Lattice $\lambda_k$ Distances'
filename = 'lattice_k.pdf'

plot_lambda_k(path,k_list,title=title,figsize=(10,4),save=True,filename=filename)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15568099053168244, 'fraction_numerical': 0.02057538237436271, 'mean_word_length': 4.769957983193278, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '244444', 'license': 'MIT', 'n_tokens_mistral': 2203, 'n_tokens_neox': 2093, 'n_words': 317, 'path': 'random_graph_ensembles.ipynb', 'repo_name': 'peterewills/graph_metrics_paper_code', 'size': '5492'}