Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class OUNoise:
- """Ornstein-Uhlenbeck process."""
- def __init__(self, size, seed, mu=0., theta=0.15, sigma=0.2):
- """Initialize parameters and noise process."""
- self.mu = mu * np.ones(size)
- self.theta = theta
- self.sigma = sigma
- self.seed = random.seed(seed)
- self.reset()
- def reset(self):
- """Reset the internal state (= noise) to mean (mu)."""
- self.state = copy.copy(self.mu)
- def sample(self):
- """Update internal state and return it as a noise sample."""
- x = self.state
- dx = self.theta * (self.mu - x) + self.sigma * np.array([random.random() for i in range(len(x))])
- self.state = x + dx
- return self.state
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement