Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
adf96a73
提交
adf96a73
authored
4月 03, 2017
作者:
amrithasuresh
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Updated numpy as np
上级
17521fd3
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
19 行增加
和
19 行删除
+19
-19
test_scan_opt.py
theano/scan_module/tests/test_scan_opt.py
+19
-19
没有找到文件。
theano/scan_module/tests/test_scan_opt.py
浏览文件 @
adf96a73
from
__future__
import
absolute_import
,
print_function
,
division
import
numpy
import
numpy
as
np
import
unittest
import
theano
...
...
@@ -18,7 +18,7 @@ class TestGaussNewton(unittest.TestCase):
This test case is based on code by Sigurd Spieckermann.
"""
def
setUp
(
self
):
self
.
rng
=
n
umpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
self
.
rng
=
n
p
.
random
.
RandomState
(
utt
.
fetch_seed
())
def
_run
(
self
,
num_features
,
num_timesteps
,
batch_size
,
mode
):
# determine shapes of inputs and targets depending on the batch size
...
...
@@ -58,8 +58,8 @@ class TestGaussNewton(unittest.TestCase):
W_hy
=
theano
.
shared
(
(
0.01
*
self
.
rng
.
uniform
(
size
=
(
10
,
1
)))
.
astype
(
config
.
floatX
),
borrow
=
True
)
b_h
=
theano
.
shared
(
n
umpy
.
zeros
(
10
)
.
astype
(
config
.
floatX
),
borrow
=
True
)
b_y
=
theano
.
shared
(
n
umpy
.
zeros
(
1
)
.
astype
(
config
.
floatX
),
borrow
=
True
)
b_h
=
theano
.
shared
(
n
p
.
zeros
(
10
)
.
astype
(
config
.
floatX
),
borrow
=
True
)
b_y
=
theano
.
shared
(
n
p
.
zeros
(
1
)
.
astype
(
config
.
floatX
),
borrow
=
True
)
params
=
[
W_xh
,
W_hh
,
W_hy
,
b_h
,
b_y
]
...
...
@@ -171,8 +171,8 @@ class TestPushOutScanOutputDot(object):
# Ensure that the function compiled with the optimization produces
# the same results as the function compiled without
v_value
=
n
umpy
.
random
.
random
((
4
))
.
astype
(
config
.
floatX
)
m_value
=
n
umpy
.
random
.
random
((
4
,
5
))
.
astype
(
config
.
floatX
)
v_value
=
n
p
.
random
.
random
((
4
))
.
astype
(
config
.
floatX
)
m_value
=
n
p
.
random
.
random
((
4
,
5
))
.
astype
(
config
.
floatX
)
output_opt
=
f_opt
(
v_value
,
m_value
)
output_no_opt
=
f_no_opt
(
v_value
,
m_value
)
...
...
@@ -217,8 +217,8 @@ class TestPushOutScanOutputDot(object):
# Ensure that the function compiled with the optimization produces
# the same results as the function compiled without
a_value
=
n
umpy
.
random
.
random
((
3
,
4
))
.
astype
(
config
.
floatX
)
b_value
=
n
umpy
.
random
.
random
((
4
,
5
))
.
astype
(
config
.
floatX
)
a_value
=
n
p
.
random
.
random
((
3
,
4
))
.
astype
(
config
.
floatX
)
b_value
=
n
p
.
random
.
random
((
4
,
5
))
.
astype
(
config
.
floatX
)
output_opt
=
f_opt
(
a_value
,
b_value
)
output_no_opt
=
f_no_opt
(
a_value
,
b_value
)
...
...
@@ -263,8 +263,8 @@ class TestPushOutScanOutputDot(object):
# Ensure that the function compiled with the optimization produces
# the same results as the function compiled without
a_value
=
n
umpy
.
random
.
random
((
3
,
4
))
.
astype
(
config
.
floatX
)
b_value
=
n
umpy
.
random
.
random
((
4
,
5
))
.
astype
(
config
.
floatX
)
a_value
=
n
p
.
random
.
random
((
3
,
4
))
.
astype
(
config
.
floatX
)
b_value
=
n
p
.
random
.
random
((
4
,
5
))
.
astype
(
config
.
floatX
)
output_opt
=
f_opt
(
a_value
,
b_value
)
output_no_opt
=
f_no_opt
(
a_value
,
b_value
)
...
...
@@ -296,7 +296,7 @@ class TestPushOutSumOfDot():
dim
=
5
# Weight matrices
U
=
theano
.
shared
(
n
umpy
.
random
.
normal
(
size
=
(
dim
,
dim
),
U
=
theano
.
shared
(
n
p
.
random
.
normal
(
size
=
(
dim
,
dim
),
scale
=
0.0001
)
.
astype
(
config
.
floatX
))
U
.
name
=
'U'
V
=
theano
.
shared
(
U
.
get_value
())
...
...
@@ -306,7 +306,7 @@ class TestPushOutSumOfDot():
# Variables and their values
x
=
T
.
tensor3
(
'x'
)
x_value
=
n
umpy
.
random
.
normal
(
size
=
(
seq_len
,
batch_size
,
dim
),
x_value
=
n
p
.
random
.
normal
(
size
=
(
seq_len
,
batch_size
,
dim
),
scale
=
0.0001
)
.
astype
(
config
.
floatX
)
ri
=
T
.
tensor3
(
'ri'
)
...
...
@@ -315,7 +315,7 @@ class TestPushOutSumOfDot():
zi
=
T
.
tensor3
(
'zi'
)
zi_value
=
x_value
init
=
T
.
alloc
(
n
umpy
.
cast
[
config
.
floatX
](
0
),
batch_size
,
dim
)
init
=
T
.
alloc
(
n
p
.
cast
[
config
.
floatX
](
0
),
batch_size
,
dim
)
def
rnn_step1
(
# sequences
x
,
ri
,
zi
,
...
...
@@ -375,8 +375,8 @@ class TestPushOutSumOfDot():
input2
=
T
.
tensor3
()
input3
=
T
.
tensor3
()
W
=
theano
.
shared
(
n
umpy
.
random
.
normal
(
size
=
(
4
,
5
)))
.
astype
(
config
.
floatX
)
U
=
theano
.
shared
(
n
umpy
.
random
.
normal
(
size
=
(
6
,
7
)))
.
astype
(
config
.
floatX
)
W
=
theano
.
shared
(
n
p
.
random
.
normal
(
size
=
(
4
,
5
)))
.
astype
(
config
.
floatX
)
U
=
theano
.
shared
(
n
p
.
random
.
normal
(
size
=
(
6
,
7
)))
.
astype
(
config
.
floatX
)
def
inner_fct
(
seq1
,
seq2
,
seq3
,
previous_output
):
temp1
=
T
.
dot
(
seq1
,
W
)
+
seq3
...
...
@@ -384,7 +384,7 @@ class TestPushOutSumOfDot():
dot_output
=
T
.
dot
(
temp1
,
temp2
)
return
previous_output
+
dot_output
init
=
T
.
as_tensor_variable
(
n
umpy
.
random
.
normal
(
size
=
(
3
,
7
)))
init
=
T
.
as_tensor_variable
(
n
p
.
random
.
normal
(
size
=
(
3
,
7
)))
# Compile the function twice, once with the optimization and once
# without
...
...
@@ -410,9 +410,9 @@ class TestPushOutSumOfDot():
# TODO
# Compare the outputs of the 2 functions
input1_value
=
n
umpy
.
random
.
random
((
2
,
3
,
4
))
.
astype
(
config
.
floatX
)
input2_value
=
n
umpy
.
random
.
random
((
2
,
5
,
6
))
.
astype
(
config
.
floatX
)
input3_value
=
n
umpy
.
random
.
random
((
2
,
3
,
5
))
.
astype
(
config
.
floatX
)
input1_value
=
n
p
.
random
.
random
((
2
,
3
,
4
))
.
astype
(
config
.
floatX
)
input2_value
=
n
p
.
random
.
random
((
2
,
5
,
6
))
.
astype
(
config
.
floatX
)
input3_value
=
n
p
.
random
.
random
((
2
,
3
,
5
))
.
astype
(
config
.
floatX
)
output_opt
=
f_opt
(
input1_value
,
input2_value
,
input3_value
)
output_no_opt
=
f_no_opt
(
input1_value
,
input2_value
,
input3_value
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论