1 Star 0 Fork 0

Jill/pytorch-maddpg

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
randomProcess.py 1.71 KB
一键复制 编辑 原始数据 按行查看 历史
xuehy 提交于 2017-07-25 09:48 . first commit
import numpy as np
class RandomProcess:
def reset_states(self):
pass
class AnnealedGaussianProcess(RandomProcess):
def __init__(self, mu, sigma, sigma_min, n_steps_annealing):
self.mu = mu
self.sigma = sigma
self.n_steps = 0
if sigma_min is not None:
self.m = -float(sigma - sigma_min) / float(n_steps_annealing)
self.c = sigma
self.sigma_min = sigma_min
else:
self.m = 0.
self.c = sigma
self.sigma_min = sigma
@property
def current_sigma(self):
sigma = max(self.sigma_min, self.m * float(self.n_steps) + self.c)
return sigma
class OrnsteinUhlenbeckProcess(AnnealedGaussianProcess):
def __init__(self, theta, mu=0., sigma=0.2,
dt=1e-2, x0=None, size=1,
sigma_min=None, n_steps_annealing=1000):
super(OrnsteinUhlenbeckProcess,
self).__init__(mu=mu,
sigma=sigma,
sigma_min=sigma_min,
n_steps_annealing=n_steps_annealing)
self.theta = theta
self.mu = mu
self.dt = dt
self.x0 = x0
self.size = size
self.reset_states()
def sample(self):
x = self.x_prev + \
self.theta * (self.mu -
self.x_prev) * self.dt + (
self.current_sigma * np.sqrt(self.dt) *
np.random.normal(size=self.size)
)
self.x_prev = x
self.n_steps += 1
return x
def reset_states(self):
self.x_prev = self.x0 if self.x0 is not None else np.zeros(self.size)
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/lxqbupt/pytorch-maddpg.git
git@gitee.com:lxqbupt/pytorch-maddpg.git
lxqbupt
pytorch-maddpg
pytorch-maddpg
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385