-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsparseTests.py
More file actions
61 lines (41 loc) · 1.23 KB
/
sparseTests.py
File metadata and controls
61 lines (41 loc) · 1.23 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
53
54
55
56
57
58
59
60
61
import numpy as np
import time
import brute
import greedy
## Random examples
print('Sparse Random Binary:')
print('---')
dataB = []
dataG = []
for n in range(4, 9):
print(n)
dB = []
dG = []
for _ in range(100):
x = np.random.choice(2, size=[2 for k in range(n)], p=[0.95,0.05])
while np.sum(x) == 0:
x = np.random.choice(2, size=[2 for k in range(n)], p=[0.95,0.05])
start = time.clock()
b = brute.findBest(x, 1e-6)
end = time.clock()
dB.append([n,sum([v.size for v in b[2]]) * 1./x.size, end - start])
start = time.clock()
g = greedy.findBest(x, 1e-6)
end = time.clock()
dG.append([n,sum([v.size for v in g]) * 1./x.size, end - start])
dataB.append(np.average(dB, axis=0))
dataG.append(np.average(dG, axis=0))
for n in range(9,16):
dG = []
print(n)
for _ in range(100):
x = np.random.choice(2, size=[2 for k in range(n)], p=[0.95,0.05])
while np.sum(x) == 0:
x = np.random.choice(2, size=[2 for k in range(n)], p=[0.95,0.05])
start = time.clock()
g = greedy.findBest(x, 1e-6)
end = time.clock()
dG.append([n,sum([v.size for v in g]) * 1./x.size, end - start])
dataG.append(np.average(dG, axis=0))
np.savetxt('Data/isingDecompSparseB.dat', dataB)
np.savetxt('Data/isingDecompSparseG.dat', dataG)