Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
8d5c376f
提交
8d5c376f
authored
12月 06, 2013
作者:
Pascal Lamblin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove error in hessian if gradient is constant
上级
2c710d23
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
29 行增加
和
2 行删除
+29
-2
gradient.py
theano/gradient.py
+7
-2
test_basic.py
theano/tensor/tests/test_basic.py
+22
-0
没有找到文件。
theano/gradient.py
浏览文件 @
8d5c376f
...
@@ -1636,12 +1636,17 @@ def hessian(cost, wrt, consider_constant=None,
...
@@ -1636,12 +1636,17 @@ def hessian(cost, wrt, consider_constant=None,
assert
input
.
ndim
==
1
,
\
assert
input
.
ndim
==
1
,
\
"tensor.hessian expects a (list of) 1 dimensional variable "
\
"tensor.hessian expects a (list of) 1 dimensional variable "
\
"as `wrt`"
"as `wrt`"
expr
=
grad
(
cost
,
input
)
expr
=
grad
(
cost
,
input
,
consider_constant
=
consider_constant
,
disconnected_inputs
=
disconnected_inputs
)
# It is possible that the inputs are disconnected from expr,
# even if they are connected to cost.
# This should not be an error.
hess
,
updates
=
theano
.
scan
(
lambda
i
,
y
,
x
:
grad
(
hess
,
updates
=
theano
.
scan
(
lambda
i
,
y
,
x
:
grad
(
y
[
i
],
y
[
i
],
x
,
x
,
consider_constant
=
consider_constant
,
consider_constant
=
consider_constant
,
disconnected_inputs
=
disconnected_inputs
),
disconnected_inputs
=
'ignore'
),
sequences
=
arange
(
expr
.
shape
[
0
]),
sequences
=
arange
(
expr
.
shape
[
0
]),
non_sequences
=
[
expr
,
input
])
non_sequences
=
[
expr
,
input
])
assert
not
updates
,
\
assert
not
updates
,
\
...
...
theano/tensor/tests/test_basic.py
浏览文件 @
8d5c376f
...
@@ -3086,6 +3086,28 @@ class T_Join_and_Split(unittest.TestCase):
...
@@ -3086,6 +3086,28 @@ class T_Join_and_Split(unittest.TestCase):
assert
numpy
.
allclose
(
Ha_v
,
2.
)
assert
numpy
.
allclose
(
Ha_v
,
2.
)
assert
numpy
.
allclose
(
Hb_v
,
2.
)
assert
numpy
.
allclose
(
Hb_v
,
2.
)
def
test_stack_hessian2
(
self
):
# Test the hessian macro when the gradient itself does not depend
# on the input (but the cost does)
a
=
tensor
.
dvector
(
'a'
)
b
=
tensor
.
dvector
(
'b'
)
A
=
stack
([
a
,
b
])
Ha
,
Hb
=
hessian
(
A
.
sum
(),
[
a
,
b
])
# Try some values
a_v
=
numpy
.
random
.
rand
(
4
)
b_v
=
numpy
.
random
.
rand
(
4
)
f
=
theano
.
function
([
a
,
b
],
[
Ha
,
Hb
])
Ha_v
,
Hb_v
=
f
(
a_v
,
b_v
)
print
Ha_v
print
Hb_v
# The Hessian is always a matrix full of 0
assert
Ha_v
.
shape
==
(
4
,
4
)
assert
Hb_v
.
shape
==
(
4
,
4
)
assert
numpy
.
allclose
(
Ha_v
,
0.
)
assert
numpy
.
allclose
(
Hb_v
,
0.
)
def
test_join_concatenate_one_element
(
self
):
def
test_join_concatenate_one_element
(
self
):
''' Fast test of concatenate as this is an alias for join.
''' Fast test of concatenate as this is an alias for join.
also test that we remove the Join op if there is only 1 input'''
also test that we remove the Join op if there is only 1 input'''
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论