-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem3.py
More file actions
135 lines (105 loc) · 3.32 KB
/
Problem3.py
File metadata and controls
135 lines (105 loc) · 3.32 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
"""
PROBLEM 3: THE Q-CORE SIZE
"""
from compnet.graphs import ConfigModelDegreeGraph
from compnet.theoretical import get_theo_qcore_size, threecore_step
import numpy as np
import matplotlib.pyplot as plt
from functools import partial
import time
start = time.time()
pi_values = np.linspace(0.01, 0.99, 25)
N_values = [100, 500, 1000]
n_samples = 20
qcoresize_means, qcoresize_stds = [], []
qcs_meas = {N: {'means': [], 'stds': []} for N in N_values}
for N in N_values:
qcs_values_means = []
qcs_values_stds = []
for pi in pi_values:
print(f'Processing q-core values for pi={pi}')
qcs_samples = []
for _ in range(n_samples):
degree_dict = {
1: 1-pi,
4: pi
}
G = ConfigModelDegreeGraph(N=N, degree_dict=degree_dict)
G.generate_graph()
G.find_neighbourhoods()
qcs = G.get_biggest_qcoresize(q=3)
qcs_samples.append(qcs / N)
qcs_values_means.append(np.mean(qcs_samples))
qcs_values_stds.append(np.std(qcs_samples) / np.sqrt(n_samples))
qcs_meas[N]['means'] = qcs_values_means
qcs_meas[N]['stds'] = qcs_values_stds
def get_threecoresize(pi):
n_vertices = 10_000
threecoresize, _ = get_theo_qcore_size(
n_vertices = n_vertices,
degree_distribution = [0, 1-pi, 0, 0, pi],
q = 3,
function=threecore_step
)
return threecoresize / n_vertices
## generate example ode figure
#
#pi = .3
#_, U = get_theo_qcore_size(
# n_vertices = 1_000,
# degree_distribution = [0, 1-pi, 0, 0, pi],
# q = 3,
# function = threecore_step)
#
#fig = plt.figure()
#for i in range(5):
# plt.plot(U[:-1, i], label=f'$d={i}$')
#plt.title('Nodes per degree in time for stochastic 3-core for $pi=0.3$')
#plt.xlabel(r'$T$')
#plt.ylabel(r'$p_d(t)$')
#plt.grid()
#plt.legend()
#plt.close()
#
#fig.savefig('assets/ode_evol_pi03.pdf', bbox_inches='tight')
#
#pi = .8
#_, U = get_theo_qcore_size(
# n_vertices = 1_000,
# degree_distribution = [0, 1-pi, 0, 0, pi],
# q = 3,
# function = threecore_step)
#
#fig = plt.figure()
#for i in range(5):
# plt.plot(U[:-1, i], label=f'$d={i}$')
#plt.title('Nodes per degree in time for stochastic 3-core for $pi=0.8$')
#plt.xlabel(r'$T$')
#plt.ylabel(r'$p_d(t)$')
#plt.grid()
#plt.legend()
#plt.close()
#
#fig.savefig('assets/ode_evol_pi08.pdf', bbox_inches='tight')
# computing theoretical values
print("Computing theoretical q-core sizes...")
get_threecoresize_vect = np.vectorize(get_threecoresize)
theo_pi_values = np.linspace(0.1, 0.99, 50)
theo_qcoresizes = get_threecoresize_vect(theo_pi_values)
fig = plt.figure()
for N in N_values:
plt.errorbar(x=pi_values, y=qcs_meas[N]['means'],
yerr=qcs_meas[N]['stds'], fmt='.',
label=f'3-core sizes for $N={N}$')
plt.plot(theo_pi_values,
theo_qcoresizes,
label='Theoretical $q$-core sizes')
plt.xlabel(r'$\pi$')
plt.ylabel(r'Relative size of 3-core')
plt.title(r'Behaviour of 3-core size in the configuration model')
plt.grid()
plt.legend()
plt.close()
fig.savefig('assets/qcore.pdf', bbox_inches='tight')
stop = time.time()
print(f'Time elapsed: {(stop-start)/60:.0f}m{(stop-start)%60:.0f}s')