## Revision c457778e

View differences:

autoPlot.py
10 10
```import time
```
11 11
```import shutil
```
12 12

13
```interval = 100
```
13
```interval = 200
```
14 14
```if len(sys.argv)>1:
```
15 15
```    interval = int(sys.argv[1])
```
16 16

17 17
```#code.interact(local=dict(globals(), **locals()))
```
18 18

19
```for fold in sorted(glob.glob('out/rwp*/')):
```
19
```for fold in sorted(glob.glob('out/nn*/')):
```
20 20
```    pass
```
21 21
```    #cmd = "python plotterBCrealization.py "+fold+" "+str(interval)
```
22 22
```    cmd = "python timeAnalysis.py "+fold+" "+str(interval)
```
plotterBCrealization.py
18 18

19 19

20 20

21
```# https://en.wikipedia.org/wiki/Sample_entropy
```
22
```def SampEn(U, m, r):
```
23
```    """Compute Sample entropy"""
```
24
```    def _maxdist(x_i, x_j):
```
25
```        return max([abs(ua - va) for ua, va in zip(x_i, x_j)])
```
26

27
```    def _phi(m):
```
28
```        x = [[U[j] for j in range(i, i + m - 1 + 1)] for i in range(N - m + 1)]
```
29
```        C = [len([1 for j in range(len(x)) if i != j and _maxdist(x[i], x[j]) <= r]) for i in range(len(x))]
```
30
```        return sum(C)
```
31

32
```    N = len(U)
```
33
```    return -np.log(_phi(m+1) / _phi(m))
```
34

35
```ss = pd.read_csv('https://raw.githubusercontent.com/selva86/datasets/master/sunspotarea.csv')
```
36
```a10 = pd.read_csv('https://raw.githubusercontent.com/selva86/datasets/master/a10.csv')
```
37
```rand_small = np.random.randint(0, 100, size=36)
```
38
```rand_big = np.random.randint(0, 100, size=136)
```
39

40
```print(SampEn(ss.value, m=2, r=0.2*np.std(ss.value)))      # 0.78
```
41
```print(SampEn(a10.value, m=2, r=0.2*np.std(a10.value)))    # 0.41
```
42
```print(SampEn(rand_small, m=2, r=0.2*np.std(rand_small)))  # 1.79
```
43
```print(SampEn(rand_big, m=2, r=0.2*np.std(rand_big)))      # 2.42
```
44

45

46

47 21
```folder = sys.argv[1]
```
48 22
```interval = 100
```
49 23
```if len(sys.argv) > 2:
```
timeAnalysis.py
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 column-index time-instant
```
27
```bcdf = pd.DataFrame()  # rows=nodes columns=BC at column-index time-instant
```
28
```degdf = pd.DataFrame()  # rows=nodes columns=DEG at column-index time-instant
```
29
```kcoredf = pd.DataFrame()  # rows=nodes columns=KCORE at column-index time-instant
```
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=Time-Lags, columns = nodes
```
51
```bcACF = pd.DataFrame()  # rows=Time-Lags, columns = nodes
```
52
```degACF = pd.DataFrame()  # rows=Time-Lags, columns = nodes
```
53
```kcoreACF = pd.DataFrame()  # rows=Time-Lags, 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 ==> time-lag
```
......
63 78
```# Plotting
```
64 79
```# Mean AutoCorrelation and Rank-Correlation
```
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='Rank-Correlation (with rank at t_0)')
```
79
```#plt.plot(x, weightedRankCorr, lw="1.5",
```
100
```# plt.plot(x, weightedRankCorr, lw="1.5",
```
80 101
```#         label='Weighted-Rank-Correlation (with rank at t_0)')
```
81 102
```plt.ylabel('Corr coeff: [ACF, Spearman rho]')
```
82 103
```plt.xlabel('Time-lags / Time')
```
......
87 108
```plt.savefig(nick+"autoCorrMean-RankSpearman.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+"autoBC-3d.pdf", format="pdf")
```
175
```plt.savefig(nick+"autoBC-3d.pdf", format="pdf")'''
```
151 176

152 177
```print "THE END"
```

Also available in: Unified diff