Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
72ed94f5
提交
72ed94f5
authored
11月 13, 2012
作者:
Ian Goodfellow
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
factored out the _is_zero logic
上级
7681f4c7
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
32 行增加
和
11 行删除
+32
-11
gradient.py
theano/gradient.py
+32
-11
没有找到文件。
theano/gradient.py
浏览文件 @
72ed94f5
...
@@ -929,14 +929,9 @@ def _populate_grad_dict(var_to_node_to_idx,
...
@@ -929,14 +929,9 @@ def _populate_grad_dict(var_to_node_to_idx,
# it's not undefined or disconnected
# it's not undefined or disconnected
# The only other valid thing it can be is 0
# The only other valid thing it can be is 0
no_constant_value
=
True
is_zero
=
_is_zero
(
term
)
try
:
assert
is_zero
in
[
'yes'
,
'no'
,
'maybe'
]:
constant_value
=
theano
.
get_constant_value
(
term
)
if
is_zero
==
'maybe'
:
no_constant_value
=
False
except
TypeError
:
pass
if
no_constant_value
:
msg
=
"
%
s.grad returned
%
s of type
%
s for input"
msg
=
"
%
s.grad returned
%
s of type
%
s for input"
msg
+=
"
%
d. This input's only connections to "
msg
+=
"
%
d. This input's only connections to "
msg
+=
"the cost through this op are via "
msg
+=
"the cost through this op are via "
...
@@ -950,8 +945,7 @@ def _populate_grad_dict(var_to_node_to_idx,
...
@@ -950,8 +945,7 @@ def _populate_grad_dict(var_to_node_to_idx,
msg
=
msg
%
(
str
(
node
.
op
),
str
(
term
),
msg
=
msg
%
(
str
(
node
.
op
),
str
(
term
),
str
(
type
(
term
)),
i
)
str
(
type
(
term
)),
i
)
raise
ValueError
(
msg
)
if
is_zero
==
'no'
:
if
constant_value
!=
0
:
msg
=
"
%
s.grad returned
%
s of type
%
s for input"
msg
=
"
%
s.grad returned
%
s of type
%
s for input"
msg
+=
"
%
d. Since this input is only connected "
msg
+=
"
%
d. Since this input is only connected "
msg
+=
"to integer-valued outputs, it should "
msg
+=
"to integer-valued outputs, it should "
...
@@ -959,7 +953,7 @@ def _populate_grad_dict(var_to_node_to_idx,
...
@@ -959,7 +953,7 @@ def _populate_grad_dict(var_to_node_to_idx,
msg
+=
"
%
s."
msg
+=
"
%
s."
msg
%
(
str
(
node
.
op
),
str
(
term
),
str
(
type
(
term
)),
msg
%
(
str
(
node
.
op
),
str
(
term
),
str
(
type
(
term
)),
i
,
str
(
constant_value
))
i
,
str
(
theano
.
get_constant_value
(
term
)
))
raise
ValueError
(
msg
)
raise
ValueError
(
msg
)
...
@@ -1688,3 +1682,30 @@ def hessian(cost, wrt, consider_constant=None,
...
@@ -1688,3 +1682,30 @@ def hessian(cost, wrt, consider_constant=None,
"script that generated the error)"
)
"script that generated the error)"
)
hessians
.
append
(
hess
)
hessians
.
append
(
hess
)
return
format_as
(
using_list
,
using_tuple
,
hessians
)
return
format_as
(
using_list
,
using_tuple
,
hessians
)
def
_is_zero
(
x
):
"""
Returns 'yes', 'no', or 'maybe' indicating whether x
is always 0.
'maybe' means that x is an expression that is complicated enough
that we can't tell that it simplifies to 0.
"""
if
not
hasattr
(
x
,
'type'
):
return
np
.
all
(
x
==
0.
)
if
isinstance
(
term
.
type
,
NullType
):
return
'no'
if
isinstance
(
term
.
type
,
DisconnectedType
):
return
'yes'
no_constant_value
=
True
try
:
constant_value
=
theano
.
get_constant_value
(
term
)
no_constant_value
=
False
except
TypeError
:
pass
if
no_constant_value
:
return
'maybe'
if
constant_value
!=
0.
:
return
no
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论