CallableIssue
- class negmas.outcomes.CallableIssue(values, name=None)[source]
Bases:
Issue
An
Issue
with a callable for generating values. This is a very limited issue type and most operations are not supported on it.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. every value in the input issue is in this issue).
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
- rtype:
is_valid
()Checks whether the given value is valid for this issue
ordered_value_generator
([n, grid, compact, ...])A generator that generates at most
n
values (in a stable order)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
- all
A generator that generates all possible values.
- cardinality
The number of possible outcomes for the issue. Returns infinity for continuous and uncountable spaces
- type
- 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:
- has_limits()
Checks whether the minimum and maximum values of the issue are known
- Return type:
- is_continuous()[source]
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:
- ordered_value_generator(n=10, grid=True, compact=False, endpoints=True)[source]
A generator that generates at most
n
values (in a stable order)- Parameters:
n (
int
|float
|None
) – The number of samples. If inf or None, all values will be generated but when the issue is infinite, it will just failgrid – 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
- Return type:
- Remarks:
This function returns a generator for the case when the number of values is very large.
If the order is not defined for this issue, this generator will still generate values in the same order every time it is called.
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]
- rand_outcomes(n, with_replacement=False, fail_if_not_enough=False)[source]
Picks n random valid value (at most).
- Parameters:
- 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. This method cannot be used to reduce the cardinality of a discrete issue.
- Parameters:
n (int | float | None) – Number of values in the resulting discrete issue. This will be ignored if the issue is already discrete. The only allowed float value is
float("inf")
. If any other float is passed, it will be silently cast to an intgrid (bool) – Sample on a grid
compact (bool) – Sample around the center
endpoints (bool) – Always incllude minimum and maximum values
- Return type:
- value_at(index)[source]
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.
- value_generator(n=10, grid=True, compact=False, endpoints=True)[source]
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
- Return type:
- 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]