diff --git a/main/.buildinfo b/main/.buildinfo index 23634d87..eff504a5 100644 --- a/main/.buildinfo +++ b/main/.buildinfo @@ -1,4 +1,4 @@ # Sphinx build info version 1 # This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done. -config: 1217b94e9dc320c1a5d71bcf937829f3 +config: cd422c5b5b718dd83afa00fd16b26bf7 tags: d77d1c0d9ca2f4c8421862c7c5a0d620 diff --git a/main/404.html b/main/404.html index c824cb4c..b764deaa 100644 --- a/main/404.html +++ b/main/404.html @@ -230,6 +230,7 @@
  • YMaze
  • +
  • Wrapper
  • Tutorial on Creating Environments
  • Troubleshooting Guide
  • Installation
  • @@ -313,7 +314,7 @@

    The requested page could not be found.
    + Overview: module code - Miniworld Documentation + + + + + + + + + +
    + +
    + + + + + + + + Contents + + + + + + Menu + + + + + + + + Expand + + + + + + Light mode + + + + + + + + + + + + + + Dark mode + + + + + + + Auto light/dark mode + + + + + + + + + + + + + + + + + +
    + + +
    + + + + + +
    +
    +
    + + + + + Back to top + +
    + +
    + +
    + +
    +
    + + +
    +
    + + +
    +
    + +
    +
    + +
    +
    + +
    +
    +
    + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/main/_modules/miniworld/wrappers/index.html b/main/_modules/miniworld/wrappers/index.html new file mode 100644 index 00000000..096d1016 --- /dev/null +++ b/main/_modules/miniworld/wrappers/index.html @@ -0,0 +1,631 @@ + + + + + + + + + + + + + + miniworld.wrappers - Miniworld Documentation + + + + + + + + + +
    +
    +
    + +
    + +
    +
    + + +
    +
    +
    +
    + + + + + + + + Contents + + + + + + Menu + + + + + + + + Expand + + + + + + Light mode + + + + + + + + + + + + + + Dark mode + + + + + + + Auto light/dark mode + + + + + + + + + + + + + + + + + +
    + + +
    + + + + + +
    +
    +
    + + + + + Back to top + +
    + +
    + +
    +
    + +

    Source code for miniworld.wrappers

    +from typing import Optional
    +
    +import gymnasium as gym
    +import numpy as np
    +
    +
    +
    +[docs] +class PyTorchObsWrapper(gym.ObservationWrapper): + """ + Transpose the observation image tensors for PyTorch + """ + + def __init__(self, env): + super().__init__(env) + + obs_shape = self.observation_space.shape + self.observation_space = gym.spaces.Box( + self.observation_space.low[0, 0, 0], + self.observation_space.high[0, 0, 0], + [obs_shape[2], obs_shape[1], obs_shape[0]], + dtype=self.observation_space.dtype, + ) + + def observation(self, observation): + return observation.transpose(2, 1, 0)
    + + + +
    +[docs] +class GreyscaleWrapper(gym.ObservationWrapper): + """ + Convert image observations from RGB to greyscale + """ + + def __init__(self, env): + super().__init__(env) + + obs_shape = self.observation_space.shape + self.observation_space = gym.spaces.Box( + self.observation_space.low[0, 0, 0], + self.observation_space.high[0, 0, 0], + (obs_shape[0], obs_shape[1], 1), + dtype=self.observation_space.dtype, + ) + + def observation(self, obs): + obs = 0.30 * obs[:, :, 0] + 0.59 * obs[:, :, 1] + 0.11 * obs[:, :, 2] + + return np.expand_dims(obs, axis=2)
    + + + +
    +[docs] +class StochasticActionWrapper(gym.ActionWrapper): + """ + Add stochasticity to the actions + + If a random action is provided, it is returned with probability `1 - prob`. + Else, a random action is sampled from the action space. + """ + + def __init__(self, env, prob: float = 0.9, random_action: Optional[int] = None): + super().__init__(env) + + self.prob = prob + self.random_action = random_action + + def action(self, action): + """ """ + if self.np_random.uniform() < self.prob: + return action + else: + if self.random_action is None: + return self.np_random.integers(0, 6) + else: + return self.random_action
    + +
    +
    +
    +
    + + +
    +
    + + +
    +
    + +
    +
    + +
    +
    + +
    +
    +
    + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/main/content/create_env/index.html b/main/content/create_env/index.html index 37ae36e3..02158df3 100644 --- a/main/content/create_env/index.html +++ b/main/content/create_env/index.html @@ -8,7 +8,7 @@ - + @@ -230,6 +230,7 @@
  • YMaze
  • +
  • Wrapper
  • Tutorial on Creating Environments
  • Troubleshooting Guide
  • Installation
  • @@ -370,7 +371,7 @@

    Add reward - + @@ -379,7 +380,7 @@

    Add rewardYMaze

    +
    Wrapper
    @@ -387,7 +388,7 @@

    Add reward
    + Wrapper - Miniworld Documentation + + + + + + + + + +
    + +
    + + + + + + + + Contents + + + + + + Menu + + + + + + + + Expand + + + + + + Light mode + + + + + + + + + + + + + + Dark mode + + + + + + + Auto light/dark mode + + + + + + + + + + + + + + + + + +
    + + +
    + + + + + +
    +
    +
    + + + + + Back to top + +
    + +
    + +
    +
    + +
    +

    Wrapper

    +

    Miniworld include several built in wrapper available to researchers in miniworld.wrappers

    +
    +
    +class miniworld.wrappers.PyTorchObsWrapper(env)[source]
    +

    Transpose the observation image tensors for PyTorch

    +
    + +
    +
    +class miniworld.wrappers.GreyscaleWrapper(env)[source]
    +

    Convert image observations from RGB to greyscale

    +
    + +
    +
    +class miniworld.wrappers.StochasticActionWrapper(env, prob: float = 0.9, random_action: int | None = None)[source]
    +

    Add stochasticity to the actions

    +

    If a random action is provided, it is returned with probability 1 - prob. +Else, a random action is sampled from the action space.

    +
    + +
    + +
    +
    + +
    + +
    +
    +
    + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/main/environments/collecthealth/index.html b/main/environments/collecthealth/index.html index b32764d6..61c578e2 100644 --- a/main/environments/collecthealth/index.html +++ b/main/environments/collecthealth/index.html @@ -230,6 +230,7 @@
  • YMaze
  • +
  • Wrapper
  • Tutorial on Creating Environments
  • Troubleshooting Guide
  • Installation
  • @@ -361,19 +362,21 @@

    Action Space

    Observation Space

    The observation space is an ndarray with shape (obs_height, obs_width, 3) -representing a RGB image of what the agents sees.

    +representing an RGB image of what the agents see.

    -

    Rewards:

    +

    Rewards

    +2 for each time step -100 for dying

    Arguments

    -
    CollectHealth(size=16)
    +
      +
    • size: size of the room

    • +
    +
    env = gymnasium.make("Miniworld-CollectHealth-v0", size=16)
     
    -

    size: size of the room

    @@ -410,7 +413,7 @@

    Arguments
    @@ -230,6 +230,7 @@
  • YMaze
  • +
  • Wrapper
  • Tutorial on Creating Environments
  • Troubleshooting Guide
  • Installation
  • @@ -346,17 +347,17 @@

    Action Space

    Observation Space

    The observation space is an ndarray with shape (obs_height, obs_width, 3) -representing a RGB image of what the agents sees.

    +representing an RGB image of what the agents see.

    -

    Rewards:

    +

    Rewards

    +(1 - 0.2 * (step_count / max_episode_steps)) when box reached

    Arguments

    -
    env = gym.make("MiniWorld-YMazeLeft-v0")
    +
    env = gymnasium.make("MiniWorld-YMazeLeft-v0")
     # or
    -env = gym.make("MiniWorld-YMazeRight-v0")
    +env = gymnasium.make("MiniWorld-YMazeRight-v0")
     
    @@ -367,12 +368,12 @@

    Arguments - +
    Next
    -
    Tutorial on Creating Environments
    +
    Wrapper
    @@ -395,7 +396,7 @@

    Arguments