<jupyter_start><jupyter_text>Last modified: 1/27/2018 SummaryAll related code/figures for oSBM. Code organization assumes working directory is notebook folder location.<jupyter_code>import sys
print(sys.version)

from __future__ import division
import os
#import igraph
import numpy as np
import pandas as pd
from matplotlib.backends.backend_pdf import PdfPages
from scipy.stats.kde import gaussian_kde
from matplotlib.ticker import FixedLocator,LinearLocator,MultipleLocator, FormatStrFormatter
from mpl_toolkits.axes_grid1 import Grid

# relevant python libraries
execfile('../functions/python_libraries.py')

# oSBM code
execfile('../functions/create_oSBM_class_specific_alternative.py')

# compute homophily + monophily
execfile('../functions/compute_homophily.py')
execfile('../functions/compute_monophily.py')
execfile('../functions/SI_functions/LINK_finalized_coeff.py')

# code for attribute prediction
execfile('../functions/benchmark_classifier.py')
execfile('../functions/LINK.py')
execfile('../functions/majority_vote.py')
execfile('../functions/ZGL.py')<jupyter_output>2.7.12 |Anaconda 2.3.0 (x86_64)| (default, Jul  2 2016, 17:43:17) 
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)]<jupyter_text>create 4 graph instances: noB-noO, yesB-noO, noB-yesO, yesB-yesO<jupyter_code>disp_val = 0.004
(adj_noBnoO_osbm, y_noBnoO_osbm) =  create_affiliation_model_temp(84,
                                          lambda_block_parameter = 1,
                                          dispersion_parameter_vect = np.array([np.array([0, 0]),
                                            np.array([0, 0])]), 
                                          class_size_vect = np.array([1000,1000]))
( adj_yesBnoO_osbm, y_yesBnoO_osbm) = create_affiliation_model_temp(84,
                                          lambda_block_parameter =1.2,
                                          dispersion_parameter_vect = np.array([np.array([0, 0]),
                                            np.array([0, 0])]),
                                          class_size_vect = np.array([1000,1000]))
(adj_noByesO_osbm, y_noByesO_osbm) = create_affiliation_model_temp(84,
                                         lambda_block_parameter =1,
                                         dispersion_parameter_vect = np.array([np.array([disp_val, disp_val]),
                                            np.array([disp_val, disp_val])]),
                                         class_size_vect = np.array([1000,1000]))
(adj_yesByesO_osbm, y_yesByesO_osbm) = create_affiliation_model_temp(84,
                                           lambda_block_parameter =1.2,
                                           dispersion_parameter_vect = np.array([np.array([disp_val, disp_val]),
                                              np.array([disp_val, disp_val])]),
                                           class_size_vect = np.array([1000,1000]))
# create proportion F

# noB-noO
degree_noBnoO = np.sum(adj_noBnoO_osbm,1)
degree_F_noBnoO = adj_noBnoO_osbm * np.matrix((y_noBnoO_osbm==1)+0).T

prop_F_noBnoO = degree_F_noBnoO/degree_noBnoO

# noB-yesO
degree_noByesO = np.sum(adj_noByesO_osbm,1)
degree_F_noByesO = adj_noByesO_osbm * np.matrix((y_noByesO_osbm==1)+0).T

prop_F_noByesO = degree_F_noByesO/degree_noByesO

# yesB-noO
degree_yesBnoO = np.sum(adj_yesBnoO_osbm,1)
degree_F_yesBnoO = adj_yesBnoO_osbm * np.matrix((y_yesBnoO_osbm==1)+0).T

prop_F_yesBnoO = degree_F_yesBnoO/degree_yesBnoO


# yesB-yesO
degree_yesByesO = np.sum(adj_yesByesO_osbm,1)
degree_F_yesByesO = adj_yesByesO_osbm * np.matrix((y_yesByesO_osbm==1)+0).T

prop_F_yesByesO = degree_F_yesByesO/degree_yesByesO<jupyter_output><empty_output><jupyter_text>null distribution on oSBM and class preference distribution<jupyter_code>n_iter = 100000

## noBnoO
d_iF_noBnoO = map(np.int,np.array(degree_noBnoO[y_noBnoO_osbm==1].T)[0])
mc_F = []
for j in range(n_iter):
    mc_F.append( np.random.binomial(n=map(np.int,np.array(d_iF_noBnoO)), 
                                    p=np.mean(prop_F_noBnoO[y_noBnoO_osbm==1]))/d_iF_noBnoO)
mc_F_final_noBnoO = np.array(mc_F).flatten()

d_iM_noBnoO = map(np.int,np.array(degree_noBnoO[y_noBnoO_osbm==0].T)[0])
mc_M = []
for j in range(n_iter):
    mc_M.append( np.random.binomial(n=map(np.int,np.array(d_iM_noBnoO)), 
                                    p=np.mean(1-prop_F_noBnoO[y_noBnoO_osbm==0]))/d_iM_noBnoO)
mc_M_final_noBnoO = np.array(mc_M).flatten()
## yesBnoO
d_iF_yesBnoO = map(np.int,np.array(degree_yesBnoO[y_yesBnoO_osbm==1].T)[0])
mc_F = []
for j in range(n_iter):
    mc_F.append( np.random.binomial(n=map(np.int,np.array(d_iF_yesBnoO)),
                                    p=np.mean(prop_F_yesBnoO[y_yesBnoO_osbm==1]))/d_iF_yesBnoO)
mc_F_final_yesBnoO = np.array(mc_F).flatten()

d_iM_yesBnoO = map(np.int,np.array(degree_yesBnoO[y_yesBnoO_osbm==0].T)[0])
mc_M = []
for j in range(n_iter):
    mc_M.append( np.random.binomial(n=map(np.int,np.array(d_iM_yesBnoO)), 
                                    p=np.mean(1-prop_F_yesBnoO[y_yesBnoO_osbm==0]))/d_iM_yesBnoO)
mc_M_final_yesBnoO = np.array(mc_M).flatten()
## noByesO
d_iF_noByesO = map(np.int,np.array(degree_noByesO[y_noByesO_osbm==1].T)[0])
mc_F = []
for j in range(n_iter):
    mc_F.append( np.random.binomial(n=map(np.int,np.array(d_iF_noByesO)),
                                    p=np.mean(prop_F_noByesO[y_noByesO_osbm==1]))/d_iF_noByesO)
mc_F_final_noByesO = np.array(mc_F).flatten()

d_iM_noByesO = map(np.int,np.array(degree_noByesO[y_noByesO_osbm==0].T)[0])
mc_M = []
for j in range(n_iter):
    mc_M.append( np.random.binomial(n=map(np.int,np.array(d_iM_noByesO)),
                                    p=np.mean(1-prop_F_noByesO[y_noByesO_osbm==0]))/d_iM_noByesO)
mc_M_final_noByesO = np.array(mc_M).flatten()
## yesByesO
d_iF_yesByesO = map(np.int,np.array(degree_yesByesO[y_yesByesO_osbm==1].T)[0])
mc_F = []
for j in range(n_iter):
    mc_F.append( np.random.binomial(n=map(np.int,np.array(d_iF_yesByesO)), 
                                    p=np.mean(prop_F_yesByesO[y_yesByesO_osbm==1]))/d_iF_yesByesO)
mc_F_final_yesByesO = np.array(mc_F).flatten()

d_iM_yesByesO = map(np.int,np.array(degree_yesByesO[y_yesByesO_osbm==0].T)[0])
mc_M = []
for j in range(n_iter):
    mc_M.append( np.random.binomial(n=map(np.int,np.array(d_iM_yesByesO)), 
                                    p=np.mean(1-prop_F_yesByesO[y_yesByesO_osbm==0]))/d_iM_yesByesO)
mc_M_final_yesByesO = np.array(mc_M).flatten()<jupyter_output><empty_output><jupyter_text>oSBM Main Paper Figure -- overdispersion versus bias<jupyter_code>%matplotlib inline

alpha_parameter = 0.25
fig = plt.figure()
binBoundaries = np.linspace(0,1,num=35)
grid = Grid(fig, rect=111, nrows_ncols=(2,2),
            axes_pad=0.6, label_mode='all'
            )
