提交 5a7351f6 authored 作者: Anton Chechetka's avatar Anton Chechetka

Change the example illustrating the effect of strict=True in the scan() doc to…

Change the example illustrating the effect of strict=True in the scan() doc to actually trigger the proper error. Existing example triggers a different one (non_sequences not aligned with the arguments of OneStep) if one simply omits some of the [W, bvis, bhid] from non_sequences.
上级 123d9007
......@@ -383,23 +383,34 @@ Using shared variables - the strict flag
As we just saw, passing the shared variables to scan may result in a simpler
computational graph, which speeds up the optimization and the execution. A
good way to remember to pass every shared variable used during scan is to use
the ``strict`` flag. When set to true, scan assumes that all the necessary
shared variables in ``fn`` are passed as a part of ``non_sequences``. This has
to be ensured by the user. Otherwise, it will result in an error.
the ``strict`` flag. When set to true, scan checks that all the necessary shared
variables in ``fn`` are passed as explicit arguments to ``fn``. This has to be
ensured by the user. Otherwise, it will result in an error.
Using the previous Gibbs sampling example:
Using the original Gibbs sampling example, with ``strict=True`` added to the
``scan()`` call:
.. testcode:: scan1
.. testcode:: scan_strict
# The new scan, using strict=True
values, updates = theano.scan(fn=OneStep,
# Same OneStep as in original example.
def OneStep(vsample) :
hmean = T.nnet.sigmoid(theano.dot(vsample, W) + bhid)
hsample = trng.binomial(size=hmean.shape, n=1, p=hmean)
vmean = T.nnet.sigmoid(theano.dot(hsample, W.T) + bvis)
return trng.binomial(size=vsample.shape, n=1, p=vmean,
dtype=theano.config.floatX)
# The new scan, adding strict=True to the original call.
# Produces an error, because W, bvis and bhid are used by OneStep, but not
# passed explicitly.
values, updates = theano.scan(OneStep,
outputs_info=sample,
non_sequences=[W, bvis, bhid],
n_steps=10,
strict=True)
If you omit to pass ``W``, ``bvis`` or ``bhid`` as a ``non_sequence``, it will
result in an error.
The above will result in an error, indicating that ``OneStep`` relies on
variables that are not passed as its explicit arguments.
Multiple outputs, several taps values - Recurrent Neural Network with Scan
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论