Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
b90ec1d2
提交
b90ec1d2
authored
2月 05, 2010
作者:
Pascal Lamblin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use utt.fetch_seed() instead of a fixed seed in test_randomstreams
上级
d5701303
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
29 行增加
和
25 行删除
+29
-25
test_randomstreams.py
theano/tensor/tests/test_randomstreams.py
+29
-25
没有找到文件。
theano/tensor/tests/test_randomstreams.py
浏览文件 @
b90ec1d2
...
@@ -6,16 +6,19 @@ import numpy
...
@@ -6,16 +6,19 @@ import numpy
from
theano.tensor.randomstreams
import
RandomStreams
,
raw_random
from
theano.tensor.randomstreams
import
RandomStreams
,
raw_random
from
theano.compile
import
Module
,
Method
,
Member
from
theano.compile
import
Module
,
Method
,
Member
from
theano.tests
import
unittest_tools
from
theano.tests
import
unittest_tools
as
utt
from
theano
import
tensor
from
theano
import
tensor
from
theano
import
compile
,
gof
from
theano
import
compile
,
gof
class
T_RandomStreams
(
unittest
.
TestCase
):
class
T_RandomStreams
(
unittest
.
TestCase
):
def
setUp
(
self
):
utt
.
seed_rng
()
def
test_basics
(
self
):
def
test_basics
(
self
):
m
=
Module
()
m
=
Module
()
m
.
random
=
RandomStreams
(
234
)
m
.
random
=
RandomStreams
(
utt
.
fetch_seed
()
)
m
.
fn
=
Method
([],
m
.
random
.
uniform
((
2
,
2
)))
m
.
fn
=
Method
([],
m
.
random
.
uniform
((
2
,
2
)))
m
.
gn
=
Method
([],
m
.
random
.
normal
((
2
,
2
)))
m
.
gn
=
Method
([],
m
.
random
.
normal
((
2
,
2
)))
made
=
m
.
make
()
made
=
m
.
make
()
...
@@ -26,7 +29,7 @@ class T_RandomStreams(unittest.TestCase):
...
@@ -26,7 +29,7 @@ class T_RandomStreams(unittest.TestCase):
gn_val0
=
made
.
gn
()
gn_val0
=
made
.
gn
()
rng_seed
=
numpy
.
random
.
RandomState
(
234
)
.
randint
(
2
**
30
)
rng_seed
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
()
)
.
randint
(
2
**
30
)
rng
=
numpy
.
random
.
RandomState
(
int
(
rng_seed
))
#int() is for 32bit
rng
=
numpy
.
random
.
RandomState
(
int
(
rng_seed
))
#int() is for 32bit
#print fn_val0
#print fn_val0
...
@@ -42,12 +45,12 @@ class T_RandomStreams(unittest.TestCase):
...
@@ -42,12 +45,12 @@ class T_RandomStreams(unittest.TestCase):
m
.
random
=
RandomStreams
(
234
)
m
.
random
=
RandomStreams
(
234
)
m
.
fn
=
Method
([],
m
.
random
.
uniform
((
2
,
2
)))
m
.
fn
=
Method
([],
m
.
random
.
uniform
((
2
,
2
)))
made
=
m
.
make
()
made
=
m
.
make
()
made
.
random
.
initialize
(
seed
=
888
)
made
.
random
.
initialize
(
seed
=
utt
.
fetch_seed
()
)
fn_val0
=
made
.
fn
()
fn_val0
=
made
.
fn
()
fn_val1
=
made
.
fn
()
fn_val1
=
made
.
fn
()
rng_seed
=
numpy
.
random
.
RandomState
(
888
)
.
randint
(
2
**
30
)
rng_seed
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
()
)
.
randint
(
2
**
30
)
rng
=
numpy
.
random
.
RandomState
(
int
(
rng_seed
))
#int() is for 32bit
rng
=
numpy
.
random
.
RandomState
(
int
(
rng_seed
))
#int() is for 32bit
#print fn_val0
#print fn_val0
...
@@ -65,12 +68,12 @@ class T_RandomStreams(unittest.TestCase):
...
@@ -65,12 +68,12 @@ class T_RandomStreams(unittest.TestCase):
made
=
m
.
make
()
made
=
m
.
make
()
made
.
random
.
initialize
(
seed
=
789
)
made
.
random
.
initialize
(
seed
=
789
)
made
.
random
.
seed
(
888
)
made
.
random
.
seed
(
utt
.
fetch_seed
()
)
fn_val0
=
made
.
fn
()
fn_val0
=
made
.
fn
()
fn_val1
=
made
.
fn
()
fn_val1
=
made
.
fn
()
rng_seed
=
numpy
.
random
.
RandomState
(
888
)
.
randint
(
2
**
30
)
rng_seed
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
()
)
.
randint
(
2
**
30
)
rng
=
numpy
.
random
.
RandomState
(
int
(
rng_seed
))
#int() is for 32bit
rng
=
numpy
.
random
.
RandomState
(
int
(
rng_seed
))
#int() is for 32bit
#print fn_val0
#print fn_val0
...
@@ -90,7 +93,7 @@ class T_RandomStreams(unittest.TestCase):
...
@@ -90,7 +93,7 @@ class T_RandomStreams(unittest.TestCase):
made
=
m
.
make
()
made
=
m
.
make
()
made
.
random
.
initialize
(
seed
=
789
)
made
.
random
.
initialize
(
seed
=
789
)
made
.
random
.
seed
(
888
)
made
.
random
.
seed
(
utt
.
fetch_seed
()
)
rng
=
numpy
.
random
.
RandomState
()
rng
=
numpy
.
random
.
RandomState
()
rng
.
set_state
(
made
.
random
[
out
.
rng
]
.
get_state
())
rng
.
set_state
(
made
.
random
[
out
.
rng
]
.
get_state
())
...
@@ -115,7 +118,7 @@ class T_RandomStreams(unittest.TestCase):
...
@@ -115,7 +118,7 @@ class T_RandomStreams(unittest.TestCase):
made
.
random
.
seed
(
888
)
made
.
random
.
seed
(
888
)
# then replace the rng of the stream we care about via setitem
# then replace the rng of the stream we care about via setitem
realseed
=
823874
realseed
=
utt
.
fetch_seed
()
rng
=
numpy
.
random
.
RandomState
(
realseed
)
rng
=
numpy
.
random
.
RandomState
(
realseed
)
made
.
random
[
out
.
rng
]
=
numpy
.
random
.
RandomState
(
realseed
)
made
.
random
[
out
.
rng
]
=
numpy
.
random
.
RandomState
(
realseed
)
...
@@ -131,7 +134,7 @@ class T_RandomStreams(unittest.TestCase):
...
@@ -131,7 +134,7 @@ class T_RandomStreams(unittest.TestCase):
def
test_multiple
(
self
):
def
test_multiple
(
self
):
M
=
Module
()
M
=
Module
()
M
.
random
=
RandomStreams
(
234
)
M
.
random
=
RandomStreams
(
utt
.
fetch_seed
()
)
out
=
M
.
random
.
uniform
((
2
,
2
))
out
=
M
.
random
.
uniform
((
2
,
2
))
M
.
m2
=
Module
()
M
.
m2
=
Module
()
M
.
m2
.
random
=
M
.
random
M
.
m2
.
random
=
M
.
random
...
@@ -176,7 +179,7 @@ class T_RandomStreams(unittest.TestCase):
...
@@ -176,7 +179,7 @@ class T_RandomStreams(unittest.TestCase):
"""Test that RandomStreams.uniform generates the same results as numpy"""
"""Test that RandomStreams.uniform generates the same results as numpy"""
# Check over two calls to see if the random state is correctly updated.
# Check over two calls to see if the random state is correctly updated.
m
=
Module
()
m
=
Module
()
m
.
random
=
RandomStreams
(
234
)
m
.
random
=
RandomStreams
(
utt
.
fetch_seed
()
)
m
.
fn
=
Method
([],
m
.
random
.
uniform
((
2
,
2
),
-
1
,
1
))
m
.
fn
=
Method
([],
m
.
random
.
uniform
((
2
,
2
),
-
1
,
1
))
made
=
m
.
make
()
made
=
m
.
make
()
...
@@ -186,7 +189,7 @@ class T_RandomStreams(unittest.TestCase):
...
@@ -186,7 +189,7 @@ class T_RandomStreams(unittest.TestCase):
print
fn_val0
print
fn_val0
print
fn_val1
print
fn_val1
rng_seed
=
numpy
.
random
.
RandomState
(
234
)
.
randint
(
2
**
30
)
rng_seed
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
()
)
.
randint
(
2
**
30
)
rng
=
numpy
.
random
.
RandomState
(
int
(
rng_seed
))
#int() is for 32bit
rng
=
numpy
.
random
.
RandomState
(
int
(
rng_seed
))
#int() is for 32bit
numpy_val0
=
rng
.
uniform
(
-
1
,
1
,
size
=
(
2
,
2
))
numpy_val0
=
rng
.
uniform
(
-
1
,
1
,
size
=
(
2
,
2
))
...
@@ -201,7 +204,7 @@ class T_RandomStreams(unittest.TestCase):
...
@@ -201,7 +204,7 @@ class T_RandomStreams(unittest.TestCase):
"""Test that RandomStreams.normal generates the same results as numpy"""
"""Test that RandomStreams.normal generates the same results as numpy"""
# Check over two calls to see if the random state is correctly updated.
# Check over two calls to see if the random state is correctly updated.
m
=
Module
()
m
=
Module
()
m
.
random
=
RandomStreams
(
234
)
m
.
random
=
RandomStreams
(
utt
.
fetch_seed
()
)
m
.
fn
=
Method
([],
m
.
random
.
normal
((
2
,
2
),
-
1
,
2
))
m
.
fn
=
Method
([],
m
.
random
.
normal
((
2
,
2
),
-
1
,
2
))
made
=
m
.
make
()
made
=
m
.
make
()
...
@@ -209,7 +212,7 @@ class T_RandomStreams(unittest.TestCase):
...
@@ -209,7 +212,7 @@ class T_RandomStreams(unittest.TestCase):
fn_val0
=
made
.
fn
()
fn_val0
=
made
.
fn
()
fn_val1
=
made
.
fn
()
fn_val1
=
made
.
fn
()
rng_seed
=
numpy
.
random
.
RandomState
(
234
)
.
randint
(
2
**
30
)
rng_seed
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
()
)
.
randint
(
2
**
30
)
rng
=
numpy
.
random
.
RandomState
(
int
(
rng_seed
))
#int() is for 32bit
rng
=
numpy
.
random
.
RandomState
(
int
(
rng_seed
))
#int() is for 32bit
numpy_val0
=
rng
.
normal
(
-
1
,
2
,
size
=
(
2
,
2
))
numpy_val0
=
rng
.
normal
(
-
1
,
2
,
size
=
(
2
,
2
))
numpy_val1
=
rng
.
normal
(
-
1
,
2
,
size
=
(
2
,
2
))
numpy_val1
=
rng
.
normal
(
-
1
,
2
,
size
=
(
2
,
2
))
...
@@ -221,7 +224,7 @@ class T_RandomStreams(unittest.TestCase):
...
@@ -221,7 +224,7 @@ class T_RandomStreams(unittest.TestCase):
"""Test that RandomStreams.random_integers generates the same results as numpy"""
"""Test that RandomStreams.random_integers generates the same results as numpy"""
# Check over two calls to see if the random state is correctly updated.
# Check over two calls to see if the random state is correctly updated.
m
=
Module
()
m
=
Module
()
m
.
random
=
RandomStreams
(
234
)
m
.
random
=
RandomStreams
(
utt
.
fetch_seed
()
)
m
.
fn
=
Method
([],
m
.
random
.
random_integers
((
20
,
20
),
-
5
,
5
))
m
.
fn
=
Method
([],
m
.
random
.
random_integers
((
20
,
20
),
-
5
,
5
))
made
=
m
.
make
()
made
=
m
.
make
()
...
@@ -229,7 +232,7 @@ class T_RandomStreams(unittest.TestCase):
...
@@ -229,7 +232,7 @@ class T_RandomStreams(unittest.TestCase):
fn_val0
=
made
.
fn
()
fn_val0
=
made
.
fn
()
fn_val1
=
made
.
fn
()
fn_val1
=
made
.
fn
()
rng_seed
=
numpy
.
random
.
RandomState
(
234
)
.
randint
(
2
**
30
)
rng_seed
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
()
)
.
randint
(
2
**
30
)
rng
=
numpy
.
random
.
RandomState
(
int
(
rng_seed
))
#int() is for 32bit
rng
=
numpy
.
random
.
RandomState
(
int
(
rng_seed
))
#int() is for 32bit
numpy_val0
=
rng
.
random_integers
(
-
5
,
5
,
size
=
(
20
,
20
))
numpy_val0
=
rng
.
random_integers
(
-
5
,
5
,
size
=
(
20
,
20
))
numpy_val1
=
rng
.
random_integers
(
-
5
,
5
,
size
=
(
20
,
20
))
numpy_val1
=
rng
.
random_integers
(
-
5
,
5
,
size
=
(
20
,
20
))
...
@@ -238,10 +241,10 @@ class T_RandomStreams(unittest.TestCase):
...
@@ -238,10 +241,10 @@ class T_RandomStreams(unittest.TestCase):
assert
numpy
.
all
(
fn_val1
==
numpy_val1
)
assert
numpy
.
all
(
fn_val1
==
numpy_val1
)
def
test_permutation
(
self
):
def
test_permutation
(
self
):
"""Test that RandomStreams.
uniform
generates the same results as numpy"""
"""Test that RandomStreams.
permutation
generates the same results as numpy"""
# Check over two calls to see if the random state is correctly updated.
# Check over two calls to see if the random state is correctly updated.
m
=
Module
()
m
=
Module
()
m
.
random
=
RandomStreams
(
234
)
m
.
random
=
RandomStreams
(
utt
.
fetch_seed
()
)
m
.
fn
=
Method
([],
m
.
random
.
permutation
((
20
,),
10
))
m
.
fn
=
Method
([],
m
.
random
.
permutation
((
20
,),
10
))
made
=
m
.
make
()
made
=
m
.
make
()
...
@@ -249,7 +252,7 @@ class T_RandomStreams(unittest.TestCase):
...
@@ -249,7 +252,7 @@ class T_RandomStreams(unittest.TestCase):
fn_val0
=
made
.
fn
()
fn_val0
=
made
.
fn
()
fn_val1
=
made
.
fn
()
fn_val1
=
made
.
fn
()
rng_seed
=
numpy
.
random
.
RandomState
(
234
)
.
randint
(
2
**
30
)
rng_seed
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
()
)
.
randint
(
2
**
30
)
rng
=
numpy
.
random
.
RandomState
(
int
(
rng_seed
))
#int() is for 32bit
rng
=
numpy
.
random
.
RandomState
(
int
(
rng_seed
))
#int() is for 32bit
# rng.permutation outputs one vector at a time, so we iterate.
# rng.permutation outputs one vector at a time, so we iterate.
...
@@ -263,7 +266,7 @@ class T_RandomStreams(unittest.TestCase):
...
@@ -263,7 +266,7 @@ class T_RandomStreams(unittest.TestCase):
"""Test that RandomStreams.multinomial generates the same results as numpy"""
"""Test that RandomStreams.multinomial generates the same results as numpy"""
# Check over two calls to see if the random state is correctly updated.
# Check over two calls to see if the random state is correctly updated.
m
=
Module
()
m
=
Module
()
m
.
random
=
RandomStreams
(
234
)
m
.
random
=
RandomStreams
(
utt
.
fetch_seed
()
)
m
.
fn
=
Method
([],
m
.
random
.
multinomial
((
20
,
20
),
1
,
[
0.1
]
*
10
))
m
.
fn
=
Method
([],
m
.
random
.
multinomial
((
20
,
20
),
1
,
[
0.1
]
*
10
))
made
=
m
.
make
()
made
=
m
.
make
()
...
@@ -271,7 +274,7 @@ class T_RandomStreams(unittest.TestCase):
...
@@ -271,7 +274,7 @@ class T_RandomStreams(unittest.TestCase):
fn_val0
=
made
.
fn
()
fn_val0
=
made
.
fn
()
fn_val1
=
made
.
fn
()
fn_val1
=
made
.
fn
()
rng_seed
=
numpy
.
random
.
RandomState
(
234
)
.
randint
(
2
**
30
)
rng_seed
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
()
)
.
randint
(
2
**
30
)
rng
=
numpy
.
random
.
RandomState
(
int
(
rng_seed
))
#int() is for 32bit
rng
=
numpy
.
random
.
RandomState
(
int
(
rng_seed
))
#int() is for 32bit
numpy_val0
=
rng
.
multinomial
(
1
,
[
0.1
]
*
10
,
size
=
(
20
,
20
))
numpy_val0
=
rng
.
multinomial
(
1
,
[
0.1
]
*
10
,
size
=
(
20
,
20
))
numpy_val1
=
rng
.
multinomial
(
1
,
[
0.1
]
*
10
,
size
=
(
20
,
20
))
numpy_val1
=
rng
.
multinomial
(
1
,
[
0.1
]
*
10
,
size
=
(
20
,
20
))
...
@@ -287,13 +290,14 @@ class T_RandomStreams(unittest.TestCase):
...
@@ -287,13 +290,14 @@ class T_RandomStreams(unittest.TestCase):
# Note that this differs from numpy.random.shuffle, where all the
# Note that this differs from numpy.random.shuffle, where all the
# elements of the matrix are shuffled.
# elements of the matrix are shuffled.
mm
=
Module
()
mm
=
Module
()
mm
.
random
=
RandomStreams
(
234
)
mm
.
random
=
RandomStreams
(
utt
.
fetch_seed
()
)
m_input
=
tensor
.
dmatrix
()
m_input
=
tensor
.
dmatrix
()
mm
.
f
=
Method
([
m_input
],
mm
.
random
.
shuffle_row_elements
(
m_input
))
mm
.
f
=
Method
([
m_input
],
mm
.
random
.
shuffle_row_elements
(
m_input
))
mmade
=
mm
.
make
()
mmade
=
mm
.
make
()
mmade
.
random
.
initialize
()
mmade
.
random
.
initialize
()
val_rng
=
numpy
.
random
.
RandomState
(
unittest_tools
.
fetch_seed
())
# Generate the elements to be shuffled
val_rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
()
+
42
)
in_mval
=
val_rng
.
uniform
(
-
2
,
2
,
size
=
(
20
,
5
))
in_mval
=
val_rng
.
uniform
(
-
2
,
2
,
size
=
(
20
,
5
))
fn_mval0
=
mmade
.
f
(
in_mval
)
fn_mval0
=
mmade
.
f
(
in_mval
)
fn_mval1
=
mmade
.
f
(
in_mval
)
fn_mval1
=
mmade
.
f
(
in_mval
)
...
@@ -304,7 +308,7 @@ class T_RandomStreams(unittest.TestCase):
...
@@ -304,7 +308,7 @@ class T_RandomStreams(unittest.TestCase):
assert
not
numpy
.
all
(
in_mval
==
fn_mval1
)
assert
not
numpy
.
all
(
in_mval
==
fn_mval1
)
assert
not
numpy
.
all
(
fn_mval0
==
fn_mval1
)
assert
not
numpy
.
all
(
fn_mval0
==
fn_mval1
)
rng_seed
=
numpy
.
random
.
RandomState
(
234
)
.
randint
(
2
**
30
)
rng_seed
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
()
)
.
randint
(
2
**
30
)
rng
=
numpy
.
random
.
RandomState
(
int
(
rng_seed
))
rng
=
numpy
.
random
.
RandomState
(
int
(
rng_seed
))
numpy_mval0
=
in_mval
.
copy
()
numpy_mval0
=
in_mval
.
copy
()
numpy_mval1
=
in_mval
.
copy
()
numpy_mval1
=
in_mval
.
copy
()
...
@@ -319,7 +323,7 @@ class T_RandomStreams(unittest.TestCase):
...
@@ -319,7 +323,7 @@ class T_RandomStreams(unittest.TestCase):
# On vectors, the behaviour is the same as numpy.random.shuffle,
# On vectors, the behaviour is the same as numpy.random.shuffle,
# except that it does not work in place, but returns a shuffled vector.
# except that it does not work in place, but returns a shuffled vector.
vm
=
Module
()
vm
=
Module
()
vm
.
random
=
RandomStreams
(
234
)
vm
.
random
=
RandomStreams
(
utt
.
fetch_seed
()
)
v_input
=
tensor
.
dvector
()
v_input
=
tensor
.
dvector
()
vm
.
f
=
Method
([
v_input
],
vm
.
random
.
shuffle_row_elements
(
v_input
))
vm
.
f
=
Method
([
v_input
],
vm
.
random
.
shuffle_row_elements
(
v_input
))
vmade
=
vm
.
make
()
vmade
=
vm
.
make
()
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论