Skip to main content

Pink noise for exploration in reinforcement learning

Project description

Colored Action Noise for Deep RL

This repository contains easy-to-use implementations of pink noise and general colored noise for use as action noise in deep reinforcement learning. Included are the following classes:

  • ColoredNoiseProcess and PinkNoiseProcess for general use, based on the colorednoise library
  • ColoredActionNoise and PinkActionNoise to be used with deterministic policy algorithms like DDPG and TD3 in Stable Baselines3, both are subclasses of stable_baselines3.common.noise.ActionNoise
  • ColoredNoiseDist, PinkNoiseDist to be used with stochastic policy algorithms like SAC in Stable Baselines3
  • MPO_CN for using colored noise (incl. pink noise) with MPO using the Tonic RL library.

For more information, please see our paper: Pink Noise Is All You Need: Colored Noise Exploration in Deep Reinforcement Learning (ICLR 2023 Spotlight).

Installation

You can install the library via pip:

pip install pink-noise-rl

Note: In Python, the import statement is simply import pink.

Usage

We provide minimal examples for using pink noise on SAC, TD3 and MPO below. An example comparing pink noise with the default action noise of SAC is included in the examples directory.

Stable Baselines3: SAC, TD3

import gym
from stable_baselines3 import SAC, TD3

# All classes mentioned above can be imported from `pink`
from pink import PinkNoiseDist, PinkActionNoise

# Initialize environment
env = gym.make("MountainCarContinuous-v0")
seq_len = env._max_episode_steps
action_dim = env.action_space.shape[-1]

SAC

# Initialize agent
model = SAC("MlpPolicy", env)

# Set action noise
model.actor.action_dist = PinkNoiseDist(seq_len, action_dim)

# Train agent
model.learn(total_timesteps=100_000)

TD3

# Initialize agent
model = TD3("MlpPolicy", env)

# Set action noise
noise_scale = 0.3
model.action_noise = PinkActionNoise(noise_scale, seq_len, action_dim)

# Train agent
model.learn(total_timesteps=100_000)

Tonic: MPO

import gym
from tonic import Trainer
from pink import MPO_CN

# Initialize environment
env = gym.make("MountainCarContinuous-v0")
seq_len = env._max_episode_steps

# Initialize agent with pink noise
beta = 1
model = MPO_CN()
model.initialize(beta, seq_len, env.observation_space, env.action_space)

# Train agent
trainer = tonic.Trainer(steps=100_000)
trainer.initialize(model, env)
trainer.run()

Citing

If you use this code in your research, please cite our paper:

@inproceedings{eberhard-2023-pink,
  title = {Pink Noise Is All You Need: Colored Noise Exploration in Deep Reinforcement Learning},
  author = {Eberhard, Onno and Hollenstein, Jakob and Pinneri, Cristina and Martius, Georg},
  booktitle = {Proceedings of the Eleventh International Conference on Learning Representations (ICLR 2023)},
  month = may,
  year = {2023},
  url = {https://openreview.net/forum?id=hQ9V5QN27eS}
}

If there are any problems, or if you have a question, don't hesitate to open an issue here on GitHub.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pink_noise_rl-2.0.1.tar.gz (8.9 kB view details)

Uploaded Source

Built Distribution

pink_noise_rl-2.0.1-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

Details for the file pink_noise_rl-2.0.1.tar.gz.

File metadata

  • Download URL: pink_noise_rl-2.0.1.tar.gz
  • Upload date:
  • Size: 8.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.11.0 Darwin/22.1.0

File hashes

Hashes for pink_noise_rl-2.0.1.tar.gz
Algorithm Hash digest
SHA256 50e3ffa2c35e21777f955b61fa9ed96843cf3c76f7ecf8298e7801a07b5cd9dd
MD5 cb00f3b9426025f61105acb82c731e00
BLAKE2b-256 4dcbdc3ed54c7938bdf95f84e3b68e13e7297d6c80e071144f9d77132bfcb1f1

See more details on using hashes here.

File details

Details for the file pink_noise_rl-2.0.1-py3-none-any.whl.

File metadata

  • Download URL: pink_noise_rl-2.0.1-py3-none-any.whl
  • Upload date:
  • Size: 9.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.11.0 Darwin/22.1.0

File hashes

Hashes for pink_noise_rl-2.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 15b70e61f4670112769226d08512ccae0bdc1eaa30638b8c4f1ef66176f5ef32
MD5 dbebe1082a5608bb977f7ad67139e6e2
BLAKE2b-256 e932153022cf4374b4bb523d86fd9c9a398555f59cd49b8ca53d16d71e1c5d0c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page