Statistics
| Branch: | Revision:

## mobicen / util / MyUtil.py @ fa4a0a42

History | View | Annotate | Download (1.39 KB)

 1 from prettytable import PrettyTable import numpy as np import networkx as nx import random as rnd import matplotlib.pyplot as plt plt.ion() import matplotlib.colors as mcolors import sys import code # code.interact(local=dict(globals(), **locals())) def draw(G, pos, xmax, ymax): lay = {k:pos[k] for k in range(0,len(pos))} measures = nx.load_centrality(G, normalized = False, weight = 'weight') measure_name = "Load" nodes = nx.draw_networkx_nodes(G, lay, node_size=100, cmap=plt.cm.gnuplot2, node_color=measures.values(), nodelist=measures.keys()) nodes.set_norm(mcolors.SymLogNorm(linthresh=0.01, linscale=1)) edges = nx.draw_networkx_edges(G, lay) plt.title(measure_name) plt.colorbar(nodes) plt.xlim(0, xmax) plt.ylim(0, ymax) plt.draw() plt.pause(0.01) plt.clf() #plt.show() def dictAlikes(d1, d2, perc): if (sorted(d1.keys()) != sorted(d2.keys())): return False for k in d1: a = float(d1[k]) b = float(d2[k]) if (not b - (b*perc) <= a <= b + (b*perc)): return False return True def summary(v): vmin=min(v) vmax=max(v) tot=sum(v) avg=np.mean(v) std=np.std(v) t = PrettyTable(['min','max', 'mean','std','tot']) s = "%.4f %.4f %.4f %.4f %.4f" % (vmin,vmax,avg,std,tot) t.add_row(s.split()) print t return avg, std, vmax, vmin, tot