InverseUFun

class negmas.preferences.InverseUFun(ufun: UFun)[source]

Bases: Protocol

Can be used to get one or more outcomes at a given range

Methods Summary

__call__(rng, normalized)

Calling an inverse ufun directly is equivalent to calling one_in()

best()

Finds the best outcome

best_in(rng, normalized)

Finds an outcome with highest utility within the given range

extreme_outcomes()

Finds the worst and best outcomes that can be returned.

init()

Used to intialize the inverse ufun.

max()

Finds the maximum utility value that can be returned.

min()

Finds the minimum utility value that can be returned.

minmax()

Finds the minimum and maximum utility values that can be returned.

next_better()

Returns the rational outcome with utility just below the last one returned from this function

next_worse()

Returns the rational outcome with utility just below the last one returned from this function

one_in(rng, normalized[, ...])

Finds an outcmoe with the given utility value.

some(rng, normalized[, n])

Finds a list of outcomes with utilities in the given range.

within_fractions(rng)

Finds outocmes within the given fractions of utility values.

within_indices(rng)

Finds outocmes within the given indices with the best at index 0 and the worst at largest index.

worst()

Finds the worst outcome

worst_in(rng, normalized)

Finds an outcome with lowest utility within the given range

Methods Documentation

abstractmethod __call__(rng: float | tuple[float, float], normalized: bool) tuple | None[source]

Calling an inverse ufun directly is equivalent to calling one_in()

abstractmethod best() tuple[source]

Finds the best outcome

abstractmethod best_in(rng: float | tuple[float, float], normalized: bool) tuple | None[source]

Finds an outcome with highest utility within the given range

Parameters:
  • rng – The range (or single value) of utility values to search for outcomes

  • normalized – if True, the input rng will be understood as ranging from 0-1 (1=max, 0=min) independent of the ufun actual range

abstractmethod extreme_outcomes() tuple[tuple, tuple][source]

Finds the worst and best outcomes that can be returned.

Remarks:

These may be different from the results of ufun.extreme_outcomes() as they can be approximate.

init()[source]

Used to intialize the inverse ufun. Any computationally expensive initialization should be done here not in the constructor.

abstractmethod max() float[source]

Finds the maximum utility value that can be returned.

Remarks:
  • May be different from the maximum of the whole ufun if there is approximation

abstractmethod min() float[source]

Finds the minimum utility value that can be returned.

Remarks:
  • May be different from the minimum of the whole ufun if there is approximation

abstractmethod minmax() tuple[float, float][source]

Finds the minimum and maximum utility values that can be returned.

Remarks:

These may be different from the results of ufun.minmax() as they can be approximate.

next_better() tuple | None[source]

Returns the rational outcome with utility just below the last one returned from this function

next_worse() tuple | None[source]

Returns the rational outcome with utility just below the last one returned from this function

abstractmethod one_in(rng: float | tuple[float, float], normalized: bool, fallback_to_higher: bool = True, fallback_to_best: bool = True) tuple | None[source]

Finds an outcmoe with the given utility value.

Parameters:
  • rng – The range (or single value) of utility values to search for outcomes

  • normalized – if True, the input rng will be understood as ranging from 0-1 (1=max, 0=min) independent of the ufun actual range

  • fall_back_to_higher – if True, any outcome above the minimum in the range will be returned if nothing can be found in the range

  • fall_back_to_best – if True, the best outcome will always be offered if no outcome in the given range is found.

abstractmethod some(rng: float | tuple[float, float], normalized: bool, n: int | None = None) list[tuple][source]

Finds a list of outcomes with utilities in the given range.

Parameters:
  • rng – The range (or single value) of utility values to search for outcomes

  • normalized – if True, the input rng will be understood as ranging from 0-1 (1=max, 0=min) independent of the ufun actual range

  • n – The maximum number of outcomes to return

Remarks:
  • If the ufun outcome space is continuous a sample of outcomes is returned

  • If the ufun outcome space is discrete all outcomes in the range are returned

abstractmethod within_fractions(rng: tuple[float, float]) list[tuple][source]

Finds outocmes within the given fractions of utility values. rng is always assumed to be normalized between 0-1

abstractmethod within_indices(rng: tuple[int, int]) list[tuple][source]

Finds outocmes within the given indices with the best at index 0 and the worst at largest index.

Remarks:
  • Works only for discrete outcome spaces

abstractmethod worst() tuple[source]

Finds the worst outcome

abstractmethod worst_in(rng: float | tuple[float, float], normalized: bool) tuple | None[source]

Finds an outcome with lowest utility within the given range

Parameters:
  • rng – The range (or single value) of utility values to search for outcomes

  • normalized – if True, the input rng will be understood as ranging from 0-1 (1=max, 0=min) independent of the ufun actual range