scml.oneshot.rl.helpers

Helpers for the observation and action managers.

Functions

recover_offers(→ dict[str, negmas.outcomes.Outcome | None])

read_offers(→ list[tuple[int, ...)

encode_offers_with_time(→ list[tuple[int, int, int]])

Encodes offers from the given partner groups into n_partners tuples of quantity, unit-price values.

encode_offers_no_time(→ list[tuple[int, int]])

Encodes offers from the given partner groups into n_partners tuples of quantity, unit-price values.

decode_offers_no_time(→ dict[str, ...)

Inverts encode_offers_no_time

normalize_offers_no_time(→ list[tuple[float, float]])

Normalize the offers to values between 0 and 1 for both quantity and unit price

unnormalize_offers(→ list[tuple[int, int]])

Reverses normalize_offers converting quantities and prices in the range 0,1 to integers

clip_normal(→ float)

Normalizes x between 0 and 1 given that it is sampled from a normal (mu, sigma).

clip(→ T)

discretize_and_clip(→ int)

normalize_and_clip(→ float)

Module Contents

scml.oneshot.rl.helpers.recover_offers(encoded: numpy.ndarray, awi: scml.oneshot.common.OneShotState | scml.oneshot.awi.OneShotAWI, n_suppliers: int, n_consumers: int, max_group_size: int, continuous: bool, n_prices: int) dict[str, negmas.outcomes.Outcome | None][source]
scml.oneshot.rl.helpers.read_offers(state: scml.oneshot.awi.OneShotAWI | scml.oneshot.common.OneShotState, n_suppliers: int, n_consumers: int, max_group_size: int, continuous: bool) list[tuple[int, int]] | list[tuple[float, float]][source]
scml.oneshot.rl.helpers.encode_offers_with_time(offers: Mapping[str, negmas.outcomes.Outcome | None], partner_groups: list[list[str]], min_price: int, max_price: int) list[tuple[int, int, int]][source]

Encodes offers from the given partner groups into n_partners tuples of quantity, unit-price values.

Parameters:
  • offers – All received offers. Keys are sources. Sources not in the partner_groups will be ignored

  • partner_groups – A list of lists of partner IDs each defining a group to be considered together

  • min_price – Minimum allowed price

  • max_price – Maximum allowed price

Returns:

A list of quantity, unit-price tuples of length len(partner_groups).

scml.oneshot.rl.helpers.encode_offers_no_time(offers: Mapping[str, negmas.outcomes.Outcome | None], partner_groups: list[list[str]], min_price: int, max_price: int) list[tuple[int, int]][source]

Encodes offers from the given partner groups into n_partners tuples of quantity, unit-price values.

Parameters:
  • offers – All received offers. Keys are sources. Sources not in the partner_groups will be ignored

  • partner_groups – A list of lists of partner IDs each defining a group to be considered together

  • min_price – Minimum allowed price

  • max_price – Maximum allowed price

Returns:

A list of quantity, unit-price tuples of length len(partner_groups).

scml.oneshot.rl.helpers.decode_offers_no_time(encoded: numpy.ndarray | list[tuple[int, int]] | list[tuple[float, float]], n_suppliers: int, n_consumers: int, suppliers: list[list[str]], consumers: list[list[str]], step: int, continuous: bool, min_buy_price: int, min_sell_price: int, max_buy_price: int = -1, max_sell_price: int = -1, max_buy_quantity: int = -1, max_sell_quantity: int = -1, n_prices: int | None = None) dict[str, negmas.outcomes.Outcome | None][source]

Inverts encode_offers_no_time

Remarks:
  • max_* are only needed if continuous is True

scml.oneshot.rl.helpers.normalize_offers_no_time(offers: list[tuple[int, int]], min_price: int, max_price: int, min_quantity: int, max_quantity: int, subtract_min_price: int = False) list[tuple[float, float]][source]

Normalize the offers to values between 0 and 1 for both quantity and unit price

scml.oneshot.rl.helpers.unnormalize_offers(offers: list[tuple[float, float]], min_price: int, max_price: int, min_quantity: int, max_quantity: int, add_min_price: bool = False) list[tuple[int, int]][source]

Reverses normalize_offers converting quantities and prices in the range 0,1 to integers

scml.oneshot.rl.helpers.clip_normal(x: float, mu: float, sigma: float, n_sigmas: float | int = 3, eps: float = 1e-06) float[source]

Normalizes x between 0 and 1 given that it is sampled from a normal (mu, sigma). This is actually a very stupid way to do it.

scml.oneshot.rl.helpers.clip(x: T, mn: T = 0, mx: T = 1) T[source]
scml.oneshot.rl.helpers.discretize_and_clip(x: float, n_bins: int) int[source]
scml.oneshot.rl.helpers.normalize_and_clip(x: int, mn: T, mx: T, eps=1e-06) float[source]