Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
62ce0a4a
提交
62ce0a4a
authored
7月 15, 2017
作者:
Aleksandar Botev
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added options for `disconnected_outputs` to Rop.
上级
83debd73
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
45 行增加
和
4 行删除
+45
-4
gradient.py
theano/gradient.py
+45
-4
没有找到文件。
theano/gradient.py
浏览文件 @
62ce0a4a
...
@@ -160,7 +160,8 @@ disconnected_type = DisconnectedType()
...
@@ -160,7 +160,8 @@ disconnected_type = DisconnectedType()
########################
########################
def
Rop
(
f
,
wrt
,
eval_points
):
def
Rop
(
f
,
wrt
,
eval_points
,
disconnected_outputs
=
"raise"
,
return_disconnected
=
"zero"
):
"""
"""
Computes the R operation on `f` wrt to `wrt` evaluated at points given
Computes the R operation on `f` wrt to `wrt` evaluated at points given
in `eval_points`. Mathematically this stands for the jacobian of `f` wrt
in `eval_points`. Mathematically this stands for the jacobian of `f` wrt
...
@@ -174,6 +175,22 @@ def Rop(f, wrt, eval_points):
...
@@ -174,6 +175,22 @@ def Rop(f, wrt, eval_points):
described by `f`
described by `f`
:type eval_points: Variable or list of Variables
:type eval_points: Variable or list of Variables
evalutation points for each of the variables in `wrt`
evalutation points for each of the variables in `wrt`
:type disconnected_outputs: str
Defines the behaviour if some of the variables in `f` are
have no dependency on any of the variable in `wrt` (or if
all links are non-differentiable). The possible values are:
- 'ignore': considers that the gradient on these parameters is zero.
- 'warn': consider the gradient zero, and print a warning.
- 'raise': raise DisconnectedInputError.
:type return_disconnected : {'zero', 'None', 'Disconnected'}
- 'zero' : If wrt[i] is disconnected, return value i will be
wrt[i].zeros_like()
- 'None' : If wrt[i] is disconnected, return value i will be
None
- 'Disconnected' : returns variables of type DisconnectedType
:rtype: :class:`~theano.gof.Variable` or list/tuple of Variables depending on type of f
:rtype: :class:`~theano.gof.Variable` or list/tuple of Variables depending on type of f
:return: symbolic expression such that
:return: symbolic expression such that
R_op[i] = sum_j ( d f[i] / d wrt[j]) eval_point[j]
R_op[i] = sum_j ( d f[i] / d wrt[j]) eval_point[j]
...
@@ -296,9 +313,33 @@ def Rop(f, wrt, eval_points):
...
@@ -296,9 +313,33 @@ def Rop(f, wrt, eval_points):
for
out
in
f
:
for
out
in
f
:
if
out
in
wrt
:
if
out
in
wrt
:
rval
.
append
(
eval_points
[
wrt
.
index
(
out
)])
rval
.
append
(
eval_points
[
wrt
.
index
(
out
)])
elif
seen_nodes
[
out
.
owner
][
out
.
owner
.
outputs
.
index
(
out
)]
is
None
:
elif
seen_nodes
.
get
(
out
.
owner
,
None
)
is
None
or
\
raise
ValueError
((
'The function is not differentiable with '
seen_nodes
[
out
.
owner
][
out
.
owner
.
outputs
.
index
(
out
)]
is
None
:
'respect to the provided inputs !'
))
message
=
(
"Rop method was asked to compute the gradient "
"with respect to a variable that is not part of "
"the computational graph of variables in wrt, or is "
"used only by a non-differentiable operator:
%
s"
%
out
)
if
disconnected_outputs
==
'ignore'
:
pass
elif
disconnected_outputs
==
'warn'
:
warnings
.
warn
(
message
,
stacklevel
=
2
)
elif
disconnected_outputs
==
'raise'
:
message
=
utils
.
get_variable_trace_string
(
out
)
raise
DisconnectedInputError
(
message
)
else
:
raise
ValueError
(
"Invalid value for keyword "
"'disconnected_inputs', valid values are "
"'ignore', 'warn' and 'raise'."
)
if
return_disconnected
.
lower
()
==
"zero"
:
rval
.
append
(
tensor
.
zeros_like
(
out
))
elif
return_disconnected
.
lower
()
==
"none"
:
rval
.
append
(
None
)
elif
return_disconnected
.
lower
()
==
"disconnected"
:
rval
.
append
(
disconnected_type
())
else
:
raise
ValueError
(
"Invalid value for keyword "
"'return_disconnected', valid values are "
"'zero', 'None' and 'Disconnected'."
)
else
:
else
:
rval
.
append
(
seen_nodes
[
out
.
owner
][
out
.
owner
.
outputs
.
index
(
out
)])
rval
.
append
(
seen_nodes
[
out
.
owner
][
out
.
owner
.
outputs
.
index
(
out
)])
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论