Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
3de75d70
提交
3de75d70
authored
10月 31, 2014
作者:
Frederic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
In verify_grad, cast the projection to float32.
This help gpuarray tests to run on device that don't support float64.
上级
e7cb39cb
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
10 行增加
和
7 行删除
+10
-7
gradient.py
theano/gradient.py
+10
-7
没有找到文件。
theano/gradient.py
浏览文件 @
3de75d70
...
@@ -1492,7 +1492,7 @@ class numeric_grad(object):
...
@@ -1492,7 +1492,7 @@ class numeric_grad(object):
def
verify_grad
(
fun
,
pt
,
n_tests
=
2
,
rng
=
None
,
eps
=
None
,
def
verify_grad
(
fun
,
pt
,
n_tests
=
2
,
rng
=
None
,
eps
=
None
,
out_type
=
None
,
abs_tol
=
None
,
out_type
=
None
,
abs_tol
=
None
,
rel_tol
=
None
,
mode
=
None
,
cast_to_output_type
=
Fals
e
):
rel_tol
=
None
,
mode
=
None
,
cast_to_output_type
=
Tru
e
):
"""Test a gradient by Finite Difference Method. Raise error on failure.
"""Test a gradient by Finite Difference Method. Raise error on failure.
Example:
Example:
...
@@ -1525,6 +1525,9 @@ def verify_grad(fun, pt, n_tests=2, rng=None, eps=None,
...
@@ -1525,6 +1525,9 @@ def verify_grad(fun, pt, n_tests=2, rng=None, eps=None,
comparison
comparison
:param rel_tol: relative tolerance used as threshold for gradient
:param rel_tol: relative tolerance used as threshold for gradient
comparison
comparison
:param cast_to_output_type: if the output is float32 and
cast_to_output_type is True, cast the random projection to
float32. Otherwise it is float64.
:note: WARNING to unit-test writers: if `op` is a function that builds
:note: WARNING to unit-test writers: if `op` is a function that builds
a graph, try to make it a SMALL graph. Often verify grad is run
a graph, try to make it a SMALL graph. Often verify grad is run
...
@@ -1602,13 +1605,13 @@ def verify_grad(fun, pt, n_tests=2, rng=None, eps=None,
...
@@ -1602,13 +1605,13 @@ def verify_grad(fun, pt, n_tests=2, rng=None, eps=None,
# random_projection should not have elements too small,
# random_projection should not have elements too small,
# otherwise too much precision is lost in numerical gradient
# otherwise too much precision is lost in numerical gradient
def
random_projection
(
dtype
):
def
random_projection
():
plain
=
rng
.
rand
(
*
o_fn_out
.
shape
)
+
0.5
plain
=
rng
.
rand
(
*
o_fn_out
.
shape
)
+
0.5
if
cast_to_output_type
:
if
cast_to_output_type
and
o_output
.
dtype
==
"float32"
:
return
numpy
.
array
(
plain
,
o_output
.
dtype
)
return
numpy
.
array
(
plain
,
o_output
.
dtype
)
return
plain
.
astype
(
dtype
)
return
plain
dtype
=
"float32"
if
all
([
p
.
dtype
==
'float32'
for
p
in
pt
])
else
"float64"
t_r
=
shared
(
random_projection
(
dtype
))
t_r
=
shared
(
random_projection
())
t_r
.
name
=
'random_projection'
t_r
.
name
=
'random_projection'
# random projection of o onto t_r
# random projection of o onto t_r
...
@@ -1643,7 +1646,7 @@ def verify_grad(fun, pt, n_tests=2, rng=None, eps=None,
...
@@ -1643,7 +1646,7 @@ def verify_grad(fun, pt, n_tests=2, rng=None, eps=None,
# get new random projection for next test
# get new random projection for next test
if
test_num
<
n_tests
-
1
:
if
test_num
<
n_tests
-
1
:
t_r
.
set_value
(
random_projection
(
t_r
.
dtype
),
borrow
=
True
)
t_r
.
set_value
(
random_projection
(),
borrow
=
True
)
except
Exception
,
e
:
except
Exception
,
e
:
e
.
args
+=
(
"
\n
The error happened with the following inputs:"
,
pt
,
e
.
args
+=
(
"
\n
The error happened with the following inputs:"
,
pt
,
"
\n
The value of eps is:"
,
eps
,
"
\n
The value of eps is:"
,
eps
,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论