2nd European Conference on Social Networks, June 14-17, 2016, Paris (http://eusn2016.sciencesconf.org/)

Contributed paper at Session 23: Modelling networks (June 15, 9h25 - 13h05)

SOCIAL INFLUENCE NETWORKS

By Moses Boudourides and Sergios Lenis

University of Patras, Greece

Graphs Assumptions & Notation

  • Let $G = (V, E)$ be a simple undirected graph with n vertices, i.e., $n = |V|$, so that, without any loss of generality,
\begin{equation} V = [n], \end{equation}\begin{equation} E = \{(i,j)\!: i \sim j, i, j \in V, i \neq j\}. \end{equation}
  • For any finite set $X$, $|X|$ denotes the number of elements of $X$.
  • For any positive integer $k$, $[k]$ denotes the set of integers from 1 to $k,$ i.e., $[k] = \{1, 2, \ldots, k\}$.
  • If vertices $i$ and $j$ are adjacent, we write $i \sim j$.
  • $\deg(i)$ denotes the degree of $i$.
  • $G$ is assumed to be connected (i.e., for any $i, \deg(i) \neq 0$).
  • $A = \{A_{ij}\}_{i, j \in [n]}$ denotes the adjacency matrix of $G$.
  • $N = \{N_{ij}\}_{i, j \in [n]}$ denotes the walk matrix (or the adjacent averaging operator) of $G$, which is defined as
\begin{equation} N = D^{-1} \, A, \end{equation}

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}
  • Finally, $L = \{L_{ij}\}_{i, j \in [n]}$ denotes the (combinatorial) Laplacian matrix of $G$, which is defined as
\begin{eqnarray} L &=& D - A \\ \nonumber &=& D(I - N), \end{eqnarray}

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}

The DeGroot-Friedkin-Johnsen Model of Social Influence

  • $G$ is a graph of persons, i.e., vertices $\equiv$ persons.
  • For each person $i \in V$ and time $t = 0, 1, 2, \ldots$ (in the discrete case considered here), $v^t(i) \in \mathbb{R}$ denotes $i$'s opinion at time $t$.
  • Person's $i$ opinion at time $t$ is updated at next instance $t + 1$ as follows:
\begin{equation} v^{t + 1}(i) = s_i \, N \, v^t(i) + (1 - s_i) \, v^0(i), \end{equation}
  • where $N \, v^t(i)$ is the average opinion of $i$'s neighbors
  • and $s_{i}$ is person's $i$ susceptibility coefficient, a scalar parameter in the interval $[0, 1]$. Moreover, $s = \{s_i\}_{i \in [n]} \in [0,1]^{n}$ denotes the vector of susceptibility coefficients of all persons (vertices) in $G$ and $S$ is the $n \times n$ diagonal matrix with its diagonal entries equal to the $s_i$'s.
  • If $s_i = 0$, then $i$'s opinion does not change ($v^{t + 1}(i) = v^0(i)$). Such a person is called stubborn or persistent in her opinion.
  • If $s_i = 1$, then $i$ adopts the average opinion of her neighbors $N \, v^t(i)$. Such a person is called malleable or fully compliant in adopting her neighbor's influence.
  • If $0 < s_i < 1$, then $i$'s opinion is inserted in-between $N \, v^t(i)$ and $v^0(i)$, where the exact inserted position is weighted by $s_i$.

A PDEs-Based Formulation

Persons with zero susceptibilities form the "boundary" of persons with positive susceptibilities.

  • Decomposition of the set $V$ of persons-vertices:
\begin{equation} V = \Omega \cup \delta \Omega, \end{equation}\begin{equation} \Omega = \{i \in V\!: s_i > 0\}, \end{equation}\begin{equation} \delta \Omega = \{i \in V\!: s_i = 0\}, \end{equation}
  • Assumptions: \begin{equation} \delta = |\delta \Omega| < n, \end{equation} \begin{equation} \forall j \in \delta \Omega, \exists i \in \Omega, i \sim j. \end{equation}

The (Evolutionary) Initial Boundary Value Problem (IBVP)

