RandSimplexGridUniform
- class poisson_approval.RandSimplexGridUniform(cls, denominator, keys, d_key_fixed_share=None, **kwargs)[source]
A random factory of an object defined by shares on a discrete simplex.
- Parameters
cls (class) – The class of object we want to create. It must accept as parameter a dictionary of the form
key: share
, where share is a number.denominator (int) – The grain of the grid.
keys (iterable) – These keys will have a variable share.
d_key_fixed_share (dict) – A dictionary. For each entry
key: fixed_share
, this key will have at least this fixed share. The total must be lower or equal to 1.kwargs – Additional parameters are passed to cls when creating the object.
Examples
Basic usage:
>>> initialize_random_seeds() >>> rand_dict = RandSimplexGridUniform(cls=DictPrintingInOrder, denominator=7, keys=['a', 'b']) >>> rand_dict() {'a': Fraction(6, 7), 'b': Fraction(1, 7)}
If d_key_fixed_share is given, then these shares are fixed, and the remaining share is split between keys:
>>> from fractions import Fraction >>> initialize_random_seeds() >>> rand_dict = RandSimplexGridUniform(cls=DictPrintingInOrder, denominator=3, keys=['a', 'b'], ... d_key_fixed_share={'c': Fraction(4, 7)}) >>> rand_dict() {'a': Fraction(2, 7), 'b': Fraction(1, 7), 'c': Fraction(4, 7)}
The keys in d_fixed_share may overlap with keys:
>>> initialize_random_seeds() >>> rand_dict = RandSimplexGridUniform(cls=DictPrintingInOrder, denominator=3, keys=['a', 'b'], ... d_key_fixed_share={'b': Fraction(4, 7)}) >>> rand_dict() {'a': Fraction(2, 7), 'b': Fraction(5, 7)}
If you want the created object to meet a particular condition, use
RandConditional
.