y_min = 0
y_max = 8
xlabel_block = 0.69 #*100
label_loc1 = 6
label_loc2 = 5
for i in range(4):
    if i == 0: 
        grid[i].tick_params('both', length=4, width=1, which='major', left=1, bottom=1, top=0, right=0)
        grid[i].annotate('Class 2', xy=(0.05, label_loc2), 
             color='black',
                         size=12)
        grid[i].annotate('Class 1', xy=(0.05, label_loc1), 
             color='red', 
                         size=12)
        grid[i].annotate('$p_{\\mathrm{in}} = p_{\\mathrm{out}}$', xy=(xlabel_block, label_loc1), 
             color='black', alpha=1, size=10)
        grid[i].annotate('$\phi_r = 0$', xy=(xlabel_block, label_loc2), 
             color='black', alpha=1, size=10)
        
        grid[i].hist(mc_F_final_noBnoO,
         bins = binBoundaries,
         normed = True,
         edgecolor = 'red',histtype='step',
         color='white',alpha=1,lw=1.5)
        
        grid[i].hist(1 - mc_M_final_noBnoO,
         bins = binBoundaries,
         normed = True,
         edgecolor = 'black',histtype='step',
         color='white',alpha=1,lw=1.5)
        
        
        grid[i].xaxis.set_major_locator(FixedLocator([0,0.25,0.50,0.75,1]))
        grid[i].yaxis.set_major_locator(FixedLocator([0,1,2,3,4,5,6,7,8]))

        grid[i].hist(prop_F_noBnoO[y_noBnoO_osbm==1], 
                    bins=binBoundaries, 
                    normed = True,
                     alpha = alpha_parameter, label='empirical',
                    edgecolor = 'white',color='red')
        
        grid[i].hist(prop_F_noBnoO[y_noBnoO_osbm==0], 
                    bins=binBoundaries,
                     normed = True,
                     alpha = alpha_parameter, label='empirical',
                    edgecolor = 'white', color='black')
        
        grid[i].spines['right'].set_visible(False)
        grid[i].spines['top'].set_visible(False)
        grid[i].set_ylabel('Normalized Frequency', size = 10)
        grid[i].set_ylim(y_min,y_max)
        grid[i].set_xlabel('Proportion of Class 1 neighbors', size = 10)


    if i == 1:
        grid[i].xaxis.set_major_locator(FixedLocator([0,.25,.50,.75,1.00]))
        grid[i].yaxis.set_major_locator(FixedLocator([0,1,2,3,4,5,6,7,8]))

        grid[i].tick_params('both', length=4, width=1, which='major', left=1, bottom=1, top=0, right=0)


        grid[i].annotate('$p_{\\mathrm{in}} = p_{\\mathrm{out}}$', xy=(xlabel_block, label_loc1), 
             color='black', alpha=1, size=10)
        grid[i].annotate('$\phi_r > 0$ ', xy=(xlabel_block, label_loc2), 
             color='black', alpha=1, size=10)

        grid[i].hist(mc_F_final_noByesO,
         bins = binBoundaries,
         normed = True,
         edgecolor = 'red',histtype='step',
         color='white',alpha=1,lw=1.5)
        
        grid[i].hist(1-mc_M_final_noByesO,
         bins = binBoundaries,
         normed = True,
         edgecolor = 'black',histtype='step',
         color='white',alpha=1,lw=1.5)

        grid[i].hist(prop_F_noByesO[y_noByesO_osbm==1], 
                     bins=binBoundaries, 
                     normed = True,
                     alpha = alpha_parameter, label='empirical',
                     edgecolor = 'white',color='red')
        
        grid[i].hist(prop_F_noByesO[y_noByesO_osbm==0], 
                     bins=binBoundaries, 
                     normed = True,
                     alpha = alpha_parameter, label='empirical',
                     edgecolor = 'white', color='black')
        grid[i].spines['right'].set_visible(False)
        grid[i].spines['top'].set_visible(False)
        grid[i].set_ylim(y_min,y_max)
        grid[i].set_ylabel('Normalized Frequency', size = 10)
        grid[i].set_xlabel('Proportion of Class 1 neighbors', size = 10)

    if i == 2:
        grid[i].xaxis.set_major_locator(FixedLocator([0,.25,.50,.75,1.00]))
        grid[i].yaxis.set_major_locator(FixedLocator([0,1,2,3,4,5,6,7,8]))

        grid[i].tick_params('both', length=4, width=1, which='major', left=1, bottom=1, top=0, right=0)

        grid[i].annotate('$p_{\\mathrm{in}} > p_{\\mathrm{out}}$', xy=(xlabel_block, label_loc1), 
             color='black', alpha=1, size=10)
        grid[i].annotate('$\phi_r = 0$', xy=(xlabel_block, label_loc2), 
             color='black', alpha=1, size=10)
        
        grid[i].hist(mc_F_final_yesBnoO,
         bins = binBoundaries,
         normed = True,
         edgecolor = 'red',histtype='step',
         color='white',alpha=1,lw=1.5)
        
        grid[i].hist(1-mc_M_final_yesBnoO,
         bins = binBoundaries,
         normed = True,
         edgecolor = 'black',histtype='step',
        color='white',alpha=1,lw=1.5)
        
        grid[i].hist(prop_F_yesBnoO[y_yesBnoO_osbm==1], 
                     bins=binBoundaries, 
                     normed = True,
                     alpha = alpha_parameter, label='empirical',
                     edgecolor = 'white', color='red')
        
        grid[i].hist(prop_F_yesBnoO[y_yesBnoO_osbm==0], 
                     bins=binBoundaries, 
                     normed = True,
                     alpha = alpha_parameter, label='empirical',
                     edgecolor = 'white', color='black')

        grid[i].set_ylim(y_min,y_max)
        grid[i].spines['right'].set_visible(False)
        grid[i].spines['top'].set_visible(False)
        grid[i].set_ylabel('Normalized Frequency', size = 10)
        grid[i].set_xlabel('Proportion of Class 1 neighbors', size = 10)

    if i == 3:
        grid[i].xaxis.set_major_locator(FixedLocator([0,.25,.50,.75,1.00]))
        grid[i].yaxis.set_major_locator(FixedLocator([0,1,2,3,4,5,6,7,8]))

        grid[i].hist(prop_F_yesByesO[y_yesByesO_osbm==1], 
                     bins=binBoundaries, 
                     normed = True,
                     alpha = alpha_parameter, label='empirical',
                     edgecolor = 'white', color='red')
        grid[i].tick_params('both', length=4, width=1, which='major', left=1, bottom=1, top=0, right=0)
        
        grid[i].hist(prop_F_yesByesO[y_yesByesO_osbm==0], 
                     bins=binBoundaries, 
                     normed = True,
                     alpha = alpha_parameter, label='empirical',
                     edgecolor = 'white', color='black')
        grid[i].annotate('$p_{\\mathrm{in}} > p_{\\mathrm{out}}$', xy=(xlabel_block, label_loc1), 
             color='black', alpha=1, size=10)
        grid[i].annotate('$\phi_r > 0$', xy=(xlabel_block, label_loc2), 
             color='black', alpha=1, size=10)

        grid[i].hist(mc_F_final_yesByesO,
         bins = binBoundaries,
         normed = True,
         edgecolor = 'red', histtype='step',
         color='white', alpha=1, lw=1.5)
        
        grid[i].hist(1 - mc_M_final_yesByesO,
         bins = binBoundaries,
         normed = True,
         edgecolor = 'black', histtype='step',
         color='white', alpha=1, lw=1.5)
        
        grid[i].spines['right'].set_visible(False)
        grid[i].spines['top'].set_visible(False)
        grid[i].set_ylim(y_min,y_max)
        grid[i].set_ylabel('Normalized Frequency', size = 10)
        grid[i].set_xlabel('Proportion of Class 1 neighbors', size = 10)

plt.tight_layout()
pp = PdfPages('../../figures/oSBM_overdispersion_consolidated.pdf')
pp.savefig()
pp.close()
%matplotlib inline

alpha_parameter = 0.25
fig = plt.figure(figsize=(3.46457,2.5), dpi = 300)
binBoundaries=np.linspace(0,1,num=35)
grid = Grid(fig, rect=111, nrows_ncols=(2,2),
            axes_pad=0.3, 
            label_mode='all'
            )
y_min = 0
y_max = 8
xlabel_block = 0.69 #*100
label_loc1 = 7.8
label_loc2 = 6.8

label_loc1p = 6
label_loc2p = 5
text_size = 8
axis_text = 8
tick_label_size = 7
for i in range(4):

    if i == 0: 
        grid[i].tick_params('both', length=4, width=1, which='major', left=1, bottom=1, top=0, right=0)
        grid[i].annotate('Class 2', xy=(0.05, label_loc2), 
             color='black',
                         size=8)
        grid[i].annotate('Class 1', xy=(0.05, label_loc1), 
             color='red', 
                         size=8)
        grid[i].annotate('$p_{\\mathrm{in}} = p_{\\mathrm{out}}$', xy=(xlabel_block, label_loc1p), 
             color='black', alpha=1, size=text_size)
        grid[i].annotate('$\phi_r = 0$', xy=(xlabel_block, label_loc2p), 
             color='black', alpha=1, size=text_size)
        
        grid[i].hist(mc_F_final_noBnoO,
         bins = binBoundaries,
         normed = True,
         edgecolor = 'red',histtype='step',
        color='white',alpha=1,lw=1.5)
        
        grid[i].hist(1-mc_M_final_noBnoO,
         bins = binBoundaries,
         normed = True,
         edgecolor = 'black',histtype='step',
        color='white',alpha=1,lw=1.5)
        
        
        grid[i].xaxis.set_major_locator(FixedLocator([0,0.25,0.50,0.75,1]))
        grid[i].yaxis.set_major_locator(FixedLocator([0,1,2,3,4,5,6,7,8]))
        grid[i].tick_params(axis = 'both',
                            labelsize=tick_label_size)
        grid[i].hist(prop_F_noBnoO[y_noBnoO_osbm==1], 
                    bins=binBoundaries, 
                    normed = True,
                     alpha = alpha_parameter, label='empirical',
                    edgecolor = 'white',color='red')
        
        grid[i].hist(prop_F_noBnoO[y_noBnoO_osbm==0], 
                    bins=binBoundaries,
                     normed = True,
                     alpha = alpha_parameter, label='empirical',
                    edgecolor = 'white', color='black')
        
        grid[i].spines['right'].set_visible(False)
        grid[i].spines['top'].set_visible(False)
        #grid[i].set_ylabel('Normalized Frequency', size = axis_text)
        grid[i].set_ylim(y_min,y_max)
        #grid[i].set_xlabel('Proportion of Class 1 neighbors', size = axis_text)


    if i == 1:
        grid[i].xaxis.set_major_locator(FixedLocator([0,.25,.50,.75,1.00]))
        grid[i].yaxis.set_major_locator(FixedLocator([0,1,2,3,4,5,6,7,8]))

        grid[i].tick_params('both', length=4, width=1, which='major', left=1, bottom=1, top=0, right=0)
        grid[i].tick_params(axis = 'both',
                            labelsize=tick_label_size)

        grid[i].annotate('$p_{\\mathrm{in}} = p_{\\mathrm{out}}$', xy=(xlabel_block, label_loc1p), 
             color='black', alpha=1, size=text_size)
        grid[i].annotate('$\phi_r > 0$ ', xy=(xlabel_block, label_loc2p), 
             color='black', alpha=1, size=text_size)

        grid[i].hist(mc_F_final_noByesO,
         bins = binBoundaries,
         normed = True,
         edgecolor = 'red',histtype='step',
        color='white',alpha=1,lw=1.5)
        
        grid[i].hist(1-mc_M_final_noByesO,
         bins = binBoundaries,
         normed = True,
         edgecolor = 'black',histtype='step',
        color='white',alpha=1,lw=1.5)

        grid[i].hist(prop_F_noByesO[y_noByesO_osbm==1], 
                    bins=binBoundaries, 
                     normed = True,
                     alpha = alpha_parameter, label='empirical',
                    edgecolor = 'white',color='red')
        
        grid[i].hist(prop_F_noByesO[y_noByesO_osbm==0], 
                    bins=binBoundaries, 
                     normed = True,
                     alpha = alpha_parameter, label='empirical',
                    edgecolor = 'white', color='black')
        grid[i].spines['right'].set_visible(False)
        grid[i].spines['top'].set_visible(False)
        grid[i].set_ylim(y_min,y_max)
        #grid[i].set_ylabel('Normalized Frequency', size = axis_text)
        #grid[i].set_xlabel('Proportion of Class 1 neighbors', size = axis_text)

    if i == 2:
        grid[i].xaxis.set_major_locator(FixedLocator([0,.25,.50,.75,1.00]))
        grid[i].yaxis.set_major_locator(FixedLocator([0,1,2,3,4,5,6,7,8]))

        grid[i].tick_params('both', length=4, width=1, which='major', left=1, bottom=1, top=0, right=0)
        grid[i].tick_params(axis = 'both',
                            labelsize=tick_label_size)

        grid[i].annotate('$p_{\\mathrm{in}} > p_{\\mathrm{out}}$', xy=(xlabel_block, label_loc1p), 
             color='black', alpha=1, size=text_size)
        grid[i].annotate('$\phi_r = 0$', xy=(xlabel_block, label_loc2p), 
             color='black', alpha=1, size=text_size)
        
        grid[i].hist(mc_F_final_yesBnoO,
         bins = binBoundaries,
         normed = True,
         edgecolor = 'red',histtype='step',
        color='white',alpha=1,lw=1.5)
        
        grid[i].hist(1-mc_M_final_yesBnoO,
         bins = binBoundaries,
         normed = True,
         edgecolor = 'black',histtype='step',
        color='white',alpha=1,lw=1.5)
        
        grid[i].hist(prop_F_yesBnoO[y_yesBnoO_osbm==1], 
                    bins=binBoundaries, 
                     normed = True,
                     alpha = alpha_parameter, label='empirical',
                   edgecolor = 'white', color='red')
        
        grid[i].hist(prop_F_yesBnoO[y_yesBnoO_osbm==0], 
                    bins=binBoundaries, 
                     normed = True,
                     alpha = alpha_parameter, label='empirical',
                    edgecolor = 'white', color='black')

        grid[i].set_ylim(y_min,y_max)
        grid[i].spines['right'].set_visible(False)
        grid[i].spines['top'].set_visible(False)
        #grid[i].set_ylabel('Normalized Frequency', size = axis_text)
        #grid[i].set_xlabel('Proportion of Class 1 neighbors', size = axis_text)



    if i == 3:
        grid[i].xaxis.set_major_locator(FixedLocator([0,.25,.50,.75,1.00]))
        grid[i].yaxis.set_major_locator(FixedLocator([0,1,2,3,4,5,6,7,8]))
        grid[i].tick_params(axis = 'both',
                            labelsize=tick_label_size)

        grid[i].hist(prop_F_yesByesO[y_yesByesO_osbm==1], 
                    bins=binBoundaries, 
                     normed = True,
                     alpha = alpha_parameter, label='empirical',
                   edgecolor = 'white', color='red')
        grid[i].tick_params('both', length=4, width=1, which='major', left=1, bottom=1, top=0, right=0)
        
        grid[i].hist(prop_F_yesByesO[y_yesByesO_osbm==0], 
                    bins=binBoundaries, 
                     normed = True,
                     alpha = alpha_parameter, label='empirical',
                    edgecolor = 'white', color='black')
        grid[i].annotate('$p_{\\mathrm{in}} > p_{\\mathrm{out}}$', xy=(xlabel_block, label_loc1p), 
             color='black', alpha=1, size=text_size)
        grid[i].annotate('$\phi_r > 0$', xy=(xlabel_block, label_loc2p), 
             color='black', alpha=1, size=text_size)

        grid[i].hist(mc_F_final_yesByesO,
         bins = binBoundaries,
         normed = True,
         edgecolor = 'red',histtype='step',
        color='white',alpha=1,lw=1.5)
        
        grid[i].hist(1-mc_M_final_yesByesO,
         bins = binBoundaries,
         normed = True,
         edgecolor = 'black',histtype='step',
        color='white',alpha=1,lw=1.5)
        
        grid[i].spines['right'].set_visible(False)
        grid[i].spines['top'].set_visible(False)
        grid[i].set_ylim(y_min,y_max)
        #grid[i].set_ylabel('Normalized Frequency', size = axis_text)
        #grid[i].set_xlabel('Proportion of Class 1 neighbors', size = axis_text)
