1 Star 0 Fork 0

sickle12138/DDPG

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
replay_buffer.py 987 Bytes
一键复制 编辑 原始数据 按行查看 历史
Rotek Song 提交于 2016-09-12 16:11 . fix bug
from collections import deque
import random
class ReplayBuffer(object):
def __init__(self, buffer_size):
self.buffer_size = buffer_size
self.num_experiences = 0
self.buffer = deque()
def get_batch(self, batch_size):
# Randomly sample batch_size examples
return random.sample(self.buffer, batch_size)
def size(self):
return self.buffer_size
def add(self, state, action, reward, new_state, done):
experience = (state, action, reward, new_state, done)
if self.num_experiences < self.buffer_size:
self.buffer.append(experience)
self.num_experiences += 1
else:
self.buffer.popleft()
self.buffer.append(experience)
def count(self):
# if buffer is full, return buffer size
# otherwise, return experience counter
return self.num_experiences
def erase(self):
self.buffer = deque()
self.num_experiences = 0
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/sickle12138/DDPG.git
git@gitee.com:sickle12138/DDPG.git
sickle12138
DDPG
DDPG
master

搜索帮助