mirror of
https://github.com/wassname/kair_algorithms_draft.git
synced 2026-09-12 12:31:54 +08:00
Add overall setting and ddpg baseline (#1)
* Add overall CI settings * Add specific build dir to travis * Add before install/script condition to travis * Add ddpg baseline * Add wandb, remove algorithms except ddpg * Remove init file in script * Separate config file for ddpg * Remove unnecessary examples * Remove unnecessary args opt * Add pre-commit setting * Change pre-commit settings * Change travis-ci setting * Fix travis-ci issue * Modify argparse arguments, fix requirements * Change arguments order
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""Noise classes for baselines."""
|
||||
|
||||
import copy
|
||||
import random
|
||||
|
||||
import numpy as np
|
||||
|
||||
|
||||
class OUNoise:
|
||||
"""Ornstein-Uhlenbeck process.
|
||||
|
||||
Taken from Udacity deep-reinforcement-learning github repository:
|
||||
https://github.com/udacity/deep-reinforcement-learning/blob/master/
|
||||
ddpg-pendulum/ddpg_agent.py
|
||||
"""
|
||||
|
||||
def __init__(self, size, seed, mu=0.0, theta=0.15, sigma=0.2):
|
||||
"""Initialize parameters and noise process."""
|
||||
self.state = np.float64(0.0)
|
||||
self.mu = mu * np.ones(size)
|
||||
self.theta = theta
|
||||
self.sigma = sigma
|
||||
self.reset()
|
||||
|
||||
random.seed(seed)
|
||||
|
||||
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 _ in range(len(x))]
|
||||
)
|
||||
self.state = x + dx
|
||||
return self.state
|
||||
Reference in New Issue
Block a user