-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAss1bplots.py
More file actions
149 lines (136 loc) · 4.6 KB
/
Ass1bplots.py
File metadata and controls
149 lines (136 loc) · 4.6 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import igraph
import scipy.stats as ss
Tdata = np.load(r'C:\Users\Thierry\Documents\Studie\TU Delft Applied Physics\CS4195 Modeling and Data Analysis in Complex Networks\Assignment1\G3_numinf.npy')
data = pd.read_excel (r'C:\Users\Thierry\Documents\Studie\TU Delft Applied Physics\CS4195 Modeling and Data Analysis in Complex Networks\Assignment1\manufacturing_emails_temporal_network.xlsx')
Nnodes = 167
perc80 = 134
perc80index = np.zeros(Nnodes)
C = np.zeros(Nnodes)
D = np.zeros(Nnodes)
Close = np.zeros(Nnodes)
Btween = np.zeros(Nnodes)
#%% 9)
Nave = np.sum(Tdata,axis=1)/Nnodes
Nvar = np.var(Tdata,axis=1)
Nstd = np.sqrt(Nvar)
t = np.linspace(1,len(Nave),len(Nave))
fig1 = plt.figure()
ax1 = fig1.add_subplot(111)
ax1.set(xlabel=r'timestamp', ylabel=r'Infected nodes')
plt.errorbar(t,Nave,yerr=Nstd,ecolor='r')
plt.title('Errorbar plot of average infected nodes on timestamp t')
plt.show()
#%% 10)
for i in range(Nnodes):
perc80index[i] = np.argmax(Tdata[:,i]>=134)
if perc80index[i] ==0:
perc80index[i] = 'NaN'
rank_perc80 = ss.rankdata(perc80index,method='min')
rank_perc80ind = rank_perc80.argsort()
#%% 11) 12)
G = data.drop(['timestamp'],axis=1)
B = G.drop_duplicates()
Nnodes = np.max([data['node1'].max(), data['node2'].max()])
Nlinks = len(B)
g = igraph.Graph()
g.add_vertices(Nnodes)
col1 = B['node1']; col2 = B['node2']
col1 = col1.tolist(); col2 = col2.tolist()
for i in range(Nlinks):
g.add_edges([(col1[i]-1,col2[i]-1)]) #nodes are names 0 to 166
for i in range(Nnodes):
C[i] = g.transitivity_local_undirected(i)
D[i] = g.outdegree(i)
Close[i] = g.closeness(i)
Btween[i] = g.betweenness(i)
rankC = ss.rankdata(-C,method='min')
rankCind = rankC.argsort()
rankD = ss.rankdata(-D,method='min')
rankDind = rankD.argsort()
rankClose = ss.rankdata(-Close,method='min')
rankCloseind = rankClose.argsort()
rankBtween = ss.rankdata(-Btween,method='min')
rankBtweenind = rankBtween.argsort()
f = np.rint(np.linspace(0.05,0.5,10)*Nnodes)
RfDf = np.zeros(len(f))
RfCf = np.zeros(len(f))
RfClf = np.zeros(len(f))
RfBf = np.zeros(len(f))
k = 0
for i in f:
Cf = np.zeros(int(i))
Df = np.zeros(int(i))
Clf = np.zeros(int(i))
Bf = np.zeros(int(i))
for j in range(int(i)):
abs_Rf = i
Rf = np.where(rank_perc80 ==1)
Df[j] = rankDind[j]
Cf[j] = rankCind[j]
Clf[j] = rankCloseind[j]
Bf[j] = rankBtweenind[j]
RfDf[k] = len(list(set(Rf[0]).intersection(Df)))/abs_Rf
RfCf[k] = len(list(set(Rf[0]).intersection(Cf)))/abs_Rf
RfClf[k] = len(list(set(Rf[0]).intersection(Clf)))/abs_Rf
RfBf[k] = len(list(set(Rf[0]).intersection(Bf)))/abs_Rf
k = k+1
F = np.linspace(0.05,0.5,10)
fig2 = plt.figure()
ax2 = fig2.add_subplot(111)
ax2.set(xlabel='f',ylabel='recognition rate')
plt.plot(F,RfCf,F,RfDf)
plt.legend(('RfCf', 'RfDf'),
loc='upper left')
plt.title('Recognition rate of Degree and Clustering coefficient')
fig3 = plt.figure()
ax3 = fig3.add_subplot(111)
ax3.set(xlabel='f',ylabel='recognition rate')
plt.plot(F,RfClf,F,RfBf)
plt.legend(('RfClf', 'RfBf'),
loc='lower left')
plt.title('Recognition rate of Closeness and Betweenness')
#%% 13)
T80 = np.zeros(Nnodes)
for j in range(Nnodes):
perc80_point = False
for i in range(1,len(Tdata)):
if Tdata[i,j] < 134 and perc80_point == False:
T80[j] = T80[j] + (Tdata[i,j]-Tdata[i-1,j])*i
elif Tdata[i,j] >= 134 and perc80_point == False:
T80[j] = T80[j]/57791
perc80_point = True
elif i == 57791 and perc80_point == False:
Tdiff = 134-Tdata[i,j]
(T80[j]+Tdiff)/i
perc80_point = True
rank_T80 = ss.rankdata(-T80,method='min')
rank_T80ind = rank_T80.argsort()
R2fCf = np.zeros(len(f))
R2fDf = np.zeros(len(f))
R2fRf = np.zeros(len(f))
k = 0
for i in f:
Cf = np.zeros(int(i))
Df = np.zeros(int(i))
Rf = np.zeros(int(i))
R2f = np.zeros(int(i))
for j in range(int(i)):
abs_Rf = i
R2f[j] = rank_T80ind[j]
Rf[j] = rank_perc80ind[j]
Df[j] = rankDind[j]
Cf[j] = rankCind[j]
R2fDf[k] = len(list(set(R2f).intersection(Df)))/abs_Rf
R2fCf[k] = len(list(set(R2f).intersection(Cf)))/abs_Rf
R2fRf[k] = len(list(set(R2f).intersection(Rf)))/abs_Rf
k = k+1
fig4 = plt.figure()
ax4 = fig4.add_subplot(111)
ax4.set(xlabel='f',ylabel='recognition rate')
plt.plot(F,R2fCf,F,R2fDf,F,R2fRf)
plt.legend(('R_primefCf', 'R_primefDf','R_primefRf'),
loc='upper left')
plt.title('Recognition rate of Degree, Clustering coefficient and R')