Revision 0a4aa24d timeAnalysis.py

View differences:

timeAnalysis.py
13 13
import numpy as np
14 14
import glob
15 15
import matplotlib
16
import seaborn as sns
17
sns.set()
16

  
18 17

  
19 18

  
20 19
folder = sys.argv[1]
21 20
lags = 100
22 21
if len(sys.argv) > 2:
23 22
    lags = int(sys.argv[2])
24
nick = folder.split('/')[-2].split('_')[0]+"_"
23
nick = folder.split('/')[-2].split('_')[0]
25 24
os.chdir(folder)
26 25

  
27 26
bcdf = pd.DataFrame()  # rows=nodes columns=BC at column-index time-instant
......
36 35
    degdf = pd.concat([degdf, df['deg']], axis=1)
37 36
    kcoredf = pd.concat([kcoredf, df['kcore']], axis=1)
38 37

  
39

  
40 38
nodes = range(len(bcdf.columns))
41 39

  
42 40
initialCentrality = {}
......
63 61
    nodekcoreACF = pd.DataFrame(
64 62
        [kcoredf.iloc[:, node].autocorr(lag) for lag in range(lags)])
65 63
    kcoreACF = pd.concat([kcoreACF, nodekcoreACF], axis=1)
66
#code.interact(local=dict(globals(), **locals()))
67 64

  
68 65
'''
69 66
X ==> time-lag
......
76 73

  
77 74
os.chdir("plots"+nick)
78 75
# Plotting
76
code.interact(local=dict(globals(), **locals()))
77

  
78
# ACF boxplots
79
bcACF.T.boxplot(column=[1]+range(5,lags,5))
80
plt.ylabel("ACF of BC for all nodes")
81
plt.xlabel("Time-lag")
82
plt.xticks(rotation="vertical")
83
plt.axhline(y=0.2, color='k', linestyle='--', lw=1.2)
84
plt.axhline(y=0.0, color='k', linestyle='--', lw=2)
85
plt.axhline(y=-0.2, color='k', linestyle='--', lw=1.2)
86
plt.ylim(-0.4, 1.0)
87
plt.yticks(np.arange(-0.4, 1.0, step=0.1))
88
plt.savefig(nick+"autoCorrBOXPLOT-BC.pdf", format='pdf')
89
plt.clf()
90

  
91
degACF.T.boxplot(column=[1]+range(5,lags,5))
92
plt.ylabel("ACF of DEG for all nodes")
93
plt.xlabel("Time-lag")
94
plt.xticks(rotation="vertical")
95
plt.axhline(y=0.2, color='k', linestyle='--', lw=1.2)
96
plt.axhline(y=0.0, color='k', linestyle='--', lw=2)
97
plt.axhline(y=-0.2, color='k', linestyle='--', lw=1.2)
98
plt.ylim(-0.4, 1.0)
99
plt.yticks(np.arange(-0.4, 1.0, step=0.1))
100
plt.savefig(nick+"autoCorrBOXPLOT-DEG.pdf", format='pdf')
101
plt.clf()
102

  
103
kcoreACF.T.boxplot(column=[1]+range(5,lags,5))
104
plt.ylabel("ACF of KCORE for all nodes")
105
plt.xlabel("Time-lag")
106
plt.xticks(rotation="vertical")
107
plt.axhline(y=0.2, color='k', linestyle='--', lw=1.2)
108
plt.axhline(y=0.0, color='k', linestyle='--', lw=2)
109
plt.axhline(y=-0.2, color='k', linestyle='--', lw=1.2)
110
plt.ylim(-0.4, 1.0)
111
plt.yticks(np.arange(-0.4, 1.0, step=0.1))
112
plt.savefig(nick+"autoCorrBOXPLOT-KCORE.pdf", format='pdf')
113
plt.clf()
114

  
115

  
116

  
79 117
# Mean AutoCorrelation and Rank-Correlation
80 118
# lags=20
81 119
firstRank = bcdf.iloc[0, :]
......
99 137
plt.plot(x, rankCorr, lw="1.5", label='Rank-Correlation (with rank at t_0)')
100 138
# plt.plot(x, weightedRankCorr, lw="1.5",
101 139
#         label='Weighted-Rank-Correlation (with rank at t_0)')
102
plt.ylabel('Corr coeff: [ACF, Spearman rho]')
140
plt.ylabel('Correlation indexes')
103 141
plt.xlabel('Time-lags / Time')
104 142
plt.grid()
105 143
plt.legend()
......
110 148

  
111 149
toWrite = pd.concat([pd.Series(meanbcACF), pd.Series(
112 150
    meandegACF), pd.Series(meankcoreACF)], axis=1).iloc[1:, :]
113
fout = open("meanAC.csv", 'w')
151
fout = open("meanAC"+nick+".csv", 'w')
114 152
toWrite.to_csv(fout, index=False)
153
fout.close()
154

  
155
bc_deg = []
156
bc_kcore = []
157
deg_kcore = []
158
for n in nodes:
159
    bcn = bcdf.iloc[:, n]
160
    degn = degdf.iloc[:, n]
161
    kn = kcoredf.iloc[:, n]
162
    cordf = pd.concat([bcn, degn, kn], axis=1)
163
    cm = cordf.corr()
164
    bc_deg.append(cm['bc']['deg'])
165
    bc_kcore.append(cm['bc']['kcore'])
166
    deg_kcore.append(cm['deg']['kcore'])
167

  
168

  
169
a = np.mean(bc_deg)
170
b = np.mean(bc_kcore)
171
c = np.mean(deg_kcore)
172
toplotdf = pd.DataFrame([[1, a, b],
173
                         [a, 1, c],
174
                         [b, c, 1]])
175
import seaborn as sns
176
sns.set()
177

  
178
#TODO
179
#sns.heatmap(degdf.corr(), cmap="RdBu_r", center=0.0, vmin=-1.0, vmax=1.0)
180

  
181

  
182
sns.heatmap(toplotdf, cmap="RdBu_r", center=0.0, vmin=-1.0, vmax=1.0)
183
plt.savefig(nick+"meanMetricsCorrelation.pdf", format='pdf')
184
plt.clf()
185

  
186
fout = open("meanMetricsCorr"+nick+".csv", 'w')
187
toplotdf.to_csv(fout, index=False)
188
fout.close()
115 189

  
116 190
'''
117 191

  

Also available in: Unified diff