Revision cf03b931

View differences:

settings.ini
168 168

  
169 169

  
170 170

  
171

  
171
[std]
172
duration = 100s
173
nodes_number = 50
174
max_x = 100
175
max_y = 100
176
min_velocity = 10.0
177
max_velocity = 100.0
178
radius = 30.0
179
mobility_timer = 1s
180
mob_model = RandomWayPoint
181
max_wait_time = 1.0
172 182

  
173 183
[fast]
174 184
duration = 100s
simulator.py
59 59
        for stat in whatLog:
60 60
            if stat == 'BC':
61 61
                bw_centrality = nx.betweenness_centrality(
62
                    G, normalized=False,  weight='weight', endpoints=False)
62
                    G, normalized=False,  weight='weight', endpoints=True)
63 63
                df = pd.DataFrame(bw_centrality.items(),
64 64
                                  columns=['Node', 'BC'])
65 65
                df.to_csv(self.OP+"/BC"+tag+".csv", sep=',',
timeAnalysis.py
15 15
nick = sys.argv[3]
16 16
os.chdir(folder)
17 17

  
18
timeBC = defaultdict(list)
18
dfn = pd.DataFrame() #rows=nodes columns=BC at column-index time-instant 
19 19
print "Loading data from", folder, "..."
20 20
for snap in sorted(glob.glob('./BC*')):
21 21
    # print snap
22
    df = pd.read_csv(snap, names=['Node', 'BC'], skiprows=1)
23
    for index, row in df.iterrows():
24
        timeBC[int(row.Node)].append(row.BC)
22
    df = pd.read_csv(snap, names=['BC'], skiprows=1)
23
    dfn = pd.concat([dfn,df], axis=1)
24

  
25
nodes = dfn.index.tolist()
25 26

  
26 27
initialCentrality = {}
27
for n in timeBC:
28
    initialCentrality[n] = timeBC[n][0]
28
for n in nodes:
29
    initialCentrality[n] = dfn.iloc[n][0]
29 30

  
30 31
from mpl_toolkits import mplot3d
31 32
import operator
......
33 34
sorted_x = sorted(initialCentrality.items(), key=operator.itemgetter(1), reverse=True)
34 35
srtNodes = [e[0] for e in sorted_x]
35 36

  
37
dfACF = pd.DataFrame() # rows=Time-Lags, columns = nodes
36 38
print "Processing data..."
37
lags2NodeACF = defaultdict(list)
38
node2ACF = defaultdict(list)
39
for node in timeBC:
40
    nodeACF = acf(timeBC[node], nlags=lags)
41
    node2ACF[node] = nodeACF
42
    for lag in range(0, len(nodeACF)):
43
        lags2NodeACF[lag].append(nodeACF[lag])
39
for node in nodes:
40
    nodeACF =[pd.Series(dfn.iloc[node]).autocorr(lag) for lag in range(lags)]
41
    #code.interact(local=dict(globals(), **locals()))
42
    nodeACF = pd.DataFrame(nodeACF)
43
    dfACF = pd.concat([dfACF, nodeACF], axis=1)
44

  
44 45

  
45 46
'''
46 47
X ==> time-lag
47 48
Y ==> i nodi in ordine di centralita a tempo_0
48 49
Z ==> l'acf del nodo y al time-lag x
49 50
'''
50
#code.interact(local=dict(globals(), **locals()))
51
'''X,Y = range(lags), srtNodes
52

  
53
def myZ(X, Y):
54
    matrix = []
55
    for x in range(len(X)):
56
        matrix.append([])
57
        for y in range(len(Y)):
58
            #print "lag = %d, node = %d" % (X[x], Y[y])
59
            matrix[x].append(node2ACF[Y[y]][X[x]])
60
    return matrix'''
61

  
62

  
63
X,Y,Z = [], [], []
64
for node in srtNodes:
65
    for lag in range(lags):
66
        X.append(lag)
67
        Y.append(node)
68
        Z.append(node2ACF[node][lag])
69

  
70
xx, yy = np.meshgrid(X, Y)
71 51

  
72 52
os.chdir("./..")
73 53
# Plotting
......
76 56
x = range(0, lags)
77 57
y = []
78 58
for i in x:
79
    y.append(np.mean(lags2NodeACF[i]))
59
    y.append(np.mean(dfACF.iloc[i])) #[:,i] ==> all values of column i, where a column
80 60

  
81 61
plt.plot(x, y, lw="1.5")
82 62
plt.ylabel('Mean Autocorrelation')
......
86 66
plt.savefig(nick+"autoCorrMean.pdf", format='pdf')
87 67
plt.clf()
88 68

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

  
71
X,Y,Z = [], [], []
72
for node in srtNodes:
73
    for lag in range(lags):
74
        X.append(lag)
75
        Y.append(node)
76
        Z.append(list(dfACF.iloc[lag])[node])
77
        
89 78

  
90 79
fig = plt.figure()
91 80
ax = plt.axes(projection='3d')
......
97 86
ax.set_ylim(0, len(srtNodes))
98 87
#ax.set_zlim(-1.0, 1.0)
99 88
plt.savefig(nick+"autoBC-3d.pdf", format="pdf")
100
#plt.show()
101
#zz = 0*xx + 0*yy
102
#ax.plot_surface(xx, yy, zz, alpha=0.2)
103 89

  
104 90
print "Plot saved in", folder+".."
105 91
print "THE END"

Also available in: Unified diff