theano/sandbox/rng_mrg.py
def uniform(self, size, low=0.0, high=1.0, ndim=None, dtype=None,
                nstreams=None, **kwargs):
        # TODO : need description for parameter 'size', 'ndim', 'nstreams'
        """
        Sample a tensor of given size whose element from a uniform
        distribution between low and high.

        If the size argument is ambiguous on the number of dimensions,
        ndim may be a plain integer to supplement the missing information.

        Parameters
        ----------
        low
            Lower bound of the interval on which values are sampled.
            If the ``dtype`` arg is provided, ``low`` will be cast into
            dtype. This bound is excluded.
        high
            Higher bound of the interval on which values are sampled.
            If the ``dtype`` arg is provided, ``high`` will be cast into
            dtype. This bound is excluded.
        size
          Can be a list of integer or Theano variable (ex: the shape
          of other Theano Variable).
        dtype
            The output data type. If dtype is not specified, it will be
            inferred from the dtype of low and high, but will be at
            least as precise as floatX.

        """
        low = as_tensor_variable(low)
        high = as_tensor_variable(high)

        if dtype is None:
            dtype = scal.upcast(config.floatX, low.dtype, high.dtype)

        low = cast(low, dtype=dtype)
        high = cast(high, dtype=dtype)

        low = undefined_grad(low)
        high = undefined_grad(high)

        if isinstance(size, tuple):
            msg = "size must be a tuple of int or a Theano variable"
            assert all([isinstance(i, (np.integer, integer_types, Variable))
                        for i in size]), msg
            if any([isinstance(i, (np.integer, integer_types)) and i <= 0
                    for i in size]):
                raise ValueError(
                    "The specified size contains a dimension with value <= 0",
                    size)

        else:
            if not (isinstance(size, Variable) and size.ndim == 1):
                raise TypeError("size must be a tuple of int or a Theano "
                                "Variable with 1 dimension, got " + str(size) +
                                " of type " + str(type(size)))
        orig_nstreams = nstreams
        if nstreams is None:
            nstreams = self.n_streams(size)
        rstates = self.get_substream_rstates(nstreams, dtype)

        d = {}
        if 'target' in kwargs:
            d = dict(target=kwargs.pop('target'))
        if len(kwargs) > 0:
            raise TypeError("uniform() got unexpected keyword arguments %s" % (str(kwargs.keys())))
        node_rstate = shared(rstates, **d)
        u = self.pretty_return(node_rstate,
                               *mrg_uniform.new(node_rstate,
                                                ndim, dtype, size),
                               size=size, nstreams=orig_nstreams)
        # Add a reference to distinguish from other shared variables
        node_rstate.tag.is_rng = True
        r = u * (high - low) + low

        if u.type.broadcastable != r.type.broadcastable:
            raise NotImplementedError(
                'Increase the size to match the broadcasting pattern of '
                '`low` and `high` arguments')

        assert r.dtype == dtype
        return r

        Sample a tensor of given size whose element from a uniform
        distribution between low and high.

        If the size argument is ambiguous on the number of dimensions,
        ndim may be a plain integer to supplement the missing information.

        Parameters
        ----------
        low
            Lower bound of the interval on which values are sampled.
            If the ``dtype`` arg is provided, ``low`` will be cast into
            dtype. This bound is excluded.
        high
            Higher bound of the interval on which values are sampled.
            If the ``dtype`` arg is provided, ``high`` will be cast into
            dtype. This bound is excluded.
        size
          Can be a list of integer or Theano variable (ex: the shape
          of other Theano Variable).
        dtype
            The output data type. If dtype is not specified, it will be
            inferred from the dtype of low and high, but will be at
            least as precise as floatX.

        
Sample a tensor of given size whose element from a uniform
distribution between low and high.

If the size argument is ambiguous on the number of dimensions,
ndim may be a plain integer to supplement the missing information.

Parameters

