提交 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 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 value val : numpy RandomState
: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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论