5 def __init__(self
,number_of_nodes
, prob
, Laplacian_dividing_factor
):
6 self
.size
= number_of_nodes
8 self
.LDF
= Laplacian_dividing_factor
10 def directed(self
): # I should think more about how I am generating them. num_edges= N(N-1)
11 nn
= self
.size
*(self
.size
)
12 indices
= np
.arange(nn
)
13 np
.random
.shuffle(indices
)
14 nonz
= np
.int(np
.floor(nn
*self
.prob
))
18 D
= Z
.reshape(self
.size
,self
.size
)
20 for i
in range(self
.size
):
24 GG
= nx
.from_numpy_matrix(np
.matrix(D
), create_using
=nx
.DiGraph
)
25 largest
= max(nx
.kosaraju_strongly_connected_components(GG
), key
=len)
27 adj
= np
.zeros((len(largest
), len(largest
)))
36 row_sum
= np
.sum(adj
, axis
= 1)
37 col_sum
= np
.sum(adj
, axis
= 0)
38 l_in
= np
.diag(row_sum
) - adj
39 l_out
= np
.diag(col_sum
) - adj
40 ZR
= l_in
/ (self
.LDF
*np
.max(row_sum
))
41 ZC
= l_out
/ (self
.LDF
*np
.max(col_sum
))
42 RS
= np
.eye(self
.size
) - ZR
43 CS
= np
.eye(self
.size
) - ZC
44 N_out
= np
.count_nonzero(CS
,axis
=0)
46 return ZR
, ZC
, RS
, CS
, N_out
, neighbors
48 def undirected(self
): # I think I were wrong N(N-1)/2 edges can an undir_graph have
49 nn
= self
.size
*self
.size
50 indices
= np
.arange(nn
)
51 np
.random
.shuffle(indices
)
52 nonz
= np
.int(np
.floor(nn
*self
.prob
))
56 U
= Z
.reshape(self
.size
,self
.size
)
57 for i
in range(self
.size
):
60 for j
in range(self
.size
):
64 row_sum
= np
.sum(adj
, axis
= 1)
65 col_sum
= np
.sum(adj
, axis
= 0)
66 l_in
= np
.diag(row_sum
) - adj
67 l_out
= np
.diag(col_sum
) - adj
68 ZR
= l_in
/ (self
.LDF
*np
.max(row_sum
))
69 ZC
= l_out
/ (self
.LDF
*np
.max(col_sum
))
70 RS
= np
.eye(self
.size
) - ZR
71 CS
= np
.eye(self
.size
) - ZC