lit_sb3.utils.spaces
source module lit_sb3.utils.spaces
Gymnasium observation-space shape validation helpers.
Functions
-
check_for_correct_spaces — Checks that the environment has same spaces as provided ones. Used by BaseAlgorithm to check if.
-
check_shape_equal — If the spaces are Box, check that they have the same shape.
-
is_vectorized_box_observation — For box observation type, detects and validates the shape,.
-
is_vectorized_discrete_observation — For discrete observation type, detects and validates the shape,.
-
is_vectorized_multidiscrete_observation — For multidiscrete observation type, detects and validates the shape,.
-
is_vectorized_multibinary_observation — For multibinary observation type, detects and validates the shape,.
-
is_vectorized_dict_observation — For dict observation type, detects and validates the shape,.
-
is_vectorized_observation — For every observation type, detects and validates the shape,.
source check_for_correct_spaces(env: GymEnv, observation_space: spaces.Space, action_space: spaces.Space) → None
Checks that the environment has same spaces as provided ones. Used by BaseAlgorithm to check if.
spaces match after loading the model with given env. Checked parameters: - observation_space - action_space.
Parameters
-
env : GymEnv — Environment to check for valid spaces
-
observation_space : spaces.Space — Observation space to check against
-
action_space : spaces.Space — Action space to check against
Raises
-
ValueError
source check_shape_equal(space1: spaces.Space, space2: spaces.Space) → None
If the spaces are Box, check that they have the same shape.
If the spaces are Dict, it recursively checks the subspaces.
Parameters
-
space1 : spaces.Space — Space
-
space2 : spaces.Space — Other space
source is_vectorized_box_observation(observation: np.ndarray, observation_space: spaces.Box) → bool
For box observation type, detects and validates the shape,.
then returns whether or not the observation is vectorized.
Parameters
-
observation : np.ndarray — the input observation to validate
-
observation_space : spaces.Box — the observation space
Returns
-
bool — whether the given observation is vectorized or not
Raises
-
ValueError
source is_vectorized_discrete_observation(observation: int | np.ndarray, observation_space: spaces.Discrete) → bool
For discrete observation type, detects and validates the shape,.
then returns whether or not the observation is vectorized.
Parameters
-
observation : int | np.ndarray — the input observation to validate
-
observation_space : spaces.Discrete — the observation space
Returns
-
bool — whether the given observation is vectorized or not
Raises
-
ValueError
source is_vectorized_multidiscrete_observation(observation: np.ndarray, observation_space: spaces.MultiDiscrete) → bool
For multidiscrete observation type, detects and validates the shape,.
then returns whether or not the observation is vectorized.
Parameters
-
observation : np.ndarray — the input observation to validate
-
observation_space : spaces.MultiDiscrete — the observation space
Returns
-
bool — whether the given observation is vectorized or not
Raises
-
ValueError
source is_vectorized_multibinary_observation(observation: np.ndarray, observation_space: spaces.MultiBinary) → bool
For multibinary observation type, detects and validates the shape,.
then returns whether or not the observation is vectorized.
Parameters
-
observation : np.ndarray — the input observation to validate
-
observation_space : spaces.MultiBinary — the observation space
Returns
-
bool — whether the given observation is vectorized or not
Raises
-
ValueError
source is_vectorized_dict_observation(observation: np.ndarray, observation_space: spaces.Dict) → bool
For dict observation type, detects and validates the shape,.
then returns whether or not the observation is vectorized.
Parameters
-
observation : np.ndarray — the input observation to validate
-
observation_space : spaces.Dict — the observation space
Returns
-
bool — whether the given observation is vectorized or not
Raises
-
ValueError
source is_vectorized_observation(observation: int | np.ndarray, observation_space: spaces.Space) → bool
For every observation type, detects and validates the shape,.
then returns whether or not the observation is vectorized.
Parameters
-
observation : int | np.ndarray — the input observation to validate
-
observation_space : spaces.Space — the observation space
Returns
-
bool — whether the given observation is vectorized or not
Raises
-
ValueError