**Scan Example: Computing the Jacobian of y = tanh(v*A) wrt x**
**Scan Example: Computing the Jacobian of y = tanh(v*A) wrt x**
...
@@ -214,6 +216,8 @@ The full documentation can be found in the library: :ref:`Scan <lib_scan>`.
...
@@ -214,6 +216,8 @@ The full documentation can be found in the library: :ref:`Scan <lib_scan>`.
# compare with numpy
# compare with numpy
print ((1 - np.tanh(x.dot(w))**2)*w).T
print ((1 - np.tanh(x.dot(w))**2)*w).T
Note that we need to iterate over the indices of ``y`` and not over the elements of ``y``. The reason is that scan create a placeholder variable for its internal function and this placeholder variable does not have the same dependencies than the variables that will replace it.
**Scan Example: Accumulate number of loop during a scan**
**Scan Example: Accumulate number of loop during a scan**
.. code-block:: python
.. code-block:: python
...
@@ -223,6 +227,7 @@ The full documentation can be found in the library: :ref:`Scan <lib_scan>`.
...
@@ -223,6 +227,7 @@ The full documentation can be found in the library: :ref:`Scan <lib_scan>`.
@@ -239,8 +244,8 @@ The full documentation can be found in the library: :ref:`Scan <lib_scan>`.
...
@@ -239,8 +244,8 @@ The full documentation can be found in the library: :ref:`Scan <lib_scan>`.
import numpy as np
import numpy as np
# define tensor variables
# define tensor variables
v = T.vector()
X = T.matrix("X")
A = T.matrix()
W = T.matrix("W")
b_sym = T.vector("b_sym")
b_sym = T.vector("b_sym")
# define shared random stream
# define shared random stream
...
@@ -256,7 +261,7 @@ The full documentation can be found in the library: :ref:`Scan <lib_scan>`.
...
@@ -256,7 +261,7 @@ The full documentation can be found in the library: :ref:`Scan <lib_scan>`.
print compute_with_bnoise(x, w, b)
print compute_with_bnoise(x, w, b)
Note that if you want to use a random variable ``d`` that will not be updated through scan loops, you should pass this variable as a ``non_sequences`` arguments.