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)
-
get_substream_rstates
(n_streams, 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 (currently n needs to be 1) times from a multinomial distribution defined by probabilities pvals.
Example : pvals = [[.98, .01, .01], [.01, .98, .01]] will probably result in [[1,0,0],[0,1,0]].
Note
-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.
-
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 – 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
Note: The parameters of dot_modulo are passed implicitly because passing them explicitly takes more time then running the function’s C-code.