Random number generator¶
-
class
stats_arrays.RandomNumberGenerator(uncertainty_type, params, size=1, maximum_iterations=100, seed=None, **kwargs)¶ -
__init__(uncertainty_type, params, size=1, maximum_iterations=100, seed=None, **kwargs)¶ Create a random number generator from a Parameter array and an uncertainty distribution.
Upon instantiation, the class checks that:
- The
minimumandmaximumbounds, if any, are reasonable - The given uncertainty type can be used
uncertainty_typeis not required to be a subclass of UncertaintyBase, but needs to have the methodbounded_random_variables.The returned class instance can be called directly:
>>> from stats_arrays import RandomNumberGenerator, TriangularUncertainty >>> params = TriangularUncertainty.from_dicts( ... {'loc': 5, 'minimum': 3, 'maximum': 10}, ... {'loc': 1, 'minimum': 0.7, 'maximum': 4.4} ... ) >>> rng = RandomNumberGenerator(TriangularUncertainty, params) >>> rng.generate_random_numbers() array([[ 8.00843856], [ 1.54968237]])
but can also be used as an iterator:
>>> zip(range(2), rng) [(0, array([[ 5.34298156], [ 1.02447677]])), (1, array([[ 5.45360508], [ 1.99372889]]))]
- Args:
- uncertainty_type (object): An uncertainty type class (subclass of
stats_arrays.distributions.UncertaintyBase) - params (array): The Parameter array
- size (int, optional): The number of samples to draw from each parameter. Default is
1. - maximum_iterations (int, optional): The number of times to draw samples that fit within the given bounds, if any, before raising
stats_arrays.MaximumIterationsError. Default is100. - seed (int, optional): Seed value for the random number generator. Default is
None.
- uncertainty_type (object): An uncertainty type class (subclass of
- Returns:
- A class instance
- The
-
verify_params(params=None, uncertainty_type=None)¶ Verify that parameters are within bounds. Mean is not restricted to bounds, unless the distribution requires it (e.g. triangular).
-
verify_uncertainty_type(uncertainty_type=None)¶ Make sure the given uncertainty type provides the method
bounded_random_variables.
-