\begin{eqnarray} v^{t + 1} &=& S \, N \, v^t + (I - S) \, \phi, {\mbox{ in }} \Omega, t > 0 \\ v^t &=& 1, {\mbox{ on }} \delta \Omega, t > 0 \\ v^0 &=& \left\{ \begin{array}{lr} \phi, & {\mbox{ in }} \Omega, \\ 1, & {\mbox{ on }} \delta \Omega. \end{array} \right. \end{eqnarray}

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.

The (Stationary) Boundary Value Problem (BVP)

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.

The Case of a Continuous Steering by a Single Source of Influence

  • $|\partial \Omega| = 1$ or $\partial \Omega = \{i[0]\}$, for a person $i = i[0] \in V$ called source (of opinion transmission in $G$).
  • $v_{i[0]}^t = 1 (\forall t \geq 1)$.
  • Let $s(i[0])_j$ be the vector of susceptibilities corresponding to source $i[0]$, i.e.,
\begin{equation} s(i[0])_j \left\{ \begin{array}{ll} = 0, & {\mbox{ for }} j = i[0],\\ > 0, & {\mbox{ for }} j \in V, j \neq i[0]. \end{array} \right. \end{equation}
  • Let $\phi(i[0])$ be the (almost everywhere) null vector of initial opinions corresponding to source $i[0]$, i.e.,
\begin{equation} \phi(i[0])_j = \left\{ \begin{array}{ll} 0, & {\mbox{ for }} j \neq i[0], {\mbox{ i.e., }} j \in \Omega,\\ 1, & {\mbox{ for }} j = i[0], {\mbox{ i.e., }} j \in \delta \Omega. \end{array} \right. \end{equation}
  • Totally, there exist $n$ potential sources $i[0]$ in $G$.
  • For each potential source, i.e., for each $i = i[0] \in V$, let $(\overline{v}(s(i),\phi(i))_j$ be the steady state opinion that person $j \in \Omega$ attains, when the source of the generated opinion is person $i$.
  • The matrix $\mathcal{U}^{\infty}$ with elements
\begin{equation} \mathcal{U}^{\infty}_{ij} = (\overline{v}(s(i),\phi(i))_j \end{equation}

is called matrix of influentiability of $G$.

  • Apparently, $\mathcal{U}^{\infty}_{ii} = 1$, while $\mathcal{U}^{\infty}_{ij} \in (0, 1]$, for $i
\begin{equation} \mathcal{U}^{\infty}_{ij} \left\{ \begin{array}{ll} = 1, & {\mbox{ for }} i = j,\\ \in (0, 1], & {\mbox{ for }} i \neq j. \end{array} \right. \end{equation}

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$.

Importing Python modules and scripts

In [1]:
%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
/home/mab/.local/lib/python2.7/site-packages/matplotlib/font_manager.py:273: UserWarning: Matplotlib is building the font cache using fc-list. This may take a moment.
  warnings.warn('Matplotlib is building the font cache using fc-list. This may take a moment.')
In [2]:
%autoreload 2
from chAs import *
import chAs as ca
import steady_utils as su
import influence as infl

Creating a graph

In [3]:
# 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]]
In [4]:
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]]])

Graph visualization

In [5]:
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
Lightning initialized
Running local mode, some functionality limited.

Karate Club Network
Out[5]:

Four Models of Social Influence

1. Constant Susceptibility Coefficients

In [6]:
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
In [7]:
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())
Out[7]:
{0.12043028313398207}
In [8]:
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))
In [9]:
%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'])
In [10]:
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)
Out[10]:
<seaborn.axisgrid.PairGrid at 0x7f59c8c20890>
In [11]:
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()
Out[11]:
Nodes Degree Centrality Closeness Centrality Influence-Out-Degree Centrality Influence-In-Degree Centrality
0 0 0.484848 0.568966 0.019755 0.003897
1 1 0.272727 0.485294 0.008886 0.003880
2 2 0.303030 0.559322 0.008097 0.003817
3 3 0.181818 0.464789 0.004638 0.003891
4 4 0.090909 0.379310 0.002399 0.003768
5 5 0.121212 0.383721 0.004340 0.003831
6 6 0.121212 0.383721 0.004340 0.003831
7 7 0.121212 0.440000 0.001678 0.003812
8 8 0.151515 0.515625 0.002083 0.003766
9 9 0.060606 0.434211 0.000582 0.003656
10 10 0.090909 0.379310 0.002399 0.003768
11 11 0.030303 0.366667 0.000229 0.003649
12 12 0.060606 0.370787 0.000848 0.003707
13 13 0.151515 0.515625 0.001896 0.003786
14 14 0.060606 0.370787 0.000527 0.003695
15 15 0.060606 0.370787 0.000527 0.003695
16 16 0.060606 0.284483 0.001885 0.003767
17 17 0.060606 0.375000 0.000643 0.003697
18 18 0.060606 0.370787 0.000527 0.003695
19 19 0.090909 0.500000 0.000860 0.003686
20 20 0.060606 0.370787 0.000527 0.003695
21 21 0.060606 0.375000 0.000643 0.003697
22 22 0.060606 0.370787 0.000527 0.003695
23 23 0.151515 0.392857 0.003626 0.003767
24 24 0.090909 0.375000 0.002793 0.003735
25 25 0.090909 0.375000 0.002611 0.003735
26 26 0.060606 0.362637 0.001143 0.003724
27 27 0.121212 0.458333 0.002548 0.003693
28 28 0.090909 0.452055 0.001201 0.003692
29 29 0.121212 0.383721 0.003137 0.003804
30 30 0.121212 0.458333 0.001691 0.003739
31 31 0.181818 0.540984 0.004532 0.003756
32 32 0.363636 0.515625 0.013946 0.003877
33 33 0.515152 0.550000 0.021704 0.003865

