Noisy Wrappers#

This module provides wrappers that introduce noise into the agent’s interaction with the environment, either through action perturbations or observation corruption.

Descriptions#

  • NoisyActionWrapper: Adds noise to the actions. For discrete actions, actions may be randomly replaced. For continuous actions, Gaussian noise is added.

  • NoisyObservationWrapper: Adds Gaussian noise to observations. Supports both NumPy arrays and dictionaries.

Classes#

class objectrl.utils.environment.noisy_wrappers.NoisyActionWrapper(env: Env, noise_act: float = 0.1)[source]#

Bases: ActionWrapper

A Gymnasium wrapper that injects noise into the agent’s actions. For discrete action spaces, the action is randomly replaced with another action with a given probability. For continuous action spaces, Gaussian noise is added.

env#

The environment to wrap.

Type:

gym.Env

noise_act#

Noise level for the action. - For discrete spaces: probability of replacing the action. - For continuous spaces: standard deviation of Gaussian noise.

Type:

float

__init__(env: Env, noise_act: float = 0.1) None[source]#

Initialize the NoisyActionWrapper.

Parameters:
  • env (gym.Env) – The environment to wrap.

  • noise_act (float) – Noise level for the action. - For discrete spaces: probability of replacing the action. - For continuous spaces: standard deviation of Gaussian noise.

Returns:

None

step(action: ndarray) tuple[source]#

Modify the action by injecting noise, then step the environment.

Parameters:

action – The original action chosen by the agent.

Returns:

(obs, reward, terminated, truncated, info) after stepping the env.

Return type:

Tuple

class objectrl.utils.environment.noisy_wrappers.NoisyObservationWrapper(env: Env, noise_obs: float = 0.1)[source]#

Bases: ObservationWrapper

A Gymnasium wrapper that injects noise into observations. Adds Gaussian noise to array-based observations or to values in dictionary observations.

env#

The environment to wrap.

Type:

gym.Env

noise_obs#

Standard deviation of Gaussian noise added to observations.

Type:

float

__init__(env: Env, noise_obs: float = 0.1) None[source]#

Initialize the NoisyObservationWrapper.

Parameters:
  • env (gym.Env) – The environment to wrap.

  • noise_obs (float) – Standard deviation of Gaussian noise added to observations.

Returns:

None

observation(obs: ndarray | dict) ndarray | dict[source]#

Apply Gaussian noise to the observation.

Parameters:

obs (np.ndarray or dict) – The observation to be noised.

Returns:

The noisy observation.

Return type:

np.ndarray or dict