plt.text(-0.8, -2.6, 'Proportion of Class 1 Neighbors', fontsize=axis_text)

plt.text(-1.45, 13.5, 'Normalized Frequency', fontsize=axis_text,
        rotation = 'vertical')

plt.tight_layout()
pp = PdfPages('../../figures/oSBM_overdispersion_consolidated_SINGLE_COLUMN.pdf')
pp.savefig(dpi = 300)
pp.close()
%matplotlib inline

alpha_parameter = 0.25
fig = plt.figure(figsize=(6.69291,5.1), dpi = 300)
binBoundaries=np.linspace(0,1,num=35)
grid = Grid(fig, rect=111, nrows_ncols=(2,2),
            axes_pad=0.55, 
            label_mode='all'
            )
y_min = 0
y_max = 8
xlabel_block = 0.69 #*100
label_loc1 = 6
label_loc2 = 5.25

text_size = 11
axis_text = 10.5
tick_label_size = 9.5
for i in range(4):

    if i == 0: 
        grid[i].tick_params('both', length=4, width=1, which='major', left=1, bottom=1, top=0, right=0)
        grid[i].annotate('Class 2', xy=(0.05, label_loc2), 
             color='black',
                         size=11)
        grid[i].annotate('Class 1', xy=(0.05, label_loc1), 
             color='red', 
                         size=11)
        grid[i].annotate('$p_{\\mathrm{in}} = p_{\\mathrm{out}}$', xy=(xlabel_block, label_loc1), 
             color='black', alpha=1, size=text_size)
        grid[i].annotate('$\phi_r = 0$', xy=(xlabel_block, label_loc2), 
             color='black', alpha=1, size=text_size)
        
        grid[i].hist(mc_F_final_noBnoO,
         bins = binBoundaries,
         normed = True,
         edgecolor = 'red',histtype='step',
        color='white',alpha=1,lw=1.5)
        
        grid[i].hist(1-mc_M_final_noBnoO,
         bins = binBoundaries,
         normed = True,
         edgecolor = 'black',histtype='step',
        color='white',alpha=1,lw=1.5)
        
        
        grid[i].xaxis.set_major_locator(FixedLocator([0,0.25,0.50,0.75,1]))
        grid[i].yaxis.set_major_locator(FixedLocator([0,1,2,3,4,5,6,7,8]))
        grid[i].tick_params(axis = 'both',
                            labelsize=tick_label_size)
        grid[i].hist(prop_F_noBnoO[y_noBnoO_osbm==1], 
                    bins=binBoundaries, 
                    normed = True,
                     alpha = alpha_parameter, label='empirical',
                    edgecolor = 'white',color='red')
        
        grid[i].hist(prop_F_noBnoO[y_noBnoO_osbm==0], 
                    bins=binBoundaries,
                     normed = True,
                     alpha = alpha_parameter, label='empirical',
                    edgecolor = 'white', color='black')
        
        grid[i].spines['right'].set_visible(False)
        grid[i].spines['top'].set_visible(False)
        #grid[i].set_ylabel('Normalized Frequency', size = axis_text)
        grid[i].set_ylim(y_min,y_max)
        #grid[i].set_xlabel('Proportion of Class 1 neighbors', size = axis_text)


    if i == 1:
        grid[i].xaxis.set_major_locator(FixedLocator([0,.25,.50,.75,1.00]))
        grid[i].yaxis.set_major_locator(FixedLocator([0,1,2,3,4,5,6,7,8]))

        grid[i].tick_params('both', length=4, width=1, which='major', left=1, bottom=1, top=0, right=0)
        grid[i].tick_params(axis = 'both',
                            labelsize=tick_label_size)

        grid[i].annotate('$p_{\\mathrm{in}} = p_{\\mathrm{out}}$', xy=(xlabel_block, label_loc1), 
             color='black', alpha=1, size=text_size)
        grid[i].annotate('$\phi_r > 0$ ', xy=(xlabel_block, label_loc2), 
             color='black', alpha=1, size=text_size)

        grid[i].hist(mc_F_final_noByesO,
         bins = binBoundaries,
         normed = True,
         edgecolor = 'red',histtype='step',
        color='white',alpha=1,lw=1.5)
        
        grid[i].hist(1-mc_M_final_noByesO,
         bins = binBoundaries,
         normed = True,
         edgecolor = 'black',histtype='step',
        color='white',alpha=1,lw=1.5)

        grid[i].hist(prop_F_noByesO[y_noByesO_osbm==1], 
                    bins=binBoundaries, 
                     normed = True,
                     alpha = alpha_parameter, label='empirical',
                    edgecolor = 'white',color='red')
        
        grid[i].hist(prop_F_noByesO[y_noByesO_osbm==0], 
                    bins=binBoundaries, 
                     normed = True,
                     alpha = alpha_parameter, label='empirical',
                    edgecolor = 'white', color='black')
        grid[i].spines['right'].set_visible(False)
        grid[i].spines['top'].set_visible(False)
        grid[i].set_ylim(y_min,y_max)
        #grid[i].set_ylabel('Normalized Frequency', size = axis_text)
        #grid[i].set_xlabel('Proportion of Class 1 neighbors', size = axis_text)

    if i == 2:
        grid[i].xaxis.set_major_locator(FixedLocator([0,.25,.50,.75,1.00]))
        grid[i].yaxis.set_major_locator(FixedLocator([0,1,2,3,4,5,6,7,8]))

        grid[i].tick_params('both', length=4, width=1, which='major', left=1, bottom=1, top=0, right=0)
        grid[i].tick_params(axis = 'both',
                            labelsize=tick_label_size)

        grid[i].annotate('$p_{\\mathrm{in}} > p_{\\mathrm{out}}$', xy=(xlabel_block, label_loc1), 
             color='black', alpha=1, size=text_size)
        grid[i].annotate('$\phi_r = 0$', xy=(xlabel_block, label_loc2), 
             color='black', alpha=1, size=text_size)
        
        grid[i].hist(mc_F_final_yesBnoO,
         bins = binBoundaries,
         normed = True,
         edgecolor = 'red',histtype='step',
        color='white',alpha=1,lw=1.5)
        
        grid[i].hist(1-mc_M_final_yesBnoO,
         bins = binBoundaries,
         normed = True,
         edgecolor = 'black',histtype='step',
        color='white',alpha=1,lw=1.5)
        
        grid[i].hist(prop_F_yesBnoO[y_yesBnoO_osbm==1], 
                    bins=binBoundaries, 
                     normed = True,
                     alpha = alpha_parameter, label='empirical',
                   edgecolor = 'white', color='red')
        
        grid[i].hist(prop_F_yesBnoO[y_yesBnoO_osbm==0], 
                    bins=binBoundaries, 
                     normed = True,
                     alpha = alpha_parameter, label='empirical',
                    edgecolor = 'white', color='black')

        grid[i].set_ylim(y_min,y_max)
        grid[i].spines['right'].set_visible(False)
        grid[i].spines['top'].set_visible(False)
        #grid[i].set_ylabel('Normalized Frequency', size = axis_text)
        #grid[i].set_xlabel('Proportion of Class 1 neighbors', size = axis_text)



    if i == 3:
        grid[i].xaxis.set_major_locator(FixedLocator([0,.25,.50,.75,1.00]))
        grid[i].yaxis.set_major_locator(FixedLocator([0,1,2,3,4,5,6,7,8]))
        grid[i].tick_params(axis = 'both',
                            labelsize=tick_label_size)

        grid[i].hist(prop_F_yesByesO[y_yesByesO_osbm==1], 
                    bins=binBoundaries, 
                     normed = True,
                     alpha = alpha_parameter, label='empirical',
                   edgecolor = 'white', color='red')
        grid[i].tick_params('both', length=4, width=1, which='major', left=1, bottom=1, top=0, right=0)
        
        grid[i].hist(prop_F_yesByesO[y_yesByesO_osbm==0], 
                    bins=binBoundaries, 
                     normed = True,
                     alpha = alpha_parameter, label='empirical',
                    edgecolor = 'white', color='black')
        grid[i].annotate('$p_{\\mathrm{in}} > p_{\\mathrm{out}}$', xy=(xlabel_block, label_loc1), 
             color='black', alpha=1, size=text_size)
        grid[i].annotate('$\phi_r > 0$', xy=(xlabel_block, label_loc2), 
             color='black', alpha=1, size=text_size)

        grid[i].hist(mc_F_final_yesByesO,
         bins = binBoundaries,
         normed = True,
         edgecolor = 'red',histtype='step',
        color='white',alpha=1,lw=1.5)
        
        grid[i].hist(1-mc_M_final_yesByesO,
         bins = binBoundaries,
         normed = True,
         edgecolor = 'black',histtype='step',
        color='white',alpha=1,lw=1.5)
        
        grid[i].spines['right'].set_visible(False)
        grid[i].spines['top'].set_visible(False)
        grid[i].set_ylim(y_min,y_max)
        #grid[i].set_ylabel('Normalized Frequency', size = axis_text)
        #grid[i].set_xlabel('Proportion of Class 1 neighbors', size = axis_text)