2. Random Susceptibility Coefficients

In [12]:
susc={}
for i in range(len(G.nodes())):
    susc[i]=random.random()
        
susc
Out[12]:
{0: 0.9165096549112369,
 1: 0.8981924672715954,
 2: 0.46739503859007847,
 3: 0.774580667443564,
 4: 0.3865812217792711,
 5: 0.477898202273514,
 6: 0.25665658587123674,
 7: 0.522618842584279,
 8: 0.9804689259232238,
 9: 0.8028193580218063,
 10: 0.47933482619842205,
 11: 0.9969850901464484,
 12: 0.17043053320720247,
 13: 0.7288533093923616,
 14: 0.6451427086627132,
 15: 0.925800093148913,
 16: 0.6303045801284627,
 17: 0.012819740876191199,
 18: 0.7883004936428921,
 19: 0.6404833637632739,
 20: 0.10529997641356348,
 21: 0.5980930348306612,
 22: 0.9151085865255514,
 23: 0.20439295107721678,
 24: 0.509960128106046,
 25: 0.8754612595535826,
 26: 0.03162242589283715,
 27: 0.07172085308334142,
 28: 0.2709700338907175,
 29: 0.7283016555472607,
 30: 0.7367889858730611,
 31: 0.37711604888074857,
 32: 0.6284506239500872,
 33: 0.36129439602152513}
In [13]:
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))
In [14]:
%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'])
In [15]:
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)
Out[15]:
<seaborn.axisgrid.PairGrid at 0x7f59cbef9f50>
In [16]:
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()
Out[16]:
Nodes Degree Centrality Closeness Centrality Influence-Out-Degree Centrality Influence-In-Degree Centrality
0 0 0.484848 0.568966 0.114515 0.048859
1 1 0.272727 0.485294 0.051211 0.045641
2 2 0.303030 0.559322 0.058975 0.022294
3 3 0.181818 0.464789 0.026371 0.037557
4 4 0.090909 0.379310 0.010551 0.014019
5 5 0.121212 0.383721 0.021675 0.018883
6 6 0.121212 0.383721 0.024412 0.010192
7 7 0.121212 0.440000 0.016298 0.024050
8 8 0.151515 0.515625 0.014597 0.041447
9 9 0.060606 0.434211 0.002300 0.025641
10 10 0.090909 0.379310 0.011390 0.017483
11 11 0.030303 0.366667 0.002065 0.030212
12 12 0.060606 0.370787 0.007557 0.006126
13 13 0.151515 0.515625 0.017154 0.033072
14 14 0.060606 0.370787 0.002800 0.022485
15 15 0.060606 0.370787 0.002764 0.032267
16 16 0.060606 0.284483 0.006319 0.021768
17 17 0.060606 0.375000 0.006978 0.000469
18 18 0.060606 0.370787 0.002782 0.027475
19 19 0.090909 0.500000 0.007535 0.023556
20 20 0.060606 0.370787 0.002872 0.003670
21 21 0.060606 0.375000 0.006537 0.021859
22 22 0.060606 0.370787 0.002765 0.031895
23 23 0.151515 0.392857 0.019951 0.007609
24 24 0.090909 0.375000 0.012839 0.018262
25 25 0.090909 0.375000 0.009140 0.030490
26 26 0.060606 0.362637 0.006704 0.001086
27 27 0.121212 0.458333 0.009485 0.002360
28 28 0.090909 0.452055 0.004535 0.008971
29 29 0.121212 0.383721 0.004842 0.025476
30 30 0.121212 0.458333 0.014332 0.030118
31 31 0.181818 0.540984 0.026508 0.014228
32 32 0.363636 0.515625 0.087052 0.030600
33 33 0.515152 0.550000 0.130993 0.016683