low
Lower bound of the interval on which values are sampled.
Sample a tensor of given size whose element from a uniform distribution between low and high . If the size argument is ambiguous on the number of dimensions ndim may be a plain integer to supplement the missing information . Parameters low Lower bound of the interval on which values are sampled .
def uniform(self, size, low=0.0, high=1.0, ndim=None, dtype=None,
                nstreams=None, **kwargs):
        low = as_tensor_variable(low)
        high = as_tensor_variable(high)
        if dtype is None:
            dtype = scal.upcast(config.floatX, low.dtype, high.dtype)
        low = cast(low, dtype=dtype)
        high = cast(high, dtype=dtype)
        low = undefined_grad(low)
        high = undefined_grad(high)
        if isinstance(size, tuple):
            msg = "size must be a tuple of int or a Theano variable"
            assert all([isinstance(i, (np.integer, integer_types, Variable))
                        for i in size]), msg
            if any([isinstance(i, (np.integer, integer_types)) and i <= 0
                    for i in size]):
                raise ValueError(
                    "The specified size contains a dimension with value <= 0",
                    size)
        else:
            if not (isinstance(size, Variable) and size.ndim == 1):
                raise TypeError("size must be a tuple of int or a Theano "
                                "Variable with 1 dimension, got " + str(size) +
                                " of type " + str(type(size)))
        orig_nstreams = nstreams
        if nstreams is None:
            nstreams = self.n_streams(size)
        rstates = self.get_substream_rstates(nstreams, dtype)
        d = {}
        if 'target' in kwargs:
            d = dict(target=kwargs.pop('target'))
        if len(kwargs) > 0:
            raise TypeError("uniform() got unexpected keyword arguments %s" % (str(kwargs.keys())))
        node_rstate = shared(rstates, **d)
        u = self.pretty_return(node_rstate,
                               *mrg_uniform.new(node_rstate,
                                                ndim, dtype, size),
                               size=size, nstreams=orig_nstreams)
        node_rstate.tag.is_rng = True
        r = u * (high - low) + low
        if u.type.broadcastable != r.type.broadcastable:
            raise NotImplementedError(
                'Increase the size to match the broadcasting pattern of '
                '`low` and `high` arguments')
        assert r.dtype == dtype
        return r
def uniform ( self , size , low = 0.0 , high = 1.0 , ndim = None , dtype = None , nstreams = None , ** kwargs ) : low = as_tensor_variable ( low ) high = as_tensor_variable ( high ) if dtype is None : dtype = scal . upcast ( config . floatX , low . dtype , high . dtype ) low = cast ( low , dtype = dtype ) high = cast ( high , dtype = dtype ) low = undefined_grad ( low ) high = undefined_grad ( high ) if isinstance ( size , tuple ) : msg = "size must be a tuple of int or a Theano variable" assert all ( [ isinstance ( i , ( np . integer , integer_types , Variable ) ) for i in size ] ) , msg if any ( [ isinstance ( i , ( np . integer , integer_types ) ) and i <= 0 for i in size ] ) : raise ValueError ( "The specified size contains a dimension with value <= 0" , size ) else : if not ( isinstance ( size , Variable ) and size . ndim == 1 ) : raise TypeError ( "size must be a tuple of int or a Theano " "Variable with 1 dimension, got " + str ( size ) + " of type " + str ( type ( size ) ) ) orig_nstreams = nstreams if nstreams is None : nstreams = self . n_streams ( size ) rstates = self . get_substream_rstates ( nstreams , dtype ) d = { } if 'target' in kwargs : d = dict ( target = kwargs . pop ( 'target' ) ) if len ( kwargs ) > 0 : raise TypeError ( "uniform() got unexpected keyword arguments %s" % ( str ( kwargs . keys ( ) ) ) ) node_rstate = shared ( rstates , ** d ) u = self . pretty_return ( node_rstate , * mrg_uniform . new ( node_rstate , ndim , dtype , size ) , size = size , nstreams = orig_nstreams ) node_rstate . tag . is_rng = True r = u * ( high - low ) + low if u . type . broadcastable != r . type . broadcastable : raise NotImplementedError ( 'Increase the size to match the broadcasting pattern of ' '`low` and `high` arguments' ) assert r . dtype == dtype return r
Sample a tensor of given size whose element from a uniform
distribution between low and high.
Sample a tensor of given size whose element from a uniform distribution between low and high .
# TODO : need description for parameter 'size', 'ndim', 'nstreams' """
        Sample a tensor of given size whose element from a uniform
        distribution between low and high.

        If the size argument is ambiguous on the number of dimensions,
        ndim may be a plain integer to supplement the missing information.

        Parameters
        ----------
        low
            Lower bound of the interval on which values are sampled.
            If the ``dtype`` arg is provided, ``low`` will be cast into
            dtype. This bound is excluded.
        high
            Higher bound of the interval on which values are sampled.
            If the ``dtype`` arg is provided, ``high`` will be cast into
            dtype. This bound is excluded.
        size
          Can be a list of integer or Theano variable (ex: the shape
          of other Theano Variable).
        dtype
            The output data type. If dtype is not specified, it will be
            inferred from the dtype of low and high, but will be at
            least as precise as floatX.

        """ # Add a reference to distinguish from other shared variables
self
size
low
high
ndim
dtype
nstreams