Statistics
| Branch: | Revision:

mobicen / util / MyUtil.py @ fa4a0a42

History | View | Annotate | Download (1.39 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
plt.ion()
7
import matplotlib.colors as mcolors
8
import sys
9
import code  # code.interact(local=dict(globals(), **locals()))
10

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

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

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

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

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