18 
18 

19 
19 

20 
20 
folder = sys.argv[1]

21 

lags = int(sys.argv[2])


21 
lags = 100


22 
if len(sys.argv) > 2:


23 
lags = int(sys.argv[2])

22 
24 
nick = folder.split('/')[2].split('_')[0]+"_"

23 
25 
os.chdir(folder)

24 
26 

25 

dfn = pd.DataFrame() # rows=nodes columns=BC at columnindex timeinstant


27 
bcdf = pd.DataFrame() # rows=nodes columns=BC at columnindex timeinstant


28 
degdf = pd.DataFrame() # rows=nodes columns=DEG at columnindex timeinstant


29 
kcoredf = pd.DataFrame() # rows=nodes columns=KCORE at columnindex timeinstant

26 
30 
print "Loading data from", folder, "..."

27 
31 
for snap in sorted(glob.glob('./stats*')):

28 

# print snap


32 
# print "",snap

29 
33 
node_id = int(snap.strip('.csv').strip('./stats'))

30 

df = pd.read_csv(snap, names=['time', str(node_id)], skiprows=1)

31 

dfn = pd.concat([dfn, df[str(node_id)]], axis=1)


34 
df = pd.read_csv(snap, names=['time', 'bc', 'deg', 'kcore'], skiprows=1)


35 
bcdf = pd.concat([bcdf, df['bc']], axis=1)


36 
degdf = pd.concat([degdf, df['deg']], axis=1)


37 
kcoredf = pd.concat([kcoredf, df['kcore']], axis=1)

32 
38 

33 
39 

34 

nodes = dfn.columns.tolist()


40 
nodes = range(len(bcdf.columns))

35 
41 

36 
42 
initialCentrality = {}

37 
43 
for n in nodes:

38 

initialCentrality[int(n)] = dfn.iloc[0][n]


44 
initialCentrality[int(n)] = bcdf.iloc[0][n]

39 
45 

40 
46 

41 
47 
sorted_x = sorted(initialCentrality.items(),

42 
48 
key=operator.itemgetter(1), reverse=True)

43 
49 
srtNodes = [e[0] for e in sorted_x]

44 
50 

45 

dfACF = pd.DataFrame() # rows=TimeLags, columns = nodes


51 
bcACF = pd.DataFrame() # rows=TimeLags, columns = nodes


52 
degACF = pd.DataFrame() # rows=TimeLags, columns = nodes


53 
kcoreACF = pd.DataFrame() # rows=TimeLags, columns = nodes

46 
54 
print "Processing data..."

47 
55 
for node in nodes:

48 

#print "Autocorr of node", node

49 

nodeACF = pd.DataFrame([dfn[node].autocorr(lag) for lag in range(lags)])

50 

dfACF = pd.concat([dfACF, nodeACF], axis=1)

51 



56 
# print "Autocorr of node", node


57 
nodebcACF = pd.DataFrame([bcdf.iloc[:, node].autocorr(lag)


58 
for lag in range(lags)])


59 
bcACF = pd.concat([bcACF, nodebcACF], axis=1)


60 
nodedegACF = pd.DataFrame(


61 
[degdf.iloc[:, node].autocorr(lag) for lag in range(lags)])


62 
degACF = pd.concat([degACF, nodedegACF], axis=1)


63 
nodekcoreACF = pd.DataFrame(


64 
[kcoredf.iloc[:, node].autocorr(lag) for lag in range(lags)])


65 
kcoreACF = pd.concat([kcoreACF, nodekcoreACF], axis=1)


66 
#code.interact(local=dict(globals(), **locals()))

52 
67 

53 
68 
'''

54 
69 
X ==> timelag

...  ...  
63 
78 
# Plotting

64 
79 
# Mean AutoCorrelation and RankCorrelation

65 
80 
# lags=20

66 

firstRank = dfn.iloc[0,:]


81 
firstRank = bcdf.iloc[0, :]

67 
82 
x = range(0, lags)

68 

meanACF = []


83 
meanbcACF = []


84 
meandegACF = []


85 
meankcoreACF = []

69 
86 
rankCorr = []

70 
87 
weightedRankCorr = []

71 
88 
for i in x:

72 
89 
#code.interact(local=dict(globals(), **locals()))

73 

meanACF.append(np.mean(dfACF.iloc[i]))

74 

rankCorr.append(stats.spearmanr(firstRank, dfn.iloc[i,:])[0])


90 
meanbcACF.append(np.mean(bcACF.iloc[i]))


91 
meandegACF.append(np.mean(degACF.iloc[i]))


92 
meankcoreACF.append(np.mean(kcoreACF.iloc[i]))


93 
rankCorr.append(stats.spearmanr(firstRank, bcdf.iloc[i, :])[0])

75 
94 
#weightedRankCorr.append(stats.weightedtau(firstRank, dfn.iloc[i,:])[0])

76 
95 

77 

plt.plot(x, meanACF, lw="1.5", label='Mean Autocorrelation')


96 
plt.plot(x, meanbcACF, lw="1.5", label='Mean BC Autocorrelation')


97 
plt.plot(x, meandegACF, lw="1.5", label='Mean DEG Autocorrelation')


98 
plt.plot(x, meankcoreACF, lw="1.5", label='Mean KCORE Autocorrelation')

78 
99 
plt.plot(x, rankCorr, lw="1.5", label='RankCorrelation (with rank at t_0)')

79 

#plt.plot(x, weightedRankCorr, lw="1.5",


100 
# plt.plot(x, weightedRankCorr, lw="1.5",

80 
101 
# label='WeightedRankCorrelation (with rank at t_0)')

81 
102 
plt.ylabel('Corr coeff: [ACF, Spearman rho]')

82 
103 
plt.xlabel('Timelags / Time')

...  ...  
87 
108 
plt.savefig(nick+"autoCorrMeanRankSpearman.pdf", format='pdf')

88 
109 
plt.clf()

89 
110 


111 
toWrite = pd.concat([pd.Series(meanbcACF), pd.Series(


112 
meandegACF), pd.Series(meankcoreACF)], axis=1).iloc[1:, :]


113 
fout = open("meanAC.csv", 'w')


114 
toWrite.to_csv(fout, index=False)

90 
115 

91 
116 
'''

92 
117 

...  ...  
127 
152 

128 
153 
'''

129 
154 

130 

X, Y, Z = [], [], []


155 
'''X, Y, Z = [], [], []

131 
156 
for node in srtNodes:

132 
157 
#print "n:", node

133 
158 
for lag in range(lags):

...  ...  
135 
160 
#code.interact(local=dict(globals(), **locals()))

136 
161 
X.append(lag)

137 
162 
Y.append(node)

138 

Z.append(list(dfACF.iloc[lag])[node])


163 
Z.append(list(bcACF.iloc[lag])[node])

139 
164 

140 
165 

141 
166 
fig = plt.figure()

...  ...  
147 
172 
ax.set_xlim(0, lags)

148 
173 
ax.set_ylim(0, len(srtNodes))

149 
174 
#ax.set_zlim(1.0, 1.0)

150 

plt.savefig(nick+"autoBC3d.pdf", format="pdf")


175 
plt.savefig(nick+"autoBC3d.pdf", format="pdf")'''

151 
176 

152 
177 
print "THE END"
