Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
e8a66108
提交
e8a66108
authored
11月 13, 2012
作者:
Ian Goodfellow
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
simplified Lop's handling of consider_constant
added some input validation to Lop
上级
6c07f25b
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
6 行增加
和
42 行删除
+6
-42
gradient.py
theano/gradient.py
+6
-42
没有找到文件。
theano/gradient.py
浏览文件 @
e8a66108
...
...
@@ -318,9 +318,6 @@ def Lop(f, wrt, eval_points, consider_constant=None,
coordinates of the tensor element in the last
If `f` is a list/tuple, then return a list/tuple with the results.
"""
if
consider_constant
is
None
:
consider_constant
=
[]
if
type
(
eval_points
)
not
in
(
list
,
tuple
):
eval_points
=
[
eval_points
]
...
...
@@ -334,48 +331,15 @@ def Lop(f, wrt, eval_points, consider_constant=None,
f
=
list
(
f
)
grads
=
list
(
eval_points
)
for
elem
in
consider_constant
:
assert
elem
not
in
f
f
.
append
(
elem
)
grads
.
append
(
elem
.
zeros_like
())
if
not
isinstance
(
wrt
,
(
list
,
tuple
)):
wrt
=
[
wrt
]
known
=
dict
(
zip
(
f
,
eval_points
))
gmap
=
dict
(
zip
(
wrt
,
grad
(
cost
=
None
,
known_grads
=
known
,
consider_constant
=
wrt
,
wrt
=
wrt
)))
# Note : If p is not in gmap there can be several reasons, among which
# is the fact that p might not be part of the computational graph. A
# simple example is that for a+b for e.g. a[0] is not part of the graph,
# so Theano does not know how to compute TT.grad(TT.sum(a+b), a[0])
# such subtle cases can be fixed by a more careful implementation of the
# gradient, but for now Theano needs to throw an exception, and make the
# user aware that it does not know how to compute that gradient
ret
=
[]
for
p
in
wrt
:
if
p
in
gmap
:
ret
.
append
(
gmap
[
p
])
else
:
message
=
(
"Lop method was asked to compute the gradient "
"with respect to a variable that is not part of "
"the computational graph of the cost, or is used "
"only by a non-differentiable operator:
%
s"
%
p
)
if
disconnected_inputs
==
'ignore'
:
pass
elif
disconnected_inputs
==
'warn'
:
warnings
.
warn
(
message
,
stacklevel
=
1
)
elif
disconnected_inputs
==
'raise'
:
raise
ValueError
(
message
)
else
:
raise
ValueError
(
"Invalid value for keyword "
"'disconnected_inputs', valid values are "
"'ignore', 'warn' and 'raise'."
)
ret
.
append
(
p
.
zeros_like
())
assert
len
(
f
)
==
len
(
grads
)
known
=
dict
(
zip
(
f
,
grads
))
ret
=
grad
(
cost
=
None
,
known_grads
=
known
,
consider_constant
=
consider_constant
,
wrt
=
wrt
,
disconnected_inputs
=
disconnected_inputs
)
return
format_as
(
using_list
,
using_tuple
,
ret
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论