forked from ml-implementations/reinforcement-learning
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
21 lines (18 loc) · 746 Bytes
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import numpy as np
class OrnsteinUhlenbeckProcess(object):
""" Ornstein-Uhlenbeck Noise (original code by @slowbull)
"""
def __init__(self, theta=0.15, mu=0, sigma=1, x0=0, dt=1e-2, n_steps_annealing=100, size=1):
self.theta = theta
self.sigma = sigma
self.n_steps_annealing = n_steps_annealing
self.sigma_step = - self.sigma / float(self.n_steps_annealing)
self.x0 = x0
self.mu = mu
self.dt = dt
self.size = size
def generate(self, step):
sigma = max(0, self.sigma_step * step + self.sigma)
x = self.x0 + self.theta * (self.mu - self.x0) * self.dt + sigma * np.sqrt(self.dt) * np.random.normal(size=self.size)
self.x0 = x
return x