Revision c16015e2 timeAnalysis.py

View differences:

timeAnalysis.py
24 24

  
25 25
dfn = pd.DataFrame()  # rows=nodes columns=BC at column-index time-instant
26 26
print "Loading data from", folder, "..."
27
for snap in sorted(glob.glob('./BC*')):
27
for snap in sorted(glob.glob('./stats*')):
28 28
    # print snap
29
    df = pd.read_csv(snap, names=['BC'], skiprows=1)
30
    dfn = pd.concat([dfn, df], axis=1)
29
    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)
31 32

  
32
nodes = dfn.index.tolist()
33

  
34
nodes = dfn.columns.tolist()
33 35

  
34 36
initialCentrality = {}
35 37
for n in nodes:
36
    initialCentrality[n] = dfn.iloc[n][0]
38
    initialCentrality[int(n)] = dfn.iloc[0][n]
37 39

  
38 40

  
39 41
sorted_x = sorted(initialCentrality.items(),
......
43 45
dfACF = pd.DataFrame()  # rows=Time-Lags, columns = nodes
44 46
print "Processing data..."
45 47
for node in nodes:
46
    nodeACF = [pd.Series(dfn.iloc[node]).autocorr(lag) for lag in range(lags)]
47
    nodeACF = pd.DataFrame(nodeACF)
48
    print "Autocorr of node", node
49
    nodeACF = pd.DataFrame([dfn[node].autocorr(lag) for lag in range(lags)])
48 50
    dfACF = pd.concat([dfACF, nodeACF], axis=1)
49 51

  
50 52

  
......
56 58

  
57 59
if not os.path.exists("plots"+nick):
58 60
    os.makedirs("plots"+nick)
61

  
59 62
os.chdir("plots"+nick)
60 63
# Plotting
61 64
# Mean AutoCorrelation and Rank-Correlation
62 65
# lags=20
63
firstRank = dfn.iloc[:, 0]
66
firstRank = dfn.iloc[0,:]
64 67
x = range(0, lags)
65 68
meanACF = []
66 69
rankCorr = []
67 70
weightedRankCorr = []
68 71
for i in x:
72
    #code.interact(local=dict(globals(), **locals()))
69 73
    meanACF.append(np.mean(dfACF.iloc[i]))
70
    rankCorr.append(stats.spearmanr(firstRank, dfn.iloc[:, i])[0])
71
    weightedRankCorr.append(stats.weightedtau(firstRank, dfn.iloc[:, i])[0])
74
    rankCorr.append(stats.spearmanr(firstRank, dfn.iloc[i,:])[0])
75
    #weightedRankCorr.append(stats.weightedtau(firstRank, dfn.iloc[i,:])[0])
76

  
72 77
plt.plot(x, meanACF, lw="1.5", label='Mean Autocorrelation')
73 78
plt.plot(x, rankCorr, lw="1.5", label='Rank-Correlation (with rank at t_0)')
74
plt.plot(x, weightedRankCorr, lw="1.5",
75
         label='Weighted-Rank-Correlation (with rank at t_0)')
79
#plt.plot(x, weightedRankCorr, lw="1.5",
80
#         label='Weighted-Rank-Correlation (with rank at t_0)')
76 81
plt.ylabel('Corr coeff: [ACF, Spearman rho]')
77 82
plt.xlabel('Time-lags / Time')
78 83
plt.grid()
......
81 86
plt.xlim(0, lags)
82 87
plt.savefig(nick+"autoCorrMean-RankSpearman.pdf", format='pdf')
83 88
plt.clf()
89

  
90

  
84 91
'''
85 92

  
86 93

  
......
118 125

  
119 126
plt.clf()
120 127

  
121
code.interact(local=dict(globals(), **locals()))'''
128
'''
122 129

  
123 130
X, Y, Z = [], [], []
124 131
for node in srtNodes:
132
    print "n:", node
125 133
    for lag in range(lags):
134
        print "\tn:%d  lag:%d" % (node,lag)
135
        #code.interact(local=dict(globals(), **locals()))
126 136
        X.append(lag)
127 137
        Y.append(node)
128 138
        Z.append(list(dfACF.iloc[lag])[node])

Also available in: Unified diff