1 Star 0 Fork 0

zhoub86/ResourceAllocationReinforcementLearning

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
replay_memory.py 1.36 KB
一键复制 编辑 原始数据 按行查看 历史
haoyye 提交于 2019-03-09 11:40 . Initial Version
import os
import random
import logging
import numpy as np
#from utils import save_npy, load_npy
class ReplayMemory:
def __init__(self, model_dir):
self.model_dir = model_dir
self.memory_size = 1000000
self.actions = np.empty(self.memory_size, dtype = np.uint8)
self.rewards = np.empty(self.memory_size, dtype = np.float64)
self.prestate = np.empty((self.memory_size, 82), dtype = np.float16)
self.poststate = np.empty((self.memory_size, 82), dtype = np.float16)
self.batch_size = 2000
self.count = 0
self.current = 0
def add(self, prestate, poststate, reward, action):
self.actions[self.current] = action
self.rewards[self.current] = reward
self.prestate[self.current] = prestate
self.poststate[self.current] = poststate
self.count = max(self.count, self.current + 1)
self.current = (self.current + 1) % self.memory_size
def sample(self):
indexes = []
while len(indexes) < self.batch_size:
index = random.randint(0, self.count - 1)
indexes.append(index)
prestate = self.prestate[indexes]
poststate = self.poststate[indexes]
actions = self.actions[indexes]
rewards = self.rewards[indexes]
return prestate, poststate, actions, rewards
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zhoub86/ResourceAllocationReinforcementLearning.git
git@gitee.com:zhoub86/ResourceAllocationReinforcementLearning.git
zhoub86
ResourceAllocationReinforcementLearning
ResourceAllocationReinforcementLearning
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385