Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
e504b1c3
提交
e504b1c3
authored
2月 23, 2010
作者:
James Bergstra
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
scan - reformatted docsting
上级
11829243
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
108 行增加
和
118 行删除
+108
-118
scan.py
theano/scan.py
+108
-118
没有找到文件。
theano/scan.py
浏览文件 @
e504b1c3
...
...
@@ -68,124 +68,114 @@ def scan(fn, sequences, initial_states, non_sequences, inplace_map={}, \
mode
=
None
):
'''Function that constructs and applies a Scan op
:param fn: Function that describes the operations involved in one step
of scan Given variables representing all the slices of input
and past values of outputs and other non sequences parameters,
``fn`` should produce variables describing the output of one
time step of scan. The order in which the argument to this
function are given is very important. You should have the
following order:
* all time slices of the first sequence (as given in the
``sequences`` list) ordered cronologically
* all time slices of the second sequence (as given in the
``sequences`` list) ordered cronologically
* ...
* all time slices of the first output (as given in the
``initial_state`` list) ordered cronologically
* all time slices of the second otuput (as given in the
``initial_state`` list) ordered cronologically
* ...
* all other parameters over which scan doesn't iterate given
in the same order as in ``non_sequences``
If you are using shared variables over which you do not want to
iterate, you do not need to provide them as arguments to
``fn``, though you can if you wish so. The function should
return the outputs after each step plus the updates for any of
the shared variables. You can either return only outputs or
only updates. If you have both outputs and updates the
function should return them as a tuple : (outputs, updates)
or (updates, outputs).
Outputs can be just a theano expression if you have only one
outputs or a list of theano expressions. Updates can be given
either as a list of as a dictionary. If you have a list of
outputs, the order of these should match that of their
``initial_states``.
:param sequences: list of Theano variables over which scan needs to
iterate.
:param initial_states: list of Theano variables containing the initial
state used for the output. Note that if the
function applied recursively uses only the
previous value of the output or none, this
initial state should have same shape
as one time step of the output; otherwise, the
initial state should have the same number of
dimension as output. This can easily be understand
through an example. For computing ``y[t]`` let
assume that we need ``y[t-1]``, ``y[t-2]`` and
``y(t-4)``. Through an abuse of notation,
when ``t = 0``, we would need values for
``y[-1]``, ``y[-2]`` and ``y[-4]``. These values
are provided by the initial state of ``y``, which
should have same number of dimension as ``y``,
where the first dimension should be large enough
to cover all past values, which in this case is 4.
If ``init_y`` is the variable containing the
initial state of ``y``, then ``init_y[0]``
corresponds to ``y[-4]``, ``init_y[1]``
corresponds to ``y[-3]``, ``init_y[2]``
corresponds to ``y[-2]``, ``init_y[3]``
corresponds to ``y[-1]``. By default, scan is set
to use the last time step for each output.
:param non_sequences: Parameters over which scan should not iterate.
These parameters are given at each time step to
the function applied recursively.
:param inplace_map: Dictionary describing outputs computed *inplace*.
``inplace_map`` is a dictionary where keys are
output indexes, and values are sequence indexes.
Assigning a value ``j`` to a key ``i`` means that
output number ``j`` will be computed inplace (in the
same memory buffer) as the input number ``i``.
:param sequences_taps: Dictionary describing what slices of the input
sequences scan should use. At each step of the
iteration you can use different slices of your
input sequences(called here taps), and this
dictionary lets you define exactly that. The
keys of the dictionary are sequence indexes,
the values are list of numbers. Having the
following entry ``i : [k_1,k_2,k_3]``, means that
at step ``t``, for sequence ``x``, that has the
index ``i`` in the list of sequences, you would
use the values ``x[t+k_1]``, ``x[t+k_2]`` and
``x[t+k_3]``. ``k_1``, ``k_2``, ``k_3`` values
can be positive or negative and the sequence for
you request this taps should be large enough to
accomodate them. If in the cronological order,
``k`` is the first past value of sequence ``x``,
then index 0 of ``x`` will correspond to step ``k``
(if ``k`` is -3, then, abusing notation ``x[0]``
will be seen by scan as ``x[-3]``). If you do not
want to use any taps for a given sequence you need
to set the corresponding entry in the dictionary
to the empy list. By default, for each sequence
that is not represented in the dictionary scan
will assume that the at every step it needs to
provide the current value of that sequence.
:param outputs_taps: Dictionary describing what slices of the input
sequences scan should use. The ``outputs_taps`` are
defined in an analogouws way to ``sequences_taps``,
just that the taps are for the outputs generated by
scan. As such they can only be negative, i.e. refer
to past value of outputs. By default scan will
expect to use for any outpu the last time step, if
nothing else is specified.
:param n_steps: Number of steps to iterate. Sometimes you want to either
enforce a fixed number of steps, or you might not even
have any sequences you want to iterate over, but rather
just to repeat some computation for a fixed number of
steps. ``n_steps`` gives you this possibility. It can be
a theano scalar or a number.
:param truncate_gradient: Number of steps to use in truncated BPTT.
If you compute gradients through a scan op,
they are computed using backpropagation through
time. By providing a different value then -1,
you choose to use truncated BPTT instead of
classical BPTT, where you only do
``truncate_gradient`` number of steps.
:param go_backwards: Flag indicating if you should go bacwards through
the sequences
:param fn:
Function that describes the operations involved in one step of scan
Given variables representing all the slices of input and past values of
outputs and other non sequences parameters, ``fn`` should produce
variables describing the output of one time step of scan. The order in
which the argument to this function are given is very important. You
should have the following order:
* all time slices of the first sequence (as given in the
``sequences`` list) ordered cronologically
* all time slices of the second sequence (as given in the
``sequences`` list) ordered cronologically
* ...
* all time slices of the first output (as given in the
``initial_state`` list) ordered cronologically
* all time slices of the second otuput (as given in the
``initial_state`` list) ordered cronologically
* ...
* all other parameters over which scan doesn't iterate given
in the same order as in ``non_sequences`` If you are using shared
variables over which you do not want to iterate, you do not need to
provide them as arguments to ``fn``, though you can if you wish so. The
function should return the outputs after each step plus the updates for
any of the shared variables. You can either return only outputs or only
updates. If you have both outputs and updates the function should return
them as a tuple : (outputs, updates) or (updates, outputs).
Outputs can be just a theano expression if you have only one outputs or
a list of theano expressions. Updates can be given either as a list of
as a dictionary. If you have a list of outputs, the order of these
should match that of their ``initial_states``.
:param sequences:
list of Theano variables over which scan needs to iterate.
:param initial_states:
list of Theano variables containing the initial state used for the
output. Note that if the function applied recursively uses only the
previous value of the output or none, this initial state should have
same shape as one time step of the output; otherwise, the initial state
should have the same number of dimension as output. This can easily be
understand through an example. For computing ``y[t]`` let assume that we
need ``y[t-1]``, ``y[t-2]`` and ``y(t-4)``. Through an abuse of
notation, when ``t = 0``, we would need values for ``y[-1]``, ``y[-2]``
and ``y[-4]``. These values are provided by the initial state of ``y``,
which should have same number of dimension as ``y``, where the first
dimension should be large enough to cover all past values, which in this
case is 4. If ``init_y`` is the variable containing the initial state
of ``y``, then ``init_y[0]`` corresponds to ``y[-4]``, ``init_y[1]``
corresponds to ``y[-3]``, ``init_y[2]`` corresponds to ``y[-2]``,
``init_y[3]`` corresponds to ``y[-1]``. By default, scan is set to use
the last time step for each output.
:param non_sequences:
Parameters over which scan should not iterate. These parameters are
given at each time step to the function applied recursively.
:param inplace_map:
Dictionary describing outputs computed *inplace*. ``inplace_map`` is a
dictionary where keys are output indexes, and values are sequence
indexes. Assigning a value ``j`` to a key ``i`` means that output
number ``j`` will be computed inplace (in the same memory buffer) as the
input number ``i``.
:param sequences_taps:
Dictionary describing what slices of the input sequences scan should
use. At each step of the iteration you can use different slices of your
input sequences(called here taps), and this dictionary lets you define
exactly that. The keys of the dictionary are sequence indexes, the
values are list of numbers. Having the following entry ``i :
[k_1,k_2,k_3]``, means that at step ``t``, for sequence ``x``, that has
the index ``i`` in the list of sequences, you would use the values
``x[t+k_1]``, ``x[t+k_2]`` and ``x[t+k_3]``. ``k_1``, ``k_2``, ``k_3``
values can be positive or negative and the sequence for you request this
taps should be large enough to accomodate them. If in the chronological
order, ``k`` is the first past value of sequence ``x``, then index 0 of
``x`` will correspond to step ``k`` (if ``k`` is -3, then, abusing
notation ``x[0]`` will be seen by scan as ``x[-3]``). If you do not want
to use any taps for a given sequence you need to set the corresponding
entry in the dictionary to the empy list. By default, for each sequence
that is not represented in the dictionary scan will assume that the at
every step it needs to provide the current value of that sequence.
:param outputs_taps:
Dictionary describing what slices of the input sequences scan should
use. The ``outputs_taps`` are defined in an analogous way to
``sequences_taps``, just that the taps are for the outputs generated by
scan. As such they can only be negative, i.e. refer to past value of
outputs. By default scan will expect to use for any output the last time
step, if nothing else is specified.
:param n_steps:
Number of steps to iterate. Sometimes you want to either enforce a fixed
number of steps, or you might not even have any sequences you want to
iterate over, but rather just to repeat some computation for a fixed
number of steps. It can be a theano scalar or a number.
:param truncate_gradient:
Number of steps to use in truncated BPTT. If you compute gradients
through a scan op, they are computed using backpropagation through time.
By providing a different value then -1, you choose to use truncated BPTT
instead of classical BPTT, where you only do ``truncate_gradient``
number of steps. (NOT YET IMPLEMENTED)
:param go_backwards:
Flag indicating if you should go backwards through the sequences
:rtype: tuple
:return: tuple of the form (outputs, updates); ``outputs`` is either a
Theano variable or a list of Theano variables representing the
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论