Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
cf15650e
提交
cf15650e
authored
2月 23, 2010
作者:
Pascal Lamblin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add a little more flexibility in matching the output gradient expression.
上级
e684f824
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
19 行增加
和
22 行删除
+19
-22
nnet.py
theano/tensor/nnet/nnet.py
+19
-22
没有找到文件。
theano/tensor/nnet/nnet.py
浏览文件 @
cf15650e
...
...
@@ -1037,31 +1037,28 @@ def local_advanced_indexing_crossentropy_onehot_grad(node):
# In the base case (output gradient = 1), incr is -1./sm[arange(len(y)), y]
# Here, we are looking for the AdvancedSubtensor term (sm[arange(len(y)), y]),
# the remaining of the expression will be used to compute outgrad_factor
# outgrad_factor will be constructed in 3 steps as follow:
# outgrad_factor = +/- 1 (initial sign)
# outgrad_factor *= numerator
# outgrad_factor /= denominator
# and constructing out_grad by incorporating the other terms.
# out_grad will be constructed in 3 steps as follow:
# out_grad = +/- 1. (according to sign)
# out_grad *= -numerator
# out_grad /= denominator
# Then, if out_grad is a scalar, it will be allocated as a vector
adv_subtensor
=
None
out
grad_factor
=
1.
out
_grad
=
1.
# If there's a 'minus' sign before the whole expression, put it in
# out
grad_factor
and iterate
# out
_grad
and iterate
if
incr
.
owner
and
incr
.
owner
.
op
==
tensor
.
neg
:
out
grad_factor
=
-
1.
out
_grad
=
-
out_grad
incr
=
incr
.
owner
.
inputs
[
0
]
if
incr
.
owner
and
incr
.
owner
.
op
==
tensor
.
true_div
:
num
,
denom
=
incr
.
owner
.
inputs
# set outgrad_factor according to the numerator,
# it may be divided later
if
hasattr
(
num
,
'data'
)
and
numpy
.
all
(
num
.
data
==
-
1
):
# Base case, num is -1
outgrad_factor
*=
1.
elif
numpy
.
all
(
num
.
broadcastable
):
# Otherwise, it should be a scalar
outgrad_factor
*=
-
num
# set out_grad according to the numerator, it may be divided later
# num should be a vector or a scalar
if
numpy
.
ndim
==
1
or
numpy
.
all
(
num
.
broadcastable
):
out_grad
*=
-
num
else
:
return
...
...
@@ -1071,10 +1068,10 @@ def local_advanced_indexing_crossentropy_onehot_grad(node):
if
isinstance
(
denom
.
owner
.
op
,
tensor
.
AdvancedSubtensor
):
# Base case
adv_subtensor
=
denom
outgrad_factor
/=
1.
#out_grad
/= 1.
elif
denom
.
owner
.
op
==
tensor
.
mul
:
# Try to find the AdvancedSubtensor node mentionned above,
# and
a scalar that is equal to
the output gradient
# and the output gradient
for
i
,
input
in
enumerate
(
denom
.
owner
.
inputs
):
if
input
.
owner
and
isinstance
(
input
.
owner
.
op
,
tensor
.
AdvancedSubtensor
):
other_inputs
=
[
in_
for
(
j
,
in_
)
in
enumerate
(
denom
.
owner
.
inputs
)
if
j
!=
i
]
...
...
@@ -1083,16 +1080,16 @@ def local_advanced_indexing_crossentropy_onehot_grad(node):
else
:
rest
=
tensor
.
mul
(
*
[
other_inputs
])
# Check that rest is a scalar
if
numpy
.
all
(
rest
.
broadcastable
):
# Check that rest is a
vector or a
scalar
if
rest
.
ndim
==
1
or
numpy
.
all
(
rest
.
broadcastable
):
adv_subtensor
=
input
out
grad_factor
/=
rest
out
_grad
/=
rest
break
else
:
return
# The output gradient needs to be a vector
out_grad
=
tensor
.
fill
(
x_var
[:,
0
],
out
grad_factor
)
out_grad
=
tensor
.
fill
(
x_var
[:,
0
],
out
_grad
)
if
adv_subtensor
is
not
None
:
try
:
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论