@@ -123,7 +123,7 @@ def get_ego_graph(g, s, t, l):
123
123
index = EGO_NETWORK + str(l - 1)
124
124
node_list = set()
125
125
for ng in nx.neighbors(g, s):
126
- if ng != t: node_list = node_list | g.node [ng][index]
126
+ if ng != t: node_list = node_list | g.nodes [ng][index]
127
127
return node_list - set([s])
128
128
129
129
@@ -133,20 +133,20 @@ def processing_link_property(iter_item):
133
133
## from s to t
134
134
135
135
base_st_nodes = set([s, t])
136
- c.node [s][0] = set() ## for removing previously accessed neighbor nodes (0~(l-1) layer neighbors)
137
- c.node [t][0] = set() ## same as above, for the other end
136
+ c.nodes [s][0] = set() ## for removing previously accessed neighbor nodes (0~(l-1) layer neighbors)
137
+ c.nodes [t][0] = set() ## same as above, for the other end
138
138
s0 = set()
139
139
t0 = set()
140
140
141
141
for i in range(sp):
142
142
l = i + 1
143
143
144
- #c.node [s][l] = get_outgoing_ego_graph(c, s, t, l) - c.node [s][0] - base_st_nodes
145
- #c.node [t][l] = get_incoming_ego_graph(c, t, s, l) - c.node [t][0] - base_st_nodes
146
- c.node [s][l] = get_ego_graph(c, s, t, l) - s0 - base_st_nodes
147
- c.node [t][l] = get_ego_graph(c, t, s, l) - t0 - base_st_nodes
144
+ #c.nodes [s][l] = get_outgoing_ego_graph(c, s, t, l) - c.nodes [s][0] - base_st_nodes
145
+ #c.nodes [t][l] = get_incoming_ego_graph(c, t, s, l) - c.nodes [t][0] - base_st_nodes
146
+ c.nodes [s][l] = get_ego_graph(c, s, t, l) - s0 - base_st_nodes
147
+ c.nodes [t][l] = get_ego_graph(c, t, s, l) - t0 - base_st_nodes
148
148
149
- common_nodes = (c.node [s][l] & c.node [t][l]) | (c.node [s][l] & c.node [t][l-1]) | (c.node [s][l-1] & c.node [t][l])
149
+ common_nodes = (c.nodes [s][l] & c.nodes [t][l]) | (c.nodes [s][l] & c.nodes [t][l-1]) | (c.nodes [s][l-1] & c.nodes [t][l])
150
150
151
151
index1 = 'w'+str(l)+'a' ## same as article, from inferior view
152
152
#index2 = 'w'+str(l)+'b' ## from superior view
@@ -156,23 +156,23 @@ def processing_link_property(iter_item):
156
156
g[s][t][index1] = 0
157
157
#g[s][t][index2] = 0
158
158
else:
159
- part1_a = min(len(c.node [s][l] ), len(c.node [t][l]) )
160
- part2_a = min(len(c.node [s][l] ), len(c.node [t][l-1]))
161
- part3_a = min(len(c.node [s][l-1]), len(c.node [t][l]) )
159
+ part1_a = min(len(c.nodes [s][l] ), len(c.nodes [t][l]) )
160
+ part2_a = min(len(c.nodes [s][l] ), len(c.nodes [t][l-1]))
161
+ part3_a = min(len(c.nodes [s][l-1]), len(c.nodes [t][l]) )
162
162
denominator_a = float(part1_a + part2_a + part3_a)
163
- #part1_b = max(len(c.node [s][l] ), len(c.node [t][l]) )
164
- #part2_b = max(len(c.node [s][l] ), len(c.node [t][l-1]))
165
- #part3_b = max(len(c.node [s][l-1]), len(c.node [t][l]) )
163
+ #part1_b = max(len(c.nodes [s][l] ), len(c.nodes [t][l]) )
164
+ #part2_b = max(len(c.nodes [s][l] ), len(c.nodes [t][l-1]))
165
+ #part3_b = max(len(c.nodes [s][l-1]), len(c.nodes [t][l]) )
166
166
#denominator_b = float(part1_b + part2_b + part3_b)
167
167
g[s][t][index1] = float(len(common_nodes)) / denominator_a
168
168
#g[s][t][index2] = float(len(common_nodes)) / denominator_b
169
169
170
170
c.graph[GRAPH_KEY_COMMON_NODES_LIST + str(l)].append(g[s][t][index1])
171
171
172
- #c.node [s][0] |= c.node [s][l]
173
- #c.node [t][0] |= c.node [t][l]
174
- s0 |= c.node [s][l]
175
- t0 |= c.node [t][l]
172
+ #c.nodes [s][0] |= c.nodes [s][l]
173
+ #c.nodes [t][0] |= c.nodes [t][l]
174
+ s0 |= c.nodes [s][l]
175
+ t0 |= c.nodes [t][l]
176
176
#pair = { g[s][t][ind]:v for ind,v in g[s][t].items() }
177
177
#gnote = { GRAPH_KEY_COMMON_NODES_LIST + str(l): c.graph[GRAPH_KEY_COMMON_NODES_LIST + str(l)] for l in range(1, sp+1) }
178
178
#compute_link_prop_bar.update(1)
@@ -186,18 +186,18 @@ def generate_ego_graph(g, sp):
186
186
for r in range(sp):
187
187
for n in g.nodes(data = False):
188
188
if r == 0:
189
- g.node [n][EGO_NETWORK + str(r)] = set([n])
189
+ g.nodes [n][EGO_NETWORK + str(r)] = set([n])
190
190
else:
191
- g.node [n][EGO_NETWORK + str(r)] = set(g.node [n][EGO_NETWORK + str(r - 1)])
191
+ g.nodes [n][EGO_NETWORK + str(r)] = set(g.nodes [n][EGO_NETWORK + str(r - 1)])
192
192
for ng in nx.neighbors(g, n):
193
- g.node [n][EGO_NETWORK + str(r)] = g.node [n][EGO_NETWORK + str(r)] | g.node [ng][EGO_NETWORK + str(r - 1)]
193
+ g.nodes [n][EGO_NETWORK + str(r)] = g.nodes [n][EGO_NETWORK + str(r)] | g.nodes [ng][EGO_NETWORK + str(r - 1)]
194
194
195
195
c.graph[GRAPH_KEY_COMMON_NODES_LIST + str(l)].append(g[s][t][index1])
196
196
197
- #c.node [s][0] |= c.node [s][l]
198
- #c.node [t][0] |= c.node [t][l]
199
- s0 |= c.node [s][l]
200
- t0 |= c.node [t][l]
197
+ #c.nodes [s][0] |= c.nodes [s][l]
198
+ #c.nodes [t][0] |= c.nodes [t][l]
199
+ s0 |= c.nodes [s][l]
200
+ t0 |= c.nodes [t][l]
201
201
#pair = { g[s][t][ind]:v for ind,v in g[s][t].items() }
202
202
#gnote = { GRAPH_KEY_COMMON_NODES_LIST + str(l): c.graph[GRAPH_KEY_COMMON_NODES_LIST + str(l)] for l in range(1, sp+1) }
203
203
#compute_link_prop_bar.update(1)
@@ -315,7 +315,7 @@ def compute_link_property(g, sp):
315
315
return g
316
316
317
317
318
- def random_once (g , kmax , Q = 100 ):
318
+ def random_once (g , kmax , Q = 2 ):
319
319
#rg = nx.DiGraph(nx.directed_configuration_model(list(d for n, d in g.in_degree()), list(d for n, d in g.out_degree()), create_using = nx.DiGraph()))
320
320
rg = g .copy ()
321
321
if g .number_of_edges () > 2 :
@@ -372,8 +372,9 @@ def get_external_threshold(g, kmax, times, random_pre):
372
372
random_results = []
373
373
#global pbar_pool
374
374
#pbar_pool = tqdm(total=times)#, desc='randomizing with no. thread: '+str(threads))
375
- tt0 = time .time ()
376
- TIME = time .time ()
375
+ if not (silent ):
376
+ tt0 = time .time ()
377
+ TIME = time .time ()
377
378
if g .number_of_edges ()> 100 :
378
379
#print 'start randomizing with no. thread: '+str(threads)
379
380
pool = pathos .multiprocessing .ProcessingPool (nodes = threads_no )
@@ -384,8 +385,9 @@ def get_external_threshold(g, kmax, times, random_pre):
384
385
for c in range (times ):
385
386
random_results .append ((randomizing ((c , g , kmax , random_pre ))))
386
387
#pbar_pool.close()
387
- tt1 = time .time ()
388
- print ('randomizing used time: {} minutes' .format ((tt1 - tt0 )/ 60. ))
388
+ if not (silent ):
389
+ tt1 = time .time ()
390
+ print ('randomizing used time: {} minutes' .format ((tt1 - tt0 )/ 60. ))
389
391
390
392
for i in range (kmax ):
391
393
rgmeans [str (i + 1 )] = [ meas [str (i + 1 )] for meas , stds in random_results ]
@@ -436,7 +438,9 @@ def bridge_or_bond(ginput, times=100, external=None, threads=4, kmax=None,
436
438
#random_pre = random_prefix
437
439
438
440
# use only the largest weakly connected component
439
- g = sorted (nx .connected_component_subgraphs (ginput , copy = False ), key = len , reverse = True )[0 ]
441
+ # g = sorted(nx.connected_component_subgraphs(ginput, copy=False), key=len, reverse=True)[0] # deprecated
442
+ largest_cc = max (nx .connected_components (ginput ), key = len )
443
+ g = ginput .subgraph (largest_cc ).copy ()
440
444
441
445
#kmax = max(1, int(nx.average_shortest_path_length(g) / 2.0)) # 決定每個節點要外看幾層,決定強弱連結
442
446
@@ -451,7 +455,7 @@ def bridge_or_bond(ginput, times=100, external=None, threads=4, kmax=None,
451
455
if not (silent ): print ('computing link property R' )
452
456
g = compute_link_property (g , kmax )
453
457
454
- if not (silent ): print ('calculating external threshold' )
458
+ if not (silent ): print ('computing external threshold' )
455
459
if output_random :
456
460
if not os .path .exists (random_dir ):
457
461
os .makedirs (random_dir )
@@ -462,6 +466,7 @@ def bridge_or_bond(ginput, times=100, external=None, threads=4, kmax=None,
462
466
if not (silent ): print ('external threshold is provided, skipped randomization' )
463
467
ext_dic = external
464
468
469
+ if not (silent ): print ('last step: identifying edge types' )
465
470
#g, bonds, Lbridges, Gbridges, silks, int_dic = edge_type_identification(g, kmax, ext_dic, return_all_list=True)
466
471
if not (ext_dic is None ):
467
472
g , int_dic = edge_type_identification (g , kmax , ext_dic , return_all_list = False )
0 commit comments