Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
7c1e4862
提交
7c1e4862
authored
1月 21, 2010
作者:
Pascal Lamblin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update the tutorial example on random numbers to account for the default_update…
Update the tutorial example on random numbers to account for the default_update mechanism. Update the corresponding test.
上级
539550b7
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
13 行增加
和
12 行删除
+13
-12
examples.txt
doc/tutorial/examples.txt
+10
-9
test_shared_randomstreams.py
theano/tensor/tests/test_shared_randomstreams.py
+3
-3
没有找到文件。
doc/tutorial/examples.txt
浏览文件 @
7c1e4862
...
...
@@ -317,9 +317,9 @@ Here's a brief example. The setup code is:
srng = RandomStreams(seed=234)
rv_u = srng.uniform((2,2))
rv_n = srng.normal((2,2))
f = function([], rv_u
, updates=[rv_u.update]
)
g = function([], rv_n
) #omitting rv_n.update
nearly_zeros = function([], rv_u + rv_u - 2 * rv_u
, updates=[rv_u.update]
)
f = function([], rv_u)
g = function([], rv_n
, no_default_updates=True) #Not updating rv_n.rng
nearly_zeros = function([], rv_u + rv_u - 2 * rv_u)
Here, 'rv_u' represents a random stream of 2x2 matrices of draws from a uniform
distribution. Likewise, 'rv_n' represenents a random stream of 2x2 matrices of
...
...
@@ -327,15 +327,16 @@ draws from a normal distribution. The distributions that are implemented are
defined in :class:`RandomStreams`.
Now let's use these things. If we call f(), we get random uniform numbers.
Since we are updating the internal state of the random number generator (via
the ``updates`` argument),
we get different random numbers every time.
The internal state of the random number generator is automatically updated,
so
we get different random numbers every time.
>>> f_val0 = f()
>>> f_val1 = f() #different numbers from f_val0
When we omit the updates argument (as in ``g``) to ``function``, then the
random number generator state is not affected by calling the returned function. So for example,
calling ``g`` multiple times will return the same numbers.
When we add the extra argument ``no_default_updates=True`` to
``function`` (as in ``g``), then the random number generator state is
not affected by calling the returned function. So for example, calling
``g`` multiple times will return the same numbers.
>>> g_val0 = g() # different numbers from f_val0 and f_val1
>>> g_val0 = g() # same numbers as g_val0 !!!
...
...
@@ -345,7 +346,7 @@ single function execution. So the ``nearly_zeros`` function is guaranteed to
return approximately 0 (except for rounding error) even though the ``rv_u``
random variable appears three times in the output expression.
>>> nearly_zeros = function([], rv_u + rv_u - 2 * rv_u
, updates=[rv_u.update]
)
>>> nearly_zeros = function([], rv_u + rv_u - 2 * rv_u)
Seedings Streams
----------------
...
...
theano/tensor/tests/test_shared_randomstreams.py
浏览文件 @
7c1e4862
...
...
@@ -19,9 +19,9 @@ class T_SharedRandomStreams(unittest.TestCase):
srng
=
RandomStreams
(
seed
=
234
)
rv_u
=
srng
.
uniform
((
2
,
2
))
rv_n
=
srng
.
normal
((
2
,
2
))
f
=
function
([],
rv_u
,
updates
=
[
rv_u
.
update
]
)
g
=
function
([],
rv_n
)
#omitting rv_n.update
nearly_zeros
=
function
([],
rv_u
+
rv_u
-
2
*
rv_u
,
updates
=
[
rv_u
.
update
]
)
f
=
function
([],
rv_u
)
g
=
function
([],
rv_n
,
no_default_updates
=
True
)
#Not updating rv_n.rng
nearly_zeros
=
function
([],
rv_u
+
rv_u
-
2
*
rv_u
)
assert
numpy
.
all
(
f
()
!=
f
())
assert
numpy
.
all
(
g
()
==
g
())
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论