SamplingInverseUtilityFunction

class negmas.preferences.SamplingInverseUtilityFunction(ufun, max_samples_per_call=10000)[source]

Bases: InverseUFun

A utility function inverter that uses sampling.

Nothing is done during initialization so the fixed cost of this inverter is minimal. Nevertheless, each time the system is asked to find an outcome within some range, it uses random sampling which is very inefficient and suffers from the curse of dimensionality.

Attributes Summary

initialized

ufun

Methods Summary

__call__(rng, normalized)

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

all(rng)

Finds all outcomes with in the given utility value range

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 some outcomes with the given utility value (if discrete, all)

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

Attributes Documentation

initialized: bool
ufun: UFun

Methods Documentation

__call__(rng, normalized)[source]

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

Return type:

tuple | None

all(rng)[source]

Finds all outcomes with in the given utility value range

Parameters:

rng (float | tuple[float, float]) – The range. If a value, outcome utilities must match it exactly

Return type:

list[tuple]

Remarks:
  • If issues or outcomes are not None, then init_inverse will be called first

  • If the outcome-space is discrete, this method will return all outcomes in the given range

abstract best()

Finds the best outcome

Return type:

tuple

best_in(rng, normalized)[source]

Finds an outcome with highest utility within the given range

Parameters:
  • rng (float | tuple[float, float]) – The range (or single value) of utility values to search for outcomes

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

Return type:

tuple | None

extreme_outcomes()[source]

Finds the worst and best outcomes that can be returned.

Return type:

tuple[tuple | None, tuple | None]

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.

abstract max()

Finds the maximum utility value that can be returned.

Return type:

float

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

abstract min()

Finds the minimum utility value that can be returned.

Return type:

float

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

minmax()[source]

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

Return type:

tuple[float, float]

Remarks:

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

next_better()

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

Return type:

tuple | None

next_worse()

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

Return type:

tuple | None

one_in(rng, normalized, fallback_to_higher=True, fallback_to_best=True)[source]

Finds an outcmoe with the given utility value.

Parameters:
  • rng (float | tuple[float, float]) – The range (or single value) of utility values to search for outcomes

  • normalized (float) – 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.

Return type:

tuple | None

some(rng, normalized, n=None)[source]

Finds some outcomes with the given utility value (if discrete, all)

Parameters:
  • rng (float | tuple[float, float]) – The range. If a value, outcome utilities must match it exactly

  • n (int | None) – The maximum number of outcomes to return

Return type:

list[tuple]

Remarks:
  • If issues or outcomes are not None, then init_inverse will be called first

  • If the outcome-space is discrete, this method will return all outcomes in the given range

abstract within_fractions(rng)

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

Return type:

list[tuple]

abstract within_indices(rng)

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

Return type:

list[tuple]

Remarks:
  • Works only for discrete outcome spaces

abstract worst()

Finds the worst outcome

Return type:

tuple

worst_in(rng, normalized)[source]

Finds an outcome with lowest utility within the given range

Parameters:
  • rng (float | tuple[float, float]) – The range (or single value) of utility values to search for outcomes

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

Return type:

tuple | None