scml.common

Common functions used in all modules

Module Contents

Functions

isinobject(x, y)

isinclass(x, y)

Checks that x is within the range specified by y. Ugly but works

isin(x, y)

Checks that x is within the range specified by y. Ugly but works

isinfloat(x, y)

Checks that x is within the range specified by y. Ugly but works

fraction_cut(→ numpy.ndarray)

Distributes n items on boxes with probabilities relative to p

integer_cut(→ list[int])

Generates l random integers that sum to n where each of them is at least l_m

realin(→ float)

Selects a random number within a range if given or the input if it was a float

strin(→ str)

Selects a random string from a list (or just returns the string if no list

intin(→ int)

Selects a random number within a range if given or the input if it was an int

make_array(→ numpy.ndarray)

Creates an array with the given choices

distribute_quantities(equal, predictability, q, a, n_steps)

Used internally by generate() methods to distribute exogenous contracts

distribute(→ list[int])

Distributes q values over n bins.

Attributes

IterableOrInt

IterableOrFloat

IterableOrClass

IterableOrObject

EPSILON

scml.common.IterableOrInt[source]
scml.common.IterableOrFloat[source]
scml.common.IterableOrClass[source]
scml.common.IterableOrObject[source]
scml.common.EPSILON = 1e-05[source]
scml.common.isinobject(x: IterableOrObject, y: IterableOrClass)[source]
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 limit

  • equal – 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 case

  • allow_zero – Allow some bins to be zero even if that is not necessary