提交 800d869c authored 作者: nouiz's avatar nouiz

Merge pull request #8 from delallea/nouiz-doc_str

A few small fixes
...@@ -131,29 +131,28 @@ Op example ...@@ -131,29 +131,28 @@ Op example
return i0_shapes return i0_shapes
def grad(self, inputs, output_grads): def grad(self, inputs, output_grads):
return [output_grads[0]*2] return [output_grads[0] * 2]
Test it! Test it!
.. code-block:: python .. code-block:: python
x = theano.tensor.matrix() x = theano.tensor.matrix()
f = theano.function([x],DoubleOp()(x)) f = theano.function([x], DoubleOp()(x))
import numpy import numpy
inp = numpy.random.rand(5,5) inp = numpy.random.rand(5, 5)
out = f(inp) out = f(inp)
assert numpy.allclose(inp*2, out) assert numpy.allclose(inp * 2, out)
print inp print inp
print out print out
Testing the gradient Testing the gradient
-------------------- --------------------
The function :ref:`verify_grad The function :ref:`verify_grad <validating_grad>`
<validating_grad>` verifies the gradient of an Op or Theano graph. It compares the
verify the gradient of an Op or Theano graph. It compare the analytic (symbolically computed) gradient and the numeric
analytic(symbolicaly computed) gradient and the numeric gradient (computed through the Finite Difference Method).
gradient(computed through the Finite Difference Method).
To verify the grad method of the DoubleOp, you can use this: To verify the grad method of the DoubleOp, you can use this:
...@@ -163,6 +162,9 @@ To verify the grad method of the DoubleOp, you can use this: ...@@ -163,6 +162,9 @@ To verify the grad method of the DoubleOp, you can use this:
import theano.tests import theano.tests
theano.tests.unittest_tools.verify_grad(DoubleOp(), [numpy.random.rand(5,7,2)]) theano.tests.unittest_tools.verify_grad(DoubleOp(), [numpy.random.rand(5,7,2)])
If nothing happens, then it works! If you want to see it fail, you can
implement a wrong gradient (for instance removing the multiplication by 2).
Exercises 8 Exercises 8
----------- -----------
......
...@@ -6,7 +6,7 @@ Frequently Asked Questions ...@@ -6,7 +6,7 @@ Frequently Asked Questions
========================== ==========================
TypeError: object of type 'TensorVariable' has no len() TypeError: object of type 'TensorVariable' has no len()
-------------------------------------------------------------- -------------------------------------------------------
If you receive this error: If you receive this error:
...@@ -14,10 +14,10 @@ If you receive this error: ...@@ -14,10 +14,10 @@ If you receive this error:
TypeError: object of type 'TensorVariable' has no len() TypeError: object of type 'TensorVariable' has no len()
We can't implement the __len__ function on Theano Varible. This is We can't implement the __len__ function on Theano Variables. This is
because Python request that we return an integer, but we can't do this because Python requires that this function returns an integer, but we
as we are working with symbolic variable. You can use `var.shape[0]` can't do this as we are working with symbolic variables. You can use
as a workaround. `var.shape[0]` as a workaround.
Also we can't change the error to a better one for some other Python Also we can't change the above error message into a more explicit one
internal behavior that we can't change. because of some other Python internal behavior that can't be modified.
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论