plt.text(-0.45, -1.29, 'Proportion of Class 1 Neighbors', fontsize=axis_text)
plt.text(-1.31, 12, 'Normalized Frequency', fontsize=axis_text,
        rotation = 'vertical')

plt.tight_layout()
pp = PdfPages('../../figures/oSBM_overdispersion_consolidated_DOUBLE_COLUMN.pdf')
pp.savefig(dpi = 300)
pp.close()<jupyter_output><empty_output><jupyter_text>Compare $\beta_j$ coefficient from LINK versus node $j$'s true label<jupyter_code>percent_initially_unlabelled = [0.1]
percent_initially_labelled = np.subtract(1, percent_initially_unlabelled)
n_iter = 1
coef = LINK_coeff(percent_initially_unlabelled, ## note: mean_se_model assumes a vector of x% initially labeled
                                                              np.array(y_yesBnoO_osbm), ## gender labels 
                                                              np.matrix(adj_yesBnoO_osbm), ## adjacency matrix
                                                              clf = linear_model.LogisticRegression(penalty='l2',
                                                                                                    C=10e20,
                                                                                                    solver='lbfgs'),
                                                              num_iter=n_iter) 
from __future__ import division
prop_class_1 =(adj_yesBnoO_osbm * np.matrix(y_yesBnoO_osbm==1).T)/(np.sum(adj_yesBnoO_osbm,1))
%matplotlib inline
ax = plt.subplot(111)
alpha_parameter = 0.5
binBoundaries=np.linspace(-4,4,num=35)

ax.hist(coef[y_noByesO_osbm==1], color='black', #alpha=0.1,
        bins=binBoundaries, 
                     normed = True,
                     alpha = alpha_parameter, label='empirical',
                    edgecolor = 'white')

ax.hist(coef[y_yesBnoO_osbm==0], color='red', #alpha=0.1,
        bins=binBoundaries, 
                     normed = True,
                     alpha = alpha_parameter, label='empirical',
                    edgecolor = 'white')
plt.xlabel(r'$\beta_j$ coefficient')
plt.ylabel('Normalized Frequency')
plt.title('yesB-noO')
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.annotate('Class 1', xy=(-3.7, 0.57), 
                 color='red', alpha=1, size=12)

ax.annotate('Class 2', xy=(-3.7, 0.54), 
                 color='black', alpha=1, size=12)


pp = PdfPages('../../figures/yesB_noO_Butterfly_actual_class_histogram.pdf')
pp.savefig()
pp.close()
coef= LINK_coeff(percent_initially_unlabelled, ## note: mean_se_model assumes a vector of x% initially labeled
                                                              np.array(y_noByesO_osbm), ## gender labels 
                                                              np.matrix(adj_noByesO_osbm), ## adjacency matrix
                                                              clf = linear_model.LogisticRegression(penalty='l2',C=10e20,
                                                                                                   solver='lbfgs'),num_iter=n_iter) 



prop_class_1 =(adj_noByesO_osbm * np.matrix(y_noByesO_osbm==1).T)/(np.sum(adj_noByesO_osbm,1))
%matplotlib inline
ax = plt.subplot(111)
alpha_parameter = 0.5
binBoundaries=np.linspace(-4,4,num=35)

ax.hist(coef[y_noByesO_osbm==1], color='black', #alpha=0.1,
        bins=binBoundaries, 
                     normed = True,
                     alpha = alpha_parameter, label='empirical',
                    edgecolor = 'white')

ax.hist(coef[y_yesBnoO_osbm==0], color='red', #alpha=0.1,
        bins=binBoundaries, 
                     normed = True,
                     alpha = alpha_parameter, label='empirical',
                    edgecolor = 'white')
plt.xlabel(r'$\beta_j$ coefficient')
plt.ylabel('Normalized Frequency')
plt.title('noB-yesO')
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.annotate('Class 1', xy=(-3.7, 0.57), 
                 color='red', alpha=1, size=12)

ax.annotate('Class 2', xy=(-3.7, 0.54), 
                 color='black', alpha=1, size=12)


pp = PdfPages('../../figures/noB_yesO_Butterfly_actual_class_histogram.pdf')
pp.savefig()
pp.close()
coef = LINK_coeff(percent_initially_unlabelled, ## note: mean_se_model assumes a vector of x% initially labeled
                                                              np.array(y_yesByesO_osbm), ## gender labels 
                                                              np.matrix(adj_yesByesO_osbm), ## adjacency matrix
                                                              clf = linear_model.LogisticRegression(penalty='l2',C=10e20,
                                                                                                   solver='lbfgs'),num_iter=n_iter) 



%matplotlib inline
ax = plt.subplot(111)
alpha_parameter = 0.5
binBoundaries=np.linspace(-4,4,num=35)

ax.hist(coef[y_yesByesO_osbm==1], color='black', #alpha=0.1,
        bins=binBoundaries, 
                     normed = True,
                     alpha = alpha_parameter, label='empirical',
                    edgecolor = 'white')

ax.hist(coef[y_yesByesO_osbm==0], color='red', #alpha=0.1,
        bins=binBoundaries, 
                     normed = True,
                     alpha = alpha_parameter, label='empirical',
                    edgecolor = 'white')
plt.xlabel(r'$\beta_j$ coefficient')
plt.ylabel('Normalized Frequency')
plt.title('yesB-yesO')
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.annotate('Class 1', xy=(-3.7, 0.57), 
                 color='red', alpha=1, size=12)

ax.annotate('Class 2', xy=(-3.7, 0.54), 
                 color='black', alpha=1, size=12)


pp = PdfPages('../../figures/yesB_yesO_Butterfly_actual_class_histogram.pdf')
pp.savefig()
pp.close()<jupyter_output><empty_output><jupyter_text>Predictions on oSBM<jupyter_code>percent_initially_unlabelled = [0.99,0.95,0.9,0.8,0.7,0.6,0.5,0.4,0.3,0.2,0.1,0.05,0.01]
percent_initially_labelled = np.subtract(1, percent_initially_unlabelled)<jupyter_output><empty_output><jupyter_text>LINKLogistic regression with minimal L2 regularization applied to LINK features.<jupyter_code>n_iter = 100
#noBnoO
(mean_accuracy_noBnoO, se_accuracy_noBnoO, mean_micro_auc_noBnoO,se_micro_auc_noBnoO, mean_wt_auc_noBnoO,se_wt_auc_noBnoO)= LINK(percent_initially_unlabelled, ## note: mean_se_model assumes a vector of x% initially labeled
                                                              np.array(y_noBnoO_osbm), ## gender labels 
                                                              adj_noBnoO_osbm, ## adjacency matrix
                                                              clf = linear_model.LogisticRegression(penalty='l2',C=10e20,
                                                                                                   solver='lbfgs'),num_iter=n_iter) 
#yesBnoO
(mean_accuracy_yesBnoO, se_accuracy_yesBnoO, mean_micro_auc_yesBnoO,se_micro_auc_yesBnoO, mean_wt_auc_yesBnoO,se_wt_auc_yesBnoO)= LINK(percent_initially_unlabelled, ## note: mean_se_model assumes a vector of x% initially labeled
                                                              np.array(y_yesBnoO_osbm), ## gender labels 
                                                              adj_yesBnoO_osbm, ## adjacency matrix
                                                              clf = linear_model.LogisticRegression(penalty='l2',C=10e20,
                                                                                                   solver='lbfgs'),num_iter=n_iter) 
#noByesO
(mean_accuracy_noByesO, se_accuracy_noByesO, mean_micro_auc_noByesO,se_micro_auc_noByesO, mean_wt_auc_noByesO,se_wt_auc_noByesO)= LINK(percent_initially_unlabelled, ## note: mean_se_model assumes a vector of x% initially labeled
                                                              np.array(y_noByesO_osbm), ## gender labels 
                                                              adj_noByesO_osbm, ## adjacency matrix
                                                              clf = linear_model.LogisticRegression(penalty='l2',C=10e20,
                                                                                                   solver='lbfgs'),num_iter=n_iter) 
#yesByesO
(mean_accuracy_yesByesO, se_accuracy_yesByesO, mean_micro_auc_yesByesO,se_micro_auc_yesByesO, mean_wt_auc_yesByesO,se_wt_auc_yesByesO)= LINK(percent_initially_unlabelled, ## note: mean_se_model assumes a vector of x% initially labeled
                                                              np.array(y_yesByesO_osbm), ## gender labels 
                                                              adj_yesByesO_osbm, ## adjacency matrix
                                                              clf = linear_model.LogisticRegression(penalty='l2',C=10e20,
                                                                                                   solver='lbfgs'),num_iter=n_iter)<jupyter_output>0.99
