提交 a25624b1 authored 作者: Nicolas Bouchard's avatar Nicolas Bouchard 提交者: Frederic

Delete old test.

上级 1294ff93
......@@ -220,166 +220,3 @@ class TrueDotTester(utt.InferShapeTester):
self.op,
data,
structured=False)
class TrueDotTester2(unittest.TestCase):
def setUp(self):
numpy.random.seed(44)
def test_basicSS(self):
for mtype in _mtypes:
x = as_sparse_variable(mtype((500, 3)))
x.data[(10, 1)] = 1
x.data[(20, 2)] = 2
self.assertTrue(_is_sparse_variable(x))
xT = x.T
self.assertTrue(_is_sparse_variable(xT))
zop = true_dot(x, xT)
self.assertTrue(_is_sparse_variable(zop))
z = eval_outputs([zop])
self.assertTrue(_is_sparse(z))
self.assertTrue(z.shape == (500, 500))
self.assertTrue(type(z) is mtype)
w = mtype((500, 500))
w[(10, 10)] = 1
w[(20, 20)] = 4
self.assertTrue(z.shape == w.shape)
self.assertTrue(type(z) == type(w))
self.assertTrue(z.dtype == w.dtype)
#self.assertTrue(z == w)
self.assertTrue(abs(z - w).nnz == 0)
z = z.todense()
w = w.todense()
self.assertTrue((z == w).all() == True)
def test_basicSD(self):
for mtype in _mtypes:
x = as_sparse_variable(mtype((500, 3)))
x.data[(10, 1)] = 1
x.data[(20, 2)] = 2
self.assertTrue(_is_sparse_variable(x))
y = tensor.as_tensor_variable([[1., 2], [3, 4], [2, 1]])
self.assertTrue(_is_dense_variable(y))
zop = true_dot(x, y)
self.assertTrue(_is_sparse_variable(zop))
z = eval_outputs([zop])
self.assertTrue(_is_sparse(z))
self.assertTrue(z.shape == (500, 2))
self.assertTrue(type(z) is mtype)
w = mtype((500, 2))
w[(10, 0)] = 3.
w[(20, 0)] = 4
w[(10, 1)] = 4
w[(20, 1)] = 2
self.assertTrue(z.shape == w.shape)
self.assertTrue(type(z) == type(w))
self.assertTrue(z.dtype == w.dtype)
#self.assertTrue(z == w)
self.assertTrue(abs(z - w).nnz == 0)
z = z.todense()
w = w.todense()
self.assertTrue((z == w).all() == True)
def test_basicDS(self):
for mtype in _mtypes:
x = as_sparse_variable(mtype((500, 3)))
x.data[(10, 1)] = 1
x.data[(20, 2)] = 2
self.assertTrue(_is_sparse_variable(x))
y = tensor.as_tensor_variable([[1., 2], [3, 4], [2, 1]])
self.assertTrue(_is_dense_variable(y))
x.data = x.data.T
y.data = y.data.T
zop = true_dot(y, x)
zop = transpose(true_dot(y, x))
self.assertTrue(_is_sparse_variable(zop))
z = eval_outputs([zop])
self.assertTrue(_is_sparse(z))
self.assertTrue(z.shape == (500, 2))
# self.assertTrue(type(z) is mtype)
w = mtype((500, 2))
w[(10, 0)] = 3.
w[(20, 0)] = 4
w[(10, 1)] = 4
w[(20, 1)] = 2
self.assertTrue(z.shape == w.shape)
# Type should switch from csr to csc and vice-versa,
# so don't perform this test
# self.assertTrue(type(z) == type(w))
self.assertTrue(z.dtype == w.dtype)
# Type should switch from csr to csc and vice-versa,
# so don't perform this test
# self.assertTrue(z == w)
self.assertTrue(abs(z - w).nnz == 0)
z = z.todense()
w = w.todense()
self.assertTrue((z == w).all() == True)
def test_graph_bprop0(self):
for mtype in _mtypes:
# x = TensorType('float64', broadcastable=[False,False], name='x')
x = tensor.matrix('x')
w = SparseType(dtype='float64',
format=_mtype_to_str[mtype]).make_variable()
xw = dense_from_sparse(true_dot(w, x))
y = dense_from_sparse(true_dot(w.T, xw))
diff = x - y
loss = tensor.sum(tensor.sqr(diff))
gw = tensor.grad(loss, w)
trainfn = compile.function([x, w], [y, loss, gw])
x = numpy.asarray([[1., 2], [3, 4], [2, 1]])
w = mtype((500, 3))
w[(10, 1)] = 1
w[(20, 2)] = 2
lr = 0.001
y, origloss, gw = trainfn(x, w)
for epoch in xrange(50):
y, loss, gw = trainfn(x, w)
w = w - (lr * gw)
# print loss
self.assertTrue(origloss > loss)
self.assertTrue('1.05191241115' == str(loss))
def test_graph_bprop_rand(self):
for i in range(10):
xorig = numpy.random.rand(3, 2)
for mtype in _mtypes:
x = tensor.matrix('x')
w = SparseType(dtype='float64',
format=_mtype_to_str[mtype]).make_variable()
xw = dense_from_sparse(true_dot(w, x))
y = dense_from_sparse(true_dot(w.T, xw))
diff = x - y
loss = tensor.sum(tensor.sqr(diff))
gw = tensor.grad(loss, w)
trainfn = compile.function([x, w], [y, loss, gw])
x = xorig
w = mtype((500, 3))
w[(10, 1)] = 1
w[(20, 2)] = 2
lr = 0.001
y, origloss, gw = trainfn(x, w)
for epoch in xrange(50):
y, loss, gw = trainfn(x, w)
w = w - (lr * gw)
self.assertTrue(origloss > loss)
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论