DiscreteOutcomeSpace

class negmas.outcomes.DiscreteOutcomeSpace(*args, **kwargs)[source]

Bases: OutcomeSpace, Collection, Protocol

The base protocol for all outcome spaces with a finite number of items.

This type of outcome-space acts as a standard python Collection which means that its length can be found using len() and it can be iterated over to return outcomes.

Attributes Summary

cardinality

The space cardinality = the number of outcomes

Methods Summary

are_types_ok(outcome)

Checks if the type of each value in the outcome is correct for the given issue

cardinality_if_discretized(levels[, ...])

Returns the cardinality if discretized the given way.

ensure_correct_types(outcome)

Returns an outcome that is guaratneed to have correct types or raises an exception

enumerate()

Enumerates the outcome space returning all its outcomes (or up to max_cardinality for infinite ones)

enumerate_or_sample([levels, max_cardinality])

Enumerates all outcomes if possible (i.e. discrete space) or returns max_cardinality different outcomes otherwise.

is_discrete()

Checks whether there are no continua components of the space

is_finite()

Checks whether the space is finite

is_float()

Checks whether all values in all outcomes are real

is_integer()

Checks whether all values in all outcomes are integers

is_numeric()

Checks whether all values in all outcomes are numeric

is_valid(outcome)

Checks if the given outcome is valid for that outcome space

limit_cardinality([max_cardinality, levels])

Limits the cardinality of the outcome space to the given maximum (or the number of levels for each issue to Logging Levels)

random_outcome()

Returns a single random outcome.

sample(n_outcomes[, with_replacement, ...])

Samples up to n_outcomes with or without replacement

to_discrete(*args, **kwargs)

Returns a stable finite outcome space.

to_largest_discrete(levels[, max_cardinality])

rtype:

DiscreteOutcomeSpace

to_single_issue([numeric, stringify])

rtype:

CartesianOutcomeSpace

Attributes Documentation

cardinality

The space cardinality = the number of outcomes

Methods Documentation

are_types_ok(outcome)

Checks if the type of each value in the outcome is correct for the given issue

Return type:

bool

cardinality_if_discretized(levels, max_cardinality=inf)

Returns the cardinality if discretized the given way.

Return type:

int

ensure_correct_types(outcome)

Returns an outcome that is guaratneed to have correct types or raises an exception

Return type:

tuple

enumerate()[source]

Enumerates the outcome space returning all its outcomes (or up to max_cardinality for infinite ones)

Return type:

Iterable[tuple]

enumerate_or_sample(levels=inf, max_cardinality=inf)

Enumerates all outcomes if possible (i.e. discrete space) or returns max_cardinality different outcomes otherwise

Return type:

Iterable[tuple]

is_discrete()[source]

Checks whether there are no continua components of the space

Return type:

bool

is_finite()

Checks whether the space is finite

Return type:

bool

is_float()

Checks whether all values in all outcomes are real

Return type:

bool

is_integer()

Checks whether all values in all outcomes are integers

Return type:

bool

is_numeric()

Checks whether all values in all outcomes are numeric

Return type:

bool

is_valid(outcome)

Checks if the given outcome is valid for that outcome space

Return type:

bool

limit_cardinality(max_cardinality=inf, levels=inf)[source]

Limits the cardinality of the outcome space to the given maximum (or the number of levels for each issue to Logging Levels)

Parameters:
  • max_cardinality (int | float) – The maximum number of outcomes in the resulting space

  • levels (int | float) – The maximum levels allowed per issue (if issues are defined for this outcome space)

Return type:

DiscreteOutcomeSpace

random_outcome()

Returns a single random outcome.

Return type:

tuple

sample(n_outcomes, with_replacement=False, fail_if_not_enough=True)[source]

Samples up to n_outcomes with or without replacement

Return type:

Iterable[tuple]

to_discrete(*args, **kwargs)[source]

Returns a stable finite outcome space. If the outcome-space is already finite. It shoud return itself.

Parameters:
  • levels – The levels of discretization of any continuous dimension (or subdimension)

  • max_cardintlity – The maximum cardinality allowed for the resulting outcomespace (if the original OS was infinite). This limitation is NOT applied for outcome spaces that are alredy discretized. See limit_cardinality() for a method to limit the cardinality of an already discrete space

Return type:

DiscreteOutcomeSpace

If called again, it should return the same discrete outcome space every time.

to_largest_discrete(levels, max_cardinality=inf, **kwargs)
Return type:

DiscreteOutcomeSpace

to_single_issue(numeric=False, stringify=True)[source]
Return type:

CartesianOutcomeSpace