Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
5b0f5ac7
提交
5b0f5ac7
authored
4月 22, 2010
作者:
Frederic Bastien
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
make scan tests work with float32 to allow to test it with the gpu too.
上级
cc3fe3ca
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
82 行增加
和
72 行删除
+82
-72
test_scan.py
theano/tests/test_scan.py
+82
-72
没有找到文件。
theano/tests/test_scan.py
浏览文件 @
5b0f5ac7
...
...
@@ -86,6 +86,8 @@ def scan_project_sum(*args, **kwargs):
rng
.
add_default_updates
=
False
return
sum
([(
s
*
rng
.
uniform
(
size
=
s
.
shape
))
.
sum
()
for
s
in
scan_outputs
])
def
asarrayX
(
value
):
return
theano
.
_asarray
(
value
,
dtype
=
theano
.
config
.
floatX
)
class
T_Scan
(
unittest
.
TestCase
):
...
...
@@ -98,8 +100,8 @@ class T_Scan(unittest.TestCase):
def
f_pow2
(
x_tm1
):
return
2
*
x_tm1
state
=
theano
.
tensor
.
d
scalar
()
n_steps
=
theano
.
tensor
.
d
scalar
()
state
=
theano
.
tensor
.
scalar
()
n_steps
=
theano
.
tensor
.
scalar
()
output
,
updates
=
theano
.
scan
(
f_pow2
,
[],
state
,
[],
n_steps
=
n_steps
,
truncate_gradient
=
-
1
,
go_backwards
=
False
)
my_f
=
theano
.
function
([
state
,
n_steps
],
output
,
updates
=
updates
)
...
...
@@ -120,10 +122,10 @@ class T_Scan(unittest.TestCase):
def
f_rnn
(
u_t
,
x_tm1
,
W_in
,
W
):
return
u_t
*
W_in
+
x_tm1
*
W
u
=
theano
.
tensor
.
d
vector
()
x0
=
theano
.
tensor
.
d
scalar
()
W_in
=
theano
.
tensor
.
d
scalar
()
W
=
theano
.
tensor
.
d
scalar
()
u
=
theano
.
tensor
.
vector
()
x0
=
theano
.
tensor
.
scalar
()
W_in
=
theano
.
tensor
.
scalar
()
W
=
theano
.
tensor
.
scalar
()
output
,
updates
=
theano
.
scan
(
f_rnn
,
u
,
x0
,[
W_in
,
W
],
n_steps
=
None
,
truncate_gradient
=
-
1
,
go_backwards
=
False
)
...
...
@@ -150,10 +152,10 @@ class T_Scan(unittest.TestCase):
# are vectors, weights are scalars; using shared variables
def
test_one_sequence_one_output_weights_shared
(
self
):
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
u
=
theano
.
tensor
.
d
vector
()
x0
=
theano
.
tensor
.
d
scalar
()
W_in
=
theano
.
shared
(
rng
.
uniform
(
),
name
=
'w_in'
)
W
=
theano
.
shared
(
rng
.
uniform
(
),
name
=
'w'
)
u
=
theano
.
tensor
.
vector
()
x0
=
theano
.
tensor
.
scalar
()
W_in
=
theano
.
shared
(
asarrayX
(
rng
.
uniform
()
),
name
=
'w_in'
)
W
=
theano
.
shared
(
asarrayX
(
rng
.
uniform
()
),
name
=
'w'
)
def
f_rnn_shared
(
u_t
,
x_tm1
,
tmp_W_in
,
tmp_W
):
return
u_t
*
tmp_W_in
+
x_tm1
*
tmp_W
...
...
@@ -179,23 +181,23 @@ class T_Scan(unittest.TestCase):
# dimension instead of scalars/vectors
def
test_multiple_inputs_multiple_outputs
(
self
):
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
vW_in2
=
rng
.
uniform
(
size
=
(
2
,),
low
=
-
5.
,
high
=
5.
)
vW
=
rng
.
uniform
(
size
=
(
2
,
2
),
low
=
-
5.
,
high
=
5.
)
vWout
=
rng
.
uniform
(
size
=
(
2
,),
low
=
-
5.
,
high
=
5.
)
vW_in1
=
rng
.
uniform
(
size
=
(
2
,
2
),
low
=
-
5.
,
high
=
5.
)
v_u1
=
rng
.
uniform
(
size
=
(
3
,
2
),
low
=
-
5.
,
high
=
5.
)
v_u2
=
rng
.
uniform
(
size
=
(
3
,),
low
=
-
5.
,
high
=
5.
)
v_x0
=
rng
.
uniform
(
size
=
(
2
,),
low
=
-
5.
,
high
=
5.
)
v_y0
=
rng
.
uniform
(
)
vW_in2
=
asarrayX
(
rng
.
uniform
(
size
=
(
2
,),
low
=
-
5.
,
high
=
5.
)
)
vW
=
asarrayX
(
rng
.
uniform
(
size
=
(
2
,
2
),
low
=
-
5.
,
high
=
5.
)
)
vWout
=
asarrayX
(
rng
.
uniform
(
size
=
(
2
,),
low
=
-
5.
,
high
=
5.
)
)
vW_in1
=
asarrayX
(
rng
.
uniform
(
size
=
(
2
,
2
),
low
=
-
5.
,
high
=
5.
)
)
v_u1
=
asarrayX
(
rng
.
uniform
(
size
=
(
3
,
2
),
low
=
-
5.
,
high
=
5.
)
)
v_u2
=
asarrayX
(
rng
.
uniform
(
size
=
(
3
,),
low
=
-
5.
,
high
=
5.
)
)
v_x0
=
asarrayX
(
rng
.
uniform
(
size
=
(
2
,),
low
=
-
5.
,
high
=
5.
)
)
v_y0
=
asarrayX
(
rng
.
uniform
()
)
W_in2
=
theano
.
shared
(
vW_in2
,
name
=
'win2'
)
W
=
theano
.
shared
(
vW
,
name
=
'w'
)
W_out
=
theano
.
shared
(
vWout
,
name
=
'wout'
)
W_in1
=
theano
.
tensor
.
d
matrix
(
'win'
)
u1
=
theano
.
tensor
.
d
matrix
(
'u1'
)
u2
=
theano
.
tensor
.
d
vector
(
'u2'
)
x0
=
theano
.
tensor
.
d
vector
(
'x0'
)
y0
=
theano
.
tensor
.
d
scalar
(
'y0'
)
W_in1
=
theano
.
tensor
.
matrix
(
'win'
)
u1
=
theano
.
tensor
.
matrix
(
'u1'
)
u2
=
theano
.
tensor
.
vector
(
'u2'
)
x0
=
theano
.
tensor
.
vector
(
'x0'
)
y0
=
theano
.
tensor
.
scalar
(
'y0'
)
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
+
\
...
...
@@ -206,8 +208,8 @@ class T_Scan(unittest.TestCase):
f4
=
theano
.
function
([
u1
,
u2
,
x0
,
y0
,
W_in1
],
outputs
,
updates
=
updates
)
# compute the values in numpy
v_x
=
numpy
.
zeros
((
3
,
2
))
v_y
=
numpy
.
zeros
((
3
,))
v_x
=
numpy
.
zeros
((
3
,
2
)
,
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
+
numpy
.
dot
(
v_x0
,
vW
)
v_y
[
0
]
=
numpy
.
dot
(
v_x0
,
vWout
)
for
i
in
xrange
(
1
,
3
):
...
...
@@ -225,13 +227,13 @@ class T_Scan(unittest.TestCase):
# taps (sequences and outputs)
def
test_using_taps_input_output
(
self
):
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
vW
=
rng
.
uniform
(
)
vW_in
=
rng
.
uniform
(
)
vu
=
rng
.
uniform
(
size
=
(
4
,),
low
=
-
5.
,
high
=
5.
)
vx0
=
rng
.
uniform
(
size
=
(
2
,),
low
=
-
5.
,
high
=
5.
)
vW
=
asarrayX
(
rng
.
uniform
()
)
vW_in
=
asarrayX
(
rng
.
uniform
()
)
vu
=
asarrayX
(
rng
.
uniform
(
size
=
(
4
,),
low
=
-
5.
,
high
=
5.
)
)
vx0
=
asarrayX
(
rng
.
uniform
(
size
=
(
2
,),
low
=
-
5.
,
high
=
5.
)
)
u
=
theano
.
tensor
.
d
vector
()
x0
=
theano
.
tensor
.
d
vector
()
u
=
theano
.
tensor
.
vector
()
x0
=
theano
.
tensor
.
vector
()
W_in
=
theano
.
shared
(
vW_in
,
name
=
'w_in'
)
W
=
theano
.
shared
(
vW
,
name
=
'w'
)
...
...
@@ -265,13 +267,13 @@ class T_Scan(unittest.TestCase):
# taps (sequences and outputs) and future taps for sequences
def
test_past_future_taps_shared
(
self
):
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
vW
=
rng
.
uniform
(
)
vW_in
=
rng
.
uniform
(
)
vu
=
rng
.
uniform
(
size
=
(
6
,),
low
=
-
5.
,
high
=
5.
)
vx0
=
rng
.
uniform
(
size
=
(
2
,),
low
=
-
5.
,
high
=
5.
)
vW
=
asarrayX
(
rng
.
uniform
()
)
vW_in
=
asarrayX
(
rng
.
uniform
()
)
vu
=
asarrayX
(
rng
.
uniform
(
size
=
(
6
,),
low
=
-
5.
,
high
=
5.
)
)
vx0
=
asarrayX
(
rng
.
uniform
(
size
=
(
2
,),
low
=
-
5.
,
high
=
5.
)
)
u
=
theano
.
tensor
.
d
vector
()
x0
=
theano
.
tensor
.
d
vector
()
u
=
theano
.
tensor
.
vector
()
x0
=
theano
.
tensor
.
vector
()
W_in
=
theano
.
shared
(
vW_in
,
name
=
'w_in'
)
W
=
theano
.
shared
(
vW
,
name
=
'w'
)
...
...
@@ -297,22 +299,22 @@ class T_Scan(unittest.TestCase):
# simple rnn ; compute inplace version 1
def
test_inplace1
(
self
):
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
vW
=
numpy
.
random
.
uniform
(
)
vW_in
=
numpy
.
random
.
uniform
(
)
vu0
=
rng
.
uniform
(
size
=
(
3
,),
low
=
-
5.
,
high
=
5.
)
vu1
=
rng
.
uniform
(
size
=
(
3
,),
low
=
-
5.
,
high
=
5.
)
vu2
=
rng
.
uniform
(
size
=
(
3
,),
low
=
-
5.
,
high
=
5.
)
vx0
=
rng
.
uniform
(
)
vx1
=
rng
.
uniform
(
)
u0
=
theano
.
tensor
.
d
vector
(
'u0'
)
u1
=
theano
.
tensor
.
d
vector
(
'u1'
)
u2
=
theano
.
tensor
.
d
vector
(
'u2'
)
vW
=
asarrayX
(
numpy
.
random
.
uniform
()
)
vW_in
=
asarrayX
(
numpy
.
random
.
uniform
()
)
vu0
=
asarrayX
(
rng
.
uniform
(
size
=
(
3
,),
low
=
-
5.
,
high
=
5.
)
)
vu1
=
asarrayX
(
rng
.
uniform
(
size
=
(
3
,),
low
=
-
5.
,
high
=
5.
)
)
vu2
=
asarrayX
(
rng
.
uniform
(
size
=
(
3
,),
low
=
-
5.
,
high
=
5.
)
)
vx0
=
asarrayX
(
rng
.
uniform
()
)
vx1
=
asarrayX
(
rng
.
uniform
()
)
u0
=
theano
.
tensor
.
vector
(
'u0'
)
u1
=
theano
.
tensor
.
vector
(
'u1'
)
u2
=
theano
.
tensor
.
vector
(
'u2'
)
mu0
=
theano
.
Param
(
u0
,
mutable
=
False
)
mu1
=
theano
.
Param
(
u1
,
mutable
=
True
)
mu2
=
theano
.
Param
(
u2
,
mutable
=
True
)
x0
=
theano
.
tensor
.
d
scalar
(
'x0'
)
x1
=
theano
.
tensor
.
d
scalar
(
'y0'
)
x0
=
theano
.
tensor
.
scalar
(
'x0'
)
x1
=
theano
.
tensor
.
scalar
(
'y0'
)
W_in
=
theano
.
shared
(
vW_in
,
'Win'
)
W
=
theano
.
shared
(
vW
,
'W'
)
mode
=
theano
.
compile
.
mode
.
get_mode
(
None
)
.
including
(
'inplace'
)
...
...
@@ -345,22 +347,22 @@ class T_Scan(unittest.TestCase):
# simple rnn ; compute inplace version 2
def
test_inplace2
(
self
):
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
vW
=
numpy
.
random
.
uniform
(
)
vW_in
=
numpy
.
random
.
uniform
(
)
vu0
=
rng
.
uniform
(
size
=
(
3
,),
low
=
-
5.
,
high
=
5.
)
vu1
=
rng
.
uniform
(
size
=
(
4
,),
low
=
-
5.
,
high
=
5.
)
vu2
=
rng
.
uniform
(
size
=
(
5
,),
low
=
-
5.
,
high
=
5.
)
vx0
=
rng
.
uniform
(
)
vx1
=
rng
.
uniform
(
)
u0
=
theano
.
tensor
.
d
vector
(
'u0'
)
u1
=
theano
.
tensor
.
d
vector
(
'u1'
)
u2
=
theano
.
tensor
.
d
vector
(
'u2'
)
vW
=
asarrayX
(
numpy
.
random
.
uniform
()
)
vW_in
=
asarrayX
(
numpy
.
random
.
uniform
()
)
vu0
=
asarrayX
(
rng
.
uniform
(
size
=
(
3
,),
low
=
-
5.
,
high
=
5.
)
)
vu1
=
asarrayX
(
rng
.
uniform
(
size
=
(
4
,),
low
=
-
5.
,
high
=
5.
)
)
vu2
=
asarrayX
(
rng
.
uniform
(
size
=
(
5
,),
low
=
-
5.
,
high
=
5.
)
)
vx0
=
asarrayX
(
rng
.
uniform
()
)
vx1
=
asarrayX
(
rng
.
uniform
()
)
u0
=
theano
.
tensor
.
vector
(
'u0'
)
u1
=
theano
.
tensor
.
vector
(
'u1'
)
u2
=
theano
.
tensor
.
vector
(
'u2'
)
mu0
=
theano
.
Param
(
u0
,
mutable
=
True
)
mu1
=
theano
.
Param
(
u1
,
mutable
=
True
)
mu2
=
theano
.
Param
(
u2
,
mutable
=
True
)
x0
=
theano
.
tensor
.
d
scalar
(
'x0'
)
x1
=
theano
.
tensor
.
d
scalar
(
'y0'
)
x0
=
theano
.
tensor
.
scalar
(
'x0'
)
x1
=
theano
.
tensor
.
scalar
(
'y0'
)
W_in
=
theano
.
shared
(
vW_in
,
'Win'
)
W
=
theano
.
shared
(
vW
,
'W'
)
mode
=
theano
.
compile
.
mode
.
get_mode
(
None
)
.
including
(
'inplace'
)
...
...
@@ -400,13 +402,21 @@ class T_Scan(unittest.TestCase):
def
test_shared_arguments_with_updates
(
self
):
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
vW1
=
asarrayX
(
rng
.
rand
(
20
,
30
))
vW2
=
asarrayX
(
rng
.
rand
(
30
,
20
))
vu1
=
asarrayX
(
rng
.
rand
(
3
,
20
))
vu2
=
asarrayX
(
rng
.
rand
(
3
,
30
))
vy0
=
asarrayX
(
rng
.
rand
(
3
,
20
))
vy1
=
asarrayX
(
rng
.
rand
(
20
))
vy2
=
asarrayX
(
rng
.
rand
(
30
))
import
pdb
;
pdb
.
set_trace
()
#TODO
vW1
=
rng
.
rand
(
20
,
30
)
vW2
=
rng
.
rand
(
30
,
20
)
vu1
=
rng
.
rand
(
3
,
20
)
vu2
=
rng
.
rand
(
3
,
30
)
vy0
=
rng
.
rand
(
3
,
20
)
vy1
=
rng
.
rand
(
20
)
vy2
=
rng
.
rand
(
30
)
vy1
=
rng
.
rand
(
20
)
vy2
=
rng
.
rand
(
30
)
W1
=
theano
.
shared
(
vW1
,
'W1'
)
W2
=
theano
.
shared
(
vW2
,
'W2'
)
u1
=
theano
.
shared
(
vu1
,
'u1'
)
...
...
@@ -523,11 +533,11 @@ class T_Scan(unittest.TestCase):
def
test_only_shared_no_input_no_output
(
self
):
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
v_state
=
rng
.
uniform
(
)
v_state
=
asarrayX
(
rng
.
uniform
()
)
state
=
theano
.
shared
(
v_state
)
def
f_2
():
return
{
state
:
2
*
state
}
n_steps
=
theano
.
tensor
.
d
scalar
()
n_steps
=
theano
.
tensor
.
scalar
()
output
,
updates
=
theano
.
scan
(
f_2
,[],[],[],
n_steps
=
n_steps
,
truncate_gradient
=
-
1
,
go_backwards
=
False
)
this_f
=
theano
.
function
([
n_steps
],
output
,
updates
=
updates
)
...
...
@@ -540,7 +550,7 @@ class T_Scan(unittest.TestCase):
def
f_rnn
(
u_t
):
return
u_t
+
3
u
=
theano
.
tensor
.
d
vector
()
u
=
theano
.
tensor
.
vector
()
outputs
,
updates
=
theano
.
scan
(
f_rnn
,
u
,[],[],
n_steps
=
None
,
truncate_gradient
=
-
1
,
go_backwards
=
False
)
...
...
@@ -570,10 +580,10 @@ class T_Scan(unittest.TestCase):
def
f_rnn
(
u_t
,
x_tm1
,
W_in
,
W
):
return
u_t
*
W_in
+
x_tm1
*
W
u
=
theano
.
tensor
.
d
vector
()
x0
=
theano
.
tensor
.
d
scalar
()
W_in
=
theano
.
tensor
.
d
scalar
()
W
=
theano
.
tensor
.
d
scalar
()
u
=
theano
.
tensor
.
vector
()
x0
=
theano
.
tensor
.
scalar
()
W_in
=
theano
.
tensor
.
scalar
()
W
=
theano
.
tensor
.
scalar
()
output
,
updates
=
theano
.
scan
(
f_rnn
,
u
,
x0
,[
W_in
,
W
],
n_steps
=
None
,
truncate_gradient
=
-
1
,
go_backwards
=
True
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论