提交 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 ...@@ -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 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 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 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 the ``strict`` flag. When set to true, scan checks that all the necessary shared
shared variables in ``fn`` are passed as a part of ``non_sequences``. This has variables in ``fn`` are passed as explicit arguments to ``fn``. This has to be
to be ensured by the user. Otherwise, it will result in an error. 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 # Same OneStep as in original example.
values, updates = theano.scan(fn=OneStep, 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, outputs_info=sample,
non_sequences=[W, bvis, bhid],
n_steps=10, n_steps=10,
strict=True) strict=True)
If you omit to pass ``W``, ``bvis`` or ``bhid`` as a ``non_sequence``, it will The above will result in an error, indicating that ``OneStep`` relies on
result in an error. variables that are not passed as its explicit arguments.
Multiple outputs, several taps values - Recurrent Neural Network with Scan Multiple outputs, several taps values - Recurrent Neural Network with Scan
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论