-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtest.py
More file actions
32 lines (23 loc) · 876 Bytes
/
Copy pathtest.py
File metadata and controls
32 lines (23 loc) · 876 Bytes
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
import unittest
from hogwildsgd import HogWildRegressor
import scipy.sparse
import numpy as np
class TestHogwild(unittest.TestCase):
def test_work(self):
X = scipy.sparse.random(20000,10, density=.2).toarray() # Guarantees sparse grad updates
real_w = np.random.uniform(0,1,size=(10,1))
y = np.dot(X,real_w)
hw = HogWildRegressor(n_jobs = 4,
n_epochs = 5,
batch_size = 1,
chunk_size = 32,
learning_rate = .001,
generator=None,
verbose=2)
hw = hw.fit(X,y)
y_hat = hw.predict(X)
y = y.reshape((len(y),))
score = np.mean(abs(y-y_hat))
self.assertTrue(score < .005)
if __name__ == '__main__':
unittest.main()