0.95
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0.05
0.01
0.99
0.95
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0.05
0.01
0.99
0.95
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0.05
0.01
0.99
0.95
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0.05
0.01<jupyter_text>Majority Vote - 1-hop, 2-hop  1-hop<jupyter_code>#noBnoO
(mean_accuracy_mv_noBnoO, se_accuracy_mv_noBnoO, 
 mean_micro_auc_mv_noBnoO, se_micro_auc_mv_noBnoO, 
 mean_wt_auc_mv_noBnoO, se_wt_auc_mv_noBnoO) = majority_vote_modified(percent_initially_unlabelled,  
                                                                np.array(y_noBnoO_osbm), 
                                                                np.array(adj_noBnoO_osbm), 
                                                                num_iter=n_iter) 
#yesBnoO
(mean_accuracy_mv_yesBnoO, se_accuracy_mv_yesBnoO, 
 mean_micro_auc_mv_yesBnoO, se_micro_auc_mv_yesBnoO, 
 mean_wt_auc_mv_yesBnoO, se_wt_auc_mv_yesBnoO) = majority_vote_modified(percent_initially_unlabelled,  
                                                                np.array(y_yesBnoO_osbm), 
                                                                np.array(adj_yesBnoO_osbm), 
                                                                num_iter=n_iter) 
#noByesO
(mean_accuracy_mv_noByesO, se_accuracy_mv_noByesO, 
 mean_micro_auc_mv_noByesO, se_micro_auc_mv_noByesO, 
 mean_wt_auc_mv_noByesO, se_wt_auc_mv_noByesO) = majority_vote_modified(percent_initially_unlabelled,  
                                                                np.array(y_noByesO_osbm), 
                                                                np.array(adj_noByesO_osbm), 
                                                                num_iter=n_iter) 
#yesByesO
(mean_accuracy_mv_yesByesO, se_accuracy_mv_yesByesO, 
 mean_micro_auc_mv_yesByesO, se_micro_auc_mv_yesByesO, 
 mean_wt_auc_mv_yesByesO, se_wt_auc_mv_yesByesO) = majority_vote_modified(percent_initially_unlabelled,  
                                                                np.array(y_yesByesO_osbm), 
                                                                np.array(adj_yesByesO_osbm), 
                                                                num_iter=n_iter)<jupyter_output>0.99
0.95
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0.05
0.01
0.99
0.95
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0.05
0.01
0.99
0.95
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0.05
0.01
0.99
0.95
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0.05
0.01<jupyter_text>2-hop<jupyter_code>adj_noBnoO_osbm2 = np.matrix(adj_noBnoO_osbm)**2
adj_noBnoO_osbm2[range(adj_noBnoO_osbm2.shape[0]),range(adj_noBnoO_osbm2.shape[0])]=0

adj_yesBnoO_osbm2 = np.matrix(adj_yesBnoO_osbm)**2
adj_yesBnoO_osbm[range(adj_yesBnoO_osbm.shape[0]),range(adj_yesBnoO_osbm.shape[0])]=0

adj_noByesO_osbm2 = np.matrix(adj_noByesO_osbm)**2
adj_noByesO_osbm2[range(adj_noByesO_osbm.shape[0]),range(adj_noByesO_osbm.shape[0])]=0

adj_yesByesO_osbm2 = np.matrix(adj_yesByesO_osbm)**2
adj_yesByesO_osbm2[range(adj_noByesO_osbm.shape[0]),range(adj_yesByesO_osbm.shape[0])]=0
#noBnoO
(mean_accuracy_mv2_noBnoO, se_accuracy_mv2_noBnoO, 
 mean_micro_auc_mv2_noBnoO, se_micro_auc_mv2_noBnoO, 
 mean_wt_auc_mv2_noBnoO, se_wt_auc_mv2_noBnoO) = majority_vote_modified(percent_initially_unlabelled,  
                                                                np.array(y_noBnoO_osbm), 
                                                                np.array(adj_noBnoO_osbm2), 
                                                                num_iter=n_iter) 
#yesBnoO
(mean_accuracy_mv2_yesBnoO, se_accuracy_mv2_yesBnoO, 
 mean_micro_auc_mv2_yesBnoO, se_micro_auc_mv2_yesBnoO, 
 mean_wt_auc_mv2_yesBnoO, se_wt_auc_mv2_yesBnoO) = majority_vote_modified(percent_initially_unlabelled,  
                                                                np.array(y_yesBnoO_osbm), 
                                                                np.array(adj_yesBnoO_osbm2), 
                                                                num_iter=n_iter) 
#noByesO
(mean_accuracy_mv2_noByesO, se_accuracy_m2v_noByesO, 
 mean_micro_auc_mv2_noByesO, se_micro_auc_mv2_noByesO, 
 mean_wt_auc_mv2_noByesO, se_wt_auc_mv2_noByesO) = majority_vote_modified(percent_initially_unlabelled,  
                                                                np.array(y_noByesO_osbm), 
                                                                np.array(adj_noByesO_osbm2), 
                                                                num_iter=n_iter) 
#yesByesO
(mean_accuracy_mv2_yesByesO, se_accuracy_mv2_yesByesO, 
 mean_micro_auc_mv2_yesByesO, se_micro_auc_mv2_yesByesO, 
 mean_wt_auc_mv2_yesByesO, se_wt_auc_mv2_yesByesO) = majority_vote_modified(percent_initially_unlabelled,  
                                                                np.array(y_yesByesO_osbm), 
                                                                np.array(adj_yesByesO_osbm2),
                                                                num_iter=n_iter)<jupyter_output>0.99
0.95
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0.05
0.01
0.99
0.95
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0.05
0.01
0.99
0.95
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0.05
0.01
0.99
0.95
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0.05
0.01<jupyter_text>ZGL<jupyter_code>(mean_accuracy_zgl_noBnoO, se_accuracy_zgl_noBnoO, 
mean_micro_auc_zgl_noBnoO, se_micro_auc_zgl_noBnoO, 
mean_wt_auc_zgl_noBnoO, se_wt_auc_zgl_noBnoO) = ZGL_finalized(np.array(adj_noBnoO_osbm),
                                    np.array(y_noBnoO_osbm), percent_initially_unlabelled, 
                                    num_iter=n_iter)
(mean_accuracy_zgl_noByesO, se_accuracy_zgl_noByesO, 
mean_micro_auc_zgl_noByesO, se_micro_auc_zgl_noByesO, 
mean_wt_auc_zgl_noByesO, se_wt_auc_zgl_noByesO) = ZGL_finalized(np.array(adj_noByesO_osbm),
                                    np.array(y_noByesO_osbm), percent_initially_unlabelled, 
                                    num_iter=n_iter)
(mean_accuracy_zgl_yesBnoO, se_accuracy_zgl_yesBnoO, 
mean_micro_auc_zgl_yesBnoO, se_micro_auc_zgl_yesBnoO, 
mean_wt_auc_zgl_yesBnoO, se_wt_auc_zgl_yesBnoO) = ZGL_finalized(np.array(adj_yesBnoO_osbm),
                                    np.array(y_yesBnoO_osbm), percent_initially_unlabelled, 
                                    num_iter=n_iter)
(mean_accuracy_zgl_yesByesO, se_accuracy_zgl_yesByesO, 
mean_micro_auc_zgl_yesBnoO, se_micro_auc_zgl_yesByesO, 
mean_wt_auc_zgl_yesByesO, se_wt_auc_zgl_yesByesO) = ZGL_finalized(np.array(adj_yesByesO_osbm),
                                    np.array(y_yesByesO_osbm), percent_initially_unlabelled, 
                                    num_iter=n_iter)<jupyter_output>0.99
0.95
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0.05
0.01<jupyter_text>Baseline<jupyter_code>(mean_wt_auc_baseline_noBnoO, se_wt_auc_baseline_noBnoO) = random_classifier(np.array(adj_noBnoO_osbm),
                                                                             np.array(y_noBnoO_osbm),
                                                                            percent_initially_unlabelled,
                                                                             num_iter=n_iter)

(mean_wt_auc_baseline_yesBnoO, se_wt_auc_baseline_yesBnoO) = random_classifier(np.array(adj_yesBnoO_osbm),
                                                                             np.array(y_yesBnoO_osbm),
                                                                            percent_initially_unlabelled,
                                                                             num_iter=n_iter)

(mean_wt_auc_baseline_noByesO, se_wt_auc_baseline_noByesO) = random_classifier(np.array(adj_noByesO_osbm),
                                                                             np.array(y_noByesO_osbm),
                                                                            percent_initially_unlabelled,
                                                                             num_iter=n_iter)

(mean_wt_auc_baseline_yesByesO, se_wt_auc_baseline_yesByesO) = random_classifier(np.array(adj_yesByesO_osbm),
                                                                             np.array(y_yesByesO_osbm),
                                                                            percent_initially_unlabelled,
                                                                             num_iter=n_iter)<jupyter_output>0.99
0.95
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0.05
0.01
0.99
0.95
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0.05
0.01
0.99
0.95
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0.05
0.01
0.99
0.95
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0.05
0.01<jupyter_text>Main Paper Figure Comparing Relative Predictive Performance on oSBM<jupyter_code>from matplotlib.ticker import FixedLocator,LinearLocator,MultipleLocator, FormatStrFormatter

fig = plt.figure()
seaborn.set_style(style='white')
from mpl_toolkits.axes_grid1 import Grid
grid = Grid(fig, rect=111, nrows_ncols=(2,2),
            axes_pad=0.6, label_mode='all')

y_max = 1.05
y_min = 0.3
x_max = 102
label_loc1 = 0.75
label_loc2 = 0.65

