Last active
April 16, 2020 21:23
-
-
Save tdavchev/2251a612b2dc662d3abe986799f90e0d to your computer and use it in GitHub Desktop.
A simple implementation of OU exploration noise.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
# Taken from https://github.com/openai/baselines/blob/master/baselines/ddpg/noise.py | |
# based on http://math.stackexchange.com/questions/1287634/implementing-ornstein-uhlenbeck-in-matlab | |
class OrnsteinUhlenbeckActionNoise(object): | |
def __init__(self, mu, sigma=0.3, theta=.15, dt=1e-2, x_0=None): | |
self.theta = theta | |
self.mu = mu | |
self.sigma = sigma | |
self.dt = dt | |
self.x_0 = x0 | |
self.reset() | |
def __call__(self): | |
x = self.x_prev + self.theta * (self.mu - self.x_prev) * self.dt + \ | |
self.sigma * np.sqrt(self.dt) * np.random.normal(size=self.mu.shape) | |
self.x_prev = x | |
return x | |
def reset(self): | |
self.x_prev = self.x_0 if self.x_0 is not None else np.zeros_like(self.mu) | |
def __repr__(self): | |
return 'OrnsteinUhlenbeckActionNoise(mu={0}, sigma={1})'.format(self.mu, self.sigma) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment