Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
8c514f5e
提交
8c514f5e
authored
8月 11, 2015
作者:
Iban Harlouchet
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
numpydoc for theano/sandbox/scan_module/scan.py
上级
63577e4f
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
31 行增加
和
30 行删除
+31
-30
scan.py
theano/sandbox/scan_module/scan.py
+31
-30
没有找到文件。
theano/sandbox/scan_module/scan.py
浏览文件 @
8c514f5e
"""
"""
This module provides the Scan Op
This module provides the Scan Op
.
Scanning is a general form of recurrence, which can be used for looping.
Scanning is a general form of recurrence, which can be used for looping.
The idea is that you *scan* a function along some input sequence, producing
The idea is that you *scan* a function along some input sequence, producing
an output at each time-step that can be seen (but not modified) by the
an output at each time-step that can be seen (but not modified) by the
function at the next time-step.
(
Technically, the function can see the
function at the next time-step. Technically, the function can see the
previous K time-steps of your outputs and L time steps (from past and
previous K time-steps of your outputs and L time steps (from past and
future) of your inputs.
future) of your inputs.
...
@@ -32,6 +32,7 @@ host at each step
...
@@ -32,6 +32,7 @@ host at each step
The Scan Op should typically be used by calling any of the following
The Scan Op should typically be used by calling any of the following
functions: ``scan()``, ``map()``, ``reduce()``, ``foldl()``,
functions: ``scan()``, ``map()``, ``reduce()``, ``foldl()``,
``foldr()``.
``foldr()``.
"""
"""
__docformat__
=
'restructedtext en'
__docformat__
=
'restructedtext en'
__authors__
=
(
"Razvan Pascanu "
__authors__
=
(
"Razvan Pascanu "
...
@@ -76,7 +77,9 @@ def scan(fn,
...
@@ -76,7 +77,9 @@ def scan(fn,
This function constructs and applies a Scan op to the provided
This function constructs and applies a Scan op to the provided
arguments.
arguments.
:param fn:
Parameters
----------
fn
``fn`` is a function that describes the operations involved in one
``fn`` is a function that describes the operations involved in one
step of ``scan``. ``fn`` should construct variables describing the
step of ``scan``. ``fn`` should construct variables describing the
output of one iteration step. It should expect as input theano
output of one iteration step. It should expect as input theano
...
@@ -167,7 +170,7 @@ def scan(fn,
...
@@ -167,7 +170,7 @@ def scan(fn,
number of steps ) is still required even though a condition is
number of steps ) is still required even though a condition is
passed (and it is used to allocate memory if needed). = {}):
passed (and it is used to allocate memory if needed). = {}):
:param sequences:
sequences
``sequences`` is the list of Theano variables or dictionaries
``sequences`` is the list of Theano variables or dictionaries
describing the sequences ``scan`` has to iterate over. If a
describing the sequences ``scan`` has to iterate over. If a
sequence is given as wrapped in a dictionary, then a set of optional
sequence is given as wrapped in a dictionary, then a set of optional
...
@@ -185,8 +188,7 @@ def scan(fn,
...
@@ -185,8 +188,7 @@ def scan(fn,
Any Theano variable in the list ``sequences`` is automatically
Any Theano variable in the list ``sequences`` is automatically
wrapped into a dictionary where ``taps`` is set to ``[0]``
wrapped into a dictionary where ``taps`` is set to ``[0]``
outputs_info
:param outputs_info:
``outputs_info`` is the list of Theano variables or dictionaries
``outputs_info`` is the list of Theano variables or dictionaries
describing the initial state of the outputs computed
describing the initial state of the outputs computed
recurrently. When this initial states are given as dictionary
recurrently. When this initial states are given as dictionary
...
@@ -243,15 +245,13 @@ def scan(fn,
...
@@ -243,15 +245,13 @@ def scan(fn,
raised (because there is no convention on how scan should map
raised (because there is no convention on how scan should map
the provided information to the outputs of ``fn``)
the provided information to the outputs of ``fn``)
non_sequences
:param non_sequences:
``non_sequences`` is the list of arguments that are passed to
``non_sequences`` is the list of arguments that are passed to
``fn`` at each steps. One can opt to exclude variable
``fn`` at each steps. One can opt to exclude variable
used in ``fn`` from this list as long as they are part of the
used in ``fn`` from this list as long as they are part of the
computational graph, though for clarity we encourage not to do so.
computational graph, though for clarity we encourage not to do so.
n_steps
:param n_steps:
``n_steps`` is the number of steps to iterate given as an int
``n_steps`` is the number of steps to iterate given as an int
or Theano scalar. If any of the input sequences do not have
or Theano scalar. If any of the input sequences do not have
enough elements, scan will raise an error. If the *value is 0* the
enough elements, scan will raise an error. If the *value is 0* the
...
@@ -261,8 +261,7 @@ def scan(fn,
...
@@ -261,8 +261,7 @@ def scan(fn,
in time. If n stpes is not provided, ``scan`` will figure
in time. If n stpes is not provided, ``scan`` will figure
out the amount of steps it should run given its input sequences.
out the amount of steps it should run given its input sequences.
truncate_gradient
:param truncate_gradient:
``truncate_gradient`` is the number of steps to use in truncated
``truncate_gradient`` is the number of steps to use in truncated
BPTT. If you compute gradients through a scan op, they are
BPTT. If you compute gradients through a scan op, they are
computed using backpropagation through time. By providing a
computed using backpropagation through time. By providing a
...
@@ -270,16 +269,14 @@ def scan(fn,
...
@@ -270,16 +269,14 @@ def scan(fn,
of classical BPTT, where you go for only ``truncate_gradient``
of classical BPTT, where you go for only ``truncate_gradient``
number of steps back in time.
number of steps back in time.
go_backwards
:param go_backwards:
``go_backwards`` is a flag indicating if ``scan`` should go
``go_backwards`` is a flag indicating if ``scan`` should go
backwards through the sequences. If you think of each sequence
backwards through the sequences. If you think of each sequence
as indexed by time, making this flag True would mean that
as indexed by time, making this flag True would mean that
``scan`` goes back in time, namely that for any sequence it
``scan`` goes back in time, namely that for any sequence it
starts from the end and goes towards 0.
starts from the end and goes towards 0.
name
:param name:
When profiling ``scan``, it is crucial to provide a name for any
When profiling ``scan``, it is crucial to provide a name for any
instance of ``scan``. The profiler will produce an overall
instance of ``scan``. The profiler will produce an overall
profile of your code as well as profiles for the computation of
profile of your code as well as profiles for the computation of
...
@@ -287,7 +284,7 @@ def scan(fn,
...
@@ -287,7 +284,7 @@ def scan(fn,
appears in those profiles and can greatly help to disambiguate
appears in those profiles and can greatly help to disambiguate
information.
information.
:param mode:
mode
It is recommended to leave this argument to None, especially
It is recommended to leave this argument to None, especially
when profiling ``scan`` (otherwise the results are not going to
when profiling ``scan`` (otherwise the results are not going to
be accurate). If you prefer the computations of one step of
be accurate). If you prefer the computations of one step of
...
@@ -296,7 +293,7 @@ def scan(fn,
...
@@ -296,7 +293,7 @@ def scan(fn,
loop are done (see ``theano.function`` for details about
loop are done (see ``theano.function`` for details about
possible values and their meaning).
possible values and their meaning).
:param profile:
profile
Flag or string. If true, or different from the empty string, a
Flag or string. If true, or different from the empty string, a
profile object will be created and attached to the inner graph of
profile object will be created and attached to the inner graph of
scan. In case ``profile`` is True, the profile object will have the
scan. In case ``profile`` is True, the profile object will have the
...
@@ -305,18 +302,21 @@ def scan(fn,
...
@@ -305,18 +302,21 @@ def scan(fn,
inner graph with the new cvm linker ( with default modes,
inner graph with the new cvm linker ( with default modes,
other linkers this argument is useless)
other linkers this argument is useless)
:rtype: tuple
Returns
:return: tuple of the form (outputs, updates); ``outputs`` is either a
-------
Theano variable or a list of Theano variables representing the
tuple
outputs of ``scan`` (in the same order as in
Tuple of the form (outputs, updates); ``outputs`` is either a
``outputs_info``). ``updates`` is a subclass of dictionary
Theano variable or a list of Theano variables representing the
specifying the
outputs of ``scan`` (in the same order as in
update rules for all shared variables used in scan
``outputs_info``). ``updates`` is a subclass of dictionary
This dictionary should be passed to ``theano.function`` when
specifying the
you compile your function. The change compared to a normal
update rules for all shared variables used in scan
dictionary is that we validate that keys are SharedVariable
This dictionary should be passed to ``theano.function`` when
and addition of those dictionary are validated to be consistent.
you compile your function. The change compared to a normal
"""
dictionary is that we validate that keys are SharedVariable
and addition of those dictionary are validated to be consistent.
"""
# Note : see the internal documentation of the scan op for naming
# Note : see the internal documentation of the scan op for naming
# conventions and all other details
# conventions and all other details
if
options
is
None
:
if
options
is
None
:
...
@@ -544,6 +544,7 @@ def one_step_scan(fn,
...
@@ -544,6 +544,7 @@ def one_step_scan(fn,
truncate_gradient
):
truncate_gradient
):
"""
"""
This function is evaluated if `n_steps` evaluates to either 1 or -1.
This function is evaluated if `n_steps` evaluates to either 1 or -1.
"""
"""
# 1. Grab slices of sequences
# 1. Grab slices of sequences
inputs_slices
=
[
input
[
0
]
for
input
in
inputs
]
inputs_slices
=
[
input
[
0
]
for
input
in
inputs
]
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论