提交 3062d85a authored 作者: Frederic's avatar Frederic

Fix the grad of theano.sparse.sandbox.sp.row_scale and test it.

上级 c3f571f8
...@@ -2,6 +2,10 @@ ...@@ -2,6 +2,10 @@
Updates in the Trunk since the last release: Updates in the Trunk since the last release:
Sparse Sandbox bugfix
* Fix the grad of theano.sparse.sandbox.sp.row_scale. It didn't
returned the right number of element. (Frederic B.)
Documentation Documentation
* Added in the tutorial documentation on how to extend Theano. * Added in the tutorial documentation on how to extend Theano.
This explains how to make a Theano Op from a Python function. This explains how to make a Theano Op from a Python function.
...@@ -36,7 +40,6 @@ New Features ...@@ -36,7 +40,6 @@ New Features
contains dimensions with bad value like 0. (Frédéric B. reported by Ian G.) contains dimensions with bad value like 0. (Frédéric B. reported by Ian G.)
Sparse Sparse
* Implement theano.sparse.mul(sparse1, sparse2) when both input don't * Implement theano.sparse.mul(sparse1, sparse2) when both input don't
have the same sparsity pattern. (Frederic B.) have the same sparsity pattern. (Frederic B.)
......
...@@ -263,7 +263,7 @@ class RowScaleCSC(Op): ...@@ -263,7 +263,7 @@ class RowScaleCSC(Op):
z[0] = scipy_sparse.csc_matrix((y_data, indices, indptr), (M, N)) z[0] = scipy_sparse.csc_matrix((y_data, indices, indptr), (M, N))
def grad(self, (x, s), (gz,)): def grad(self, (x, s), (gz,)):
return [row_scale(gz, s), sp_sum(x * gz, axis=0)] return [row_scale(gz, s), sp_sum(x * gz, axis=1)]
def col_scale(x, s): def col_scale(x, s):
......
...@@ -494,19 +494,17 @@ def test_diag_grad(): ...@@ -494,19 +494,17 @@ def test_diag_grad():
utt.verify_grad(d, [diag_mat], utt.verify_grad(d, [diag_mat],
mode=theano.Mode(linker='py', optimizer='fast_compile')) mode=theano.Mode(linker='py', optimizer='fast_compile'))
def test_row_scale(): def test_row_scale():
x = theano.sparse.csc_dmatrix() x = theano.sparse.csc_dmatrix()
s = theano.tensor.dvector() s = theano.tensor.dvector()
def d(x,s):
return sp.sp_sum(sp.row_scale(x, s), sparse_grad=True)
rng = numpy.random.RandomState(8723) rng = numpy.random.RandomState(8723)
R = 5 R = 5
C = 8 C = 8
x_val_dense = numpy.zeros((R, C),dtype='d') x_val_dense = numpy.zeros((R, C), dtype='d')
for idx in [(0,0), (4, 1), (2,1), (3, 3), (4, 4), (3, 7), (2, 7)]: for idx in [(0, 0), (4, 1), (2, 1), (3, 3), (4, 4), (3, 7), (2, 7)]:
x_val_dense.__setitem__(idx, rng.randn()) x_val_dense.__setitem__(idx, rng.randn())
x_val = scipy.sparse.csc_matrix(x_val_dense) x_val = scipy.sparse.csc_matrix(x_val_dense)
...@@ -519,11 +517,8 @@ def test_row_scale(): ...@@ -519,11 +517,8 @@ def test_row_scale():
assert numpy.all(f(x_val, s_val).toarray() == (x_val_dense.T * s_val).T) assert numpy.all(f(x_val, s_val).toarray() == (x_val_dense.T * s_val).T)
if 0: verify_grad_sparse(sp.row_scale, [x_val, s_val], structured=False)
tensor.verify_grad(None, d, [x_val, s_val],
mode=theano.Mode(linker='py', optimizer='fast_compile'))
else:
print >> sys.stderr, "WARNING: skipping gradient test because verify_grad doesn't support sparse arguments"
def test_col_scale(): def test_col_scale():
x = theano.sparse.csc_dmatrix() x = theano.sparse.csc_dmatrix()
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论