scml.common
Common functions used in all modules
Attributes
Functions
|
|
|
Checks that x is within the range specified by y. Ugly but works |
|
Checks that x is within the range specified by y. Ugly but works |
|
Checks that x is within the range specified by y. Ugly but works |
|
Distributes n items on boxes with probabilities relative to p |
|
Generates l random integers that sum to n where each of them is at least l_m |
|
Selects a random number within a range if given or the input if it was a float |
|
Selects a random string from a list (or just returns the string if no list |
|
Selects a random number within a range if given or the input if it was an int |
|
Creates an array with the given choices |
|
Used internally by generate() methods to distribute exogenous contracts |
|
Distributes q values over n bins. |
Module Contents
- scml.common.isinclass(x: IterableOrClass, y: IterableOrClass)[source]
Checks that x is within the range specified by y. Ugly but works
- scml.common.isin(x: IterableOrInt, y: IterableOrInt)[source]
Checks that x is within the range specified by y. Ugly but works
- scml.common.isinfloat(x: IterableOrFloat, y: IterableOrFloat)[source]
Checks that x is within the range specified by y. Ugly but works
- scml.common.fraction_cut(n: int, p: numpy.ndarray) numpy.ndarray [source]
Distributes n items on boxes with probabilities relative to p
- scml.common.integer_cut(total: int, n: int, mx: int | list[int], mn: int | list[int] | None = None, randomize: bool = True) list[int] [source]
Generates l random integers that sum to n where each of them is at least l_m :param n: total :param l: number of levels :param l_m: minimum per level :param l_x: maximum per level :param randomize: If true, the integers resulting are randomized otherwise they will always be in the same order
Returns:
- scml.common.realin(rng: tuple[float, float] | float | list[float] | numpy.ndarray) float [source]
Selects a random number within a range if given or the input if it was a float
- Parameters:
rng – Range or single value
- Returns:
the real within the given range
- scml.common.strin(lst: list[str] | str) str [source]
Selects a random string from a list (or just returns the string if no list is given)
- Parameters:
lst – list of value
- Returns:
the real within the given range
- scml.common.intin(rng: tuple[int, int] | int | list[int] | numpy.ndarray) int [source]
Selects a random number within a range if given or the input if it was an int
- Parameters:
rng – Range or single value
- Returns:
the int within the given range
- scml.common.make_array(x: numpy.ndarray | list[int] | tuple[int | float, int | float] | int | float, n: int, dtype: type[float] | type[int] = int, min_total: int = 0) numpy.ndarray [source]
Creates an array with the given choices
- scml.common.distribute_quantities(equal: bool, predictability: float, q: list[int] | numpy.typing.NDArray, a: int, n_steps: int, limit: list[int] | None = None)[source]
Used internally by generate() methods to distribute exogenous contracts
- Parameters:
equal – whether the quantities are to be distributed equally
predictability – how much are quantities for the same agent at different times are similar
q – The quantity per step to be distributed
a – The number of agents to distribute over.
limit – The maximum quantity per step for each agent (len(limit) == a). Only used if
equal==False
- Returns:
an n_steps * a list of lists giving the distributed quantities where sum[s, :] ~= q[s]. The error can be up to 2*a per step
- scml.common.distribute(q: int, n: int, *, mx: int | None = None, equal=False, concentrated=False, allow_zero=False) list[int] [source]
Distributes q values over n bins.
- Parameters:
q – Quantity to distribute
n – number of bins to distribute q over
mx – Maximum allowed per bin.
None
for no limitequal – Try to make the values in each bins as equal as possible
concentrated – If true, will try to concentrate offers in few bins.
mx
must be passed in this caseallow_zero – Allow some bins to be zero even if that is not necessary