Normalize Observation Wrapper

Enviroment wrapper to normalize the observation space.

Note

Only works for Box observation spaces.

Example use

from kobuki_maze_rl.task_env import kobuki_maze
from frobs_rl.common import ros_gazebo
import gym
import rospy

from frobs_rl.wrappers.NormalizeObservWrapper import NormalizeObservWrapper

if __name__ == '__main__':

    # Launch Gazebo
    ros_gazebo.launch_Gazebo(paused=True, gui=False)

    # Start node
    rospy.logwarn("Start")
    rospy.init_node('kobuki_maze_train')

    # Launch the task environment
    env = gym.make('KobukiMazeEnv-v0')

    #--- Normalize observation space
    env = NormalizeObservWrapper(env)

Wrapper documentation

class NormalizeObservWrapper.NormalizeObservWrapper(env)[source]

Wrapper to normalize the observation space.

Parameters

env – (gym.Env) Gym environment that will be wrapped

reset()[source]

Reset the environment

scale_observation(observation)[source]

Scale the observation from [low, high] to [-1, 1].

Parameters

observation (np.ndarray) – Observation to scale

Returns

scaled observation

Return type

np.ndarray

step(action)[source]
Parameters

action (float or int) – Action taken by the agent

Returns

observation, reward, is the episode over, additional informations

Return type

(np.ndarray, float, bool, dict)