Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
02528764
提交
02528764
authored
9月 05, 2012
作者:
Ian Goodfellow
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
documented new op contract
上级
4ca430a8
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
46 行增加
和
0 行删除
+46
-0
op.txt
doc/extending/op.txt
+46
-0
没有找到文件。
doc/extending/op.txt
浏览文件 @
02528764
...
...
@@ -239,6 +239,52 @@ following methods:
Both the partial differentiation and the multiplication have to be performed by
:func:`grad`.
Theano currently imposes the following constraints on the values returned by the grad method:
1) They must be Variable instances.
2) When they are types that have dtypes, they must never have an integer dtype.
Integers are a tricky subject. Integers are the main reason for having DisconnectedType,
NullType or zero gradient. When you have an integer as an argument to your grad method,
recall the definition of a derivative to help you decide what value to return:
:math:`\frac{d f}{d x} = \lim_{\epsilon \rightarrow 0} (f(x+\epsilon)-f(x))/\epsilon`.
Suppose your function f has an integer-valued output. For most functions you're likely
to implement in theano, this means your gradient should be zero, because f(x+epsilon)
= f(x) for almost all x. (The only other option is that the gradient could be undefined,
if your function is discontinuous everywhere, like the rational indicator function)
Suppose your function f has an integer-valued input. This is a little trickier, because
you need to think about what you mean mathematically when you make a variable integer-valued
in theano. Most of the time in machine learning we mean "f is a function of a real-valued
x, but we are only going to pass in integer-values of x". In this case, f(x+epsilon) exists,
so the gradient through f should be the same whether x is an integer or a floating point
variable. Sometimes what we mean is "f is a function of an integer-valued x, and f is only
defined where x is an integer." Since f(x+epsilon) doesn't exist, the gradient is undefined.
Finally, many times in theano, integer valued inputs don't actually affect the elements of
the output, only its shape.
Examples:
1) f(x,y) = dot product between x and y. x and y are integers.
Since the output is also an integer, f is a step function.
Its gradient is zero almost everywhere, so Op.grad should return
zeros in the shape of x and y.
2) f(x,y) = dot product between x and y. x is floating point and y is an integer.
In this case the output is floating point. It doesn't matter that y is an integer.
We consider f to still be defined at f(x,y+epsilon). The gradient is exactly the
same as if y were floating point.
3) f(x,y) = argmax of x along axis y.
The gradient with respect to y is undefined, because f(x,y) is not defined for
floating point y. How could you take an argmax along a fractional axis?
4) f(x,y) = a vector with y elements, each of which taking on the value x
The grad method should return DisconnectedType()() for y, because the elements of
f don't depend on y. Only the shape of f depends on y. You probably also want to
implement a connection_pattern method to encode this.
.. function:: infer_shape(node, shapes)
Optional.
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论