Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
9c86dee5
提交
9c86dee5
authored
5月 15, 2015
作者:
--global
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add test case for scan optimization fix
上级
21f87538
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
75 行增加
和
0 行删除
+75
-0
test_scan.py
theano/scan_module/tests/test_scan.py
+75
-0
没有找到文件。
theano/scan_module/tests/test_scan.py
浏览文件 @
9c86dee5
...
...
@@ -2830,6 +2830,81 @@ class T_Scan(unittest.TestCase):
# Run it so DebugMode can detect optimization problems.
f
(
x_val
,
y_val
)
def
test_pushout_seqs
(
self
):
def
init_predictive_output
(
inputs
,
targets
,
hyp
,
x_star
,
s_star
):
E
=
hyp
.
shape
[
0
]
def
init_K
(
i
,
X
,
Y
):
XX
=
X
.
sum
(
1
)
.
reshape
((
X
.
shape
[
0
],
1
))
K
=
(
XX
+
XX
.
T
)
return
K
.
sum
()
beta
,
K_updts
=
theano
.
scan
(
init_K
,
sequences
=
tensor
.
arange
(
E
),
non_sequences
=
[
inputs
,
targets
])
# mean
def
predict_mean_i
(
i
,
x_star
,
s_star
,
X
,
beta
,
h
):
n
,
D
=
tensor
.
shape
(
X
)
# rescale every dimension by the corresponding inverse lengthscale
iL
=
tensor
.
diag
(
h
[
i
,:
D
])
inp
=
(
X
-
x_star
)
.
dot
(
iL
)
# compute the mean
B
=
iL
.
dot
(
s_star
)
.
dot
(
iL
)
t
=
inp
.
dot
(
B
)
lb
=
(
inp
*
t
)
.
sum
()
+
beta
.
sum
()
Mi
=
tensor
.
sum
(
lb
)
*
h
[
i
,
D
];
return
Mi
(
M
),
M_updts
=
theano
.
scan
(
predict_mean_i
,
sequences
=
tensor
.
arange
(
E
),
non_sequences
=
[
x_star
,
s_star
,
inputs
,
beta
,
hyp
]
)
return
M
# some initializations
hypx
=
numpy
.
log
(
numpy
.
tile
([
1
,
1
,
1
,
1
,
1
,
1
,
0.01
],
(
3
,
1
)))
# variables used in the following expressions
hyp
=
theano
.
shared
(
hypx
)
inputs
=
tensor
.
dmatrix
(
'X'
)
targets
=
tensor
.
dmatrix
(
'Y'
)
x_star
=
tensor
.
dvector
(
'x_star'
)
s_star
=
tensor
.
dmatrix
(
's_star'
)
M
=
init_predictive_output
(
inputs
,
targets
,
hyp
,
x_star
,
s_star
)
X
=
numpy
.
random
.
random
((
10
,
4
))
Y
=
numpy
.
random
.
random
((
10
,
3
))
test_m
=
numpy
.
random
.
random
((
4
,))
test_s
=
numpy
.
eye
(
4
)
# Compute expected outputs (jacobian of M wrt x_star)
dfdm
=
theano
.
function
([
inputs
,
targets
,
x_star
,
s_star
],
[
tensor
.
grad
(
M
[
0
],
x_star
),
tensor
.
grad
(
M
[
1
],
x_star
),
tensor
.
grad
(
M
[
2
],
x_star
)])
expected_output
=
dfdm
(
X
,
Y
,
test_m
,
test_s
)
# equivalent code for the jacobian using scan
dMdm
,
dMdm_updts
=
theano
.
scan
(
lambda
i
,
M
,
x
:
tensor
.
grad
(
M
[
i
],
x
),
sequences
=
tensor
.
arange
(
M
.
shape
[
0
]),
non_sequences
=
[
M
,
x_star
])
dfdm
=
theano
.
function
([
inputs
,
targets
,
x_star
,
s_star
],
[
dMdm
[
0
],
dMdm
[
1
],
dMdm
[
2
]])
scan_output
=
dfdm
(
X
,
Y
,
test_m
,
test_s
)
# equivalent code for the jacobian using tensor.jacobian
dMdm_j
=
tensor
.
jacobian
(
M
,
x_star
)
dfdm_j
=
theano
.
function
([
inputs
,
targets
,
x_star
,
s_star
],
[
dMdm_j
[
0
],
dMdm_j
[
1
],
dMdm_j
[
2
]])
jacobian_outputs
=
dfdm_j
(
X
,
Y
,
test_m
,
test_s
)
utt
.
assert_allclose
(
expected_output
,
scan_output
)
utt
.
assert_allclose
(
expected_output
,
jacobian_outputs
)
def
test_sequence_dict
(
self
):
# Test that we can specify sequences as a dictionary with
# only the 'input' key
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论