Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
0c17002e
提交
0c17002e
authored
6月 27, 2014
作者:
Frederic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
some pep8
上级
eb25bd23
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
31 行增加
和
33 行删除
+31
-33
test_scan.py
theano/scan_module/tests/test_scan.py
+31
-33
没有找到文件。
theano/scan_module/tests/test_scan.py
浏览文件 @
0c17002e
...
@@ -86,7 +86,7 @@ class multiple_outputs_numeric_grad:
...
@@ -86,7 +86,7 @@ class multiple_outputs_numeric_grad:
dtype_eps
=
_eps
dtype_eps
=
_eps
self
.
ndarray_mask
=
ndarray_mask
self
.
ndarray_mask
=
ndarray_mask
#'''
#
'''
# Compute clean output:
# Compute clean output:
f_x
=
f
(
*
pt
)
f_x
=
f
(
*
pt
)
gx
=
[]
gx
=
[]
...
@@ -148,7 +148,7 @@ class multiple_outputs_numeric_grad:
...
@@ -148,7 +148,7 @@ class multiple_outputs_numeric_grad:
return
numpy
.
inf
,
0
return
numpy
.
inf
,
0
#TODO: Test this function, and if it works,
#
TODO: Test this function, and if it works,
# use it with the normal verify_grad rather than the
# use it with the normal verify_grad rather than the
# copy-and-pasted one above.
# copy-and-pasted one above.
# Also - add a reference to this technique in the
# Also - add a reference to this technique in the
...
@@ -201,7 +201,6 @@ def grab_scan_node(output):
...
@@ -201,7 +201,6 @@ def grab_scan_node(output):
class
T_Scan
(
unittest
.
TestCase
):
class
T_Scan
(
unittest
.
TestCase
):
#class T_Scan(object):
def
setUp
(
self
):
def
setUp
(
self
):
utt
.
seed_rng
()
utt
.
seed_rng
()
...
@@ -230,7 +229,7 @@ class T_Scan(unittest.TestCase):
...
@@ -230,7 +229,7 @@ class T_Scan(unittest.TestCase):
updates
=
updates
,
updates
=
updates
,
allow_input_downcast
=
True
)
allow_input_downcast
=
True
)
#
##
TESTING PICKLE-ing this function
# TESTING PICKLE-ing this function
origdir
=
os
.
getcwd
()
origdir
=
os
.
getcwd
()
tmpdir
=
None
tmpdir
=
None
try
:
try
:
...
@@ -367,7 +366,7 @@ class T_Scan(unittest.TestCase):
...
@@ -367,7 +366,7 @@ class T_Scan(unittest.TestCase):
# This first version test the first case in the optimizer to the gpu.
# This first version test the first case in the optimizer to the gpu.
def
test_one_sequence_one_output_weights_gpu1
(
self
):
def
test_one_sequence_one_output_weights_gpu1
(
self
):
from
theano.sandbox
import
cuda
from
theano.sandbox
import
cuda
if
cuda
.
cuda_available
==
Fals
e
:
if
not
cuda
.
cuda_availabl
e
:
raise
SkipTest
(
'Optional package cuda disabled'
)
raise
SkipTest
(
'Optional package cuda disabled'
)
def
f_rnn
(
u_t
,
x_tm1
,
W_in
,
W
):
def
f_rnn
(
u_t
,
x_tm1
,
W_in
,
W
):
...
@@ -447,7 +446,7 @@ class T_Scan(unittest.TestCase):
...
@@ -447,7 +446,7 @@ class T_Scan(unittest.TestCase):
# This second version test the second case in the optimizer to the gpu.
# This second version test the second case in the optimizer to the gpu.
def
test_one_sequence_one_output_weights_gpu2
(
self
):
def
test_one_sequence_one_output_weights_gpu2
(
self
):
from
theano.sandbox
import
cuda
from
theano.sandbox
import
cuda
if
cuda
.
cuda_available
==
Fals
e
:
if
not
cuda
.
cuda_availabl
e
:
raise
SkipTest
(
'Optional package cuda disabled'
)
raise
SkipTest
(
'Optional package cuda disabled'
)
def
f_rnn
(
u_t
,
x_tm1
,
W_in
,
W
):
def
f_rnn
(
u_t
,
x_tm1
,
W_in
,
W
):
...
@@ -511,7 +510,7 @@ class T_Scan(unittest.TestCase):
...
@@ -511,7 +510,7 @@ class T_Scan(unittest.TestCase):
# outputs when is running on GPU
# outputs when is running on GPU
def
test_gpu3_mixture_dtype_outputs
(
self
):
def
test_gpu3_mixture_dtype_outputs
(
self
):
from
theano.sandbox
import
cuda
from
theano.sandbox
import
cuda
if
cuda
.
cuda_available
==
Fals
e
:
if
not
cuda
.
cuda_availabl
e
:
raise
SkipTest
(
'Optional package cuda disabled'
)
raise
SkipTest
(
'Optional package cuda disabled'
)
def
f_rnn
(
u_t
,
x_tm1
,
W_in
,
W
):
def
f_rnn
(
u_t
,
x_tm1
,
W_in
,
W
):
...
@@ -595,8 +594,8 @@ class T_Scan(unittest.TestCase):
...
@@ -595,8 +594,8 @@ class T_Scan(unittest.TestCase):
v_out
=
numpy
.
zeros
((
4
,))
v_out
=
numpy
.
zeros
((
4
,))
v_out
[
0
]
=
v_u
[
0
]
*
W_in
.
get_value
()
+
v_x0
*
W
.
get_value
()
v_out
[
0
]
=
v_u
[
0
]
*
W_in
.
get_value
()
+
v_x0
*
W
.
get_value
()
for
step
in
xrange
(
1
,
4
):
for
step
in
xrange
(
1
,
4
):
v_out
[
step
]
=
v_u
[
step
]
*
W_in
.
get_value
()
+
\
v_out
[
step
]
=
(
v_u
[
step
]
*
W_in
.
get_value
()
+
v_out
[
step
-
1
]
*
W
.
get_value
(
)
v_out
[
step
-
1
]
*
W
.
get_value
()
)
theano_values
=
f3
(
v_u
,
v_x0
)
theano_values
=
f3
(
v_u
,
v_x0
)
assert
numpy
.
allclose
(
theano_values
,
v_out
)
assert
numpy
.
allclose
(
theano_values
,
v_out
)
...
@@ -624,7 +623,7 @@ class T_Scan(unittest.TestCase):
...
@@ -624,7 +623,7 @@ class T_Scan(unittest.TestCase):
y0
=
theano
.
tensor
.
scalar
(
'y0'
)
y0
=
theano
.
tensor
.
scalar
(
'y0'
)
def
f_rnn_cmpl
(
u1_t
,
u2_t
,
x_tm1
,
y_tm1
,
W_in1
):
def
f_rnn_cmpl
(
u1_t
,
u2_t
,
x_tm1
,
y_tm1
,
W_in1
):
return
[
theano
.
dot
(
u1_t
,
W_in1
)
+
u2_t
*
W_in2
+
\
return
[
theano
.
dot
(
u1_t
,
W_in1
)
+
u2_t
*
W_in2
+
theano
.
dot
(
x_tm1
,
W
),
theano
.
dot
(
x_tm1
,
W_out
)]
theano
.
dot
(
x_tm1
,
W
),
theano
.
dot
(
x_tm1
,
W_out
)]
outputs
,
updates
=
theano
.
scan
(
f_rnn_cmpl
,
outputs
,
updates
=
theano
.
scan
(
f_rnn_cmpl
,
...
@@ -643,12 +642,12 @@ class T_Scan(unittest.TestCase):
...
@@ -643,12 +642,12 @@ class T_Scan(unittest.TestCase):
# compute the values in numpy
# compute the values in numpy
v_x
=
numpy
.
zeros
((
3
,
2
),
dtype
=
theano
.
config
.
floatX
)
v_x
=
numpy
.
zeros
((
3
,
2
),
dtype
=
theano
.
config
.
floatX
)
v_y
=
numpy
.
zeros
((
3
,),
dtype
=
theano
.
config
.
floatX
)
v_y
=
numpy
.
zeros
((
3
,),
dtype
=
theano
.
config
.
floatX
)
v_x
[
0
]
=
numpy
.
dot
(
v_u1
[
0
],
vW_in1
)
+
v_u2
[
0
]
*
vW_in2
+
\
v_x
[
0
]
=
(
numpy
.
dot
(
v_u1
[
0
],
vW_in1
)
+
v_u2
[
0
]
*
vW_in2
+
numpy
.
dot
(
v_x0
,
vW
)
numpy
.
dot
(
v_x0
,
vW
)
)
v_y
[
0
]
=
numpy
.
dot
(
v_x0
,
vWout
)
v_y
[
0
]
=
numpy
.
dot
(
v_x0
,
vWout
)
for
i
in
xrange
(
1
,
3
):
for
i
in
xrange
(
1
,
3
):
v_x
[
i
]
=
numpy
.
dot
(
v_u1
[
i
],
vW_in1
)
+
v_u2
[
i
]
*
vW_in2
+
\
v_x
[
i
]
=
(
numpy
.
dot
(
v_u1
[
i
],
vW_in1
)
+
v_u2
[
i
]
*
vW_in2
+
numpy
.
dot
(
v_x
[
i
-
1
],
vW
)
numpy
.
dot
(
v_x
[
i
-
1
],
vW
)
)
v_y
[
i
]
=
numpy
.
dot
(
v_x
[
i
-
1
],
vWout
)
v_y
[
i
]
=
numpy
.
dot
(
v_x
[
i
-
1
],
vWout
)
(
theano_x
,
theano_y
)
=
f4
(
v_u1
,
v_u2
,
v_x0
,
v_y0
,
vW_in1
)
(
theano_x
,
theano_y
)
=
f4
(
v_u1
,
v_u2
,
v_x0
,
v_y0
,
vW_in1
)
...
@@ -684,8 +683,8 @@ class T_Scan(unittest.TestCase):
...
@@ -684,8 +683,8 @@ class T_Scan(unittest.TestCase):
y_tm1
,
y_tm1
,
y_tm3
,
y_tm3
,
W_in1
):
W_in1
):
return
[
theano
.
dot
(
u1_t
,
W_in1
)
+
\
return
[
theano
.
dot
(
u1_t
,
W_in1
)
+
(
u2_t
+
u2_tm1
*
u2_tp1
)
*
W_in2
+
\
(
u2_t
+
u2_tm1
*
u2_tp1
)
*
W_in2
+
theano
.
dot
(
x_tm1
,
W
),
theano
.
dot
(
x_tm1
,
W
),
(
y_tm1
+
y_tm3
)
*
theano
.
dot
(
x_tm1
,
W_out
),
(
y_tm1
+
y_tm3
)
*
theano
.
dot
(
x_tm1
,
W_out
),
theano
.
dot
(
u1_t
,
W_in1
)]
theano
.
dot
(
u1_t
,
W_in1
)]
...
@@ -891,10 +890,10 @@ class T_Scan(unittest.TestCase):
...
@@ -891,10 +890,10 @@ class T_Scan(unittest.TestCase):
numpy_x0
[
0
]
=
vu0
[
0
]
*
vW_in
+
vx0
*
vW
+
vu1
[
0
]
*
vu2
[
0
]
numpy_x0
[
0
]
=
vu0
[
0
]
*
vW_in
+
vx0
*
vW
+
vu1
[
0
]
*
vu2
[
0
]
numpy_x1
[
0
]
=
vu0
[
0
]
*
vW_in
+
vx1
*
vW
+
vu1
[
0
]
+
vu2
[
0
]
numpy_x1
[
0
]
=
vu0
[
0
]
*
vW_in
+
vx1
*
vW
+
vu1
[
0
]
+
vu2
[
0
]
for
i
in
xrange
(
1
,
3
):
for
i
in
xrange
(
1
,
3
):
numpy_x0
[
i
]
=
vu0
[
i
]
*
vW_in
+
numpy_x0
[
i
-
1
]
*
vW
+
\
numpy_x0
[
i
]
=
(
vu0
[
i
]
*
vW_in
+
numpy_x0
[
i
-
1
]
*
vW
+
vu1
[
i
]
*
vu2
[
i
]
vu1
[
i
]
*
vu2
[
i
])
numpy_x1
[
i
]
=
vu0
[
i
]
*
vW_in
+
numpy_x1
[
i
-
1
]
*
vW
+
\
numpy_x1
[
i
]
=
(
vu0
[
i
]
*
vW_in
+
numpy_x1
[
i
-
1
]
*
vW
+
vu1
[
i
]
+
vu2
[
i
]
vu1
[
i
]
+
vu2
[
i
])
# note theano computes inplace, so call function after numpy
# note theano computes inplace, so call function after numpy
# equivalent is done
# equivalent is done
...
@@ -908,8 +907,8 @@ class T_Scan(unittest.TestCase):
...
@@ -908,8 +907,8 @@ class T_Scan(unittest.TestCase):
# Old way of doing inplace operations is deprecated .. tests don't
# Old way of doing inplace operations is deprecated .. tests don't
# make sense anymore.
# make sense anymore.
##
utt.assert_allclose(
theano_x0 , vu2)
##
utt.assert_allclose(
theano_x0 , vu2)
## utt.assert_allclose(
theano_x1 , vu1)
## utt.assert_allclose(theano_x1 , vu1)
# simple rnn ; compute inplace version 2
# simple rnn ; compute inplace version 2
def
test_inplace2
(
self
):
def
test_inplace2
(
self
):
...
@@ -971,10 +970,10 @@ class T_Scan(unittest.TestCase):
...
@@ -971,10 +970,10 @@ class T_Scan(unittest.TestCase):
numpy_x0
[
0
]
=
vu0
[
0
]
*
vW_in
+
vx0
*
vW
+
vu1
[
0
]
*
vu1
[
1
]
numpy_x0
[
0
]
=
vu0
[
0
]
*
vW_in
+
vx0
*
vW
+
vu1
[
0
]
*
vu1
[
1
]
numpy_x1
[
0
]
=
vu0
[
0
]
*
vW_in
+
vx1
*
vW
+
vu2
[
0
]
+
vu2
[
1
]
+
vu2
[
2
]
numpy_x1
[
0
]
=
vu0
[
0
]
*
vW_in
+
vx1
*
vW
+
vu2
[
0
]
+
vu2
[
1
]
+
vu2
[
2
]
for
i
in
xrange
(
1
,
3
):
for
i
in
xrange
(
1
,
3
):
numpy_x0
[
i
]
=
vu0
[
i
]
*
vW_in
+
numpy_x0
[
i
-
1
]
*
vW
+
\
numpy_x0
[
i
]
=
(
vu0
[
i
]
*
vW_in
+
numpy_x0
[
i
-
1
]
*
vW
+
vu1
[
i
]
*
vu1
[
i
+
1
]
vu1
[
i
]
*
vu1
[
i
+
1
])
numpy_x1
[
i
]
=
vu0
[
i
]
*
vW_in
+
numpy_x1
[
i
-
1
]
*
vW
+
\
numpy_x1
[
i
]
=
(
vu0
[
i
]
*
vW_in
+
numpy_x1
[
i
-
1
]
*
vW
+
vu2
[
i
]
+
vu2
[
i
+
1
]
+
vu2
[
i
+
2
]
vu2
[
i
]
+
vu2
[
i
+
1
]
+
vu2
[
i
+
2
])
# note theano computes inplace, so call function after numpy
# note theano computes inplace, so call function after numpy
# equivalent is done
# equivalent is done
...
@@ -1069,8 +1068,8 @@ class T_Scan(unittest.TestCase):
...
@@ -1069,8 +1068,8 @@ class T_Scan(unittest.TestCase):
y1
=
theano
.
shared
(
vy1
,
'y1'
)
y1
=
theano
.
shared
(
vy1
,
'y1'
)
def
f
(
u1_t
,
u2_t
,
y0_tm3
,
y0_tm2
,
y0_tm1
,
y1_tm1
):
def
f
(
u1_t
,
u2_t
,
y0_tm3
,
y0_tm2
,
y0_tm1
,
y1_tm1
):
y0_t
=
theano
.
dot
(
theano
.
dot
(
u1_t
,
W1
),
W2
)
+
0.1
*
y0_tm1
+
\
y0_t
=
(
theano
.
dot
(
theano
.
dot
(
u1_t
,
W1
),
W2
)
+
0.1
*
y0_tm1
+
0.33
*
y0_tm2
+
0.17
*
y0_tm3
0.33
*
y0_tm2
+
0.17
*
y0_tm3
)
y1_t
=
theano
.
dot
(
u2_t
,
W2
)
+
y1_tm1
y1_t
=
theano
.
dot
(
u2_t
,
W2
)
+
y1_tm1
y2_t
=
theano
.
dot
(
u1_t
,
W1
)
y2_t
=
theano
.
dot
(
u1_t
,
W1
)
nwW1
=
W1
+
.
1
nwW1
=
W1
+
.
1
...
@@ -1106,14 +1105,13 @@ class T_Scan(unittest.TestCase):
...
@@ -1106,14 +1105,13 @@ class T_Scan(unittest.TestCase):
numpy_W1
=
vW1
.
copy
()
numpy_W1
=
vW1
.
copy
()
numpy_W2
=
vW2
.
copy
()
numpy_W2
=
vW2
.
copy
()
for
idx
in
xrange
(
3
):
for
idx
in
xrange
(
3
):
numpy_y0
[
idx
+
3
]
=
numpy
.
dot
(
\
numpy_y0
[
idx
+
3
]
=
numpy
.
dot
(
numpy
.
dot
(
vu1
[
idx
,
:],
numpy_W1
),
numpy
.
dot
(
vu1
[
idx
,
:],
numpy_W1
),
\
numpy_W2
)
+
\
numpy_W2
)
+
\
0.1
*
numpy_y0
[
idx
+
2
]
+
\
0.1
*
numpy_y0
[
idx
+
2
]
+
\
0.33
*
numpy_y0
[
idx
+
1
]
+
\
0.33
*
numpy_y0
[
idx
+
1
]
+
\
0.17
*
numpy_y0
[
idx
]
0.17
*
numpy_y0
[
idx
]
numpy_y1
[
idx
+
1
]
=
numpy
.
dot
(
vu2
[
idx
,
:],
numpy_W2
)
+
\
numpy_y1
[
idx
+
1
]
=
(
numpy
.
dot
(
vu2
[
idx
,
:],
numpy_W2
)
+
numpy_y1
[
idx
]
numpy_y1
[
idx
])
numpy_y2
[
idx
]
=
numpy
.
dot
(
vu1
[
idx
,
:],
numpy_W1
)
numpy_y2
[
idx
]
=
numpy
.
dot
(
vu1
[
idx
,
:],
numpy_W1
)
numpy_W1
=
numpy_W1
+
.
1
numpy_W1
=
numpy_W1
+
.
1
numpy_W2
=
numpy_W2
+
.
05
numpy_W2
=
numpy_W2
+
.
05
...
@@ -1196,7 +1194,7 @@ class T_Scan(unittest.TestCase):
...
@@ -1196,7 +1194,7 @@ class T_Scan(unittest.TestCase):
def
test_cuda_gibbs_chain
(
self
):
def
test_cuda_gibbs_chain
(
self
):
from
theano.sandbox
import
cuda
from
theano.sandbox
import
cuda
if
cuda
.
cuda_available
==
Fals
e
:
if
not
cuda
.
cuda_availabl
e
:
raise
SkipTest
(
'Optional package cuda disabled'
)
raise
SkipTest
(
'Optional package cuda disabled'
)
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论