raw_random
– Lowlevel random numbers¶
Raw random provides the randomnumber drawing functionality, that underlies
the friendlier RandomStreams
interface.
Reference¶

class
theano.tensor.raw_random.
RandomStreamsBase
(object)[source]¶ This is the interface for the
theano.tensor.shared_randomstreams.RandomStreams
subclass
binomial(self, size=(), n=1, p=0.5, ndim=None):
Sample
n
times with probability of successp
for each trial and return the number of successes.If
size
is ambiguous on the number of dimensions,ndim
may be a plain integer to supplement the missing information.This wraps the numpy implementation, so it has the same behavior.

uniform(self, size=(), low=0.0, high=1.0, ndim=None):
Sample a tensor of the given size whose elements come from a uniform distribution between low and high.
If
size
is ambiguous on the number of dimensions,ndim
may be a plain integer to supplement the missing information.This wraps the numpy implementation, so it has the same bounds: [
low
,high
[.

normal(self, size=(), avg=0.0, std=1.0, ndim=None):
Sample from a normal distribution centered on
avg
with the specified standard deviation (std
)If
size
is ambiguous on the number of dimensions,ndim
may be a plain integer to supplement the missing information.This wrap numpy implementation, so it have the same behavior.

random_integers(self, size=(), low=0, high=1, ndim=None):
Sample a random integer between low and high, both inclusive.
If
size
is ambiguous on the number of dimensions,ndim
may be a plain integer to supplement the missing information.This is a generalization of
numpy.random.random_integers()
to the case where low and high are tensors. Otherwise it behaves the same.

choice(self, size=(), a=2, replace=True, p=None, ndim=None, dtype='int64'):
Choose values from
a
with or without replacement.a
can be a 1D array or a positive scalar. Ifa
is a scalar, the samples are drawn from the range [0,a
[.If
size
is ambiguous on the number of dimensions,ndim
may be a plain integer to supplement the missing information.This wraps the numpy implementation so it has the same behavior.

poisson(self, size=(), lam=None, ndim=None, dtype='int64'):
Draw samples from a Poisson distribution.
The Poisson distribution is the limit of the Binomial distribution for large N.
If
size
is ambiguous on the number of dimensions,ndim
may be a plain integer to supplement the missing information.This wraps the numpy implementation so it has the same behavior.

permutation(self, size=(), n=1, ndim=None):
Returns permutations of the integers between 0 and
n1
, as many times as required bysize
. For instance, ifsize=(p,q)
,p*q
permutations will be generated, and the output shape will be(p,q,n)
, because each permutation is of sizen
.Theano tries to infer the number of dimensions from the length of
size
, but you may always specify it withndim
.Note
The output will have
ndim+1
dimensions.This is a generalization of
numpy.random.permutation()
to tensors. Otherwise it behaves the same.

multinomial(self, size=(), n=1, pvals=[0.5, 0.5], ndim=None):
Sample n times from a multinomial distribution defined by probabilities
pvals
, as many times as required bysize
. For instance, ifsize=(p,q)
,p*q
samples will be drawn, and the output shape will be(p,q,len(pvals))
.Theano tries to infer the number of dimensions from the length of
size
, but you may always specify it withndim
.Note
The output will have
ndim+1
dimensions.This is a generalization of
numpy.random.multinomial()
to the case wheren
andpvals
are tensors. Otherwise it behaves the same.

shuffle_row_elements(self, input):
Return a variable with every row (rightmost index) shuffled.
This uses a permutation random variable internally, available via the
.permutation
attribute of the return value.


class
theano.tensor.raw_random.
RandomStateType
(gof.Type)[source]¶ A Type for variables that will take
numpy.random.RandomState
values.

theano.tensor.raw_random.
random_state_type
(name=None)[source]¶ Return a new Variable whose
.type
israndom_state_type
.

class
theano.tensor.raw_random.
RandomFunction
(gof.Op)[source]¶ Op that draws random numbers from a numpy.RandomState object. This Op is parametrized to draw numbers from many possible distributions.

theano.tensor.raw_random.
uniform
(random_state, size=None, low=0.0, high=1.0, ndim=None, dtype=None)[source]¶ Sample from a uniform distribution between low and high.
If the size argument is ambiguous on the number of dimensions, the first argument may be a plain integer to supplement the missing information.
 Returns
RandomVariable
, NewRandomState

theano.tensor.raw_random.
binomial
(random_state, size=None, n=1, p=0.5, ndim=None, dtype='int64')[source]¶ Sample
n
times with probability of successp
for each trial and return the number of successes.If
size
is ambiguous on the number of dimensions,ndim
may be a plain integer to supplement the missing information. Returns
RandomVariable
, NewRandomState

theano.tensor.raw_random.
normal
(random_state, size=None, avg=0.0, std=1.0, ndim=None, dtype=None)[source]¶ Sample from a normal distribution centered on
avg
with the specified standard deviation (std
).If
size
is ambiguous on the number of dimensions,ndim
may be a plain integer to supplement the missing information. Returns
RandomVariable
, NewRandomState

theano.tensor.raw_random.
random_integers
(random_state, size=None, low=0, high=1, ndim=None, dtype='int64')[source]¶ Sample random integers in [
low
,high
] to fill upsize
.If
size
is ambiguous on the number of dimensions,ndim
may be a plain integer to supplement the missing information. Returns
RandomVariable
, NewRandomState

theano.tensor.raw_random.
permutation
(random_state, size=None, n=1, ndim=None, dtype='int64')[source]¶ Returns permutations of the integers in [0,
n
[, as many times as required bysize
. For instance, ifsize=(p,q)
,p*q
permutations will be generated, and the output shape will be(p,q,n)
, because each permutation is of sizen
.If
size
is ambiguous on the number of dimensions,ndim
may be a plain integer, which should correspond tolen(size)
.Note
The output will have
ndim+1
dimensions. Returns
RandomVariable
, NewRandomState

theano.tensor.raw_random.
multinomial
(random_state, size=None, p_vals=[0.5, 0.5], ndim=None, dtype='int64')[source]¶ Sample from a multinomial distribution defined by probabilities
pvals
, as many times as required bysize
. For instance, ifsize=(p,q)
,p*q
samples will be drawn, and the output shape will be(p,q,len(pvals))
.If
size
is ambiguous on the number of dimensions,ndim
may be a plain integer, which should correspond tolen(size)
.Note
The output will have
ndim+1
dimensions. Returns
RandomVariable
, NewRandomState