PresortingInverseUtilityFunction
- class negmas.preferences.PresortingInverseUtilityFunction(ufun, levels=10, max_cache_size=10000000000, rational_only=False, n_waypints=10, eps=1e-12, rel_eps=1e-06)[source]
Bases:
InverseUFun
A utility function inverter that uses pre-sorting.
The outcome-space is sampled if it is continuous and enumerated if it is discrete during the call to
init()
and an ordered list of outcomes with their utility values is then cached.- Parameters:
ufun (
BaseUtilityFunction
) – The utility function to be invertedlevels (
int
) – discretization levels per issuemax_cache_size (
int
) – maximum allowed number of outcomes in the resulting inverserational_only (
bool
) – If true, rational outcomes will be sorted but irrational outcomes will not be sorted (should be faster if the reserved value is high)n_waypoints – Used to speedup sampling outcomes at given utilities. The larger, the slower init() will be but the faster worst_in() and best_in()
eps (
float
) – Absolute difference between utility values to consider them equal (zero or negative to disable).rel_eps (
float
) – Relative difference between utility values to consider them equal (zero or negative to disable).
- Remarks:
The actual limit used to judge ufun equality is max(eps, rel_eps * range) where range is the difference between max and min utilities for rational outcomes. Set both eps, rel_eps to zero or a negative number to disable cycling through outcomes with equal utilities (or set cycle=False when calling the appropriate function).
Attributes Summary
Methods Summary
__call__
(rng, normalized)Calling an inverse ufun directly is equivalent to calling
one_in()
all
(rng, normalized)Finds all outcomes with in the given utility value range
best
()Finds the best outcome (of the rational outcomes if constructed with
sort_rational_only
)best_in
(rng, normalized[, cycle])Finds an outcome with the highest possible utility within the given range (if any)
Finds the worst and best outcomes that can be returned.
init
()Used to intialize the inverse ufun.
max
()Finds the maximum rational utility value (of the rational outcomes if constructed with
sort_rational_only
)min
()Finds the minimum utility value (of the rational outcomes if constructed with
sort_rational_only
)minmax
()Finds the minimum and maximum utility values that can be returned.
Returns the rational outcome with utility just above the last one returned from this function
Returns the rational outcome with utility just below the last one returned from this function
one_in
(rng, normalized[, ...])Finds an outcome within the given range of utilities.
outcome_at
(indx)reset
()- rtype:
some
(rng, normalized[, n])Finds some outcomes with the given utility value (if discrete, all)
utility_at
(indx)- rtype:
within_fractions
(rng)Finds outcomes within the given fractions of utility values (the fractions must be between zero and one).
within_indices
(rng)Finds outcomes within the given indices with the best at index 0 and the worst at largest index.
worst
()Finds the worst outcome (of the rational outcomes if constructed with
sort_rational_only
)worst_in
(rng, normalized[, cycle])Finds an outcome with the lowest possible utility within the given range (if any)
Attributes Documentation
- initialized: bool
- ufun: UFun
Methods Documentation
- __call__(rng, normalized)[source]
Calling an inverse ufun directly is equivalent to calling
one_in()
- all(rng, normalized)[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:
- 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
- best()[source]
Finds the best outcome (of the rational outcomes if constructed with
sort_rational_only
)
- best_in(rng, normalized, cycle=True)[source]
Finds an outcome with the highest possible utility within the given range (if any)
- Parameters:
- Return type:
- Remarks:
Returns None if no such outcome exists
This is an O(log(n)) operation (where n is the number of outcomes)
- extreme_outcomes()[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.
- max()[source]
Finds the maximum rational utility value (of the rational outcomes if constructed with
sort_rational_only
)- Return type:
- min()[source]
Finds the minimum utility value (of the rational outcomes if constructed with
sort_rational_only
)- Return type:
- minmax()[source]
Finds the minimum and maximum utility values that can be returned.
Remarks: :rtype:
tuple
[float
,float
]These may be different from the results of
ufun.minmax()
as they can be approximate.Will only consider rational outcomes if constructed with
sort_rational_only
- next_better()[source]
Returns the rational outcome with utility just above the last one returned from this function
- next_worse()[source]
Returns the rational outcome with utility just below the last one returned from this function
- one_in(rng, normalized, fallback_to_higher=True, fallback_to_best=True)[source]
Finds an outcome within the given range of utilities.
- Remarks:
This is an O(log(n)) operation (where n is the number of outcomes)
We only search rational outcomes
- some(rng, normalized, n=None)[source]
Finds some outcomes with the given utility value (if discrete, all)
- Parameters:
- Return type:
- 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
- within_fractions(rng)[source]
Finds outcomes within the given fractions of utility values (the fractions must be between zero and one).
- Remarks:
This is an O(n) operation (where n is the number of outcomes)
- within_indices(rng)[source]
Finds outcomes within the given indices with the best at index 0 and the worst at largest index.
- Remarks:
Works only for discrete outcome spaces
- worst()[source]
Finds the worst outcome (of the rational outcomes if constructed with
sort_rational_only
)
- worst_in(rng, normalized, cycle=True)[source]
Finds an outcome with the lowest possible utility within the given range (if any)
- Parameters:
- Return type:
- Remarks:
Returns None if no such outcome exists, or the worst outcome in the given range is irrational
This is an O(log(n)) operation (where n is the number of outcomes)