Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
0b042130
提交
0b042130
authored
12月 10, 2012
作者:
Guillaume Desjardins
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
BUG FIX: state_updates should be initialized in MRG_RandomStreams.__init__ to
prevent different random number generators from sharing state.
上级
ae33d372
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
24 行增加
和
4 行删除
+24
-4
rng_mrg.py
theano/sandbox/rng_mrg.py
+4
-4
test_rng_mrg.py
theano/sandbox/test_rng_mrg.py
+20
-0
没有找到文件。
theano/sandbox/rng_mrg.py
浏览文件 @
0b042130
...
...
@@ -637,10 +637,6 @@ def guess_n_streams(size, warn=True):
class
MRG_RandomStreams
(
object
):
"""Module component with similar interface to numpy.random (numpy.random.RandomState)"""
state_updates
=
[]
"""A list of pairs of the form (input_r, output_r), representing the
update rules of all the random states generated by this RandomStreams"""
def
updates
(
self
):
return
list
(
self
.
state_updates
)
...
...
@@ -655,6 +651,10 @@ class MRG_RandomStreams(object):
M2 = 2147462579, and not all 0.
"""
# A list of pairs of the form (input_r, output_r), representing the
# update rules of all the random states generated by this RandomStreams"""
self
.
state_updates
=
[]
super
(
MRG_RandomStreams
,
self
)
.
__init__
()
if
isinstance
(
seed
,
int
):
if
seed
==
0
:
...
...
theano/sandbox/test_rng_mrg.py
浏览文件 @
0b042130
...
...
@@ -677,3 +677,23 @@ class T_MRG(unittest.TestCase):
self
.
assertRaises
(
ValueError
,
R
.
binomial
,
size
)
self
.
assertRaises
(
ValueError
,
R
.
multinomial
,
size
,
1
,
[])
self
.
assertRaises
(
ValueError
,
R
.
normal
,
size
)
def
test_multiple_rng
():
"""
Test that we can have multiple random number generators in parallel, and
that we can replicate the stream of one with another. This is meant to fix a
previous bug in rng_mrg.MRG_RandomStreams where state_updates was
initialized as a class variable, instead of in the __init__ method. This
would cause all MRG_RandomStreams objects to share the same state.
"""
rng1
=
MRG_RandomStreams
(
1234
)
var1
=
theano
.
shared
(
numpy
.
ones
(
1
))
out1
=
rng1
.
uniform
(
size
=
(
1
,))
f1
=
theano
.
function
([],
out1
,
updates
=
{
var1
:
out1
})
assert
len
(
rng1
.
state_updates
)
==
1
rng2
=
MRG_RandomStreams
(
1234
)
out2
=
rng2
.
uniform
(
size
=
(
1
,))
f2
=
theano
.
function
([],
out2
,
updates
=
{
var1
:
out2
})
assert
len
(
rng1
.
state_updates
)
==
1
assert
len
(
rng2
.
state_updates
)
==
1
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论