Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
356653bd
提交
356653bd
authored
8月 06, 2015
作者:
Iban Harlouchet
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
numpydoc for theano/tensor/shared_randomstreams.py
上级
3ff5c1bf
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
70 行增加
和
47 行删除
+70
-47
shared_randomstreams.py
theano/tensor/shared_randomstreams.py
+70
-47
没有找到文件。
theano/tensor/shared_randomstreams.py
浏览文件 @
356653bd
"""Define RandomStreams, providing random number variables for Theano
graphs.
"""
"""
Define RandomStreams, providing random number variables for Theano
graphs.
"""
import
copy
import
copy
import
numpy
import
numpy
...
@@ -37,20 +38,20 @@ class RandomStreams(raw_random.RandomStreamsBase):
...
@@ -37,20 +38,20 @@ class RandomStreams(raw_random.RandomStreamsBase):
"""
"""
Module component with similar interface to numpy.random
Module component with similar interface to numpy.random
(numpy.random.RandomState)
(numpy.random.RandomState)
Parameters
----------
seed: None or int
A default seed to initialize the RandomState
instances after build. See `RandomStreamsInstance.__init__`
for more details.
"""
"""
def
updates
(
self
):
def
updates
(
self
):
return
list
(
self
.
state_updates
)
return
list
(
self
.
state_updates
)
def
__init__
(
self
,
seed
=
None
):
def
__init__
(
self
,
seed
=
None
):
"""
:type seed: None or int
:param seed: a default seed to initialize the RandomState
instances after build. See `RandomStreamsInstance.__init__`
for more details.
"""
super
(
RandomStreams
,
self
)
.
__init__
()
super
(
RandomStreams
,
self
)
.
__init__
()
# A list of pairs of the form (input_r, output_r). This will be
# A list of pairs of the form (input_r, output_r). This will be
# over-ridden by the module instance to contain stream generators.
# over-ridden by the module instance to contain stream generators.
...
@@ -62,14 +63,18 @@ class RandomStreams(raw_random.RandomStreamsBase):
...
@@ -62,14 +63,18 @@ class RandomStreams(raw_random.RandomStreamsBase):
self
.
gen_seedgen
=
numpy
.
random
.
RandomState
(
seed
)
self
.
gen_seedgen
=
numpy
.
random
.
RandomState
(
seed
)
def
seed
(
self
,
seed
=
None
):
def
seed
(
self
,
seed
=
None
):
"""Re-initialize each random stream
"""
Re-initialize each random stream.
:param seed: each random stream will be assigned a unique
state that depends deterministically on this value.
:type seed: None or integer in range 0 to 2**30
Parameters
----------
seed : None or integer in range 0 to 2**30
Each random stream will be assigned a unique state that depends
deterministically on this value.
:rtype: None
Returns
-------
None
"""
"""
if
seed
is
None
:
if
seed
is
None
:
...
@@ -82,54 +87,72 @@ class RandomStreams(raw_random.RandomStreamsBase):
...
@@ -82,54 +87,72 @@ class RandomStreams(raw_random.RandomStreamsBase):
borrow
=
True
)
borrow
=
True
)
def
__getitem__
(
self
,
item
):
def
__getitem__
(
self
,
item
):
"""Retrieve the numpy RandomState instance associated with a
"""
particular stream
Retrieve the numpy RandomState instance associated with a particular
stream.
:param item: a variable of type RandomStateType, associated
Parameters
with this RandomStream
----------
item
A variable of type RandomStateType, associated
with this RandomStream.
:rtype: numpy RandomState (or None, before initialize)
Returns
-------
numpy RandomState (or None, before initialize)
:note: This is kept for compatibility with
Notes
`tensor.randomstreams.RandomStreams`. The simpler syntax
-----
``item.rng.get_value()`` is also valid.
This is kept for compatibility with `tensor.randomstreams.RandomStreams`.
The simpler syntax ``item.rng.get_value()`` is also valid.
"""
"""
return
item
.
get_value
(
borrow
=
True
)
return
item
.
get_value
(
borrow
=
True
)
def
__setitem__
(
self
,
item
,
val
):
def
__setitem__
(
self
,
item
,
val
):
"""
Set the numpy RandomState instance associated with a
"""
particular stream
Set the numpy RandomState instance associated with a particular stream.
:param item: a variable of type RandomStateType, associated
Parameters
with this RandomStream
----------
item
A variable of type RandomStateType, associated with this
RandomStream.
:param val: the new valu
e
val : numpy RandomStat
e
:type val: numpy RandomState
The new value.
:rtype: None
Returns
-------
None
:note: This is kept for compatibility with
Notes
`tensor.randomstreams.RandomStreams`. The simpler syntax
-----
``item.rng.set_value(val)`` is also valid.
This is kept for compatibility with `tensor.randomstreams.RandomStreams`.
The simpler syntax ``item.rng.set_value(val)`` is also valid.
"""
"""
item
.
set_value
(
val
,
borrow
=
True
)
item
.
set_value
(
val
,
borrow
=
True
)
def
gen
(
self
,
op
,
*
args
,
**
kwargs
):
def
gen
(
self
,
op
,
*
args
,
**
kwargs
):
"""Create a new random stream in this container.
"""
Create a new random stream in this container.
:param op: a RandomFunction instance to
Parameters
:param args: interpreted by `op`
----------
op
:param kwargs: interpreted by `op`
A RandomFunction instance to
args
:returns: The symbolic random draw part of op()'s return
Interpreted by `op`.
value. This function stores the updated RandomStateType
kwargs
Variable for use at `build` time.
Interpreted by `op`.
:rtype: TensorVariable
Returns
-------
Tensor Variable
The symbolic random draw part of op()'s return value.
This function stores the updated RandomStateType Variable
for use at `build` time.
"""
"""
seed
=
int
(
self
.
gen_seedgen
.
randint
(
2
**
30
))
seed
=
int
(
self
.
gen_seedgen
.
randint
(
2
**
30
))
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论