for i in range(4):
    if i == 0:
        grid[i].tick_params('both', length=4, width=1, which='major', left=1, bottom=1, top=0, right=0)
        grid[i].xaxis.set_major_locator(FixedLocator([0,25,50,75,100]))
        grid[i].yaxis.set_major_locator(FixedLocator([0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1]))

        grid[i].errorbar(percent_initially_labelled*100, mean_wt_auc_baseline_noBnoO, 
            yerr=se_wt_auc_baseline_noBnoO, fmt='--o', capthick=2,
                alpha=1, elinewidth=3, color='gray')
        grid[i].errorbar(percent_initially_labelled*100, mean_wt_auc_noBnoO, 
            yerr=se_wt_auc_noBnoO, fmt='--o', capthick=2,
            alpha=1, elinewidth=3, color='black')
        grid[i].errorbar(percent_initially_labelled*100, mean_wt_auc_zgl_noBnoO,
            yerr=se_wt_auc_zgl_noBnoO, fmt='--o', capthick=2,
            alpha=1, elinewidth=3, color='orange')
        grid[i].errorbar(percent_initially_labelled*100, mean_wt_auc_mv_noBnoO,
            yerr=se_wt_auc_mv_noBnoO, fmt='--o', capthick=2,
            alpha=1, elinewidth=3, color='red')
        grid[i].errorbar(percent_initially_labelled*100, mean_wt_auc_mv2_noBnoO, 
            yerr=se_wt_auc_mv2_noBnoO, fmt='--o', capthick=2,
                alpha=1, elinewidth=3, color='maroon')
        grid[i].set_xlim(0,x_max)
        grid[i].annotate('LINK', xy=(3, 0.99), 
                 color='black', alpha=1, size=12)
        grid[i].annotate('2-hop MV', xy=(3, 0.9), 
                 color='maroon', alpha=1, size=12)
        grid[i].annotate('1-hop MV', xy=(3, 0.9-0.09), 
                 color='red', alpha=1, size=12)
        grid[i].annotate('ZGL', xy=(3, 0.9-2*0.09), 
                 color='orange', alpha=1, size=12)
        grid[i].annotate('Baseline', xy=(3, 0.9-3*0.09), 
                 color='gray', alpha=1, size=12)
        grid[i].set_ylim(y_min,y_max)
        grid[i].spines['right'].set_visible(False)
        grid[i].spines['top'].set_visible(False)
        grid[i].tick_params(axis='both', which='major', labelsize=9)
        grid[i].tick_params(axis='both', which='minor', labelsize=9)
        grid[i].annotate('$p_{\\mathrm{in}} = p_{\\mathrm{out}}$', xy=(xlabel_block*100, label_loc1), 
             color='black', alpha=1, size=10)
        grid[i].annotate('$\phi_r = 0$', xy=(xlabel_block*100, label_loc2), 
             color='black', alpha=1, size=10)
        grid[i].set_xlabel('Percent of Nodes Initially Labeled', size = 10)
        grid[i].set_ylabel('AUC', size = 10)

    if i == 1:
        grid[i].tick_params('both', length=4, width=1, which='major', left=1, bottom=1, top=0, right=0)
        grid[i].xaxis.set_major_locator(FixedLocator([0,25,50,75,100]))
        grid[i].yaxis.set_major_locator(FixedLocator([0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1]))
        grid[i].errorbar(percent_initially_labelled*100, mean_wt_auc_baseline_noByesO, 
            yerr=se_wt_auc_baseline_noByesO, fmt='--o', capthick=2,
                alpha=1, elinewidth=3, color='gray')
        grid[i].errorbar(percent_initially_labelled*100, mean_wt_auc_noByesO, 
            yerr=se_wt_auc_noByesO, fmt='--o', capthick=2,
            alpha=1, elinewidth=3, color='black')
        grid[i].errorbar(percent_initially_labelled*100, mean_wt_auc_zgl_noByesO,
            yerr=se_wt_auc_zgl_noByesO, fmt='--o', capthick=2,
            alpha=1, elinewidth=3, color='orange')
        grid[i].errorbar(percent_initially_labelled*100, mean_wt_auc_mv_noByesO,
            yerr=se_wt_auc_mv_noByesO, fmt='--o', capthick=2,
            alpha=1, elinewidth=3, color='red')
        grid[i].errorbar(percent_initially_labelled*100, mean_wt_auc_mv2_noByesO, 
            yerr=se_wt_auc_mv2_noByesO, fmt='--o', capthick=2,
                alpha=1, elinewidth=3, color='maroon')
        grid[i].annotate('$p_{\\mathrm{in}} = p_{\\mathrm{out}}$', xy=(xlabel_block*100, label_loc1), 
             color='black', alpha=1, size=10)
        grid[i].annotate('$\phi_r > 0$', xy=(xlabel_block*100, label_loc2), 
             color='black', alpha=1, size=10)
        grid[i].set_ylim(y_min,y_max)
        grid[i].set_xlim(0,x_max)
        grid[i].spines['right'].set_visible(False)
        grid[i].spines['top'].set_visible(False)
        grid[i].set_ylabel('AUC', size = 10)
        grid[i].set_xlabel('Percent of Nodes Initially Labeled', size = 10)

    if i == 2:
        grid[i].tick_params('both', length=4, width=1, which='major', left=1, bottom=1, top=0, right=0)
        grid[i].xaxis.set_major_locator(FixedLocator([0,25,50,75,100]))
        grid[i].yaxis.set_major_locator(FixedLocator([0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1]))
        grid[i].errorbar(percent_initially_labelled*100, mean_wt_auc_baseline_yesBnoO, 
            yerr=se_wt_auc_baseline_yesBnoO, fmt='--o', capthick=2,
                alpha=1, elinewidth=3, color='gray')
        grid[i].errorbar(percent_initially_labelled*100, mean_wt_auc_yesBnoO, 
            yerr=se_wt_auc_yesBnoO, fmt='--o', capthick=2,
            alpha=1, elinewidth=3, color='black')
        grid[i].errorbar(percent_initially_labelled*100, mean_wt_auc_zgl_yesBnoO,
            yerr=se_wt_auc_zgl_yesBnoO, fmt='--o', capthick=2,
            alpha=1, elinewidth=3, color='orange')
        grid[i].errorbar(percent_initially_labelled*100, mean_wt_auc_mv_yesBnoO,
            yerr=se_wt_auc_mv_yesBnoO, fmt='--o', capthick=2,
            alpha=1, elinewidth=3, color='red')
        grid[i].errorbar(percent_initially_labelled*100, mean_wt_auc_mv2_yesBnoO, 
            yerr=se_wt_auc_mv2_yesBnoO, fmt='--o', capthick=2,
                alpha=1, elinewidth=3, color='maroon')
        grid[i].annotate('$p_{\\mathrm{in}} > p_{\\mathrm{out}}$', xy=(xlabel_block*100, label_loc1), 
             color='black', alpha=1, size=10)
        grid[i].annotate('$\phi_r = 0$', xy=(xlabel_block*100, label_loc2), 
             color='black', alpha=1, size=10)
        grid[i].set_ylim(y_min,y_max)
        grid[i].set_xlim(0,x_max)
        grid[i].spines['right'].set_visible(False)
        grid[i].spines['top'].set_visible(False)
        grid[i].set_ylabel('AUC', size = 10)
        grid[i].set_xlabel('Percent of Nodes Initially Labeled', size = 10)

    if i == 3:
        grid[i].tick_params('both', length=4, width=1, which='major', left=1, bottom=1, top=0, right=0)
        grid[i].xaxis.set_major_locator(FixedLocator([0,25,50,75,100]))
        grid[i].yaxis.set_major_locator(FixedLocator([0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1]))
        grid[i].errorbar(percent_initially_labelled*100, mean_wt_auc_baseline_yesByesO, 
            yerr=se_wt_auc_baseline_yesByesO, fmt='--o', capthick=2,
                alpha=1, elinewidth=3, color='gray')
        grid[i].errorbar(percent_initially_labelled*100, mean_wt_auc_yesByesO, 
            yerr=se_wt_auc_yesByesO, fmt='--o', capthick=2,
            alpha=1, elinewidth=3, color='black')
        grid[i].errorbar(percent_initially_labelled*100, mean_wt_auc_zgl_yesByesO,
            yerr=se_wt_auc_zgl_yesByesO, fmt='--o', capthick=2,
            alpha=1, elinewidth=3, color='orange')
        grid[i].errorbar(percent_initially_labelled*100, mean_wt_auc_mv_yesByesO,
            yerr=se_wt_auc_mv_yesByesO, fmt='--o', capthick=2,
            alpha=1, elinewidth=3, color='red')
        grid[i].errorbar(percent_initially_labelled*100, mean_wt_auc_mv2_yesByesO, 
            yerr=se_wt_auc_mv2_yesByesO, fmt='--o', capthick=2,
                alpha=1, elinewidth=3, color='maroon')
        grid[i].set_ylim(y_min,y_max)
        grid[i].set_xlim(0,x_max)
        grid[i].spines['right'].set_visible(False)
        grid[i].spines['top'].set_visible(False)
        grid[i].annotate('$p_{\\mathrm{in}} > p_{\\mathrm{out}}$', xy=(xlabel_block*100, label_loc1), 
             color='black', alpha=1, size=10)
        grid[i].annotate('$\phi_r > 0$', xy=(xlabel_block*100, label_loc2), 
             color='black', alpha=1, size=10)
        grid[i].set_ylabel('AUC', size = 10)
        grid[i].set_xlabel('Percent of Nodes Initially Labeled', size = 10)

pp = PdfPages('../../figures/oSBM_predictions.pdf')
pp.savefig()
pp.close()
from matplotlib.ticker import FixedLocator,LinearLocator,MultipleLocator, FormatStrFormatter

fig = plt.figure(figsize=(3.46457,2.5), dpi = 300)
seaborn.set_style(style='white')
from mpl_toolkits.axes_grid1 import Grid
grid = Grid(fig, rect=111, 
            nrows_ncols=(2,2),
            axes_pad=0.3, 
            label_mode='all')

y_max = 1.05
y_min = 0.3
x_max = 102
label_loc1 = 0.74
label_loc2 = 0.64
text_size = 8
axis_text = 8
tick_label_size = 7
xlabel_block = 0.63

elw = 3
cpt = 2

