Statistics
| Branch: | Revision:

mobicen / util / MyUtil.py @ e1cf8bea

History | View | Annotate | Download (1.37 KB)

1
from prettytable import PrettyTable
2
import numpy as np
3
import networkx as nx 
4
import random as rnd
5
import matplotlib.pyplot as plt
6
import matplotlib.colors as mcolors
7
import sys
8
import code  # code.interact(local=dict(globals(), **locals()))
9

    
10
def draw(G, pos, xmax, ymax):
11
    lay = {k:pos[k] for k in range(0,len(pos))}
12
    measures = nx.load_centrality(G, normalized = False, weight = 'weight')
13
    measure_name = "Load"
14
    nodes = nx.draw_networkx_nodes(G, lay, node_size=100, cmap=plt.cm.gnuplot2, 
15
                                   node_color=measures.values(),
16
                                   nodelist=measures.keys())
17
    nodes.set_norm(mcolors.SymLogNorm(linthresh=0.01, linscale=1))
18

    
19
    edges = nx.draw_networkx_edges(G, lay)
20
    plt.title(measure_name)
21
    plt.colorbar(nodes)
22

    
23
    plt.xlim(0, xmax)
24
    plt.ylim(0, ymax)
25
    
26
    plt.draw()
27
    plt.pause(0.01)
28
    plt.clf()
29
    
30

    
31
def dictAlikes(d1, d2, perc):
32
        if (sorted(d1.keys()) != sorted(d2.keys())):
33
                return False
34
        for k in d1:
35
                a = float(d1[k])
36
                b = float(d2[k])
37
                if (not b - (b*perc) <= a <= b + (b*perc)):
38
                        return False
39
        return True
40

    
41
def summary(v):
42
    vmin=min(v)
43
    vmax=max(v)
44
    tot=sum(v)
45
    avg=np.mean(v)
46
    std=np.std(v)
47
    t = PrettyTable(['min','max', 'mean','std','tot'])
48
    s = "%.4f %.4f %.4f %.4f %.4f" % (vmin,vmax,avg,std,tot)
49
    t.add_row(s.split())
50
    print t
51
    return avg, std, vmax, vmin, tot