where $D$ is the diagonal degree matrix with entries equal to the degree $\deg(i)$ of vertex $i$. Notice that
\begin{equation} N_{ij} = \left\{ \begin{array}{lr} \frac{1}{\deg(i)}, & {\mbox{ whenever }} i \sim j, \\ 0, & {\mbox{ otherwise, }} \end{array} \right. \end{equation}where $I$ is the unit matrix, i.e., as \begin{equation} L_{ij} = \left{ \begin{array}{lr} \deg(i), & {\mbox{ whenever }} i = j, \ -1, & {\mbox{ whenever }} i \sim j, \ 0, & {\mbox{ otherwise. }} \end{array} \right. \end{equation}
To solve this problem one needs to first consider the problem for the rate of opinion change at the unit time step, i.e.,
\begin{equation} u^t = v^t - v^{t - 1}, \end{equation}which can be easily transformed to the following linear parabolic IBVP with Dirichlet boundary conditions:
\begin{eqnarray} w^{t + 1} &=& S \, (I - \mathcal{L}) \, w^t, {\mbox{ in }} \Omega, t > 0, \\ w^t &=& 0, {\mbox{ on }} \delta \Omega, t > 0, \\ w^1 &=& \left\{ \begin{array}{lr} D^{1/2} \, S \, (N - I) \, \phi, & {\mbox{ in }} \Omega, \\ 0, & {\mbox{ on }} \delta \Omega, \end{array} \right. \end{eqnarray}where $\mathcal{L}$ is the symmetric normalized Laplacian operator.
Thus, spectral graph theory implies the existence of a unique solution $v^t = v^t(s,\phi)$, which may be expressed in terms of the $s$-dependent Dirichlet heat kernel:
\begin{equation} \mathcal{H}_t^s = (S \, (I - \mathcal{L}))^{t - 1}, t > 1. \end{equation}Apparently, $S = I$ reduces the IBVP of social influence to the difusion/heat equation.
After some standard transformations, the corresponsing stationary problem is easily seen to be (of the form):
\begin{eqnarray} \big(I - S \, (I - \mathcal{L} \big) \, \overline{w} &=& S \, D^{-1/2} \, (N - I) \, \phi, {\mbox{ in }} \Omega, \\ \overline{w} &=& 0, {\mbox{ on }} \delta \Omega, \end{eqnarray}which is an elliptic BVP with Dirichlet boundary conditions.
Again, spectral graph theory guarantees the existence of a unique steady state solution $\overline{v} = \overline{v}(s,\phi)$, which can be expressed in terms of the $s$--dependent Green function:
\begin{equation} \mathcal{G}^s = \big(I - S \, (I - \mathcal{L})\big)^{-1}, \end{equation}Again, when $S = I$, the BVP of social influence is reduced to the Laplace/Poison equation.
is called matrix of influentiability of $G$.
I. The index of influence-out-degree centrality of person $i$: \begin{equation} c{influence-out-degree}(i) = \frac{1}{n - 1} \, \sum{j \in [n], j \sim i} \mathcal{U}^{\infty}_{i, j}. \end{equation}
The index of influence-out-degree centrality of person $i$ determines the normalized cumulative volume of opinion broadcasting that $i$ broadcasts to all her neighbors, when $i$ is the single (exclusive) source of opinion transmission. Apparently, this index depends only on the vector of susceptibility coefficients $s$, i.e., $c_{influence-out-degree}(i) = c_{influence-out-degree}^{s}(i)$ in such a way that:
\begin{equation} 0 = c_{influence-out-degree}^{0}(i) \leq c_{influence-out-degree}^{s}(i) \leq c_{influence-out-degree}^{1}(i) = c_{degree}(i), \end{equation}where the last term in the previous inequality would be the index of out-degree centrality of person/vertex $i$.
II. The index of influence-in-degree centrality of person $i$: \begin{equation} c{influence-in-degree}(i) = \frac{1}{n - 1} \, \sum{j \in [n], j \sim i} \mathcal{U}^{\infty}_{j, i}. \end{equation}
The index of influence-in-degree centrality of person $i$ determines the normalized cumulative volume of opinion reception that can be delivered cumulatively to $i$ from all her neighbors, each time a neighbor of $i$ is a source opinion transmission. Apparently, this index depends only on the vector of susceptibility coefficients $s$, i.e., $c_{influence-in-degree}(i) = c_{influence-out-degree}^{s}(i)$ in such a way that:
\begin{equation} c_{degree}(i) = c_{influence-in-degree}^{0}(i) \leq c_{influence-in-degree}^{s}(i) \leq c_{influence-in-degree}^{1}(i) = 1. \end{equation}Notice that if the above social influence model was reformulated in such a way that it could be applicable to directed graphs too, the first term in the previous inequality would be the index of in-degree centrality of person/vertex $i$.
%matplotlib inline
%load_ext autoreload
import networkx as nx
import pandas as pd
import numpy as np
from numpy import linalg
from numpy.linalg import inv
from scipy.linalg import eigvalsh
from datetime import datetime
from lightning import Lightning
import create_imgtex as crim
import seaborn as sns
from scipy import stats
import os
import random
# !pip install --user tabulate
%autoreload 2
from chAs import *
import chAs as ca
import steady_utils as su
import influence as infl
# n=10
# p=.3
# G=ca.create_conn_random_graph(n,p)
# source = [G.nodes()[0]]
# name = 'A connected Random-Renyi graph with %i nodes and probability %f' %(n,p)
# G=nx.petersen_graph()
# name = 'Petersen Graph'
# n=10
# G=nx.complete_graph(n)
# name = 'Complete Graph of %i nodes' %n
G=nx.karate_club_graph()
name = 'Karate Club Network'
# G=nx.florentine_families_graph()
# gnod={}
# for i,nd in enumerate(G.nodes()):
# gnod[nd]=i
# G=nx.relabel_nodes(G,gnod)
# print G.nodes()
# print gnod
# name = 'Florentine Families Network'
# G=nx.krackhardt_kite_graph()
# name = 'Krackhardt Kite Network'
n=len(G.nodes())
p=0
source = [G.nodes()[0]]
degrc=nx.degree_centrality(G)
closc=nx.closeness_centrality(G)
labels={}
llabels={}
lllabels={}
noodd={}
groups={}
for i,nd in enumerate(G.nodes()):
noodd[nd]=i
labels[i]='id = %s, deg_cent = %.4f, clos_cent = %4f' %(nd,degrc[nd],closc[nd]) #degggss[nd],closs[nd])
llabels[i]='id = %s, %s' %(nd,nx.neighbors(G,nd))
lllabels[i]='id = %s, %s, deg_cent = %.4f, clos_cent = %4f' %(nd,nx.neighbors(G,nd),degrc[nd],closc[nd]) #degggss[nd],closs[nd])
if nd in source:
groups[i]=1
elif nd not in source:
groups[i]=2
lali=[]
grouli=[]
nlali=[]
nnlali=[]
for v in G.nodes():
lali.append(labels[noodd[v]])
nlali.append(llabels[noodd[v]])
nnlali.append(lllabels[noodd[v]])
grouli.append(groups[noodd[v]])
edgess=[]
for edg in G.edges():
edgess.append([noodd[edg[0]],noodd[edg[1]]])
lgn = Lightning(ipython=True,local=True,size='large') # local vis
# lgn = Lightning(ipython=True, host='http://public.lightning-viz.org',size='full') # vis at server
# NODE COLORS
# 1. To use different colors for each country, set "group=grouli" below
# 1. To use different colors for type of node (officer, intermediary, entity, address), set "group=None" below
vis=lgn.force(conn=edgess, values=None, labels=nnlali, color=None, group=grouli, colormap=None, size=None, tooltips=True,
width=1200, brush=True,zoom=True, height=None)#,
# To display in locally, use the first command and to display it online the second:
print '%s' %name
vis # local vis
from influence import influence_sim_dh_F_J_mu
iterations=1000
fjfun='ssa*Xnei+(1-ssa)*y_orig[nd]'
sa=1
source_u=[1]
su=0
susc={}
n=len(G.nodes())
rs=random.random()
for i in range(n):
susc[i]=rs
# susc = {key: 1 for key in range(len(G.nodes()))}
# if i <= n/2-1:
# susc[i] = 0.05
# else:
# susc[i] = 0.95
set(susc.values())
sasd={}
for ii in G.nodes():
if ii == source[0]:
sasd[ii]=0
else:
sasd[ii]=susc[ii]
F,nodds,source,y_orig,final_d,no_zeros=influence_sim_dh_F_J_mu(n,p,iterations,G=G,scale=1000,
new_old=True,source = source,source_u=source_u,su=su,h=0.3,funcion=fjfun,
insrplot=False,no_change=False,
ssas_d=sasd,ax3ylim=(0.,1),ax4ylin=(0.,1))
%autoreload 2
from chAs import synthetic_multi_level_bip_dic
from steady_utils import steady_sols_calc_multi,steady_sols_calc_multi_one,steady_sols_calc_multi_one_cut
k=1
n=[n]
p=[p]
sas=susc #degrc #degggss
dic_of_Graphs_final={(0,0):G}
edgelist=G.edges()
try:
os.stat('out')
except:
os.mkdir('out')
os.chdir('out')
G,list_ofNod,steady_sols_dict,dic_of_nodes_multi,ssas_ds,no_iterations_dict,no_zero_time_dict,no_zero_val_dict,comparison_dict,steady_sols_dict_t=steady_sols_calc_multi_one_cut(k,G,dic_of_Graphs_final,n,p,sas,
edgelist,iterations,fjfun,precision=.3,sa_u=0,source_u=[1.],su=1.,h=1.,form_float_val=6,form_float_val_stead=6)
data_s=crim.create_tex_tabul(G,list_ofNod,steady_sols_dict,dic_of_nodes_multi,outfile_name='stead_sols.tex')
crim.create_heat_maps_sea_s(G,list_ofNod,steady_sols_dict,dic_of_nodes_multi,ssas_ds,data_s,vm_s='stead_sols',outfile_name='3d.png',annot=False)
data_s=crim.create_tex_tabul(G,list_ofNod,no_iterations_dict,dic_of_nodes_multi,outfile_name='NoofIterations.tex')
data_s=crim.create_tex_tabul(G,list_ofNod,no_zero_time_dict,dic_of_nodes_multi,outfile_name='NoofZeroTime.tex')
data_s=crim.create_tex_tabul(G,list_ofNod,no_zero_val_dict,dic_of_nodes_multi,outfile_name='NoofZeroVal.tex')
crim.create_tex_tabul(G,list_ofNod,comparison_dict,dic_of_nodes_multi,outfile_name='Compare_NS_S.tex')
tem_dici,dici_tem= crim.create_tex_sum_steady(G,list_ofNod,steady_sols_dict_t,dic_of_nodes_multi,outfile_name='inOut.tex')
crim.create_tex_sum_steady_sub(G,k,list_ofNod,steady_sols_dict_t,dic_of_nodes_multi,outfile_name='inOut_sub.tex')
cent_dict=crim.create_tex_sum_central(G,tem_dici,dici_tem,dic_of_nodes_multi,outfile_name='scent_out.tex')
idici_tem,item_dici,odici_tem,otem_dici=crim.create_inf_nei_clos(G,list_ofNod,steady_sols_dict_t,dic_of_nodes_multi)
dinf_cinf_d=crim.create_dinf_tex(G,idici_tem,item_dici,odici_tem,otem_dici,list_ofNod,sas,ssas_ds)
def calc_centralization(dat_fr,col):
mono=0
dmax=max(dat_fr)
for i in dat_fr:
mono+=dmax-i
return mono/len(dat_fr)
dinf_cinf_data=pd.DataFrame(dinf_cinf_d,columns=['Node','Influence-In-Degree','Influence-Out-Degree','In-CINF','OB_Closeness_CI','Degree','Closeness'])
columns=['Degree' , 'Closeness','Influence-In-Degree', 'Influence-Out-Degree']
ndir=dinf_cinf_data[columns]
def corrfunc(x, y, **kws):
r, _ = stats.pearsonr(x, y)
ax = plt.gca()
ax.annotate("r = {:.3f}".format(r),
xy=(.1, .9), xycoords=ax.transAxes)
nel=len(columns)
g = sns.PairGrid(ndir)#, vars=columns)#,size=4)#,hue='Layer',size=4)#,palette="Set2",hue_kws={"marker": ["o", "s", "D"]})
g.map_upper(plt.scatter)#,color='grey')
g.map_diag(plt.hist)
g.map_lower(plt.scatter)#,color='grey')
g.map_lower(corrfunc)
iod = ndir['Influence-Out-Degree'].tolist()
iid = ndir['Influence-In-Degree'].tolist()
# for i in range(len(G.nodes())):
# print 'dc = %.4f, cc = %.4f, iod = %.4f, iid = %.4f' %(degggss[i],closs[i],iod[i],iid[i])
cdf=pd.DataFrame.from_items([('Nodes',degrc.keys()),('Degree Centrality',degrc.values()),
('Closeness Centrality',closc.values()),
('Influence-Out-Degree Centrality', iod),
('Influence-In-Degree Centrality', iid)])
cdf#.head()
susc={}
for i in range(len(G.nodes())):
susc[i]=random.random()
susc
sasd={}
for ii in G.nodes():
if ii == source[0]:
sasd[ii]=0
else:
sasd[ii]=susc[ii]
F,nodds,source,y_orig,final_d,no_zeros=influence_sim_dh_F_J_mu(n,p,iterations,G=G,scale=1000,
new_old=True,source = source,source_u=source_u,su=su,h=0.3,funcion=fjfun,
insrplot=False,no_change=False,
ssas_d=sasd,ax3ylim=(0.,1),ax4ylin=(0.,1))
%autoreload 2
from chAs import synthetic_multi_level_bip_dic
from steady_utils import steady_sols_calc_multi,steady_sols_calc_multi_one,steady_sols_calc_multi_one_cut
k=1
n=[n]
p=[p]
sas=susc #degrc #degggss
dic_of_Graphs_final={(0,0):G}
edgelist=G.edges()
try:
os.stat('out')
except:
os.mkdir('out')
os.chdir('out')
G,list_ofNod,steady_sols_dict,dic_of_nodes_multi,ssas_ds,no_iterations_dict,no_zero_time_dict,no_zero_val_dict,comparison_dict,steady_sols_dict_t=steady_sols_calc_multi_one_cut(k,G,dic_of_Graphs_final,n,p,sas,
edgelist,iterations,fjfun,precision=.3,sa_u=0,source_u=[1.],su=1.,h=1.,form_float_val=6,form_float_val_stead=6)
data_s=crim.create_tex_tabul(G,list_ofNod,steady_sols_dict,dic_of_nodes_multi,outfile_name='stead_sols.tex')
crim.create_heat_maps_sea_s(G,list_ofNod,steady_sols_dict,dic_of_nodes_multi,ssas_ds,data_s,vm_s='stead_sols',outfile_name='3d.png',annot=False)
data_s=crim.create_tex_tabul(G,list_ofNod,no_iterations_dict,dic_of_nodes_multi,outfile_name='NoofIterations.tex')
data_s=crim.create_tex_tabul(G,list_ofNod,no_zero_time_dict,dic_of_nodes_multi,outfile_name='NoofZeroTime.tex')
data_s=crim.create_tex_tabul(G,list_ofNod,no_zero_val_dict,dic_of_nodes_multi,outfile_name='NoofZeroVal.tex')
crim.create_tex_tabul(G,list_ofNod,comparison_dict,dic_of_nodes_multi,outfile_name='Compare_NS_S.tex')
tem_dici,dici_tem= crim.create_tex_sum_steady(G,list_ofNod,steady_sols_dict_t,dic_of_nodes_multi,outfile_name='inOut.tex')
crim.create_tex_sum_steady_sub(G,k,list_ofNod,steady_sols_dict_t,dic_of_nodes_multi,outfile_name='inOut_sub.tex')
cent_dict=crim.create_tex_sum_central(G,tem_dici,dici_tem,dic_of_nodes_multi,outfile_name='scent_out.tex')
idici_tem,item_dici,odici_tem,otem_dici=crim.create_inf_nei_clos(G,list_ofNod,steady_sols_dict_t,dic_of_nodes_multi)
dinf_cinf_d=crim.create_dinf_tex(G,idici_tem,item_dici,odici_tem,otem_dici,list_ofNod,sas,ssas_ds)
def calc_centralization(dat_fr,col):
mono=0
dmax=max(dat_fr)
for i in dat_fr:
mono+=dmax-i
return mono/len(dat_fr)
dinf_cinf_data=pd.DataFrame(dinf_cinf_d,columns=['Node','Influence-In-Degree', 'Influence-Out-Degree' , 'In-CINF' , 'OB_Closeness_CI' ,'Degree' , 'Closeness'])
columns=['Degree' , 'Closeness','Influence-In-Degree', 'Influence-Out-Degree']
ndir=dinf_cinf_data[columns]
def corrfunc(x, y, **kws):
r, _ = stats.pearsonr(x, y)
ax = plt.gca()
ax.annotate("r = {:.3f}".format(r),
xy=(.1, .9), xycoords=ax.transAxes)
nel=len(columns)
g = sns.PairGrid(ndir)#, vars=columns)#,size=4)#,hue='Layer',size=4)#,palette="Set2",hue_kws={"marker": ["o", "s", "D"]})
g.map_upper(plt.scatter)#,color='grey')
g.map_diag(plt.hist)
g.map_lower(plt.scatter)#,color='grey')
g.map_lower(corrfunc)
iod = ndir['Influence-Out-Degree'].tolist()
iid = ndir['Influence-In-Degree'].tolist()
# for i in range(len(G.nodes())):
# print 'dc = %.4f, cc = %.4f, iod = %.4f, iid = %.4f' %(degggss[i],closs[i],iod[i],iid[i])
cdf=pd.DataFrame.from_items([('Nodes',degrc.keys()),('Degree Centrality',degrc.values()),
('Closeness Centrality',closc.values()),
('Influence-Out-Degree Centrality', iod),
('Influence-In-Degree Centrality', iid)])
cdf#.head()
susc=degrc
susc
sasd={}
for ii in G.nodes():
if ii == source[0]:
sasd[ii]=0
else:
sasd[ii]=susc[ii]
F,nodds,source,y_orig,final_d,no_zeros=influence_sim_dh_F_J_mu(n,p,iterations,G=G,scale=1000,
new_old=True,source = source,source_u=source_u,su=su,h=0.3,funcion=fjfun,
insrplot=False,no_change=False,
ssas_d=sasd,ax3ylim=(0.,1),ax4ylin=(0.,1))
%autoreload 2
from chAs import synthetic_multi_level_bip_dic
from steady_utils import steady_sols_calc_multi,steady_sols_calc_multi_one,steady_sols_calc_multi_one_cut
k=1
n=[n]
p=[p]
sas=susc #degrc #degggss
dic_of_Graphs_final={(0,0):G}
edgelist=G.edges()
try:
os.stat('out')
except:
os.mkdir('out')
os.chdir('out')
G,list_ofNod,steady_sols_dict,dic_of_nodes_multi,ssas_ds,no_iterations_dict,no_zero_time_dict,no_zero_val_dict,comparison_dict,steady_sols_dict_t=steady_sols_calc_multi_one_cut(k,G,dic_of_Graphs_final,n,p,sas,
edgelist,iterations,fjfun,precision=.3,sa_u=0,source_u=[1.],su=1.,h=1.,form_float_val=6,form_float_val_stead=6)
data_s=crim.create_tex_tabul(G,list_ofNod,steady_sols_dict,dic_of_nodes_multi,outfile_name='stead_sols.tex')
crim.create_heat_maps_sea_s(G,list_ofNod,steady_sols_dict,dic_of_nodes_multi,ssas_ds,data_s,vm_s='stead_sols',outfile_name='3d.png',annot=False)
data_s=crim.create_tex_tabul(G,list_ofNod,no_iterations_dict,dic_of_nodes_multi,outfile_name='NoofIterations.tex')
data_s=crim.create_tex_tabul(G,list_ofNod,no_zero_time_dict,dic_of_nodes_multi,outfile_name='NoofZeroTime.tex')
data_s=crim.create_tex_tabul(G,list_ofNod,no_zero_val_dict,dic_of_nodes_multi,outfile_name='NoofZeroVal.tex')
crim.create_tex_tabul(G,list_ofNod,comparison_dict,dic_of_nodes_multi,outfile_name='Compare_NS_S.tex')
tem_dici,dici_tem= crim.create_tex_sum_steady(G,list_ofNod,steady_sols_dict_t,dic_of_nodes_multi,outfile_name='inOut.tex')
crim.create_tex_sum_steady_sub(G,k,list_ofNod,steady_sols_dict_t,dic_of_nodes_multi,outfile_name='inOut_sub.tex')
cent_dict=crim.create_tex_sum_central(G,tem_dici,dici_tem,dic_of_nodes_multi,outfile_name='scent_out.tex')
idici_tem,item_dici,odici_tem,otem_dici=crim.create_inf_nei_clos(G,list_ofNod,steady_sols_dict_t,dic_of_nodes_multi)
dinf_cinf_d=crim.create_dinf_tex(G,idici_tem,item_dici,odici_tem,otem_dici,list_ofNod,sas,ssas_ds)
def calc_centralization(dat_fr,col):
mono=0
dmax=max(dat_fr)
for i in dat_fr:
mono+=dmax-i
return mono/len(dat_fr)
dinf_cinf_data=pd.DataFrame(dinf_cinf_d,columns=['Node','Influence-In-Degree', 'Influence-Out-Degree' , 'In-CINF' , 'OB_Closeness_CI' ,'Degree' , 'Closeness'])
columns=['Degree' , 'Closeness','Influence-In-Degree', 'Influence-Out-Degree']
ndir=dinf_cinf_data[columns]
def corrfunc(x, y, **kws):
r, _ = stats.pearsonr(x, y)
ax = plt.gca()
ax.annotate("r = {:.3f}".format(r),
xy=(.1, .9), xycoords=ax.transAxes)
nel=len(columns)
g = sns.PairGrid(ndir)#, vars=columns)#,size=4)#,hue='Layer',size=4)#,palette="Set2",hue_kws={"marker": ["o", "s", "D"]})
g.map_upper(plt.scatter)#,color='grey')
g.map_diag(plt.hist)
g.map_lower(plt.scatter)#,color='grey')
g.map_lower(corrfunc)
iod = ndir['Influence-Out-Degree'].tolist()
iid = ndir['Influence-In-Degree'].tolist()
# for i in range(len(G.nodes())):
# print 'dc = %.4f, cc = %.4f, iod = %.4f, iid = %.4f' %(degggss[i],closs[i],iod[i],iid[i])
cdf=pd.DataFrame.from_items([('Nodes',degrc.keys()),('Degree Centrality',degrc.values()),
('Closeness Centrality',closc.values()),
('Influence-Out-Degree Centrality', iod),
('Influence-In-Degree Centrality', iid)])
cdf#.head()
susc=closc
susc
sasd={}
for ii in G.nodes():
if ii == source[0]:
sasd[ii]=0
else:
sasd[ii]=susc[ii]
F,nodds,source,y_orig,final_d,no_zeros=influence_sim_dh_F_J_mu(n,p,iterations,G=G,scale=1000,
new_old=True,source = source,source_u=source_u,su=su,h=0.3,funcion=fjfun,
insrplot=False,no_change=False,
ssas_d=sasd,ax3ylim=(0.,1),ax4ylin=(0.,1))
%autoreload 2
from chAs import synthetic_multi_level_bip_dic
from steady_utils import steady_sols_calc_multi,steady_sols_calc_multi_one,steady_sols_calc_multi_one_cut
k=1
n=[n]
p=[p]
sas=susc #degrc #degggss
dic_of_Graphs_final={(0,0):G}
edgelist=G.edges()
try:
os.stat('out')
except:
os.mkdir('out')
os.chdir('out')
G,list_ofNod,steady_sols_dict,dic_of_nodes_multi,ssas_ds,no_iterations_dict,no_zero_time_dict,no_zero_val_dict,comparison_dict,steady_sols_dict_t=steady_sols_calc_multi_one_cut(k,G,dic_of_Graphs_final,n,p,sas,
edgelist,iterations,fjfun,precision=.3,sa_u=0,source_u=[1.],su=1.,h=1.,form_float_val=6,form_float_val_stead=6)
data_s=crim.create_tex_tabul(G,list_ofNod,steady_sols_dict,dic_of_nodes_multi,outfile_name='stead_sols.tex')
crim.create_heat_maps_sea_s(G,list_ofNod,steady_sols_dict,dic_of_nodes_multi,ssas_ds,data_s,vm_s='stead_sols',outfile_name='3d.png',annot=False)
data_s=crim.create_tex_tabul(G,list_ofNod,no_iterations_dict,dic_of_nodes_multi,outfile_name='NoofIterations.tex')
data_s=crim.create_tex_tabul(G,list_ofNod,no_zero_time_dict,dic_of_nodes_multi,outfile_name='NoofZeroTime.tex')
data_s=crim.create_tex_tabul(G,list_ofNod,no_zero_val_dict,dic_of_nodes_multi,outfile_name='NoofZeroVal.tex')
crim.create_tex_tabul(G,list_ofNod,comparison_dict,dic_of_nodes_multi,outfile_name='Compare_NS_S.tex')
tem_dici,dici_tem= crim.create_tex_sum_steady(G,list_ofNod,steady_sols_dict_t,dic_of_nodes_multi,outfile_name='inOut.tex')
crim.create_tex_sum_steady_sub(G,k,list_ofNod,steady_sols_dict_t,dic_of_nodes_multi,outfile_name='inOut_sub.tex')
cent_dict=crim.create_tex_sum_central(G,tem_dici,dici_tem,dic_of_nodes_multi,outfile_name='scent_out.tex')
idici_tem,item_dici,odici_tem,otem_dici=crim.create_inf_nei_clos(G,list_ofNod,steady_sols_dict_t,dic_of_nodes_multi)
dinf_cinf_d=crim.create_dinf_tex(G,idici_tem,item_dici,odici_tem,otem_dici,list_ofNod,sas,ssas_ds)
def calc_centralization(dat_fr,col):
mono=0
dmax=max(dat_fr)
for i in dat_fr:
mono+=dmax-i
return mono/len(dat_fr)
dinf_cinf_data=pd.DataFrame(dinf_cinf_d,columns=['Node','Influence-In-Degree', 'Influence-Out-Degree' , 'In-CINF' , 'OB_Closeness_CI' ,'Degree' , 'Closeness'])
columns=['Degree' , 'Closeness','Influence-In-Degree', 'Influence-Out-Degree']
ndir=dinf_cinf_data[columns]
def corrfunc(x, y, **kws):
r, _ = stats.pearsonr(x, y)
ax = plt.gca()
ax.annotate("r = {:.3f}".format(r),
xy=(.1, .9), xycoords=ax.transAxes)
nel=len(columns)
g = sns.PairGrid(ndir)#, vars=columns)#,size=4)#,hue='Layer',size=4)#,palette="Set2",hue_kws={"marker": ["o", "s", "D"]})
g.map_upper(plt.scatter)#,color='grey')
g.map_diag(plt.hist)
g.map_lower(plt.scatter)#,color='grey')
g.map_lower(corrfunc)
iod = ndir['Influence-Out-Degree'].tolist()
iid = ndir['Influence-In-Degree'].tolist()
# for i in range(len(G.nodes())):
# print 'dc = %.4f, cc = %.4f, iod = %.4f, iid = %.4f' %(degggss[i],closs[i],iod[i],iid[i])
cdf=pd.DataFrame.from_items([('Nodes',degrc.keys()),('Degree Centrality',degrc.values()),
('Closeness Centrality',closc.values()),
('Influence-Out-Degree Centrality', iod),
('Influence-In-Degree Centrality', iid)])
cdf#.head()