msize = 5
for i in range(4):
    if i == 0:
        grid[i].tick_params('both', length=4, width=1, which='major', left=1, bottom=1, top=0, right=0)
        grid[i].xaxis.set_major_locator(FixedLocator([0,25,50,75,100]))
        grid[i].yaxis.set_major_locator(FixedLocator([0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1]))

        grid[i].errorbar(percent_initially_labelled*100, mean_wt_auc_baseline_noBnoO, 
            yerr=se_wt_auc_baseline_noBnoO, fmt='--o', capthick=cpt,
                alpha=1, elinewidth=elw, color='gray',markersize=msize )
        grid[i].errorbar(percent_initially_labelled*100, mean_wt_auc_noBnoO, 
            yerr=se_wt_auc_noBnoO, fmt='--o', capthick=cpt,
            alpha=1, elinewidth=elw, color='black',markersize=msize )
        grid[i].errorbar(percent_initially_labelled*100, mean_wt_auc_zgl_noBnoO,
            yerr=se_wt_auc_zgl_noBnoO, fmt='--o', capthick=cpt,
            alpha=1, elinewidth=elw, color='orange',markersize=msize )
        grid[i].errorbar(percent_initially_labelled*100, mean_wt_auc_mv_noBnoO,
            yerr=se_wt_auc_mv_noBnoO, fmt='--o', capthick=cpt,
            alpha=1, elinewidth=elw, color='red',markersize=msize )
        grid[i].errorbar(percent_initially_labelled*100, mean_wt_auc_mv2_noBnoO, 
            yerr=se_wt_auc_mv2_noBnoO, fmt='--o', capthick=cpt,
                alpha=1, elinewidth=elw, color='maroon',markersize=msize )
        grid[i].set_xlim(0,x_max)
        grid[i].annotate('LINK', xy=(3, 0.99), 
                 color='black', alpha=1, size=text_size )
        grid[i].annotate('2-hop MV', xy=(3, 0.9), 
                 color='maroon', alpha=1, size=text_size)
        grid[i].annotate('1-hop MV', xy=(3, 0.9-0.09), 
                 color='red', alpha=1, size=text_size)
        grid[i].annotate('ZGL', xy=(3, 0.9-2*0.09), 
                 color='orange', alpha=1, size=text_size )
        grid[i].annotate('Baseline', xy=(3, 0.9-3*0.09), 
                 color='gray', alpha=1, size=text_size )
        grid[i].set_ylim(y_min,y_max)
        grid[i].spines['right'].set_visible(False)
        grid[i].spines['top'].set_visible(False)
        grid[i].tick_params(axis='both', which='major', labelsize=9)
        grid[i].tick_params(axis='both', which='minor', labelsize=9)
        grid[i].annotate('$p_{\\mathrm{in}} = p_{\\mathrm{out}}$', xy=(xlabel_block*100, label_loc1), 
             color='black', alpha=1, size=text_size)
        grid[i].annotate('$\phi_r = 0$', xy=(xlabel_block*100, label_loc2), 
             color='black', alpha=1, size=text_size)
        #grid[i].set_xlabel('Percent of Nodes Initially Labeled', size = axis_text)
        #grid[i].set_ylabel('AUC', size = axis_text)
        grid[i].tick_params(axis = 'both',
                            labelsize=tick_label_size)

    if i == 1:
        grid[i].tick_params('both', length=4, width=1, which='major', left=1, bottom=1, top=0, right=0)
        grid[i].xaxis.set_major_locator(FixedLocator([0,25,50,75,100]))
        grid[i].yaxis.set_major_locator(FixedLocator([0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1]))
        grid[i].errorbar(percent_initially_labelled*100, mean_wt_auc_baseline_noByesO, 
            yerr=se_wt_auc_baseline_noByesO, fmt='--o', capthick=cpt,
                alpha=1, elinewidth=elw, color='gray',markersize=msize )
        grid[i].errorbar(percent_initially_labelled*100, mean_wt_auc_noByesO, 
            yerr=se_wt_auc_noByesO, fmt='--o', capthick=cpt,
            alpha=1, elinewidth=elw, color='black',markersize=msize )
        grid[i].errorbar(percent_initially_labelled*100, mean_wt_auc_zgl_noByesO,
            yerr=se_wt_auc_zgl_noByesO, fmt='--o', capthick=cpt,
            alpha=1, elinewidth=elw, color='orange',markersize=msize )
        grid[i].errorbar(percent_initially_labelled*100, mean_wt_auc_mv_noByesO,
            yerr=se_wt_auc_mv_noByesO, fmt='--o', capthick=cpt,
            alpha=1, elinewidth=elw, color='red',markersize=msize )
        grid[i].errorbar(percent_initially_labelled*100, mean_wt_auc_mv2_noByesO, 
            yerr=se_wt_auc_mv2_noByesO, fmt='--o', capthick=cpt,
                alpha=1, elinewidth=elw, color='maroon',markersize=msize )
        grid[i].annotate('$p_{\\mathrm{in}} = p_{\\mathrm{out}}$', xy=(xlabel_block*100, label_loc1), 
             color='black', alpha=1, size=text_size)
        grid[i].annotate('$\phi_r > 0$', xy=(xlabel_block*100, label_loc2), 
             color='black', alpha=1, size=text_size)
        grid[i].set_ylim(y_min,y_max)
        grid[i].set_xlim(0,x_max)
        grid[i].spines['right'].set_visible(False)
        grid[i].spines['top'].set_visible(False)
        #grid[i].set_ylabel('AUC', size = 10)
        #grid[i].set_xlabel('Percent of Nodes Initially Labeled', size = 10)
        grid[i].tick_params(axis = 'both',
                            labelsize=tick_label_size)

    if i == 2:
        grid[i].tick_params('both', length=4, width=1, which='major', left=1, bottom=1, top=0, right=0)
        grid[i].xaxis.set_major_locator(FixedLocator([0,25,50,75,100]))
        grid[i].yaxis.set_major_locator(FixedLocator([0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1]))
        grid[i].errorbar(percent_initially_labelled*100, mean_wt_auc_baseline_yesBnoO, 
            yerr=se_wt_auc_baseline_yesBnoO, fmt='--o', capthick=cpt,
                alpha=1, elinewidth=elw, color='gray',markersize=msize )
        grid[i].errorbar(percent_initially_labelled*100, mean_wt_auc_yesBnoO, 
            yerr=se_wt_auc_yesBnoO, fmt='--o', capthick=cpt,
            alpha=1, elinewidth=elw, color='black',markersize=msize )
        grid[i].errorbar(percent_initially_labelled*100, mean_wt_auc_zgl_yesBnoO,
            yerr=se_wt_auc_zgl_yesBnoO, fmt='--o', capthick=cpt,
            alpha=1, elinewidth=elw, color='orange',markersize=msize )
        grid[i].errorbar(percent_initially_labelled*100, mean_wt_auc_mv_yesBnoO,
            yerr=se_wt_auc_mv_yesBnoO, fmt='--o', capthick=cpt,
            alpha=1, elinewidth=elw, color='red',markersize=msize )
        grid[i].errorbar(percent_initially_labelled*100, mean_wt_auc_mv2_yesBnoO, 
            yerr=se_wt_auc_mv2_yesBnoO, fmt='--o', capthick=cpt,
                alpha=1, elinewidth=elw, color='maroon',markersize=msize )
        grid[i].annotate('$p_{\\mathrm{in}} > p_{\\mathrm{out}}$', xy=(xlabel_block*100, label_loc1), 
             color='black', alpha=1, size=text_size)
        grid[i].annotate('$\phi_r = 0$', xy=(xlabel_block*100, label_loc2), 
             color='black', alpha=1, size=text_size)
        grid[i].set_ylim(y_min,y_max)
        grid[i].set_xlim(0,x_max)
        grid[i].spines['right'].set_visible(False)
        grid[i].spines['top'].set_visible(False)
        #grid[i].set_ylabel('AUC', size = 10)
        #grid[i].set_xlabel('Percent of Nodes Initially Labeled', size = 10)
        grid[i].tick_params(axis = 'both',
                            labelsize=tick_label_size)


    if i == 3:
        grid[i].tick_params('both', length=4, width=1, which='major', left=1, bottom=1, top=0, right=0)
        grid[i].xaxis.set_major_locator(FixedLocator([0,25,50,75,100]))
        grid[i].yaxis.set_major_locator(FixedLocator([0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1]))
        grid[i].errorbar(percent_initially_labelled*100, mean_wt_auc_baseline_yesByesO, 
            yerr=se_wt_auc_baseline_yesByesO, fmt='--o', capthick=cpt,
                alpha=1, elinewidth=elw, color='gray',markersize=msize )
        grid[i].errorbar(percent_initially_labelled*100, mean_wt_auc_yesByesO, 
            yerr=se_wt_auc_yesByesO, fmt='--o', capthick=cpt,
            alpha=1, elinewidth=elw, color='black',markersize=msize )
        grid[i].errorbar(percent_initially_labelled*100, mean_wt_auc_zgl_yesByesO,
            yerr=se_wt_auc_zgl_yesByesO, fmt='--o', capthick=cpt,
            alpha=1, elinewidth=elw, color='orange',markersize=msize )
        grid[i].errorbar(percent_initially_labelled*100, mean_wt_auc_mv_yesByesO,
            yerr=se_wt_auc_mv_yesByesO, fmt='--o', capthick=cpt,
            alpha=1, elinewidth=elw, color='red',markersize=msize )
        grid[i].errorbar(percent_initially_labelled*100, mean_wt_auc_mv2_yesByesO, 
            yerr=se_wt_auc_mv2_yesByesO, fmt='--o', capthick=cpt,
                alpha=1, elinewidth=elw, color='maroon',markersize=msize )
        grid[i].set_ylim(y_min,y_max)
        grid[i].set_xlim(0,x_max)
        grid[i].spines['right'].set_visible(False)
        grid[i].spines['top'].set_visible(False)
        grid[i].annotate('$p_{\\mathrm{in}} > p_{\\mathrm{out}}$', xy=(xlabel_block*100, label_loc1), 
             color='black', alpha=1, size=text_size)
        grid[i].annotate('$\phi_r > 0$', xy=(xlabel_block*100, label_loc2), 
             color='black', alpha=1, size=text_size)
        grid[i].tick_params(axis = 'both',
                            labelsize=tick_label_size)


        #grid[i].set_ylabel('AUC', size = 10)
        #grid[i].set_xlabel('Percent of Nodes Initially Labeled', size = 10)
plt.text(-85.5, 0.05, 'Percent of Nodes Initially Labeled', 
         fontsize=axis_text)
plt.text(-155, 1.25, 'AUC', 
         fontsize=axis_text,
        rotation = 'vertical')        
plt.tight_layout()


pp = PdfPages('../../figures/oSBM_predictions_SINGLE_COLUMN.pdf')
pp.savefig(dpi = 300)
pp.close()
from matplotlib.ticker import FixedLocator,LinearLocator,MultipleLocator, FormatStrFormatter

fig = plt.figure(figsize=(6.69291,5.1), dpi = 300)
seaborn.set_style(style='white')
from mpl_toolkits.axes_grid1 import Grid
grid = Grid(fig, rect=111, 
            nrows_ncols=(2,2),
            axes_pad=0.55, 
            label_mode='all')

y_max = 1.05
y_min = 0.3
x_max = 102
label_loc1 = 0.74
label_loc2 = label_loc1-0.06
text_size = 11
axis_text = 10.5
tick_label_size = 9.5
xlabel_block = 0.63

