OutcomeSpace

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

Bases: Container, Protocol

The base protocol for all outcome spaces.

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_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

random_outcome()

Returns a single random outcome.

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

Samples up to n_outcomes with or without replacement

to_discrete([levels, max_cardinality])

Returns a stable finite outcome space.

to_largest_discrete(levels[, max_cardinality])

Attributes Documentation

cardinality

The space cardinality = the number of outcomes

Methods Documentation

are_types_ok(outcome: Outcome) bool[source]

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

cardinality_if_discretized(levels: int, max_cardinality: int | float = inf) int[source]

Returns the cardinality if discretized the given way.

ensure_correct_types(outcome: Outcome) Outcome[source]

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

enumerate_or_sample(levels: int | float = inf, max_cardinality: int | float = inf) Iterable[Outcome][source]

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

is_discrete() bool[source]

Checks whether there are no continua components of the space

is_finite() bool[source]

Checks whether the space is finite

is_float() bool[source]

Checks whether all values in all outcomes are real

is_integer() bool[source]

Checks whether all values in all outcomes are integers

is_numeric() bool[source]

Checks whether all values in all outcomes are numeric

is_valid(outcome: Outcome) bool[source]

Checks if the given outcome is valid for that outcome space

random_outcome() Outcome[source]

Returns a single random outcome.

sample(n_outcomes: int, with_replacement: bool = False, fail_if_not_enough=False) Iterable[Outcome][source]

Samples up to n_outcomes with or without replacement

to_discrete(levels: int | float = 5, max_cardinality: int | float = inf) DiscreteOutcomeSpace[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

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

to_largest_discrete(levels: int, max_cardinality: int | float = inf, **kwargs) DiscreteOutcomeSpace[source]