ContinuousInfiniteIssue

class negmas.outcomes.ContinuousInfiniteIssue(values, name=None, n_levels=10)[source]

Bases: ContinuousIssue, InfiniteIssue

An issue that can represent all real numbers

Attributes Summary

all

A generator that generates all possible values.

cardinality

The number of possible outcomes for the issue.

type

Returns a nice name for the issue type

value_type

Returns the type of values in this issue

values

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()

has_finite_limits()

Checks whether the minimum and maximum values of the issue are known and are finite

has_limits()

Checks whether the minimum and maximum values of the issue are known

is_continuous()

The issue has a continuous set of values.

is_discrete()

Checks whether the issue has a discrete set of values.

is_discrete_valued()

Checks that each value of this issue is not a real number

is_finite()

Checks whether the issue has a discrete set of values

is_float()

Checks that each value of this issue is a real number

is_integer()

Checks that each value of this issue is an integer

is_numeric()

Checks that each value of this issue is a number

is_uncountable()

rtype:

bool

is_valid(v)

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.

rand_invalid()

Pick a random invalid value

rand_outcomes(n[, with_replacement, ...])

Picks n random valid value (at most).

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, 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
cardinality
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 or generate_values

Methods Documentation

contains(issue)[source]

Checks weather this issue contains the input issue (i.e. every value in the input issue is in this issue)

Return type:

bool

classmethod from_dict(d)

Constructs an issue from a dict generated using to_dict()

has_finite_limits()

Checks whether the minimum and maximum values of the issue are known and are finite

Return type:

bool

has_limits()

Checks whether the minimum and maximum values of the issue are known

Return type:

bool

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:

bool

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 and is_discrete_valued which checks that they are discrete.

Return type:

bool

is_discrete_valued()

Checks that each value of this issue is not a real number

Return type:

bool

is_finite()

Checks whether the issue has a discrete set of values

Return type:

bool

is_float()

Checks that each value of this issue is a real number

Return type:

bool

is_integer()

Checks that each value of this issue is an integer

Return type:

bool

is_numeric()

Checks that each value of this issue is a number

Return type:

bool

is_uncountable()
Return type:

bool

is_valid(v)

Checks whether the given value is valid for this issue

ordered_value_generator(n=10, grid=True, compact=False, endpoints=True)

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 fail

  • 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:

Generator[float, None, None]

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()

Picks a random valid value.

Return type:

float

rand_invalid()

Pick a random invalid value

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 sample

  • with_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 to n

Return type:

list[float]

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 int

  • grid (bool) – Sample on a grid

  • compact (bool) – Sample around the center

  • endpoints (bool) – Always incllude minimum and maximum values

Return type:

DiscreteIssue

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.

value_generator(n=10, grid=True, compact=False, 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

Return type:

Generator[float, None, None]

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]