Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
90cba7f8
提交
90cba7f8
authored
4月 20, 2011
作者:
Razvan Pascanu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
renamed flag from strict to assume_continiously_differentiable
上级
e42d146d
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
12 行增加
和
9 行删除
+12
-9
basic.py
theano/tensor/basic.py
+7
-6
test_basic.py
theano/tensor/tests/test_basic.py
+5
-3
没有找到文件。
theano/tensor/basic.py
浏览文件 @
90cba7f8
...
@@ -4677,7 +4677,7 @@ outer = Outer()
...
@@ -4677,7 +4677,7 @@ outer = Outer()
#########################
#########################
def
grad
(
cost
,
wrt
,
g_cost
=
None
,
consider_constant
=
[],
warn_type
=
False
,
def
grad
(
cost
,
wrt
,
g_cost
=
None
,
consider_constant
=
[],
warn_type
=
False
,
strict
=
Tru
e
):
assume_continuously_differentiable
=
Fals
e
):
"""
"""
:type cost: Scalar (0-dimensional) `Variable`
:type cost: Scalar (0-dimensional) `Variable`
:type wrt: `Variable` or list of `Variable`s.
:type wrt: `Variable` or list of `Variable`s.
...
@@ -4689,12 +4689,12 @@ def grad(cost, wrt, g_cost=None, consider_constant=[], warn_type=False,
...
@@ -4689,12 +4689,12 @@ def grad(cost, wrt, g_cost=None, consider_constant=[], warn_type=False,
:param warn_type: a value of True will cause warnings to be logged for any Op that emits a
:param warn_type: a value of True will cause warnings to be logged for any Op that emits a
gradient that does not match its input type.
gradient that does not match its input type.
:param
strict
: flag that says if grad is strict about what it returns.
:param
assume_continuously_differentiable
: flag that says if grad is strict about what it returns.
If set to
tru
e it will raise an exception for any argument in
If set to
fals
e it will raise an exception for any argument in
``wrt`` for which there is no gradient either because some op does
``wrt`` for which there is no gradient either because some op does
not know how to compute the gradient with respect to that argument
not know how to compute the gradient with respect to that argument
or the argument is not part of the computational graph. If the flag
or the argument is not part of the computational graph. If the flag
is set to
fals
e, the ``grad`` method returns zeros like the argument
is set to
tru
e, the ``grad`` method returns zeros like the argument
( i.e. it makes the assumption that the gradient should be 0).
( i.e. it makes the assumption that the gradient should be 0).
:rtype: `Variable` or list of `Variable`s (depending upon `wrt`)
:rtype: `Variable` or list of `Variable`s (depending upon `wrt`)
...
@@ -4738,7 +4738,7 @@ def grad(cost, wrt, g_cost=None, consider_constant=[], warn_type=False,
...
@@ -4738,7 +4738,7 @@ def grad(cost, wrt, g_cost=None, consider_constant=[], warn_type=False,
wrt
=
[
wrt
]
wrt
=
[
wrt
]
ret
=
[]
ret
=
[]
for
p
in
wrt
:
for
p
in
wrt
:
if
p
not
in
gmap
and
strict
:
if
p
not
in
gmap
and
not
assume_continuously_differentiable
:
raise
ValueError
((
"grad method was asked to compute the graident "
raise
ValueError
((
"grad method was asked to compute the graident "
"with respect to a variable that is not part of "
"with respect to a variable that is not part of "
"the computational graph of the cost or is used "
"the computational graph of the cost or is used "
...
@@ -5018,7 +5018,8 @@ def verify_grad(fun, pt, n_tests=2, rng=None, eps=None, abs_tol=None, rel_tol=No
...
@@ -5018,7 +5018,8 @@ def verify_grad(fun, pt, n_tests=2, rng=None, eps=None, abs_tol=None, rel_tol=No
if
cast_to_output_type
:
if
cast_to_output_type
:
g_cost
=
cast
(
g_cost
,
o_output
.
dtype
)
g_cost
=
cast
(
g_cost
,
o_output
.
dtype
)
symbolic_grad
=
grad
(
cost
,
tensor_pt
,
g_cost
,
strict
=
False
)
symbolic_grad
=
grad
(
cost
,
tensor_pt
,
g_cost
,
assume_continuously_differentiable
=
True
)
#if o_output.dtype in ['float32','float64']:
#if o_output.dtype in ['float32','float64']:
# assert all([x.dtype == o_output.dtype for x in symbolic_grad]),("Expected grad of type %s, got %s "%( symbolic_grad.dtype, o_output.dtyp))
# assert all([x.dtype == o_output.dtype for x in symbolic_grad]),("Expected grad of type %s, got %s "%( symbolic_grad.dtype, o_output.dtyp))
...
...
theano/tensor/tests/test_basic.py
浏览文件 @
90cba7f8
...
@@ -3234,7 +3234,8 @@ class test_grad(unittest.TestCase):
...
@@ -3234,7 +3234,8 @@ class test_grad(unittest.TestCase):
"""grad: Test returning a single zero value from grad"""
"""grad: Test returning a single zero value from grad"""
o
=
test_grad
.
O
()
o
=
test_grad
.
O
()
a1
=
o
.
make_node
()
a1
=
o
.
make_node
()
g
=
grad
(
a1
.
outputs
[
0
],
a1
.
outputs
[
1
],
strict
=
False
)
g
=
grad
(
a1
.
outputs
[
0
],
a1
.
outputs
[
1
],
assume_continuously_differentiable
=
True
)
self
.
assertTrue
(
g
.
owner
.
op
==
fill
)
self
.
assertTrue
(
g
.
owner
.
op
==
fill
)
self
.
assertTrue
(
g
.
owner
.
inputs
[
1
]
.
data
==
0
)
self
.
assertTrue
(
g
.
owner
.
inputs
[
1
]
.
data
==
0
)
try
:
try
:
...
@@ -3248,7 +3249,7 @@ class test_grad(unittest.TestCase):
...
@@ -3248,7 +3249,7 @@ class test_grad(unittest.TestCase):
o
=
test_grad
.
O
()
o
=
test_grad
.
O
()
a1
=
o
.
make_node
()
a1
=
o
.
make_node
()
g0
,
g1
,
g2
=
grad
(
a1
.
outputs
[
0
],
a1
.
inputs
+
[
scalar
(
'z'
)],
g0
,
g1
,
g2
=
grad
(
a1
.
outputs
[
0
],
a1
.
inputs
+
[
scalar
(
'z'
)],
strict
=
Fals
e
)
assume_continuously_differentiable
=
Tru
e
)
self
.
assertTrue
(
o
.
gval0
is
g0
)
self
.
assertTrue
(
o
.
gval0
is
g0
)
self
.
assertTrue
(
o
.
gval1
is
g1
)
self
.
assertTrue
(
o
.
gval1
is
g1
)
self
.
assertTrue
(
g2
.
owner
.
op
==
fill
)
self
.
assertTrue
(
g2
.
owner
.
op
==
fill
)
...
@@ -3257,7 +3258,8 @@ class test_grad(unittest.TestCase):
...
@@ -3257,7 +3258,8 @@ class test_grad(unittest.TestCase):
def
test_zero_gradient_shape
(
self
):
def
test_zero_gradient_shape
(
self
):
"""Ensure that a zero gradient has the proper shape."""
"""Ensure that a zero gradient has the proper shape."""
x
=
dmatrix
()
x
=
dmatrix
()
f
=
theano
.
function
([
x
],
grad
(
dscalar
(),
x
,
strict
=
False
))
f
=
theano
.
function
([
x
],
grad
(
dscalar
(),
x
,
assume_continuously_differentiable
=
True
))
a
=
numpy
.
ones
((
3
,
7
))
a
=
numpy
.
ones
((
3
,
7
))
self
.
assertTrue
((
f
(
a
)
==
0
)
.
all
())
# Zero gradient.
self
.
assertTrue
((
f
(
a
)
==
0
)
.
all
())
# Zero gradient.
self
.
assertTrue
(
a
.
shape
==
f
(
a
)
.
shape
)
# With proper shape.
self
.
assertTrue
(
a
.
shape
==
f
(
a
)
.
shape
)
# With proper shape.
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论