MCPcopy Create free account
hub / github.com/dask/dask / Generator

Class Generator

dask/array/_array_expr/random.py:23–377  ·  view source on GitHub ↗

Container for the BitGenerators. ``Generator`` exposes a number of methods for generating random numbers drawn from a variety of probability distributions and serves as a replacement for ``RandomState``. The main difference between the two is that ``Generator`` relies on an add

Source from the content-addressed store, hash-verified

21
22
23class Generator:
24 """
25 Container for the BitGenerators.
26
27 ``Generator`` exposes a number of methods for generating random
28 numbers drawn from a variety of probability distributions and serves
29 as a replacement for ``RandomState``. The main difference between the
30 two is that ``Generator`` relies on an additional ``BitGenerator`` to
31 manage state and generate the random bits, which are then transformed
32 into random values from useful distributions. The default ``BitGenerator``
33 used by ``Generator`` is ``PCG64``. The ``BitGenerator`` can be changed
34 by passing an instantiated ``BitGenerator`` to ``Generator``.
35
36 The function :func:`dask.array.random.default_rng` is the recommended way
37 to instantiate a ``Generator``.
38
39 .. warning::
40
41 No Compatibility Guarantee.
42
43 ``Generator`` does not provide a version compatibility guarantee. In
44 particular, as better algorithms evolve the bit stream may change.
45
46 Parameters
47 ----------
48 bit_generator : BitGenerator
49 BitGenerator to use as the core generator.
50
51 Notes
52 -----
53 In addition to the distribution-specific arguments, each ``Generator``
54 method takes a keyword argument `size` that defaults to ``None``. If
55 `size` is ``None``, then a single value is generated and returned. If
56 `size` is an integer, then a 1-D array filled with generated values is
57 returned. If `size` is a tuple, then an array with that shape is
58 filled and returned.
59
60 The Python stdlib module `random` contains pseudo-random number generator
61 with a number of methods that are similar to the ones available in
62 ``Generator``. It uses Mersenne Twister, and this bit generator can
63 be accessed using ``MT19937``. ``Generator``, besides being
64 Dask-aware, has the advantage that it provides a much larger number
65 of probability distributions to choose from.
66
67 All ``Generator`` methods are identical to ``np.random.Generator`` except
68 that they also take a `chunks=` keyword argument.
69
70 ``Generator`` does not guarantee parity in the generated numbers
71 with any third party library. In particular, numbers generated by
72 `Dask` and `NumPy` will differ even if they use the same seed.
73
74 Examples
75 --------
76 >>> from numpy.random import PCG64
77 >>> from dask.array.random import Generator
78 >>> rng = Generator(PCG64())
79 >>> rng.standard_normal().compute() # doctest: +SKIP
80 array(0.44595957) # random

Callers 1

default_rngFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected