sandbox.rng_mrg
– MRG random number generator¶
API¶
Implementation of MRG31k3p random number generator for Theano.
Generator code in SSJ package (L’Ecuyer & Simard). http://www.iro.umontreal.ca/~simardr/ssj/indexe.html
-
class
theano.sandbox.rng_mrg.
DotModulo
(use_c_code='/usr/bin/g++')¶ Efficient and numerically stable implementation of a dot product followed by a modulo operation. This performs the same function as matVecModM.
We do this 2 times on 2 triple inputs and concatenating the output.
-
class
theano.sandbox.rng_mrg.
MRG_RandomStreams
(seed=12345, use_cuda=None)¶ Module component with similar interface to numpy.random (numpy.random.RandomState).
Parameters: seed (int or list of 6 int) – A default seed to initialize the random state. If a single int is given, it will be replicated 6 times. The first 3 values of the seed must all be less than M1 = 2147483647, and not all 0; and the last 3 values must all be less than M2 = 2147462579, and not all 0. -
get_substream_rstates
(n_streams, dtype, inc_rstate=True)¶ Initialize a matrix in which each row is a MRG stream state, and they are spaced by 2**72 samples.
-
inc_rstate
()¶ Update self.rstate to be skipped 2^134 steps forward to the next stream start.
-
multinomial
(size=None, n=1, pvals=None, ndim=None, dtype='int64', nstreams=None)¶ Sample n (n needs to be >= 1, default 1) times from a multinomial distribution defined by probabilities pvals.
Example : pvals = [[.98, .01, .01], [.01, .49, .50]] and n=1 will probably result in [[1,0,0],[0,0,1]]. When setting n=2, this will probably result in [[2,0,0],[0,1,1]].
Notes
-size and ndim are only there keep the same signature as other uniform, binomial, normal, etc. TODO : adapt multinomial to take that into account
-Does not do any value checking on pvals, i.e. there is no check that the elements are non-negative, less than 1, or sum to 1. passing pvals = [[-2., 2.]] will result in sampling [[0, 0]]
-
normal
(size, avg=0.0, std=1.0, ndim=None, dtype=None, nstreams=None)¶ Parameters: - size – Can be a list of integers or Theano variables (ex: the shape of another 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.
- nstreams – Number of streams.
-
seed
(seed=None)¶ Re-initialize each random stream.
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. Returns: Return type: None
-
uniform
(size, low=0.0, high=1.0, ndim=None, dtype=None, nstreams=None)¶ 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 – Lower bound of the interval on which values are sampled.
If the
-
-
theano.sandbox.rng_mrg.
guess_n_streams
(size, warn=False)¶ Return a guess at a good number of streams.
Parameters: warn (bool, optional) – If True, warn when a guess cannot be made (in which case we return 60 * 256).
-
theano.sandbox.rng_mrg.
multMatVect
(v, A, m1, B, m2)¶ Multiply the first half of v by A with a modulo of m1 and the second half by B with a modulo of m2.
Notes
The parameters of dot_modulo are passed implicitly because passing them explicitly takes more time than running the function’s C-code.