-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCL_degree_distributions.R
50 lines (39 loc) · 992 Bytes
/
CL_degree_distributions.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
library(igraph)
## create the Chung-Lu graphs
# define the parameters
m <- 1000
n <- 100
pA <- seq(0.7, 1, 0.1)
rA <- seq(0, 0.09, 0.03)
dstrb <- array(0, c(length(pA), length(rA), m, n))
for (aa in 1:length(pA)) {
for (bb in 1:length(rA)) {
p = pA[[aa]]
r = rA[[bb]]
# create the first graph
w = matrix(1:n,1,n)
w = n*p*((w/n)^r)
B = (t(w)%*%w)/sum(w)
B = B*(B < 1) + (B > 1)
Q = matrix(runif(n*n, 0, 1),n,n)
Q = matrix(1,n,n)*(B > Q)
Q = upper.tri(Q)*Q
Q = Q + t(Q)
G <- list(graph.adjacency(Q, "undirected"))
dstrb[aa,bb,1,1:length(degree.distribution(G[[1]]))] = degree.distribution(G[[1]])
if (m > 1) {
for (i in 2:m) {
w = matrix(1:n,1,n)
w = n*p*((w/n)^r)
B = (t(w)%*%w)/sum(w)
B = B*(B < 1) + (B > 1)
Q = matrix(runif(n*n, 0, 1),n,n)
Q = matrix(1,n,n)*(B > Q)
Q = upper.tri(Q)*Q
Q = Q + t(Q)
G <- c(G, list(graph.adjacency(Q, "undirected")))
dstrb[aa,bb,i,1:length(degree.distribution(G[[i]]))] = degree.distribution(G[[i]])
}
}
}
}