-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_sampling_funcs.py
149 lines (117 loc) · 3.97 KB
/
test_sampling_funcs.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
""" Test Default Block Sampling Functions """
from __future__ import absolute_import, division, unicode_literals, print_function
import numpy as np
# parameters
n = 10
p = 2
step = 3
sparse = False
def test_generic(sample):
sample(n,p,init=True)
S, scale = sample(n,p,sparse=sparse)
print(S), print(1/scale**2)
S, scale = sample(n,p,sparse=sparse)
print(S), print(1/scale**2)
S, scale = sample(n,p,step=step,sparse=sparse)
print(S), print(1/scale**2)
S, scale = sample(n,p,sparse=sparse)
print(S), print(1/scale**2)
S, scale = sample(n,p,step=step,sparse=sparse)
print(S), print(1/scale**2)
S, scale = sample(n,p,step=step,sparse=sparse)
print(S), print(1/scale**2)
def test_random_coordinate():
from sampling_funcs import random_coordinate
print('\nTesting random sampling...')
test_generic(random_coordinate)
def test_cyclic_coordinate():
from sampling_funcs import cyclic_coordinate
print('\nTesting cyclic...')
test_generic(cyclic_coordinate)
def test_partition_coordinate():
from sampling_funcs import partition_coordinate
print('\nTesting partition...')
test_generic(partition_coordinate)
def test_gauss_southwell_coordinate():
from sampling_funcs import gauss_southwell_coordinate as sample
from sampling_funcs import gauss_southwell_update_gradient
print('\nTesting Gauss-Southwell...')
sample(n,p,init=True)
# gradient 1
gradf = np.arange(n)
gauss_southwell_update_gradient(gradf)
S, scale = sample(n,p,sparse=sparse)
print(S), print(1/scale**2)
S, scale = sample(n,p,sparse=sparse)
print(S), print(1/scale**2)
S, scale = sample(n,p,step=step,sparse=sparse)
print(S), print(1/scale**2)
# gradient 2
gradf = -1*np.arange(n)
gauss_southwell_update_gradient(gradf)
S, scale = sample(n,p,sparse=sparse)
print(S), print(1/scale**2)
S, scale = sample(n,p,step=step,sparse=sparse)
print(S), print(1/scale**2)
S, scale = sample(n,p,step=step,sparse=sparse)
print(S), print(1/scale**2)
def test_random_gaussian():
from sampling_funcs import random_gaussian
print('\nTesting Gaussian...')
test_generic(random_gaussian)
def test_random_hashing():
from sampling_funcs import random_hashing as sample
p = 5
print('\nTesting hashing...')
sample(n,p,init=True)
print('s = 1')
S, scale = sample(n,p,s=1,sparse=sparse)
print(S), print(1/scale**2)
S, scale = sample(n,p,s=1,sparse=sparse)
print(S), print(1/scale**2)
print('s = 3')
S, scale = sample(n,p,s=3,sparse=sparse)
print(S), print(1/scale**2)
S, scale = sample(n,p,s=3,sparse=sparse)
print(S), print(1/scale**2)
def test_random_hashing_variant():
from sampling_funcs import random_hashing_variant as sample
p = 5
print('\nTesting hashing variant...')
sample(n,p,init=True)
print('s = 1')
S, scale = sample(n,p,s=1,sparse=sparse)
print(S), print(1/scale**2)
S, scale = sample(n,p,s=1,sparse=sparse)
print(S), print(1/scale**2)
print('s = 3')
S, scale = sample(n,p,s=3,sparse=sparse)
print(S), print(1/scale**2)
S, scale = sample(n,p,s=3,sparse=sparse)
print(S), print(1/scale**2)
def test_thompson_coordinate():
from sampling_funcs import thompson_coordinate as sample
from sampling_funcs import thompson_update_gradient
print('\nTesting Thompson...')
sample(n,p,init=True)
# gradient 1
gradf = np.ones(n)
thompson_update_gradient(gradf)
S, scale = sample(n,p,sparse=sparse)
print(S), print(1/scale**2)
S, scale = sample(n,p,sparse=sparse)
print(S), print(1/scale**2)
# gradient 2
gradf = -1*np.ones(n)
thompson_update_gradient(gradf)
S, scale = sample(n,p,sparse=sparse)
print(S), print(1/scale**2)
# run tests
test_random_coordinate()
test_cyclic_coordinate()
test_partition_coordinate()
test_gauss_southwell_coordinate()
test_random_gaussian()
test_random_hashing()
test_random_hashing_variant()
test_thompson_coordinate()