3. Degree Centralities as Susceptibility Coefficients

In [17]:
susc=degrc
susc
Out[17]:
{0: 0.48484848484848486,
 1: 0.2727272727272727,
 2: 0.30303030303030304,
 3: 0.18181818181818182,
 4: 0.09090909090909091,
 5: 0.12121212121212122,
 6: 0.12121212121212122,
 7: 0.12121212121212122,
 8: 0.15151515151515152,
 9: 0.06060606060606061,
 10: 0.09090909090909091,
 11: 0.030303030303030304,
 12: 0.06060606060606061,
 13: 0.15151515151515152,
 14: 0.06060606060606061,
 15: 0.06060606060606061,
 16: 0.06060606060606061,
 17: 0.06060606060606061,
 18: 0.06060606060606061,
 19: 0.09090909090909091,
 20: 0.06060606060606061,
 21: 0.06060606060606061,
 22: 0.06060606060606061,
 23: 0.15151515151515152,
 24: 0.09090909090909091,
 25: 0.09090909090909091,
 26: 0.06060606060606061,
 27: 0.12121212121212122,
 28: 0.09090909090909091,
 29: 0.12121212121212122,
 30: 0.12121212121212122,
 31: 0.18181818181818182,
 32: 0.36363636363636365,
 33: 0.5151515151515151}
In [18]:
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))
In [19]:
%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'])
In [20]:
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)
Out[20]:
<seaborn.axisgrid.PairGrid at 0x7f59c8a1f150>
In [21]:
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()
Out[21]:
Nodes Degree Centrality Closeness Centrality Influence-Out-Degree Centrality Influence-In-Degree Centrality
0 0 0.484848 0.568966 0.015868 0.016053
1 1 0.272727 0.485294 0.009070 0.009098
2 2 0.303030 0.559322 0.009962 0.009995
3 3 0.181818 0.464789 0.006172 0.006161
4 4 0.090909 0.379310 0.002893 0.002880
5 5 0.121212 0.383721 0.003870 0.003861
6 6 0.121212 0.383721 0.003870 0.003861
7 7 0.121212 0.440000 0.004090 0.004065
8 8 0.151515 0.515625 0.004979 0.004946
9 9 0.060606 0.434211 0.001870 0.001848
10 10 0.090909 0.379310 0.002893 0.002880
11 11 0.030303 0.366667 0.000932 0.000918
12 12 0.060606 0.370787 0.001920 0.001902
13 13 0.151515 0.515625 0.005043 0.005011
14 14 0.060606 0.370787 0.001935 0.001911
15 15 0.060606 0.370787 0.001935 0.001911
16 16 0.060606 0.284483 0.001900 0.001896
17 17 0.060606 0.375000 0.001926 0.001906
18 18 0.060606 0.370787 0.001935 0.001911
19 19 0.090909 0.500000 0.002869 0.002838
20 20 0.060606 0.370787 0.001935 0.001911
21 21 0.060606 0.375000 0.001926 0.001906
22 22 0.060606 0.370787 0.001935 0.001911
23 23 0.151515 0.392857 0.004884 0.004869
24 24 0.090909 0.375000 0.002824 0.002820
25 25 0.090909 0.375000 0.002826 0.002822
26 26 0.060606 0.362637 0.001915 0.001898
27 27 0.121212 0.458333 0.003778 0.003760
28 28 0.090909 0.452055 0.002856 0.002833
29 29 0.121212 0.383721 0.003955 0.003935
30 30 0.121212 0.458333 0.003913 0.003886
31 31 0.181818 0.540984 0.005762 0.005744
32 32 0.363636 0.515625 0.011918 0.011998
33 33 0.515152 0.550000 0.016645 0.016861

