Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
2df16b66
提交
2df16b66
authored
9月 06, 2012
作者:
Ian Goodfellow
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fixed grad for Minimum, Sub, Trunc, Sum, and ConvTransp3D
上级
e87e11cf
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
24 行增加
和
17 行删除
+24
-17
basic.py
theano/scalar/basic.py
+14
-14
elemwise.py
theano/tensor/elemwise.py
+1
-1
ConvTransp3D.py
theano/tensor/nnet/ConvTransp3D.py
+9
-2
没有找到文件。
theano/scalar/basic.py
浏览文件 @
2df16b66
...
...
@@ -1124,11 +1124,13 @@ class Minimum(BinaryScalarOp):
def
grad
(
self
,
(
x
,
y
),
(
gz
,
)):
assert
gz
.
type
not
in
complex_types
# max is not defined for complex_types
gx
,
gy
=
None
,
None
if
x
.
type
in
float_types
:
gx
=
cast
(
eq
(
minimum
(
x
,
y
),
x
)
*
gz
,
x
.
type
.
dtype
)
if
y
.
type
in
float_types
:
gy
=
cast
(
eq
(
minimum
(
x
,
y
),
y
)
*
gz
,
y
.
type
.
dtype
)
output
=
minimum
(
x
,
y
)
if
output
.
type
in
discrete_types
:
return
[
x
.
zeros_like
()
.
astype
(
theano
.
config
.
floatX
),
y
.
zeros_like
()
.
astype
(
theano
.
config
.
floatX
)]
gx
=
eq
(
output
,
x
)
*
gz
gy
=
eq
(
output
,
y
)
*
gz
return
(
gx
,
gy
)
minimum
=
Minimum
(
upcast_out
,
name
=
'minimum'
)
...
...
@@ -1225,15 +1227,13 @@ class Sub(BinaryScalarOp):
if
gz
.
type
in
complex_types
:
raise
NotImplementedError
()
if
x
.
type
in
float_types
:
first_part
=
cast
(
gz
,
x
.
type
.
dtype
)
else
:
first_part
=
None
if
(
x
-
y
)
.
type
in
discrete_types
:
return
[
x
.
zeros_like
()
.
astype
(
theano
.
config
.
floatX
),
y
.
zeros_like
()
.
astype
(
theano
.
config
.
floatX
)]
first_part
=
gz
second_part
=
-
gz
if
y
.
type
in
float_types
:
second_part
=
cast
(
-
gz
,
y
.
type
.
dtype
)
else
:
second_part
=
None
return
first_part
,
second_part
sub
=
Sub
(
upcast_out
,
name
=
'sub'
)
...
...
@@ -1767,7 +1767,7 @@ class Trunc(UnaryScalarOp):
return
numpy
.
trunc
(
x
)
def
grad
(
self
,
(
x
,),
(
gz
,)):
return
None
,
return
x
.
zeros_like
()
.
astype
(
theano
.
config
.
floatX
)
def
c_code
(
self
,
node
,
name
,
(
x
,),
(
z
,),
sub
):
return
"
%(z)
s =
%(x)
s >= 0? floor(
%(x)
s): -floor(-
%(x)
s);"
%
locals
()
...
...
theano/tensor/elemwise.py
浏览文件 @
2df16b66
...
...
@@ -1612,7 +1612,7 @@ class Sum(CAReduceDtype):
new_dims
.
append
(
i
)
i
+=
1
ds_op
=
DimShuffle
(
gz
.
type
.
broadcastable
,
new_dims
)
gx
=
Elemwise
(
scalar
.
second
)(
x
,
ds_op
(
gz
)
.
astype
(
x
.
dtype
)
)
gx
=
Elemwise
(
scalar
.
second
)(
x
,
ds_op
(
gz
))
return
[
gx
]
def
R_op
(
self
,
inputs
,
eval_points
):
...
...
theano/tensor/nnet/ConvTransp3D.py
浏览文件 @
2df16b66
...
...
@@ -2,6 +2,8 @@ import numpy as N
from
theano.tensor
import
basic
as
T
from
theano.misc
import
strutil
import
theano
from
theano.gradient
import
grad_undefined
from
theano.gradient
import
DisconnectedType
class
ConvTransp3D
(
theano
.
Op
):
""" "Transpose" of Conv3D (Conv3D implements multiplication by an implicitly defined matrix W. This implements multiplication by its transpose) """
...
...
@@ -42,6 +44,9 @@ class ConvTransp3D(theano.Op):
W_shape
,
b_shape
,
d_shape
,
H_shape
,
RShape_shape
=
input_shapes
return
[(
H_shape
[
0
],
RShape
[
0
],
RShape
[
1
],
RShape
[
2
],
W_shape
[
4
])]
def
connection_pattern
(
self
,
node
):
return
[[
True
],
[
True
],
[
True
],
[
True
],
[
False
]]
def
grad
(
self
,
inputs
,
output_gradients
):
W
,
b
,
d
,
H
,
RShape
=
inputs
dCdR
,
=
output_gradients
...
...
@@ -49,8 +54,10 @@ class ConvTransp3D(theano.Op):
WShape
=
W
.
shape
dCdW
=
convGrad3D
(
dCdR
,
d
,
WShape
,
H
)
dCdb
=
T
.
sum
(
dCdR
,
axis
=
(
0
,
1
,
2
,
3
))
dCdd
=
None
#not differentiable, since d is not continuous
dCdRShape
=
None
#not differentiable, since RShape is not continuous
# not differentiable, since d affects the output elements
dCdd
=
grad_undefined
(
self
,
2
,
d
)
# disconnected, since RShape just determines the output shape
dCdRShape
=
DisconnectedType
()()
if
'name'
in
dir
(
dCdR
)
and
dCdR
.
name
is
not
None
:
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论