Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
8c449ca8
提交
8c449ca8
authored
11月 10, 2010
作者:
Pascal Lamblin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Extends a bit the documentation on automatic differentiation.
上级
8bbbc82c
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
40 行增加
和
20 行删除
+40
-20
op.txt
doc/extending/op.txt
+16
-10
gradient.txt
doc/library/gradient.txt
+19
-9
basic.txt
doc/library/tensor/basic.txt
+5
-1
没有找到文件。
doc/extending/op.txt
浏览文件 @
8c449ca8
...
@@ -137,17 +137,23 @@ following methods:
...
@@ -137,17 +137,23 @@ following methods:
the gradient of the Op's output but rather the gradient of some
the gradient of the Op's output but rather the gradient of some
other criterion C with respect to the Op's input.
other criterion C with respect to the Op's input.
If the outputs of your op are
[ f_1, ... f_n]
, then
If the outputs of your op are
:math:`[ f_1, ... f_n]`
, then
``output_derivatives`` gives
[ grad_{f_1} C, grad_{f_2} C, ... , grad_{f_n} C ]
``output_derivatives`` gives
If the inputs of your op are [x_1, ..., x_n], then your Op.grad should
:math:`[ grad_{f_1}(C), grad_{f_2}(C), ... , grad_{f_n}(C) ]`.
return [ grad_{x_1} C, grad_{x_2} C, ..., grad_{x_n} C ]
If the inputs of your op are :math:`[x_1, ..., x_m]`, then your Op.grad
should return :math:`[ grad_{x_1}(C), grad_{x_2}(C), ..., grad_{x_m}(C) ]`,
where
(grad_{y} z)_i = partial z / partial y_i (and i can have any
where
:math:`(grad_{y} z)_i = \frac{\partial z}{\partial y_i}`
number of dimensions)
(and :math:`i` can have any number of dimensions).
(
n
ote: in the case where i is 2 dimensional, this definition of grad
(
N
ote: in the case where i is 2 dimensional, this definition of grad
is different from the standard mathematical definition of the gradient
is different from the standard mathematical definition of the gradient
of a scalar with respect to a matrix, where you transpose the indices)
of a scalar with respect to a matrix, where you transpose the indices.)
In other words, :func:`grad` does not return
:math:`\frac{\partial f_i}{\partial x_j}`, but
:math:`\frac{\partial C}{\partial x_j} =
\frac{\partial C}{\partial f_i} \cdot \frac{\partial f_i}{\partial x_j}`.
Both the partial derivation and that multiplication have to be done by
:func:`grad`.
At a bare minimum, a new Op must define ``make_node`` and ``perform``, which have no defaults.
At a bare minimum, a new Op must define ``make_node`` and ``perform``, which have no defaults.
...
...
doc/library/gradient.txt
浏览文件 @
8c449ca8
...
@@ -18,11 +18,15 @@ awkward to use when :func:`tensor.grad` can do the job.
...
@@ -18,11 +18,15 @@ awkward to use when :func:`tensor.grad` can do the job.
.. function:: grad_sources_inputs(sources, graph_inputs, warn_type=True)
.. function:: grad_sources_inputs(sources, graph_inputs, warn_type=True)
A gradient source is a pair (``r``, ``g_r``), in which ``r`` is a `Variable`, and ``g_r`` is a
A gradient source is a pair (``v``, ``g_v``), in which ``v`` is
`Variable` that is a gradient wrt ``r``.
a `Variable`, and ``g_v`` is a `Variable` that is a gradient wrt
``v``. More specifically, ``g_v`` is the gradient of an external
scalar cost, ``cost`` (that is not explicitly used), wrt ``v``.
This function traverses the graph backward from the ``r`` sources,
This function traverses the graph backward from the ``r`` sources,
calling ``op.grad(...)`` for all ops with some non-None gradient on an output.
calling ``op.grad(...)`` for all ops with some non-None gradient
on an output, to compute gradients of ``cost`` wrt intermediate
variables and ``graph_inputs``.
The ``op.grad(...)`` functions are called like this:
The ``op.grad(...)`` functions are called like this:
...
@@ -30,14 +34,20 @@ awkward to use when :func:`tensor.grad` can do the job.
...
@@ -30,14 +34,20 @@ awkward to use when :func:`tensor.grad` can do the job.
op.grad(op.inputs[:], [total_gradient(v) for v in op.outputs])
op.grad(op.inputs[:], [total_gradient(v) for v in op.outputs])
This call to ``op.grad`` should return a list or tuple: one symbolic gradient per input.
This call to ``op.grad`` should return a list or tuple: one symbolic
If ``op`` has a single input, then ``op.grad`` should return a list or tuple of length 1.
gradient per input. These gradients represent the gradients of
the same implicit ``cost`` mentionned above, wrt ``op.inputs``. Note
that this is **not** the same as the gradient of ``op.outputs`` wrt
``op.inputs``.
For each input wrt to which ``op`` is not differentiable, it should return ``None`` instead
If ``op`` has a single input, then ``op.grad`` should return a list
of a `Variable` instance.
or tuple of length 1.
For each input wrt to which ``op`` is not differentiable, it should
return ``None`` instead of a `Variable` instance.
If a source ``r`` receives a gradient from another source ``r2``,
then the effective gradient on ``r`` is the sum of both gradients.
If a source ``r`` receives a gradient from another source ``r2``, then the effective
gradient on ``r`` is the sum of both gradients.
:type sources: list of pairs of Variable: (v, gradient-on-v) to
:type sources: list of pairs of Variable: (v, gradient-on-v) to
initialize the total_gradient dictionary
initialize the total_gradient dictionary
...
...
doc/library/tensor/basic.txt
浏览文件 @
8c449ca8
...
@@ -1106,9 +1106,13 @@ Gradient / Differentiation
...
@@ -1106,9 +1106,13 @@ Gradient / Differentiation
Return symbolic gradients for one or more variables with respect to some
Return symbolic gradients for one or more variables with respect to some
cost.
cost.
For more information about how automatic differentiation works in Theano,
see :mod:`gradient`. For information on how to implement the gradient of
a certain Op, see :func:`grad`.
:type cost: 0-d tensor variable
:type cost: 0-d tensor variable
:type wrt: tensor variable or list of tensor variables
:type wrt: tensor variable or list of tensor variables
:type g_cost: same as `cost`
:type g_cost: same as
type of
`cost`
:type consider_constant: list of variables
:type consider_constant: list of variables
:type warn_type: bool
:type warn_type: bool
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论