5.2.2. ChooserBase¶
Many classes what to have ways to choose among values, possibly with different distributions. The interface and much of the infrastructure for such choices is likely to be the same in each instance, so this file provides a class to both handle much of the common infrastructure and to provide that interface.
- class ChooserBase.ChooserBase(dist, args, seed)¶
This is an abstract class that provides setup for managing the distribution that will inform choices. Subclasses will have to decide what to do with those values.
Parameters:
dist: the name of the distrbution to use
args: a tuple of any arguments the distribution needs during initialization
seed: the seed to give to the random number generator
- get_all_choices()¶
Return a set of all the potential choices, regardless of how likely each is.
- next_choice()¶
Return: the next choice
- num_choices()¶
Return the number of possible choices this instance might consider.
- set_dist(dist, args=None, seed=None)¶
Set the distribution for this chooser to be of the given type, if args and seed are both None and dist is a string that contains commas it will be split on comma to get the args
Parameters:
dist: the name of the distrbution to use
args: a tuple of any arguments the distribution needs during initialization
seed: the seed to give to the random number generator
- set_logger(logger)¶
Set the logger that should be used by this instance. This is expected to be a subclass of <no title>
Parameters:
logger: an instance of <no title> to write messages to
- set_seed(seed)¶
Set the seed for the underlying distribution to the correct value
Parameters:
seed: the new seed to use
- ChooserBase.test()¶
Run a simple unittest to make sure all the implemented functions work