提交 356653bd authored 作者: Iban Harlouchet's avatar Iban Harlouchet

numpydoc for theano/tensor/shared_randomstreams.py

上级 3ff5c1bf
"""Define RandomStreams, providing random number variables for Theano
graphs.
"""
Define RandomStreams, providing random number variables for Theano
graphs.
"""
import copy
import numpy
......@@ -37,20 +38,20 @@ class RandomStreams(raw_random.RandomStreamsBase):
"""
Module component with similar interface to numpy.random
(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):
return list(self.state_updates)
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__()
# A list of pairs of the form (input_r, output_r). This will be
# over-ridden by the module instance to contain stream generators.
......@@ -62,14 +63,18 @@ class RandomStreams(raw_random.RandomStreamsBase):
self.gen_seedgen = numpy.random.RandomState(seed)
def seed(self, seed=None):
"""Re-initialize each random stream
:param seed: each random stream will be assigned a unique
state that depends deterministically on this value.
"""
Re-initialize each random stream.
: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:
......@@ -82,54 +87,72 @@ class RandomStreams(raw_random.RandomStreamsBase):
borrow=True)
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
with this RandomStream
Parameters
----------
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
`tensor.randomstreams.RandomStreams`. The simpler syntax
``item.rng.get_value()`` is also valid.
Notes
-----
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)
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
with this RandomStream
Parameters
----------
item
A variable of type RandomStateType, associated with this
RandomStream.
:param val: the new value
:type val: numpy RandomState
val : numpy RandomState
The new value.
:rtype: None
Returns
-------
None
:note: This is kept for compatibility with
`tensor.randomstreams.RandomStreams`. The simpler syntax
``item.rng.set_value(val)`` is also valid.
Notes
-----
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)
def gen(self, op, *args, **kwargs):
"""Create a new random stream in this container.
:param op: a RandomFunction instance to
:param args: interpreted by `op`
:param kwargs: interpreted by `op`
:returns: The symbolic random draw part of op()'s return
value. This function stores the updated RandomStateType
Variable for use at `build` time.
:rtype: TensorVariable
"""
Create a new random stream in this container.
Parameters
----------
op
A RandomFunction instance to
args
Interpreted by `op`.
kwargs
Interpreted by `op`.
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))
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论