importeasygraphaseg__all__=["plot_Followers","plot_Connected_Communities","plot_Betweenness_Centrality","plot_Neighborhood_Followers",]# Number of Followers
[docs]defplot_Followers(G,SHS):""" Returns the CDF curves of "Number of Followers" of SH spanners and ordinary users in graph G. Parameters ---------- G : graph A easygraph graph. SHS : list The SH Spanners in graph G. Returns ------- plt : CDF curves the CDF curves of "Number of Followers" of SH spanners and ordinary users in graph G. """importmatplotlib.pyplotaspltimportnumpyasnpimportstatsmodels.apiassmOU=[]foriinG:ifinotinSHS:OU.append(i)degree=G.degree()sample1=[]sample2=[]foriindegree.keys():ifiinOU:sample1.append(degree[i])elifiinSHS:sample2.append(degree[i])X1=np.linspace(min(sample1),max(sample1))ecdf=sm.distributions.ECDF(sample1)Y1=ecdf(X1)X2=np.linspace(min(sample2),max(sample2))ecdf=sm.distributions.ECDF(sample2)Y2=ecdf(X2)plt.plot(X1,Y1,"b--",label="Ordinary User")plt.plot(X2,Y2,"r",label="SH Spanner")plt.title("Number of Followers")plt.xlabel("Number of Followers")plt.ylabel("Cumulative Distribution Function")plt.legend(loc="lower right")plt.show()
# Number of Connected Communities
[docs]defplot_Connected_Communities(G,SHS):""" Returns the CDF curves of "Number of Connected Communities" of SH spanners and ordinary users in graph G. Parameters ---------- G : graph A easygraph graph. SHS : list The SH Spanners in graph G. Returns ------- plt : CDF curves the CDF curves of "Number of Connected Communities" of SH spanners and ordinary users in graph G. """importmatplotlib.pyplotaspltimportnumpyasnpimportstatsmodels.apiassmOU=[]foriinG:ifinotinSHS:OU.append(i)sample1=[]sample2=[]cmts=eg.LPA(G)foriinOU:s=set()neighbors=G.neighbors(node=i)forjinneighbors:forkincmts:ifjincmts[k]:s.add(k)sample1.append(len(s))foriinSHS:s=set()neighbors=G.neighbors(node=i)forjinneighbors:forkincmts:ifjincmts[k]:s.add(k)sample2.append(len(s))print(len(cmts))print(sample1)print(sample2)X1=np.linspace(min(sample1),max(sample1))ecdf=sm.distributions.ECDF(sample1)Y1=ecdf(X1)X2=np.linspace(min(sample2),max(sample2))ecdf=sm.distributions.ECDF(sample2)Y2=ecdf(X2)plt.plot(X1,Y1,"b--",label="Ordinary User")plt.plot(X2,Y2,"r",label="SH Spanner")plt.title("Number of Connected Communities")plt.xlabel("Number of Connected Communities")plt.ylabel("Cumulative Distribution Function")plt.legend(loc="lower right")plt.show()
# Betweenness Centrality
[docs]defplot_Betweenness_Centrality(G,SHS):""" Returns the CDF curves of "Betweenness Centralitys" of SH spanners and ordinary users in graph G. Parameters ---------- G : graph A easygraph graph. SHS : list The SH Spanners in graph G. Returns ------- plt : CDF curves the CDF curves of "Betweenness Centrality" of SH spanners and ordinary users in graph G. """importmatplotlib.pyplotaspltimportnumpyasnpimportstatsmodels.apiassmOU=[]foriinG:ifinotinSHS:OU.append(i)bc=eg.betweenness_centrality(G)sample1=[]sample2=[]foriinbc.keys():ifiinOU:sample1.append(bc[i])elifiinSHS:sample2.append(bc[i])X1=np.linspace(min(sample1),max(sample1))ecdf=sm.distributions.ECDF(sample1)Y1=ecdf(X1)X2=np.linspace(min(sample2),max(sample2))ecdf=sm.distributions.ECDF(sample2)Y2=ecdf(X2)plt.plot(X1,Y1,"b--",label="Ordinary User")plt.plot(X2,Y2,"r",label="SH Spanner")plt.title("Betweenness Centrality")plt.xlabel("Betweenness Centrality")plt.ylabel("Cumulative Distribution Function")plt.legend(loc="lower right")plt.show()
# Arg. Number of Followers of the Neighborhood Users
[docs]defplot_Neighborhood_Followers(G,SHS):""" Returns the CDF curves of "Arg. Number of Followers of the Neighborhood Users" of SH spanners and ordinary users in graph G. Parameters ---------- G : graph A easygraph graph. SHS : list The SH Spanners in graph G. Returns ------- plt : CDF curves the CDF curves of "Arg. Number of Followers of the Neighborhood Users " of SH spanners and ordinary users in graph G. """importmatplotlib.pyplotaspltimportnumpyasnpimportstatsmodels.apiassmOU=[]foriinG:ifinotinSHS:OU.append(i)sample1=[]sample2=[]degree=G.degree()foriinOU:num=0sum=0forneighborinG.neighbors(node=i):num=num+1sum=sum+degree[neighbor]sample1.append(sum/num)foriinSHS:num=0sum=0forneighborinG.neighbors(node=i):num=num+1sum=sum+degree[neighbor]sample2.append(sum/num)X1=np.linspace(min(sample1),max(sample1))ecdf=sm.distributions.ECDF(sample1)Y1=ecdf(X1)X2=np.linspace(min(sample2),max(sample2))ecdf=sm.distributions.ECDF(sample2)Y2=ecdf(X2)plt.plot(X1,Y1,"b--",label="Ordinary User")plt.plot(X2,Y2,"r",label="SH Spanner")plt.title("Arg. Number of Followers of the Neighborhood Users")plt.xlabel("Arg. Number of Followers of the Neighborhood Users")plt.ylabel("Cumulative Distribution Function")plt.legend(loc="lower right")plt.show()