Commit 7ffbc6a92bdda0db272e80535612a38e52e829f0

Authored by Brice Colombier
1 parent a537329b06
Exists in master

Add random selection

Showing 4 changed files with 33 additions and 18 deletions

... ... @@ -4,5 +4,11 @@
4 4 test.py
5 5 CC.py
6 6 parsers/
7   -benchmarks/
  7 +benchmarks*.*/
  8 +benchmarks_*/
  9 +Tests/
  10 +convert_back_vhd.py
  11 +data/
  12 +*.csv
  13 +gen_mod_netlists.py
heuristic_approximated_current_flow_betweenness.py View file @ 7ffbc6a
... ... @@ -3,14 +3,14 @@
3 3 import numpy as np
4 4 import networkx as nx
5 5  
6   -def heuristic_approximated_current_flow_betweenness(g_nx, key_size, prim_in, exclude = " "):
  6 +def heuristic_approximated_current_flow_betweenness(g_nx, key_size, prim_in, exclude = " ", epsilons = [10.0, 30.0, 60.0]):
7 7 try:
8 8 # print("Trying option 1 (fastest)")
9 9 list_nodes_to_mask = [x for x in list(col.OrderedDict(sorted(nx.approximate_current_flow_betweenness_centrality(g_nx,
10 10 normalized = False,
11 11 solver = "full",
12 12 dtype = np.float32,
13   - epsilon = 1.0).items(), key=lambda t: t[1]))) if exclude not in x and x not in prim_in][-key_size:]
  13 + epsilon = epsilons[0]).items(), key=lambda t: t[1]))) if exclude not in x and x not in prim_in][-key_size:]
14 14 except:
15 15 try:
16 16 # print("Trying option 1 (fastest)")
... ... @@ -18,7 +18,7 @@
18 18 normalized = False,
19 19 solver = "full",
20 20 dtype = np.float32,
21   - epsilon = 5.0).items(), key=lambda t: t[1]))) if exclude not in x and x not in prim_in][-key_size:]
  21 + epsilon = epsilons[1]).items(), key=lambda t: t[1]))) if exclude not in x and x not in prim_in][-key_size:]
22 22 except:
23 23 try:
24 24 # print("Trying option 1 (fastest)")
... ... @@ -26,7 +26,7 @@
26 26 normalized = False,
27 27 solver = "full",
28 28 dtype = np.float32,
29   - epsilon = 10.0).items(), key=lambda t: t[1]))) if exclude not in x and x not in prim_in][-key_size:]
  29 + epsilon = epsilons[2]).items(), key=lambda t: t[1]))) if exclude not in x and x not in prim_in][-key_size:]
30 30 except:
31 31 try:
32 32 # print("Trying option 2 (average)")
... ... @@ -34,7 +34,7 @@
34 34 normalized = False,
35 35 solver = "lu",
36 36 dtype = np.float32,
37   - epsilon = 1.0).items(), key=lambda t: t[1]))) if exclude not in x and x not in prim_in][-key_size:]
  37 + epsilon = epsilons[0]).items(), key=lambda t: t[1]))) if exclude not in x and x not in prim_in][-key_size:]
38 38 except:
39 39 try:
40 40 # print("Trying option 2 (average)")
... ... @@ -42,7 +42,7 @@
42 42 normalized = False,
43 43 solver = "lu",
44 44 dtype = np.float32,
45   - epsilon = 5.0).items(), key=lambda t: t[1]))) if exclude not in x and x not in prim_in][-key_size:]
  45 + epsilon = epsilons[1]).items(), key=lambda t: t[1]))) if exclude not in x and x not in prim_in][-key_size:]
46 46 except:
47 47 try:
48 48 # print("Trying option 2 (average)")
... ... @@ -50,7 +50,7 @@
50 50 normalized = False,
51 51 solver = "lu",
52 52 dtype = np.float32,
53   - epsilon = 10.0).items(), key=lambda t: t[1]))) if exclude not in x and x not in prim_in][-key_size:]
  53 + epsilon = epsilons[2]).items(), key=lambda t: t[1]))) if exclude not in x and x not in prim_in][-key_size:]
54 54 except:
55 55 try:
56 56 # print("Trying option 3 (slowest)")
... ... @@ -58,7 +58,7 @@
58 58 normalized = False,
59 59 solver = "cg",
60 60 dtype = np.float32,
61   - epsilon = 1.0).items(), key=lambda t: t[1]))) if exclude not in x and x not in prim_in][-key_size:]
  61 + epsilon = epsilons[0]).items(), key=lambda t: t[1]))) if exclude not in x and x not in prim_in][-key_size:]
62 62 except:
63 63 try:
64 64 # print("Trying option 3 (slowest)")
... ... @@ -66,7 +66,7 @@
66 66 normalized = False,
67 67 solver = "cg",
68 68 dtype = np.float32,
69   - epsilon = 5.0).items(), key=lambda t: t[1]))) if exclude not in x and x not in prim_in][-key_size:]
  69 + epsilon = epsilons[1]).items(), key=lambda t: t[1]))) if exclude not in x and x not in prim_in][-key_size:]
70 70 except:
71 71 try:
72 72 # print("Trying option 3 (slowest)")
73 73  
... ... @@ -74,9 +74,9 @@
74 74 normalized = False,
75 75 solver = "cg",
76 76 dtype = np.float32,
77   - epsilon = 10.0).items(), key=lambda t: t[1]))) if exclude not in x and x not in prim_in][-key_size:]
  77 + epsilon = epsilons[2]).items(), key=lambda t: t[1]))) if exclude not in x and x not in prim_in][-key_size:]
78 78 except:
79   - print("Failed !")
  79 + raise Exception("Failed !")
80 80 return
81 81 return list_nodes_to_mask
... ... @@ -95,12 +95,11 @@
95 95 if __name__ == "__main__":
96 96 for name in ["./benchmarks/c432.txt"]:
97 97 overhead = 0.1
98   - for heuristic in ["current_flow_closeness"]:
99   - # ,
100   - # "approximated_current_flow_betweenness",
101   - # "closeness",
102   - # "betweenness",
103   - # "current_flow_betweenness"]:
  98 + for heuristic in ["current_flow_closeness",
  99 + "approximated_current_flow_betweenness",
  100 + "closeness",
  101 + "betweenness",
  102 + "current_flow_betweenness"]:
104 103 g, prim_in, prim_out, nodes = build_bench(name)
105 104 print heuristic
106 105 nodes_to_mask = masking(g, prim_in, prim_out, nodes, overhead, heuristic, exclude="", mod=False)
rand_select.py View file @ 7ffbc6a
  1 +import random as rd
  2 +import time as time
  3 +
  4 +with open("timing_report_rand.csv", "a") as timing_file:
  5 + for size in [1000, 5000, 10000, 50000, 100000]:
  6 + list_nodes = range(size)
  7 + t0 = time.clock()
  8 + a = rd.sample(list_nodes, int(0.05*size))
  9 + print a
  10 + timing_file.write(str(size)+","+str(round(time.clock() - t0, 2))+"\n")