Advertisement
Guest User

Untitled

a guest
Jul 24th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. class OUNoise:
  2. """Ornstein-Uhlenbeck process."""
  3.  
  4. def __init__(self, size, seed, mu=0., theta=0.15, sigma=0.2):
  5. """Initialize parameters and noise process."""
  6. self.mu = mu * np.ones(size)
  7. self.theta = theta
  8. self.sigma = sigma
  9. self.seed = random.seed(seed)
  10. self.reset()
  11.  
  12. def reset(self):
  13. """Reset the internal state (= noise) to mean (mu)."""
  14. self.state = copy.copy(self.mu)
  15.  
  16. def sample(self):
  17. """Update internal state and return it as a noise sample."""
  18. x = self.state
  19. dx = self.theta * (self.mu - x) + self.sigma * np.array([random.random() for i in range(len(x))])
  20. self.state = x + dx
  21. return self.state
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement