forked from bachsh/kplex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
73 lines (58 loc) · 1.68 KB
/
tests.py
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import networkx as nx
from kplex import kplexAlg
import matplotlib.pyplot as plt
from time import time
import pandas as pd
import pickle
from os.path import isfile
def simpleExample():
print "running simple example"
G = nx.Graph({
0: {1,2},
1: {0, 4,5},
2: {3,4,0},
3: {2,4,5},
4: {1,2,3},
5: {1,2,3}
})
N = len(G.nodes())
k = 2
analyzeNetwork(G, k, "simple")
# kplexes = kplexAlg(G, k)
def timings():
N_range = [5, 10, 30, 50, 100, 200, 500, 1000, 10000]
N_range = [5, 10, 30, 50, 100, 200]
df = pd.DataFrame({}, columns=["N", "time"])
for N in N_range:
print N
G = nx.fast_gnp_random_graph(N, 10./N)
start_time = time()
kplexAlg(G, 2)
run_time = time()-start_time
print run_time
df.loc[len(df)] = [N, run_time]
df = df.set_index("N")
print df
def analyzeNetwork(G, k=2, filename=None):
# Get kplexes
if filename and isfile(filename):
kplexesMax = pickle.load(open(filename))
else:
_, kplexesMax = kplexAlg(G, k, verbose=True)
if filename:
pickle.dump(kplexesMax, open(filename, 'wb'))
print "List of {}-plexes".format(k)
print kplexesMax
# get histogram for size of kplex
kplexSizes = map(len, kplexesMax)
plt.hist(kplexSizes)
# get MCC size...
def c_elegans():
print "Reading worm..."
G = nx.read_gml("Networks/CelegansNeural/celegansneural.gml")
print "Done Reading worm. Worm has {} nodes and {} edges".format(len(G.nodes()), len(G.edges()))
analyzeNetwork(G, 2, "worm")
if __name__ == "__main__":
# simpleExample()
# timings()
c_elegans()