Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
77ad25de
提交
77ad25de
authored
1月 20, 2012
作者:
Olivier Delalleau
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fixed some typos + PEP8
上级
1cbe24c8
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
14 行增加
和
13 行删除
+14
-13
tensor_grad.py
theano/tensor/tensor_grad.py
+12
-11
test_2nd_order_grads.py
theano/tensor/tests/test_2nd_order_grads.py
+2
-2
没有找到文件。
theano/tensor/tensor_grad.py
浏览文件 @
77ad25de
...
...
@@ -28,13 +28,13 @@ def format_as(use_list, use_tuple, outputs):
"""
Formats the outputs according to the flags `use_list` and `use_tuple`.
If `use_list` is True, `outputs` is returned as a list (if `outputs`
is not a list or a tuple then it is converted in a one element list)
is not a list or a tuple then it is converted in a one element list)
.
If `use_tuple` is True, `outputs` is returned as a tuple (if `outputs`
is not a list or a tuple then it is converted into a one element tuple)
is not a list or a tuple then it is converted into a one element tuple)
.
Otherwise (if both flags are false), `outputs` is returned.
"""
assert
not
(
use_list
and
use_tuple
),
\
"Both flags can
not be simultaneously True"
"Both flags cannot be simultaneously True"
if
(
use_list
or
use_tuple
)
and
not
isinstance
(
outputs
,
(
list
,
tuple
)):
if
use_list
:
return
[
outputs
]
...
...
@@ -701,14 +701,15 @@ class GradientError(Exception):
def
__str__
(
self
):
# args may have been inserted by e.g. makeTester
args_msg
=
", "
.
join
(
str
(
a
)
for
a
in
self
.
args
)
return
"""GradientError: numeric gradient and analytic gradient exceed tolerance:
return
"""
\
GradientError: numeric gradient and analytic gradient exceed tolerance:
At position
%
i of argument
%
i,
abs. error =
%
f, abs. tolerance =
%
f
rel. error =
%
f, rel. tolerance =
%
f
\n
Exception args:
%
s
"""
%
(
self
.
err_pos
,
self
.
arg
,
self
.
abs_err
,
self
.
abs_tol
,
self
.
rel_err
,
self
.
rel_tol
,
args_msg
)
rel. error =
%
f, rel. tolerance =
%
f
Exception args:
%
s"""
%
(
self
.
err_pos
,
self
.
arg
,
self
.
abs_err
,
self
.
abs_tol
,
self
.
rel_err
,
self
.
rel_tol
,
args_msg
)
verify_grad
.
E_grad
=
GradientError
...
...
@@ -789,8 +790,8 @@ def hessian(cost, wrt, consider_constant=None, warn_type=False,
disconnected_inputs
=
'raise'
):
"""
:type cost: Scalar (0-dimensional) `Variable`
:type wrt: Vector (1-dimensional tensor
s
) 'Variable' or list of
vectors (1-dimensional tensors) `Variable
s
`s
:type wrt: Vector (1-dimensional tensor) 'Variable' or list of
vectors (1-dimensional tensors) `Variable`s
:param consider_constant: a list of expressions not to backpropagate
through
...
...
theano/tensor/tests/test_2nd_order_grads.py
浏览文件 @
77ad25de
...
...
@@ -94,7 +94,7 @@ def test002_jacobian_matrix():
evx
[
dx
,
dx
,
:]
=
vx
[
dx
,
:]
evz
[
dx
,
dx
,
:]
=
vz
[
dx
,
:]
assert
numpy
.
allclose
(
vJs
[
0
],
evz
)
assert
numpy
.
allclose
(
vJs
[
1
],
evx
)
assert
numpy
.
allclose
(
vJs
[
1
],
evx
)
def
test003_jacobian_scalar
():
...
...
@@ -117,7 +117,7 @@ def test003_jacobian_scalar():
# test when the jacobian is called with a list as wrt
Jx
=
tensor
.
jacobian
(
y
,
[
x
])
assert
isinstance
(
Jx
,
list
)
assert
isinstance
(
Jx
,
list
)
f
=
theano
.
function
([
x
],
Jx
[
0
])
vx
=
numpy
.
cast
[
theano
.
config
.
floatX
](
rng
.
uniform
())
assert
numpy
.
allclose
(
f
(
vx
),
2
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论