NLevelsComparatorMixin

class negmas.negotiators.NLevelsComparatorMixin[source]

Bases: object

Attributes Summary

thresholds

Returns the internal thresholds and None if they do not exist

Methods Summary

compare_nlevels(first, second[, n])

Compares two offers using the ufun returning an integer in [-n, n] (i.e.

equiprobable_thresholds(n, ufun, issues[, …])

Generates thresholds for the n given levels where levels are equally likely approximately

generate_thresholds(n[, ufun_min, ufun_max, …])

Generates thresholds for the n given levels assuming the ufun ranges and scale function

init()

is_better(first, second[, epsilon])

Compares two offers using the ufun returning whether the first is better than the second

Attributes Documentation

thresholds

Returns the internal thresholds and None if they do not exist

Methods Documentation

compare_nlevels(first: Outcome, second: Outcome, n: int = 2)Optional[int][source]

Compares two offers using the ufun returning an integer in [-n, n] (i.e. 2n+1 possible values) which defines which outcome is better and the strength of the difference (discretized using internal thresholds)

Parameters
  • first – First outcome to be compared

  • second – Second outcome to be compared

  • n – number of levels to use

Returns

  • None if either there is no ufun defined or the number of thresholds required cannot be satisfied

  • 0 iff |u(first) - u(second)| <= thresholds[0]

  • -i if
    • thresholds[i-1] < u(first) - u(second) <= -thresholds[i]

  • +i if

    thresholds[i-1] > u(first) - u(second) >= thresholds[i]

Remarks:

  • thresholds is an internal array that can be set using thresholds property

  • thresholds[n] is assumed to equal infinity

  • n must be <= the length of the internal thresholds array. If n > that length, a ValueError will be raised. If n < the length of the internal thresholds array, the first n values of the array will be used

classmethod equiprobable_thresholds(n: int, ufun: UtilityFunction, issues: List[negmas.outcomes.Issue], n_samples: int = 1000)List[float][source]

Generates thresholds for the n given levels where levels are equally likely approximately

Parameters
  • n – Number of scale levels (one side)

  • ufun – The utility function to use

  • issues – The issues to generate the thresholds for

  • n_samples – The number of samples to use during the process

classmethod generate_thresholds(n: int, ufun_min: float = 0.0, ufun_max: float = 1.0, scale: Optional[Union[str, Callable[[float], float]]] = None)List[float][source]

Generates thresholds for the n given levels assuming the ufun ranges and scale function

Parameters
  • n – Number of scale levels (one side)

  • ufun_min – minimum value of all utilities

  • ufun_max – maximum value of all utilities

  • scale – Scales the ufun values. Can be a callable or ‘log’, ‘exp’, ‘linear’. If None, it is ‘linear’

init()[source]
is_better(first: Outcome, second: Outcome, epsilon: float = 1e-10)Optional[bool][source]

Compares two offers using the ufun returning whether the first is better than the second

Parameters
  • first – First outcome to be compared

  • second – Second outcome to be compared

  • epsilon – comparison threshold. If the utility difference within the range [-epsilon, epsilon] the two outcomes are assumed to be compatible

Returns

True if utility(first) > utility(second) + epsilon None if |utility(first) - utility(second)| <= epsilon or the utun is not defined False if utility(first) < utility(second) - epsilon