Statistics
| Branch: | Revision:

mobicen / nkStudy.py @ 9f4f3f35

History | View | Annotate | Download (3.37 KB)

1
import code  # code.interact(local=dict(globals(), **locals()))
2
from collections import deque
3
from scipy import stats
4
import matplotlib.pyplot as plt
5
from collections import defaultdict
6
import os
7
import sys
8
from statsmodels.graphics.tsaplots import plot_acf, acf
9
import operator
10
from mpl_toolkits import mplot3d
11
import pandas as pd
12
from pprint import pprint
13
import numpy as np
14
import glob
15

    
16

    
17

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

    
25
bcdf = pd.DataFrame()  # rows=nodes columns=BC at column-index time-instant
26
degdf = pd.DataFrame()  # rows=nodes columns=DEG at column-index time-instant
27
kcoredf = pd.DataFrame()  # rows=nodes columns=KCORE at column-index time-instant
28
allnkd=pd.DataFrame()
29
print "Loading data from", folder, "..."
30
for snap in sorted(glob.glob('./stats*')):
31
    # print "",snap
32
    node_id = int(snap.strip('.csv').strip('./stats'))
33
    df = pd.read_csv(snap, names=['time', 'bc', 'deg', 'kcore'], skiprows=1)
34
    d={(node_id, t): (df.iloc[t]['bc'], df.iloc[t]['deg'], df.iloc[t]['kcore']) for t in df.index}
35
    nkd=pd.DataFrame.from_dict(d, orient='index', columns=['bc', 'deg', 'kcore'])
36
    allnkd=allnkd.append(nkd)
37

    
38
srtNK=allnkd.sort_values(by=['bc'], ascending=False)
39

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

    
42
#min-max Normalize columns
43
for c in srtNK.columns:
44
    srtNK[c] = (srtNK[c] - srtNK[c].min()) / (srtNK[c].max() - srtNK[c].min())
45

    
46
bc, deg, kcore = srtNK['bc'], srtNK['deg'], srtNK['kcore']
47

    
48
bcc = bc - bc.mean()
49
degc = deg - deg.mean()
50
kcorec = kcore - kcore.mean()
51

    
52
y=srtNK['bc']
53
bcdeg = bcc * degc
54
degkcore = degc * kcorec
55
bckcore = bcc * kcorec
56

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

    
60
os.chdir("plots"+nick)
61

    
62
'''import math
63
ymin=math.floor(min(map(min, [bcdeg, degkcore, bckcore, y])))
64
ymax=math.ceil(max(map(max, [bcdeg, degkcore, bckcore, y])))'''
65

    
66

    
67
bcdeg.plot(label='bc-deg', style='b--')
68
y.plot(label='BC', kind='line', style='k-')
69
plt.xticks([], [])
70
plt.legend()
71
plt.axhline(y=0.1, color='r', linestyle='--', lw=1.2)
72
plt.axhline(y=0.0, color='r', linestyle='--', lw=2)
73
plt.axhline(y=-0.1, color='r', linestyle='--', lw=1.2)
74
plt.ylim(-0.2, 1.0)
75
plt.yticks(np.arange(-0.2, 1.0, step=0.1))
76
plt.xlabel("(nodeID, time) couples, sorted by BC")
77
plt.ylabel("Product of First Central Moments")
78
plt.savefig(nick+"bc-degEvo.pdf", format='pdf')
79
plt.clf()
80

    
81
degkcore.plot(label='deg-kcore', style='r-')
82
y.plot(label='BC', kind='line', style='k-')
83
plt.xticks([], [])
84
plt.legend()
85
plt.axhline(y=0.1, color='r', linestyle='--', lw=1.2)
86
plt.axhline(y=0.0, color='r', linestyle='--', lw=2)
87
plt.axhline(y=-0.1, color='r', linestyle='--', lw=1.2)
88
plt.ylim(-0.2, 1.0)
89
plt.xlabel("(nodeID, time) couples, sorted by BC")
90
plt.ylabel("Product of First Central Moments")
91
plt.yticks(np.arange(-0.2, 1.0, step=0.1))
92
plt.savefig(nick+"deg-kcoreEvo.pdf", format='pdf')
93
plt.clf()
94

    
95
bckcore.plot(label='bc-kcore', style='g-')
96
y.plot(label='BC', kind='line', style='k-')
97
plt.legend()
98
plt.axhline(y=0.1, color='r', linestyle='--', lw=1.2)
99
plt.axhline(y=0.0, color='r', linestyle='--', lw=2)
100
plt.axhline(y=-0.1, color='r', linestyle='--', lw=1.2)
101
plt.ylim(-0.2, 1.0)
102
plt.yticks(np.arange(-0.2, 1.0, step=0.1))
103
plt.xticks([], [])
104
plt.xlabel("(nodeID, time) couples, sorted by BC")
105
plt.ylabel("Product of First Central Moments")
106
plt.savefig(nick+"bc-kcoreEvo.pdf", format='pdf')
107
plt.clf()
108

    
109
print "THE END"