MCPcopy Create free account
hub / github.com/easy-graph/Easy-Graph / plot_Connected_Communities

Function plot_Connected_Communities

easygraph/functions/drawing/plot.py:62–121  ·  view source on GitHub ↗

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 cur

(G, SHS)

Source from the content-addressed store, hash-verified

60
61# Number of Connected Communities
62def plot_Connected_Communities(G, SHS):
63 """
64 Returns the CDF curves of "Number of Connected Communities" of SH spanners and ordinary users in graph G.
65
66 Parameters
67 ----------
68 G : graph
69 A easygraph graph.
70
71 SHS : list
72 The SH Spanners in graph G.
73
74 Returns
75 -------
76 plt : CDF curves
77 the CDF curves of "Number of Connected Communities" of SH spanners and ordinary users in graph G.
78 """
79 import matplotlib.pyplot as plt
80 import numpy as np
81 import statsmodels.api as sm
82
83 OU = []
84 for i in G:
85 if i not in SHS:
86 OU.append(i)
87 sample1 = []
88 sample2 = []
89 cmts = eg.LPA(G)
90 for i in OU:
91 s = set()
92 neighbors = G.neighbors(node=i)
93 for j in neighbors:
94 for k in cmts:
95 if j in cmts[k]:
96 s.add(k)
97 sample1.append(len(s))
98 for i in SHS:
99 s = set()
100 neighbors = G.neighbors(node=i)
101 for j in neighbors:
102 for k in cmts:
103 if j in cmts[k]:
104 s.add(k)
105 sample2.append(len(s))
106 print(len(cmts))
107 print(sample1)
108 print(sample2)
109 X1 = np.linspace(min(sample1), max(sample1))
110 ecdf = sm.distributions.ECDF(sample1)
111 Y1 = ecdf(X1)
112 X2 = np.linspace(min(sample2), max(sample2))
113 ecdf = sm.distributions.ECDF(sample2)
114 Y2 = ecdf(X2)
115 plt.plot(X1, Y1, "b--", label="Ordinary User")
116 plt.plot(X2, Y2, "r", label="SH Spanner")
117 plt.title("Number of Connected Communities")
118 plt.xlabel("Number of Connected Communities")
119 plt.ylabel("Cumulative Distribution Function")

Callers

nothing calls this directly

Calls 3

appendMethod · 0.80
addMethod · 0.80
neighborsMethod · 0.45

Tested by

no test coverage detected