Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
5f215b3c
提交
5f215b3c
authored
2月 04, 2016
作者:
carriepl
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Establish documentation outline
上级
538300f6
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
39 行增加
和
130 行删除
+39
-130
scan.txt
doc/developer/scan.txt
+39
-130
没有找到文件。
doc/developer/scan.txt
浏览文件 @
5f215b3c
.. _scan_internals:
.. _scan_internals:
Internal documentation of the scan op
Developper documentation for Scan
=====================================
+++++++++++++++++++++++++++++++++
Top-level description of scan
Context
-----------------------------
=======
The `scan` operation is meant to be able to describe symbolically loops,
recurrent relations or dynamical systems. In general, we will say that the
scan op implements system of equations of the following form:
Pre-requisites
.. math::
==============
\mathbf{x}_1(t) = f_{\mathbf{x}_1}
(\mathbf{u}_1(t), \mathbf{u}_1(t-1), \ldots, \mathbf{u}_1(t-l_1),
\mathbf{u}_2(t), \ldots, \mathbf{u}_2(t-l_2),
\ldots,
Relevant code files
\mathbf{u}_M(t), \ldots, \mathbf{u}_M(t - l_M),
===================
\mathbf{x}_1(t-1), \ldots, \mathbf{x}_1(t-k_1),
\ldots,
\mathbf{x}_N(t-1), \ldots, \mathbf{x}_N(t-k_N),
\mathbf{w}_1, \ldots, \mathbf{w}_Q)
\vdots
\mathbf{x}_N(t) = f_{\mathbf{x}_N}
(\mathbf{u}_1(t), \mathbf{u}_1(t-1), \ldots, \mathbf{u}_1(t-l_1),
\mathbf{u}_2(t), \ldots, \mathbf{u}_2(t-l_2),
\ldots,
\mathbf{u}_M(t), \ldots, \mathbf{u}_M(t - l_M),
\mathbf{x}_1(t-1), \ldots, \mathbf{x}_1(t-k_1),
\ldots,
\mathbf{x}_N(t-1), \ldots, \mathbf{x}_N(t-k_N),
\mathbf{w}_1, \ldots, \mathbf{w}_Q)
\mathbf{y}_1(t) = f_{\mathbf{y}_1}
(\mathbf{u}_1(t), \mathbf{u}_1(t-1), \ldots, \mathbf{u}_1(t-l_1),
\mathbf{u}_2(t), \ldots, \mathbf{u}_2(t-l_2),
\ldots,
\mathbf{u}_M(t), \ldots, \mathbf{u}_M(t - l_M),
\mathbf{x}_1(t-1), \ldots, \mathbf{x}_1(t-k_1),
\ldots,
\mathbf{x}_N(t-1), \ldots, \mathbf{x}_N(t-k_N),
\mathbf{w}_1, \ldots, \mathbf{w}_Q)
\vdots
\mathbf{y}_M(t) = f_{\mathbf{y}_M}
(\mathbf{u}_1(t), \mathbf{u}_1(t-1), \ldots, \mathbf{u}_1(t-l_1),
\mathbf{u}_2(t), \ldots, \mathbf{u}_2(t-l_2),
\ldots,
\mathbf{u}_M(t), \ldots, \mathbf{u}_M(t - l_M),
\mathbf{x}_1(t-1), \ldots, \mathbf{x}_1(t-k_1),
\ldots,
\mathbf{x}_N(t-1), \ldots, \mathbf{x}_N(t-k_N),
\mathbf{w}_1, \ldots, \mathbf{w}_Q)
The equations describe a system evolving in time, where :math:`t` represents the
current step. The system is described by inputs, states, outputs and
parameteres.
The inputs, denoted by :math:`\mathbf{u}` are time-varying quantities,
hence indexed by :math:`t`. They however only influence the system, but are
not influenced by the system.
The states :math:`\mathbf{x}` are time-varying quantities, whose value at
time :math:`t` depends on its (or other state) previous values as well as
the inputs and parameters. Note that the first few values of the states are
always provided, otherwise we could not imploy the recurrent equation to
generate these sequence of values without a starting point.
The outputs, :math:`\mathbf{y}` are outputs of the system, i.e. values that
depend on the previous values of the states and inputs. The difference
between outputs and states is that outputs do not feed back into the system.
The parameters :math:`\mathbf{w}` are fixed quantities that are re-used at
every time step of the evolution of the system.
Each of the equations above are implemented by the **inner function** of scan. You
can think of the **inner function** as a theano function that gets executed
at each step to get the new values. This **inner function** should not be
confused with the **constructive function**, which is what the user gives to
the scan function. The **constructive function** is used to construct the
computational graph that is afterwards compiled into the **inner function**.
Naming conventions
------------------
* ``input_state`` will stand for a state :math:`\mathbf{x}`, when it is
provided as an input to the recurrent formula (the inner function) that
will generate the new value of the state
* ``output_state`` will stand for a state :math:`\mathbf{x}` when it refers
to the result of the recurrent formula (the output of the inner function)
* ``output`` will stand for an output :math:`\mathbf{y}`
* ``input`` will be an input :math:`\mathbf{u}`
* ``parameter`` will stand for a parameter tensor :math:`\mathbf{w}` that stays
constant at each step of the inner function
* ``non_numeric_input_state`` will stand for states that are not numeric in nature,
more specifically *random states*, when they are provided as an input. The
same holds for ``non_numeric_output_state``.
* ``t`` is the time index (the current step in the evolution of the system).
* ``T`` is the total number of steps in the evolution of the system.
* the suffix ``_slices`` added to either ``x`` or ``u`` will mean the list of
variables representing slices of states or inputs. These are the arguments
given to the constructive function of scan (see above).
* the suffix ``_inner`` added to ``x``, ``y``, ``xy``, ``u``, ``w`` or ``z``
will mean the variables representing the state/output/input/weights in the
inner function
* the suffix ``_outer`` added to ``x``, ``y``, ``xy``, ``u``, ``w`` or ``z``
will mean the variables representing the state/output/input/weights in the
main computational graph (the one containing the scan op).
Files
-----
The implementation of scan is spread over several files. The different
The implementation of scan is spread over several files. The different
files, and section of the code they deal with, are :
files, and section of the code they deal with, are :
...
@@ -123,7 +26,7 @@ files, and section of the code they deal with, are :
...
@@ -123,7 +26,7 @@ files, and section of the code they deal with, are :
afterwards calls the constructed scan op on the arguments. This function
afterwards calls the constructed scan op on the arguments. This function
takes care of figuring out missing inputs and shared variables.
takes care of figuring out missing inputs and shared variables.
* ``scan_op.py`` implements the ``
scanOp`` class. The ``scanOp
`` respects
* ``scan_op.py`` implements the ``
Scan`` Op class. The ``Scan
`` respects
the ``Op`` interface, and contains most of the logic of the scan operator.
the ``Op`` interface, and contains most of the logic of the scan operator.
* ``scan_utils.py`` contains several helpful functions used through out the
* ``scan_utils.py`` contains several helpful functions used through out the
...
@@ -135,19 +38,25 @@ files, and section of the code they deal with, are :
...
@@ -135,19 +38,25 @@ files, and section of the code they deal with, are :
* ``scan_opt.py`` contains the list of all optimizations for the scan
* ``scan_opt.py`` contains the list of all optimizations for the scan
operator.
operator.
The logical flow
----------------
Notation
========
First the scan arguments are parsed by the function ``canonical_arguments``,
that wraps them into lists and adds default values for the arguments. One
important step that happens in this function is that the inputs arguments
are converted such that they all have a single tap, namely 0. For example
if you have ``[{'input':u, 'taps':[0, 4]}]`` as the list of inputs arguments
Scan Op
to scan, it gets converted into ``[{'input':u, 'taps':[0]}, {'input':u[4:],
=======
'taps':[0]}]``.
The second step is to check if ``n_steps`` is a constant and has the value 1
or -1. If that is true then the function ``one_step_scan`` is called which
unwraps the computation of the inner function into the outer graph without
Optimizations
adding any scan op in the graph.
=============
Helper classes and functions
============================
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论