msize = 6
for i in range(4):
    if i == 0:
        grid[i].tick_params('both', length=4, width=1, which='major', left=1, bottom=1, top=0, right=0)
        grid[i].xaxis.set_major_locator(FixedLocator([0,25,50,75,100]))
        grid[i].yaxis.set_major_locator(FixedLocator([0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1]))

        grid[i].errorbar(percent_initially_labelled*100, mean_wt_auc_baseline_noBnoO, 
            yerr=se_wt_auc_baseline_noBnoO, fmt='--o', capthick=2,
                alpha=1, elinewidth=3, color='gray',markersize=msize )
        grid[i].errorbar(percent_initially_labelled*100, mean_wt_auc_noBnoO, 
            yerr=se_wt_auc_noBnoO, fmt='--o', capthick=2,
            alpha=1, elinewidth=3, color='black',markersize=msize )
        grid[i].errorbar(percent_initially_labelled*100, mean_wt_auc_zgl_noBnoO,
            yerr=se_wt_auc_zgl_noBnoO, fmt='--o', capthick=2,
            alpha=1, elinewidth=3, color='orange',markersize=msize )
        grid[i].errorbar(percent_initially_labelled*100, mean_wt_auc_mv_noBnoO,
            yerr=se_wt_auc_mv_noBnoO, fmt='--o', capthick=2,
            alpha=1, elinewidth=3, color='red',markersize=msize )
        grid[i].errorbar(percent_initially_labelled*100, mean_wt_auc_mv2_noBnoO, 
            yerr=se_wt_auc_mv2_noBnoO, fmt='--o', capthick=2,
                alpha=1, elinewidth=3, color='maroon',markersize=msize )
        grid[i].set_xlim(0,x_max)
        grid[i].annotate('LINK', xy=(3, 0.99), 
                 color='black', alpha=1, size=text_size)
        grid[i].annotate('2-hop MV', xy=(3, 0.93), 
                 color='maroon', alpha=1, size=text_size)
        grid[i].annotate('1-hop MV', xy=(3, 0.93-0.06), 
                 color='red', alpha=1, size=text_size)
        grid[i].annotate('ZGL', xy=(3, 0.93-2*0.06), 
                 color='orange', alpha=1, size=text_size)
        grid[i].annotate('Baseline', xy=(3, 0.93-3*0.06), 
                 color='gray', alpha=1, size=text_size)
        grid[i].set_ylim(y_min,y_max)
        grid[i].spines['right'].set_visible(False)
        grid[i].spines['top'].set_visible(False)
        grid[i].tick_params(axis='both', which='major', labelsize=9)
        grid[i].tick_params(axis='both', which='minor', labelsize=9)
        grid[i].annotate('$p_{\\mathrm{in}} = p_{\\mathrm{out}}$', xy=(xlabel_block*100, label_loc1), 
             color='black', alpha=1, size=text_size)
        grid[i].annotate('$\phi_r = 0$', xy=(xlabel_block*100, label_loc2), 
             color='black', alpha=1, size=text_size)
        #grid[i].set_xlabel('Percent of Nodes Initially Labeled', size = axis_text)
        #grid[i].set_ylabel('AUC', size = axis_text)
        grid[i].tick_params(axis = 'both',
                            labelsize=tick_label_size)

    if i == 1:
        grid[i].tick_params('both', length=4, width=1, which='major', left=1, bottom=1, top=0, right=0)
        grid[i].xaxis.set_major_locator(FixedLocator([0,25,50,75,100]))
        grid[i].yaxis.set_major_locator(FixedLocator([0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1]))
        grid[i].errorbar(percent_initially_labelled*100, mean_wt_auc_baseline_noByesO, 
            yerr=se_wt_auc_baseline_noByesO, fmt='--o', capthick=2,
                alpha=1, elinewidth=3, color='gray',markersize=msize )
        grid[i].errorbar(percent_initially_labelled*100, mean_wt_auc_noByesO, 
            yerr=se_wt_auc_noByesO, fmt='--o', capthick=2,
            alpha=1, elinewidth=3, color='black',markersize=msize )
        grid[i].errorbar(percent_initially_labelled*100, mean_wt_auc_zgl_noByesO,
            yerr=se_wt_auc_zgl_noByesO, fmt='--o', capthick=2,
            alpha=1, elinewidth=3, color='orange',markersize=msize )
        grid[i].errorbar(percent_initially_labelled*100, mean_wt_auc_mv_noByesO,
            yerr=se_wt_auc_mv_noByesO, fmt='--o', capthick=2,
            alpha=1, elinewidth=3, color='red',markersize=msize )
        grid[i].errorbar(percent_initially_labelled*100, mean_wt_auc_mv2_noByesO, 
            yerr=se_wt_auc_mv2_noByesO, fmt='--o', capthick=2,
                alpha=1, elinewidth=3, color='maroon',markersize=msize )
        grid[i].annotate('$p_{\\mathrm{in}} = p_{\\mathrm{out}}$', xy=(xlabel_block*100, label_loc1), 
             color='black', alpha=1, size=text_size)
        grid[i].annotate('$\phi_r > 0$', xy=(xlabel_block*100, label_loc2), 
             color='black', alpha=1, size=text_size)
        grid[i].set_ylim(y_min,y_max)
        grid[i].set_xlim(0,x_max)
        grid[i].spines['right'].set_visible(False)
        grid[i].spines['top'].set_visible(False)
        #grid[i].set_ylabel('AUC', size = 10)
        #grid[i].set_xlabel('Percent of Nodes Initially Labeled', size = 10)
        grid[i].tick_params(axis = 'both',
                            labelsize=tick_label_size)

    if i == 2:
        grid[i].tick_params('both', length=4, width=1, which='major', left=1, bottom=1, top=0, right=0)
        grid[i].xaxis.set_major_locator(FixedLocator([0,25,50,75,100]))
        grid[i].yaxis.set_major_locator(FixedLocator([0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1]))
        grid[i].errorbar(percent_initially_labelled*100, mean_wt_auc_baseline_yesBnoO, 
            yerr=se_wt_auc_baseline_yesBnoO, fmt='--o', capthick=2,
                alpha=1, elinewidth=3, color='gray',markersize=msize )
        grid[i].errorbar(percent_initially_labelled*100, mean_wt_auc_yesBnoO, 
            yerr=se_wt_auc_yesBnoO, fmt='--o', capthick=2,
            alpha=1, elinewidth=3, color='black',markersize=msize )
        grid[i].errorbar(percent_initially_labelled*100, mean_wt_auc_zgl_yesBnoO,
            yerr=se_wt_auc_zgl_yesBnoO, fmt='--o', capthick=2,
            alpha=1, elinewidth=3, color='orange',markersize=msize )
        grid[i].errorbar(percent_initially_labelled*100, mean_wt_auc_mv_yesBnoO,
            yerr=se_wt_auc_mv_yesBnoO, fmt='--o', capthick=2,
            alpha=1, elinewidth=3, color='red',markersize=msize )
        grid[i].errorbar(percent_initially_labelled*100, mean_wt_auc_mv2_yesBnoO, 
            yerr=se_wt_auc_mv2_yesBnoO, fmt='--o', capthick=2,
                alpha=1, elinewidth=3, color='maroon',markersize=msize )
        grid[i].annotate('$p_{\\mathrm{in}} > p_{\\mathrm{out}}$', xy=(xlabel_block*100, label_loc1), 
             color='black', alpha=1, size=text_size)
        grid[i].annotate('$\phi_r = 0$', xy=(xlabel_block*100, label_loc2), 
             color='black', alpha=1, size=text_size)
        grid[i].set_ylim(y_min,y_max)
        grid[i].set_xlim(0,x_max)
        grid[i].spines['right'].set_visible(False)
        grid[i].spines['top'].set_visible(False)
        #grid[i].set_ylabel('AUC', size = 10)
        #grid[i].set_xlabel('Percent of Nodes Initially Labeled', size = 10)
        grid[i].tick_params(axis = 'both',
                            labelsize=tick_label_size)


    if i == 3:
        grid[i].tick_params('both', length=4, width=1, which='major', left=1, bottom=1, top=0, right=0)
        grid[i].xaxis.set_major_locator(FixedLocator([0,25,50,75,100]))
        grid[i].yaxis.set_major_locator(FixedLocator([0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1]))
        grid[i].errorbar(percent_initially_labelled*100, mean_wt_auc_baseline_yesByesO, 
            yerr=se_wt_auc_baseline_yesByesO, fmt='--o', capthick=2,
                alpha=1, elinewidth=3, color='gray',markersize=msize )
        grid[i].errorbar(percent_initially_labelled*100, mean_wt_auc_yesByesO, 
            yerr=se_wt_auc_yesByesO, fmt='--o', capthick=2,
            alpha=1, elinewidth=3, color='black',markersize=msize )
        grid[i].errorbar(percent_initially_labelled*100, mean_wt_auc_zgl_yesByesO,
            yerr=se_wt_auc_zgl_yesByesO, fmt='--o', capthick=2,
            alpha=1, elinewidth=3, color='orange',markersize=msize )
        grid[i].errorbar(percent_initially_labelled*100, mean_wt_auc_mv_yesByesO,
            yerr=se_wt_auc_mv_yesByesO, fmt='--o', capthick=2,
            alpha=1, elinewidth=3, color='red',markersize=msize )
        grid[i].errorbar(percent_initially_labelled*100, mean_wt_auc_mv2_yesByesO, 
            yerr=se_wt_auc_mv2_yesByesO, fmt='--o', capthick=2,
                alpha=1, elinewidth=3, color='maroon',markersize=msize )
        grid[i].set_ylim(y_min,y_max)
        grid[i].set_xlim(0,x_max)
        grid[i].spines['right'].set_visible(False)
        grid[i].spines['top'].set_visible(False)
        grid[i].annotate('$p_{\\mathrm{in}} > p_{\\mathrm{out}}$', xy=(xlabel_block*100, label_loc1), 
             color='black', alpha=1, size=text_size)
        grid[i].annotate('$\phi_r > 0$', xy=(xlabel_block*100, label_loc2), 
             color='black', alpha=1, size=text_size)
        grid[i].tick_params(axis = 'both',
                            labelsize=tick_label_size)


        #grid[i].set_ylabel('AUC', size = 10)
        #grid[i].set_xlabel('Percent of Nodes Initially Labeled', size = 10)
plt.text(-50, 0.18, 'Percent of Nodes Initially Labeled', 
         fontsize=axis_text)
plt.text(-136, 1.15, 'AUC', 
         fontsize=axis_text,
        rotation = 'vertical')        
plt.tight_layout()


pp = PdfPages('../../figures/oSBM_predictions_DOUBLE_COLUMN.pdf')
pp.savefig(dpi = 300)
pp.close()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13973661383171673, 'fraction_numerical': 0.03727361143968667, 'mean_word_length': 2.377291490967198, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 67, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 208, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '12', 'dir': 'jupyter-structured-clean-dedup', 'id': '231103', 'license': 'MIT', 'n_tokens_mistral': 29282, 'n_tokens_neox': 27581, 'n_words': 3460, 'path': 'code/0_oSBM/a_create_oSBM.ipynb', 'repo_name': 'kaltenburger/homophily_monophily_NHB', 'size': '76086'}