-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalculate-stats.py
More file actions
52 lines (38 loc) · 1.38 KB
/
calculate-stats.py
File metadata and controls
52 lines (38 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from networkx import *
import pickle
import numpy as np
import pandas as pd
from scipy import stats
from algo import *
from centrality import *
with open("./computed-data/final-graph.pickle") as infile:
g = pickle.load(infile)
G = g
#print("radius: %d" % radius(G))
#print("diameter: %d" % diameter(G))
# print("eccentricity: %s" % eccentricity(G))
#print("center: %s" % center(G))
#print("periphery: %s" % periphery(G))
#print("density: %s" % density(G))
# draw(G)
# this part was wrong before. Must use int not string if that's what I built graph with in first place
# print "degree of 222 is %s" % nx.degree(g, 222)
print "number of nodes: %i" % G.number_of_nodes()
print "number of edges: %i" % G.number_of_edges()
# print "neighbors of 222: %s " % g.neighbors(222)
# print "nodes: %s " % g.nodes()
# print "edges: %s " % g.edges()
at_risk_nodes = (n for n in G if G.node[n]['at_risk'] == 1)
at_risk_list = list (at_risk_nodes)
not_at_risk_nodes = (n for n in G if G.node[n]['at_risk'] == 0)
not_at_risk_list = list(not_at_risk_nodes)
print "#### clustering coeff"
cluster = Clustering("clustering_coeff")
cluster.run(G, at_risk_list, not_at_risk_list)
print "#### betweenness centrality"
b = BetweennessCentrality("betweenness", at_risk_list,not_at_risk_list)
b.run(G)
print "#### degree centrality"
d = DegreeCentrality("degree-centrality", at_risk_list,not_at_risk_list)
d.run(G)
print "done."