Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
9189850b
提交
9189850b
authored
12月 11, 2012
作者:
Guillaume Desjardins
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added unit-test for transfering random states between theano graphs
上级
ad55f02a
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
41 行增加
和
2 行删除
+41
-2
test_rng_mrg.py
theano/sandbox/test_rng_mrg.py
+22
-1
test_shared_randomstreams.py
theano/tensor/tests/test_shared_randomstreams.py
+19
-1
没有找到文件。
theano/sandbox/test_rng_mrg.py
浏览文件 @
9189850b
...
...
@@ -678,7 +678,8 @@ class T_MRG(unittest.TestCase):
self
.
assertRaises
(
ValueError
,
R
.
multinomial
,
size
,
1
,
[])
self
.
assertRaises
(
ValueError
,
R
.
normal
,
size
)
def
test_multiple_rng
():
def
test_multiple_rng_aliasing
():
"""
Test that when we have multiple random number generators, we do not alias
the state_updates member. `state_updates` can be useful when attempting to
...
...
@@ -689,3 +690,23 @@ def test_multiple_rng():
rng1
=
MRG_RandomStreams
(
1234
)
rng2
=
MRG_RandomStreams
(
2392
)
assert
rng1
.
state_updates
is
not
rng2
.
state_updates
def
test_random_state_transfer
():
"""
Test that random state can be transferred from one theano graph to another.
"""
class
Graph
():
def
__init__
(
self
,
seed
=
123
):
self
.
rng
=
MRG_RandomStreams
(
seed
)
self
.
y
=
self
.
rng
.
uniform
(
size
=
(
1
,))
g1
=
Graph
(
seed
=
123
)
f1
=
theano
.
function
([],
g1
.
y
)
g2
=
Graph
(
seed
=
987
)
f2
=
theano
.
function
([],
g2
.
y
)
g2
.
rng
.
rstate
=
g1
.
rng
.
rstate
for
(
su1
,
su2
)
in
zip
(
g1
.
rng
.
state_updates
,
g2
.
rng
.
state_updates
):
su2
[
0
]
.
set_value
(
su1
[
0
]
.
get_value
())
numpy
.
testing
.
assert_array_almost_equal
(
f1
(),
f2
(),
decimal
=
6
)
theano/tensor/tests/test_shared_randomstreams.py
浏览文件 @
9189850b
...
...
@@ -715,7 +715,7 @@ class T_SharedRandomStreams(unittest.TestCase):
s_rng
.
set_value
(
rr
,
borrow
=
True
)
assert
rr
is
s_rng
.
container
.
storage
[
0
]
def
test_multiple_rng
(
self
):
def
test_multiple_rng
_aliasing
(
self
):
"""
Test that when we have multiple random number generators, we do not alias
the state_updates member. `state_updates` can be useful when attempting to
...
...
@@ -728,6 +728,24 @@ class T_SharedRandomStreams(unittest.TestCase):
assert
rng1
.
state_updates
is
not
rng2
.
state_updates
assert
rng1
.
gen_seedgen
is
not
rng2
.
gen_seedgen
def
test_random_state_transfer
(
self
):
"""
Test that random state can be transferred from one theano graph to another.
"""
class
Graph
():
def
__init__
(
self
,
seed
=
123
):
self
.
rng
=
RandomStreams
(
seed
)
self
.
y
=
self
.
rng
.
uniform
(
size
=
(
1
,))
g1
=
Graph
(
seed
=
123
)
f1
=
function
([],
g1
.
y
)
g2
=
Graph
(
seed
=
987
)
f2
=
function
([],
g2
.
y
)
for
(
su1
,
su2
)
in
zip
(
g1
.
rng
.
state_updates
,
g2
.
rng
.
state_updates
):
su2
[
0
]
.
set_value
(
su1
[
0
]
.
get_value
())
numpy
.
testing
.
assert_array_almost_equal
(
f1
(),
f2
(),
decimal
=
6
)
if
__name__
==
'__main__'
:
from
theano.tests
import
main
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论