Module ai.environments.action_spaces
Action spaces for environments.
Expand source code
"""Action spaces for environments."""
from ._base import Base
from ._discrete import Discrete
__all__ = ["Base", "Discrete"]
Classes
class Base-
Base environment action space.
Ancestors
- abc.ABC
Subclasses
Methods
def as_discrete(self) ‑> Discrete-
Casts this object to a discrete action space. This operation is equivalent to
as_type(action_spaces.Discrete).Expand source code
def as_discrete(self) -> "ai.environments.action_spaces.Discrete": """Casts this object to a discrete action space. This operation is equivalent to `as_type(action_spaces.Discrete)`.""" return self.as_type(ai.environments.action_spaces.Discrete) def as_type(self, t: ~T) ‑> ~T-
Casts the action space to the specific type.
Args
t:T- Type to which the space should be cast
Raises
RuntimeError- If the object is not castable to the requested type.
Returns
T- The same object.
Expand source code
def as_type(self, t: T) -> T: """Casts the action space to the specific type. Args: t (T): Type to which the space should be cast Raises: RuntimeError: If the object is not castable to the requested type. Returns: T: The same object. """ if not isinstance(self, t): raise RuntimeError(f"Failed casting {self} to {t}") return self def contains(self, action: Any) ‑> bool-
Determines if the given action is in the action space or not.
Args
action:Any- Action.
Returns
bool- True if the given action is legal, otherwise False.
Expand source code
@abstractmethod def contains(self, action: Any) -> bool: """Determines if the given action is in the action space or not. Args: action (Any): Action. Returns: bool: True if the given action is legal, otherwise False. """ raise NotImplementedError def sample(self) ‑> Any-
Samples an action from the action space.
Returns
Any- An action.
Expand source code
@abstractmethod def sample(self) -> Any: """Samples an action from the action space. Returns: Any: An action. """ raise NotImplementedError
class Discrete-
Discrete action space.
Discrete action spaces identify actions using the an integer and have a fixed size. Moreover, all action are not necessarily legal in every state. Legal actions are given by the action mask, a boolean vector whose elements at legal action indices are
Trueand illegal action indicesFalse.Ancestors
- Base
- abc.ABC
Subclasses
- ai.environments._gym_wrapper.GymWrapper.ActionSpace
Instance variables
var action_mask : numpy.ndarray-
The boolean action mask of the current environmental state. Legal actions are marked with
Trueand illegal actions withFalse.Expand source code
@property @abstractmethod def action_mask(self) -> np.ndarray: """The boolean action mask of the current environmental state. Legal actions are marked with `True` and illegal actions with `False`.""" raise NotImplementedError var size : int-
The size of the discrete action space.
Expand source code
@property @abstractmethod def size(self) -> int: """The size of the discrete action space.""" raise NotImplementedError
Inherited members