Statistics
| Branch: | Revision:

## mobicen / nkStudy.py @ 9f4f3f35

 1 ```import code # code.interact(local=dict(globals(), **locals())) ``` ```from collections import deque ``` ```from scipy import stats ``` ```import matplotlib.pyplot as plt ``` ```from collections import defaultdict ``` ```import os ``` ```import sys ``` ```from statsmodels.graphics.tsaplots import plot_acf, acf ``` ```import operator ``` ```from mpl_toolkits import mplot3d ``` ```import pandas as pd ``` ```from pprint import pprint ``` ```import numpy as np ``` ```import glob ``` ```folder = sys.argv[1] ``` ```lags = 100 ``` ```if len(sys.argv) > 2: ``` ``` lags = int(sys.argv[2]) ``` ```nick = folder.split('/')[-2].split('_')[0] ``` ```os.chdir(folder) ``` ```bcdf = pd.DataFrame() # rows=nodes columns=BC at column-index time-instant ``` ```degdf = pd.DataFrame() # rows=nodes columns=DEG at column-index time-instant ``` ```kcoredf = pd.DataFrame() # rows=nodes columns=KCORE at column-index time-instant ``` ```allnkd=pd.DataFrame() ``` ```print "Loading data from", folder, "..." ``` ```for snap in sorted(glob.glob('./stats*')): ``` ``` # print "",snap ``` ``` node_id = int(snap.strip('.csv').strip('./stats')) ``` ``` df = pd.read_csv(snap, names=['time', 'bc', 'deg', 'kcore'], skiprows=1) ``` ``` d={(node_id, t): (df.iloc[t]['bc'], df.iloc[t]['deg'], df.iloc[t]['kcore']) for t in df.index} ``` ``` nkd=pd.DataFrame.from_dict(d, orient='index', columns=['bc', 'deg', 'kcore']) ``` ``` allnkd=allnkd.append(nkd) ``` ```srtNK=allnkd.sort_values(by=['bc'], ascending=False) ``` ```#code.interact(local=dict(globals(), **locals())) ``` ```#min-max Normalize columns ``` ```for c in srtNK.columns: ``` ``` srtNK[c] = (srtNK[c] - srtNK[c].min()) / (srtNK[c].max() - srtNK[c].min()) ``` ```bc, deg, kcore = srtNK['bc'], srtNK['deg'], srtNK['kcore'] ``` ```bcc = bc - bc.mean() ``` ```degc = deg - deg.mean() ``` ```kcorec = kcore - kcore.mean() ``` ```y=srtNK['bc'] ``` ```bcdeg = bcc * degc ``` ```degkcore = degc * kcorec ``` ```bckcore = bcc * kcorec ``` ```if not os.path.exists("plots"+nick): ``` ``` os.makedirs("plots"+nick) ``` ```os.chdir("plots"+nick) ``` ```'''import math ``` ```ymin=math.floor(min(map(min, [bcdeg, degkcore, bckcore, y]))) ``` ```ymax=math.ceil(max(map(max, [bcdeg, degkcore, bckcore, y])))''' ``` ```bcdeg.plot(label='bc-deg', style='b--') ``` ```y.plot(label='BC', kind='line', style='k-') ``` ```plt.xticks([], []) ``` ```plt.legend() ``` ```plt.axhline(y=0.1, color='r', linestyle='--', lw=1.2) ``` ```plt.axhline(y=0.0, color='r', linestyle='--', lw=2) ``` ```plt.axhline(y=-0.1, color='r', linestyle='--', lw=1.2) ``` ```plt.ylim(-0.2, 1.0) ``` ```plt.yticks(np.arange(-0.2, 1.0, step=0.1)) ``` ```plt.xlabel("(nodeID, time) couples, sorted by BC") ``` ```plt.ylabel("Product of First Central Moments") ``` ```plt.savefig(nick+"bc-degEvo.pdf", format='pdf') ``` ```plt.clf() ``` ```degkcore.plot(label='deg-kcore', style='r-') ``` ```y.plot(label='BC', kind='line', style='k-') ``` ```plt.xticks([], []) ``` ```plt.legend() ``` ```plt.axhline(y=0.1, color='r', linestyle='--', lw=1.2) ``` ```plt.axhline(y=0.0, color='r', linestyle='--', lw=2) ``` ```plt.axhline(y=-0.1, color='r', linestyle='--', lw=1.2) ``` ```plt.ylim(-0.2, 1.0) ``` ```plt.xlabel("(nodeID, time) couples, sorted by BC") ``` ```plt.ylabel("Product of First Central Moments") ``` ```plt.yticks(np.arange(-0.2, 1.0, step=0.1)) ``` ```plt.savefig(nick+"deg-kcoreEvo.pdf", format='pdf') ``` ```plt.clf() ``` ```bckcore.plot(label='bc-kcore', style='g-') ``` ```y.plot(label='BC', kind='line', style='k-') ``` ```plt.legend() ``` ```plt.axhline(y=0.1, color='r', linestyle='--', lw=1.2) ``` ```plt.axhline(y=0.0, color='r', linestyle='--', lw=2) ``` ```plt.axhline(y=-0.1, color='r', linestyle='--', lw=1.2) ``` ```plt.ylim(-0.2, 1.0) ``` ```plt.yticks(np.arange(-0.2, 1.0, step=0.1)) ``` ```plt.xticks([], []) ``` ```plt.xlabel("(nodeID, time) couples, sorted by BC") ``` ```plt.ylabel("Product of First Central Moments") ``` ```plt.savefig(nick+"bc-kcoreEvo.pdf", format='pdf') ``` ```plt.clf() ``` ```print "THE END" ```