Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
459d004b
提交
459d004b
authored
4月 15, 2015
作者:
carriepl
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #2750 from SinaHonari/issue2500
Tracking Ops with grad methods returning None
上级
928a8af5
9f7b2e71
显示空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
61 行增加
和
19 行删除
+61
-19
ops.py
theano/compile/ops.py
+2
-2
scan_op.py
theano/sandbox/scan_module/scan_op.py
+0
-6
basic.py
theano/scalar/basic.py
+18
-3
basic.py
theano/sparse/basic.py
+16
-5
sp2.py
theano/sparse/sandbox/sp2.py
+25
-3
没有找到文件。
theano/compile/ops.py
浏览文件 @
459d004b
...
@@ -385,8 +385,8 @@ class Shape_i(gof.Op):
...
@@ -385,8 +385,8 @@ class Shape_i(gof.Op):
return
[()]
return
[()]
def
grad
(
self
,
inp
,
grads
):
def
grad
(
self
,
inp
,
grads
):
return
[
None
]
return
[
theano
.
gradient
.
grad_not_implemented
(
op
=
self
,
x_pos
=
0
,
x
=
inp
[
0
],
comment
=
"No gradient for the shape of a matrix is implemented."
)]
def
shape_i
(
var
,
i
,
fgraph
=
None
):
def
shape_i
(
var
,
i
,
fgraph
=
None
):
"""Equivalent of var.shape[i], but apply if possible the shape
"""Equivalent of var.shape[i], but apply if possible the shape
...
...
theano/sandbox/scan_module/scan_op.py
浏览文件 @
459d004b
...
@@ -341,12 +341,6 @@ class ScanOp(PureOp):
...
@@ -341,12 +341,6 @@ class ScanOp(PureOp):
rval
.
lazy
=
False
rval
.
lazy
=
False
return
rval
return
rval
def
grad
(
self
,
args
,
g_outs
):
pass
def
R_op
(
self
,
inputs
,
eval_points
):
pass
@theano.compile.profilemode.register_profiler_printer
@theano.compile.profilemode.register_profiler_printer
def
profile_printer
(
fct_name
,
compile_time
,
fct_call_time
,
fct_call
,
def
profile_printer
(
fct_name
,
compile_time
,
fct_call_time
,
fct_call
,
...
...
theano/scalar/basic.py
浏览文件 @
459d004b
...
@@ -1155,8 +1155,22 @@ class InRange(LogicalComparison):
...
@@ -1155,8 +1155,22 @@ class InRange(LogicalComparison):
return
(
"
%(z)
s =
%(x)
s
%(cmp1)
s
%(low)
s &&"
return
(
"
%(z)
s =
%(x)
s
%(cmp1)
s
%(low)
s &&"
"
%(x)
s
%(cmp2)
s
%(hi)
s;"
%
locals
())
"
%(x)
s
%(cmp2)
s
%(hi)
s;"
%
locals
())
def
get_grad
(
self
,
elem
):
if
elem
.
type
in
complex_types
:
msg
=
"No gradient implemented for complex numbers in
\
class scalar.basic.InRange"
raise
NotImplementedError
(
msg
)
elif
elem
.
type
in
discrete_types
:
return
elem
.
zeros_like
()
.
astype
(
theano
.
config
.
floatX
)
else
:
return
elem
.
zeros_like
()
def
grad
(
self
,
(
x
,
low
,
hi
),
(
gz
,
)):
def
grad
(
self
,
(
x
,
low
,
hi
),
(
gz
,
)):
return
None
,
None
,
None
grads
=
[]
for
elem
in
[
x
,
low
,
hi
]:
grads
.
append
(
get_grad
(
elem
))
return
grads
inopenrange
=
InRange
(
True
,
True
)
inopenrange
=
InRange
(
True
,
True
)
inclosedrange
=
InRange
(
False
,
False
)
inclosedrange
=
InRange
(
False
,
False
)
...
@@ -2928,7 +2942,8 @@ class Imag(UnaryScalarOp):
...
@@ -2928,7 +2942,8 @@ class Imag(UnaryScalarOp):
elif
x
.
type
in
float_types
:
elif
x
.
type
in
float_types
:
return
[
second
(
x
,
0
)]
return
[
second
(
x
,
0
)]
else
:
else
:
return
[
None
]
return
[
x
.
zeros_like
(
dtype
=
theano
.
config
.
floatX
)]
imag
=
Imag
(
real_out
,
name
=
'imag'
)
imag
=
Imag
(
real_out
,
name
=
'imag'
)
...
@@ -2959,7 +2974,7 @@ class Angle(UnaryScalarOp):
...
@@ -2959,7 +2974,7 @@ class Angle(UnaryScalarOp):
elif
c
in
float_types
:
elif
c
in
float_types
:
return
[
cast
(
second
(
x
,
0
),
x
.
type
.
dtype
)]
return
[
cast
(
second
(
x
,
0
),
x
.
type
.
dtype
)]
else
:
else
:
return
[
None
]
return
[
c
.
zeros_like
(
dtype
=
theano
.
config
.
floatX
)
]
angle
=
Angle
(
specific_out
(
float64
),
name
=
'angle'
)
angle
=
Angle
(
specific_out
(
float64
),
name
=
'angle'
)
...
...
theano/sparse/basic.py
浏览文件 @
459d004b
...
@@ -832,11 +832,23 @@ class Cast(gof.op.Op):
...
@@ -832,11 +832,23 @@ class Cast(gof.op.Op):
out
[
0
]
=
x
.
astype
(
self
.
out_type
)
out
[
0
]
=
x
.
astype
(
self
.
out_type
)
def
grad
(
self
,
inputs
,
outputs_gradients
):
def
grad
(
self
,
inputs
,
outputs_gradients
):
if
inputs
[
0
]
.
dtype
in
tensor
.
continuous_dtypes
:
gz
=
outputs_gradients
[
0
]
gz
=
outputs_gradients
[
0
]
return
[
Cast
(
inputs
[
0
]
.
dtype
)(
gz
)]
if
gz
.
dtype
in
complex_dtypes
:
raise
NotImplementedError
(
"grad not implemented for complex types"
)
if
inputs
[
0
]
.
dtype
in
complex_dtypes
:
raise
NotImplementedError
(
"grad not implemented for complex types"
)
if
gz
.
dtype
in
discrete_dtypes
:
if
inputs
[
0
]
.
dtype
in
discrete_dtypes
:
return
[
inputs
[
0
]
.
zeros_like
(
dtype
=
theano
.
config
.
floatX
)]
else
:
else
:
return
[
None
]
return
[
inputs
[
0
]
.
zeros_like
()]
else
:
if
inputs
[
0
]
.
dtype
in
discrete_dtypes
:
return
[
gz
]
else
:
return
[
Cast
(
inputs
[
0
]
.
dtype
)(
gz
)]
def
infer_shape
(
self
,
node
,
ins_shapes
):
def
infer_shape
(
self
,
node
,
ins_shapes
):
return
ins_shapes
return
ins_shapes
...
@@ -1647,8 +1659,7 @@ class SpSum(gof.op.Op):
...
@@ -1647,8 +1659,7 @@ class SpSum(gof.op.Op):
def
grad
(
self
,
(
x
,),
(
gz
,)):
def
grad
(
self
,
(
x
,),
(
gz
,)):
if
x
.
dtype
not
in
continuous_dtypes
:
if
x
.
dtype
not
in
continuous_dtypes
:
return
[
None
]
return
[
x
.
zeros_like
(
dtype
=
theano
.
config
.
floatX
)]
if
self
.
structured
:
if
self
.
structured
:
if
self
.
axis
is
None
:
if
self
.
axis
is
None
:
r
=
gz
*
theano
.
sparse
.
sp_ones_like
(
x
)
r
=
gz
*
theano
.
sparse
.
sp_ones_like
(
x
)
...
...
theano/sparse/sandbox/sp2.py
浏览文件 @
459d004b
import
numpy
import
numpy
import
theano
import
scipy.sparse
import
scipy.sparse
from
theano
import
gof
,
tensor
from
theano
import
gof
,
tensor
...
@@ -79,7 +80,10 @@ class Poisson(gof.op.Op):
...
@@ -79,7 +80,10 @@ class Poisson(gof.op.Op):
out
[
0
]
.
eliminate_zeros
()
out
[
0
]
.
eliminate_zeros
()
def
grad
(
self
,
inputs
,
outputs_gradients
):
def
grad
(
self
,
inputs
,
outputs_gradients
):
return
[
None
]
comment
=
"No gradient exists for class Poisson in
\
theano/sparse/sandbox/sp2.py"
return
[
theano
.
gradient
.
grad_undefined
(
op
=
self
,
x_pos
=
0
,
x
=
inputs
[
0
],
comment
=
comment
)]
def
infer_shape
(
self
,
node
,
ins_shapes
):
def
infer_shape
(
self
,
node
,
ins_shapes
):
return
ins_shapes
return
ins_shapes
...
@@ -131,8 +135,19 @@ class Binomial(gof.op.Op):
...
@@ -131,8 +135,19 @@ class Binomial(gof.op.Op):
csx_matrix
=
getattr
(
scipy
.
sparse
,
self
.
format
+
'_matrix'
)
csx_matrix
=
getattr
(
scipy
.
sparse
,
self
.
format
+
'_matrix'
)
out
[
0
]
=
csx_matrix
(
binomial
,
dtype
=
self
.
dtype
)
out
[
0
]
=
csx_matrix
(
binomial
,
dtype
=
self
.
dtype
)
def
connection_pattern
(
self
,
node
):
return
[[
True
],
[
True
],
[
False
]]
def
grad
(
self
,
(
n
,
p
,
shape
,
),
(
gz
,)):
def
grad
(
self
,
(
n
,
p
,
shape
,
),
(
gz
,)):
return
None
,
None
,
None
comment_n
=
"No gradient exists for the number of samples in class
\
Binomial of theano/sparse/sandbox/sp2.py"
comment_p
=
"No gradient exists for the prob of success in class
\
Binomial of theano/sparse/sandbox/sp2.py"
return
[
theano
.
gradient
.
grad_undefined
(
op
=
self
,
x_pos
=
0
,
x
=
n
,
comment
=
comment_n
),
theano
.
gradient
.
grad_undefined
(
op
=
self
,
x_pos
=
1
,
x
=
p
,
comment
=
comment_p
),
theano
.
gradient
.
disconnected_type
()]
def
infer_shape
(
self
,
node
,
ins_shapes
):
def
infer_shape
(
self
,
node
,
ins_shapes
):
return
[(
node
.
inputs
[
2
][
0
],
node
.
inputs
[
2
][
1
])]
return
[(
node
.
inputs
[
2
][
0
],
node
.
inputs
[
2
][
1
])]
...
@@ -202,7 +217,14 @@ class Multinomial(gof.op.Op):
...
@@ -202,7 +217,14 @@ class Multinomial(gof.op.Op):
out
[
0
]
.
data
[
k
:
l
]
=
numpy
.
random
.
multinomial
(
n
[
i
],
p
.
data
[
k
:
l
])
out
[
0
]
.
data
[
k
:
l
]
=
numpy
.
random
.
multinomial
(
n
[
i
],
p
.
data
[
k
:
l
])
def
grad
(
self
,
inputs
,
outputs_gradients
):
def
grad
(
self
,
inputs
,
outputs_gradients
):
return
[
None
,
None
]
comment_n
=
"No gradient exists for the number of samples in class
\
Multinomial of theano/sparse/sandbox/sp2.py"
comment_p
=
"No gradient exists for the prob of success in class
\
Multinomial of theano/sparse/sandbox/sp2.py"
return
[
theano
.
gradient
.
grad_undefined
(
op
=
self
,
x_pos
=
0
,
x
=
inputs
[
0
],
comment
=
comment_n
),
theano
.
gradient
.
grad_undefined
(
op
=
self
,
x_pos
=
1
,
x
=
inputs
[
1
],
comment
=
comment_p
)]
def
infer_shape
(
self
,
node
,
ins_shapes
):
def
infer_shape
(
self
,
node
,
ins_shapes
):
return
[
ins_shapes
[
1
]]
return
[
ins_shapes
[
1
]]
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论