ó ùµÈ[c@@sbdZddlmZddlZddlmZmZddlTddlm Z dd „Z dS( s!Random number interface of MXNet.i(tabsolute_importNi(t_LIBt check_call(t*(tContexttallcC@s~t|tƒstdƒ‚ntj|ƒ}|dkrOttj|ƒƒn+t|ƒ}ttj ||j |j ƒƒdS(sð Seeds the random number generators in MXNet. This affects the behavior of modules in MXNet that uses random number generators, like the dropout operator and `NDArray`'s random sampling operators. Parameters ---------- seed_state : int The random number seed. ctx : Context The device context of the generator. The default is "all" which means seeding random number generators of all devices. Notes ----- Random number generators in MXNet are device specific. `mx.random.seed(seed_state)` sets the state of each generator using `seed_state` and the device id. Therefore, random numbers generated from different devices can be different even if they are seeded using the same seed. To produce identical random number sequences independent of the device id, set optional `ctx` argument. This produces the same sequence of random numbers independent of the device id, but the sequence can be different on different kind of devices as MXNet's random number generators for CPU and GPU use different algorithms. Example ------- >>> print(mx.nd.random.normal(shape=(2,2)).asnumpy()) [[ 1.36481571 -0.62203991] [-1.4962182 -0.08511394]] >>> print(mx.nd.random.normal(shape=(2,2)).asnumpy()) [[ 1.09544981 -0.20014545] [-0.20808885 0.2527658 ]] # Same results on the same device with the same seed >>> mx.random.seed(128) >>> print(mx.nd.random.normal(shape=(2,2)).asnumpy()) [[ 0.47400656 -0.75213492] [ 0.20251541 0.95352972]] >>> mx.random.seed(128) >>> print(mx.nd.random.normal(shape=(2,2)).asnumpy()) [[ 0.47400656 -0.75213492] [ 0.20251541 0.95352972]] # Different results on gpu(0) and gpu(1) with the same seed >>> mx.random.seed(128) >>> print(mx.nd.random.normal(shape=(2,2), ctx=mx.gpu(0)).asnumpy()) [[ 2.5020072 -1.6884501] [-0.7931333 -1.4218881]] >>> mx.random.seed(128) >>> print(mx.nd.random.normal(shape=(2,2), ctx=mx.gpu(1)).asnumpy()) [[ 0.24336822 -1.664805 ] [-1.0223296 1.253198 ]] # Seeding with `ctx` argument produces identical results on gpu(0) and gpu(1) >>> mx.random.seed(128, ctx=mx.gpu(0)) >>> print(mx.nd.random.normal(shape=(2,2), ctx=mx.gpu(0)).asnumpy()) [[ 2.5020072 -1.6884501] [-0.7931333 -1.4218881]] >>> mx.random.seed(128, ctx=mx.gpu(1)) >>> print(mx.nd.random.normal(shape=(2,2), ctx=mx.gpu(1)).asnumpy()) [[ 2.5020072 -1.6884501] [-0.7931333 -1.4218881]] sseed_state must be intRN( t isinstancetintt ValueErrortctypestc_intRRt MXRandomSeedRtMXRandomSeedContextt device_typeidt device_id(t seed_statetctx((sL/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/random.pytseeds?  ( t__doc__t __future__RR tbaseRRtndarray.randomtcontextRR(((sL/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/random.pyts