4. Closeness Centralities as Susceptibility Coefficients

In [22]:
susc=closc
susc
Out[22]:
{0: 0.5689655172413793,
 1: 0.4852941176470588,
 2: 0.559322033898305,
 3: 0.4647887323943662,
 4: 0.3793103448275862,
 5: 0.38372093023255816,
 6: 0.38372093023255816,
 7: 0.44,
 8: 0.515625,
 9: 0.4342105263157895,
 10: 0.3793103448275862,
 11: 0.36666666666666664,
 12: 0.3707865168539326,
 13: 0.515625,
 14: 0.3707865168539326,
 15: 0.3707865168539326,
 16: 0.28448275862068967,
 17: 0.375,
 18: 0.3707865168539326,
 19: 0.5,
 20: 0.3707865168539326,
 21: 0.375,
 22: 0.3707865168539326,
 23: 0.39285714285714285,
 24: 0.375,
 25: 0.375,
 26: 0.3626373626373626,
 27: 0.4583333333333333,
 28: 0.4520547945205479,
 29: 0.38372093023255816,
 30: 0.4583333333333333,
 31: 0.5409836065573771,
 32: 0.515625,
 33: 0.55}
In [23]:
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))
In [24]:
%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'])
In [25]:
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)
Out[25]:
<seaborn.axisgrid.PairGrid at 0x7f59c0f5cf90>
In [26]:
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()
Out[26]:
Nodes Degree Centrality Closeness Centrality Influence-Out-Degree Centrality Influence-In-Degree Centrality
0 0 0.484848 0.568966 0.079518 0.024355
1 1 0.272727 0.485294 0.038366 0.020326
2 2 0.303030 0.559322 0.037012 0.022560
3 3 0.181818 0.464789 0.020815 0.019382
4 4 0.090909 0.379310 0.008800 0.013247
5 5 0.121212 0.383721 0.014130 0.013976
6 6 0.121212 0.383721 0.014130 0.013976
7 7 0.121212 0.440000 0.008889 0.017058
8 8 0.151515 0.515625 0.010534 0.019255
9 9 0.060606 0.434211 0.002958 0.013751
10 10 0.090909 0.379310 0.008800 0.013247
11 11 0.030303 0.366667 0.001172 0.011111
12 12 0.060606 0.370787 0.003889 0.012340
13 13 0.151515 0.515625 0.010189 0.019801
14 14 0.060606 0.370787 0.002701 0.012411
15 15 0.060606 0.370787 0.002701 0.012411
16 16 0.060606 0.284483 0.006603 0.009653
17 17 0.060606 0.375000 0.003156 0.012475
18 18 0.060606 0.370787 0.002701 0.012411
19 19 0.090909 0.500000 0.004319 0.016646
20 20 0.060606 0.370787 0.002701 0.012411
21 21 0.060606 0.375000 0.003156 0.012475
22 22 0.060606 0.370787 0.002701 0.012411
23 23 0.151515 0.392857 0.014344 0.014261
24 24 0.090909 0.375000 0.011124 0.012723
25 25 0.090909 0.375000 0.010048 0.012726
26 26 0.060606 0.362637 0.004284 0.012018
27 27 0.121212 0.458333 0.009733 0.015341
28 28 0.090909 0.452055 0.006103 0.015131
29 29 0.121212 0.383721 0.011632 0.014132
30 30 0.121212 0.458333 0.008383 0.016396
31 31 0.181818 0.540984 0.018011 0.019558
32 32 0.363636 0.515625 0.053950 0.021375
33 33 0.515152 0.550000 0.086757 0.022961