Random numbers¶
-
class
RandomDistribution
(distribution, parameters_pos=None, rng=None, **parameters_named)[source]¶ Class which defines a next(n) method which returns an array of n random numbers from a given distribution.
- Arguments:
- distribution:
- the name of a random number distribution.
- parameters_pos:
- parameters of the distribution, provided as a tuple. For the correct ordering, see random.available_distributions.
- rng:
- if present, should be a
NumpyRNG
,GSLRNG
orNativeRNG
object. - parameters_named:
- parameters of the distribution, provided as keyword arguments.
Parameters may be provided either through parameters_pos or through parameters_named, but not both. All parameters must be provided, there are no default values. Parameter names are, in general, as used in Wikipedia.
Examples:
>>> rd = RandomDistribution('uniform', (-70, -50)) >>> rd = RandomDistribution('normal', mu=0.5, sigma=0.1) >>> rng = NumpyRNG(seed=8658764) >>> rd = RandomDistribution('gamma', k=2.0, theta=5.0, rng=rng)
Available distributions:
Name Parameters Comments binomial n, p gamma k, theta exponential beta lognormal mu, sigma normal mu, sigma normal_clipped mu, sigma, low, high Values outside (low, high) are redrawn normal_clipped_to_boundary mu, sigma, low, high Values below/above low/high are set to low/high poisson lambda_ Trailing underscore since lambda is a Python keyword uniform low, high uniform_int low, high vonmises mu, kappa
-
class
NumpyRNG
(seed=None, parallel_safe=True)[source]¶ Bases:
pyNN.random.WrappedRNG
Wrapper for the
numpy.random.RandomState
class (Mersenne Twister PRNG).-
translations
= {'vonmises': ('vonmises', {'mu': 'mu', 'kappa': 'kappa'}), 'poisson': ('poisson', {'lambda_': 'lam'}), 'normal': ('normal', {'mu': 'loc', 'sigma': 'scale'}), 'lognormal': ('lognormal', {'mu': 'mean', 'sigma': 'sigma'}), 'exponential': ('exponential', {'beta': 'scale'}), 'normal_clipped': ('normal_clipped', {'mu': 'mu', 'low': 'low', 'high': 'high', 'sigma': 'sigma'}), 'gamma': ('gamma', {'k': 'shape', 'theta': 'scale'}), 'uniform_int': ('randint', {'low': 'low', 'high': 'high'}), 'uniform': ('uniform', {'low': 'low', 'high': 'high'}), 'binomial': ('binomial', {'n': 'n', 'p': 'p'}), 'normal_clipped_to_boundary': ('normal_clipped_to_boundary', {'mu': 'mu', 'low': 'low', 'high': 'high', 'sigma': 'sigma'})}¶
-
describe
()¶
-
next
(n=None, distribution=None, parameters=None, mask_local=None)¶ Return n random numbers from the specified distribution.
- If:
- n is None, return a float,
- n >= 1, return a Numpy array,
- n < 0, raise an Exception,
- n is 0, return an empty array.
If called with distribution=None, returns uniformly distributed floats in the range [0, 1)
-
-
class
GSLRNG
(seed=None, type='mt19937', parallel_safe=True)[source]¶ Bases:
pyNN.random.WrappedRNG
Wrapper for the GSL random number generators.
-
translations
= {'poisson': ('poisson', {'lambda_': 'mu'}), 'normal': ('normal', {'mu': 'mu', 'sigma': 'sigma'}), 'lognormal': ('lognormal', {'mu': 'zeta', 'sigma': 'sigma'}), 'exponential': ('exponential', {'beta': 'mu'}), 'normal_clipped': ('normal_clipped', {'mu': 'mu', 'low': 'low', 'high': 'high', 'sigma': 'sigma'}), 'gamma': ('gamma', {'k': 'k', 'theta': 'theta'}), 'uniform': ('flat', {'low': 'a', 'high': 'b'}), 'binomial': ('binomial', {'n': 'n', 'p': 'p'}), 'uniform_int': ('uniform_int', {'low': 'low', 'high': 'high'})}¶
-
describe
()¶
-
next
(n=None, distribution=None, parameters=None, mask_local=None)¶ Return n random numbers from the specified distribution.
- If:
- n is None, return a float,
- n >= 1, return a Numpy array,
- n < 0, raise an Exception,
- n is 0, return an empty array.
If called with distribution=None, returns uniformly distributed floats in the range [0, 1)
-
-
class
NativeRNG
(seed=None)[source]¶ Bases:
pyNN.random.AbstractRNG
Signals that the simulator’s own native RNG should be used. Each simulator module should implement a class of the same name which inherits from this and which sets the seed appropriately.
-
next
(n=None, distribution=None, parameters=None, mask_local=None)¶ Return n random numbers from the specified distribution.
- If:
- n is None, return a float,
- n >= 1, return a Numpy array,
- n < 0, raise an Exception,
- n is 0, return an empty array.
If called with distribution=None, returns uniformly distributed floats in the range [0, 1)
-
Adapting a different random number generator to work with PyNN¶
Todo
write this