OrdinalIssue
- class negmas.outcomes.OrdinalIssue(values, name=None)[source]
Bases:
negmas.outcomes.base_issue.Issue
An
Issue
that have some defined ordering of outcomes but not necessarily a meaningful difference function between its values.Attributes Summary
A generator that generates all possible values.
The number of possible outcomes for the issue.
Returns a nice name for the issue type
Returns the type of values in this issue
Returns the raw values representation of the issue.
Methods Summary
contains
(issue)Checks weather this issue contains the input issue (i.e.
from_dict
(d)Constructs an issue from a dict generated using
to_dict()
Checks whether the minimum and maximum values of the issue are known and are finite
Checks whether the minimum and maximum values of the issue are known
The issue has a continuous set of values.
Checks whether the issue has a discrete set of values.
Checks that each value of this issue is not a real number
Checks whether the issue has a discrete set of values
is_float
()Checks that each value of this issue is a real number
Checks that each value of this issue is an integer
Checks that each value of this issue is a number
is_valid
(v)Checks whether the given value is valid for this issue
ordered_value_generator
([n, grid, compact, ...])rand
()Picks a random valid value.
Pick a random invalid value
rand_outcomes
(n[, with_replacement, ...])Picks n random valid value (at most).
Generates a random valid value for this issue
to_dict
()Converts the issue to a dictionary from which it can be constructed again using
Issue.from_dict()
to_discrete
([n, grid, compact, endpoints])Converts the issue to a discrete issue by samling from it.
value_at
(index)Returns the value at the given indes of the issue.
value_generator
([n, grid, compact, endpoints])A generator that generates at most
n
values (in any order)Attributes Documentation
- cardinality
The number of possible outcomes for the issue. Returns infinity for continuous and uncountable spaces
- value_type
Returns the type of values in this issue
- values
Returns the raw values representation of the issue. Only use if you know what you are doing. To get all the values that can be assigned to this issue use
all
orgenerate_values
Methods Documentation
- contains(issue)
Checks weather this issue contains the input issue (i.e. every value in the input issue is in this issue)
- Return type
- has_finite_limits()
Checks whether the minimum and maximum values of the issue are known and are finite
- Return type
- abstract is_continuous()
The issue has a continuous set of values. Note that this is different from having values that are real (which is tested using
is_float
)- Return type
- is_discrete()
Checks whether the issue has a discrete set of values. This is different from
is_integer
which checks that the values themselves are integers andis_discrete_valued
which checks that they are discrete.- Return type
- abstract is_valid(v)
Checks whether the given value is valid for this issue
- abstract rand_invalid()
Pick a random invalid value
- abstract rand_outcomes(n, with_replacement=False, fail_if_not_enough=False)
Picks n random valid value (at most).
- Parameters
n (
int
) – The number of outcome values to samplewith_replacement – If true, sampling is done with replacement (i.e.repetition is allowed)
fail_if_not_enough – If true, raises an exception if it is not possible to sample exactly
n
values. If false, will sample as many values as possible up ton
- Return type
- Returns
A list of sampled values
- rand_valid()
Generates a random valid value for this issue
- to_dict()
Converts the issue to a dictionary from which it can be constructed again using
Issue.from_dict()
- to_discrete(n=10, grid=True, compact=True, endpoints=True)
Converts the issue to a discrete issue by samling from it. If the issue is already discret it will just return itself
- Parameters
- Return type
- abstract value_at(index)
Returns the value at the given indes of the issue. The same index will have the same values always indepdendent of whether the values of the issue have defined ordering.
- abstract value_generator(n=10, grid=True, compact=True, endpoints=True)
A generator that generates at most
n
values (in any order)- Parameters
grid – Sample on a grid (equally distanced as much as possible)
compact – If True, the samples will be choosen near each other (see endpoints though)
endpoints – If given, the first and last index are guaranteed to be in the samples
- Remarks:
This function returns a generator for the case when the number of values is very large.
If you need a list then use something like:
>>> from negmas.outcomes import make_issue >>> list(make_issue(5).value_generator()) [0, 1, 2, 3, 4] >>> list(int(10 * _) for _ in make_issue((0.0, 1.0)).value_generator(11)) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
- Return type
Generator[Any, None, None]