Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
2484dde0
提交
2484dde0
authored
10月 31, 2012
作者:
Ian Goodfellow
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix bug in gradient when some outputs of a node have different connection patterns
(Razvan's branch will introduce a test that catches this bug)
上级
5d568c17
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
36 行增加
和
30 行删除
+36
-30
gradient.py
theano/gradient.py
+36
-30
没有找到文件。
theano/gradient.py
浏览文件 @
2484dde0
...
@@ -602,31 +602,39 @@ def _populate_var_to_node_to_idx(outputs, wrt):
...
@@ -602,31 +602,39 @@ def _populate_var_to_node_to_idx(outputs, wrt):
respect to.
respect to.
returns:
returns:
var_to_node_to_idx: a dictionary mapping a variable to
a second dictionary.
var_to_app_to_idx:
the second dictionary maps apply nodes acting on
this variable to the variable's index in the apply
A dictionary mapping a variable to a second dictionary.
node's input list
The second dictionary maps apply nodes acting on this
variable to the variable's index in the apply node's
input list.
This dictionary will only contain variables that
This dictionary will only contain variables that
meet two criteria:
meet two criteria:
1) The elements of at least one output are a
1) The elements of at least one output are a
function of the elements of the variable
function of the elements of the variable
2) The elements of the variable are a function
of the elements of at least one member of
2) The elements of the variable are a function of the
wrt
elements of at least one member of wrt.
This set is exactly the set of variables that
connect the variables in wrt to the cost being
This set is exactly the set of variables that connect
differentiated.
the variables in wrt to the cost being
differentiated.
"""
"""
# var_to_node_to_idx[var][node] = [i,j] means node has
# var_to_node_to_idx[var][node] = [i,j] means node has
# var as input at positions i and j
# var as input at positions i and j
var_to_node_to_idx
=
{}
var_to_app_to_idx
=
{}
# set of variables or nodes that have been added to their true parents
# Set of variables that have been added to their true parents
# ('true' here means that the elements of the variable are a function
# ('true' here means that the elements of the variable are a function
# of the elements of the parent, according to the op's
# of the elements of the parent, according to the op's
# connection_pattern)
# connection_pattern)
# Note: we need to revisit the apply nodes repeatedly, because
# different outputs of the apply node are connected to
# different subsets of the inputs.
accounted_for
=
set
([])
accounted_for
=
set
([])
def
account_for
(
var
):
def
account_for
(
var
):
...
@@ -634,27 +642,25 @@ def _populate_var_to_node_to_idx(outputs, wrt):
...
@@ -634,27 +642,25 @@ def _populate_var_to_node_to_idx(outputs, wrt):
return
return
accounted_for
.
add
(
var
)
accounted_for
.
add
(
var
)
if
var
.
owner
is
not
None
:
if
var
.
owner
is
not
None
:
node
=
var
.
owner
app
=
var
.
owner
if
node
not
in
accounted_for
:
accounted_for
.
add
(
node
)
connection_pattern
=
_node_to_pattern
(
node
)
connection_pattern
=
_node_to_pattern
(
app
)
var_idx
=
node
.
outputs
.
index
(
var
)
var_idx
=
app
.
outputs
.
index
(
var
)
for
i
,
ipt
in
enumerate
(
node
.
inputs
):
for
i
,
ipt
in
enumerate
(
app
.
inputs
):
#don't process ipt if it is not a true
#don't process ipt if it is not a true
#parent of var
#parent of var
if
not
connection_pattern
[
i
][
var_idx
]:
if
not
connection_pattern
[
i
][
var_idx
]:
continue
continue
if
ipt
not
in
var_to_node
_to_idx
:
if
ipt
not
in
var_to_app
_to_idx
:
var_to_node
_to_idx
[
ipt
]
=
{}
var_to_app
_to_idx
[
ipt
]
=
{}
node_to_idx
=
var_to_node
_to_idx
[
ipt
]
app_to_idx
=
var_to_app
_to_idx
[
ipt
]
if
node
not
in
node
_to_idx
:
if
app
not
in
app
_to_idx
:
node_to_idx
[
node
]
=
[]
app_to_idx
[
app
]
=
[]
idx
=
node_to_idx
[
node
]
idx
=
app_to_idx
[
app
]
assert
i
not
in
idx
assert
i
not
in
idx
idx
.
append
(
i
)
idx
.
append
(
i
)
account_for
(
ipt
)
account_for
(
ipt
)
...
@@ -671,10 +677,10 @@ def _populate_var_to_node_to_idx(outputs, wrt):
...
@@ -671,10 +677,10 @@ def _populate_var_to_node_to_idx(outputs, wrt):
def
visit
(
var
):
def
visit
(
var
):
if
var
in
visited
:
if
var
in
visited
:
return
return
if
var
not
in
var_to_
node
_to_idx
:
if
var
not
in
var_to_
app
_to_idx
:
return
return
visited
.
add
(
var
)
visited
.
add
(
var
)
nodes
=
var_to_
node
_to_idx
[
var
]
nodes
=
var_to_
app
_to_idx
[
var
]
for
node
in
nodes
:
for
node
in
nodes
:
connection_pattern
=
_node_to_pattern
(
node
)
connection_pattern
=
_node_to_pattern
(
node
)
for
idx
in
nodes
[
node
]:
for
idx
in
nodes
[
node
]:
...
@@ -686,12 +692,12 @@ def _populate_var_to_node_to_idx(outputs, wrt):
...
@@ -686,12 +692,12 @@ def _populate_var_to_node_to_idx(outputs, wrt):
visit
(
elem
)
visit
(
elem
)
# Remove variables that don't have wrt as a true ancestor
# Remove variables that don't have wrt as a true ancestor
orig_vars
=
list
(
var_to_
node
_to_idx
.
keys
())
orig_vars
=
list
(
var_to_
app
_to_idx
.
keys
())
for
var
in
orig_vars
:
for
var
in
orig_vars
:
if
var
not
in
visited
:
if
var
not
in
visited
:
del
var_to_
node
_to_idx
[
var
]
del
var_to_
app
_to_idx
[
var
]
return
var_to_
node
_to_idx
return
var_to_
app
_to_idx
def
_populate_grad_dict
(
var_to_node_to_idx
,
def
_populate_grad_dict
(
var_to_node_to_idx
,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论