-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreplay_buffer.py
31 lines (24 loc) · 1021 Bytes
/
replay_buffer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import torch
class ReplayBuffer(object):
def __init__(self, args: dict):
self.s = torch.zeros((args["batch_size"], 12, args["state_dim"], args["state_dim"]))
self.a = torch.zeros((args["batch_size"], 1))
self.a_log_prob = torch.zeros((args["batch_size"], 1))
self.r = torch.zeros((args["batch_size"], 1))
self.s_ = torch.zeros((args["batch_size"], 12, args["state_dim"], args["state_dim"]))
self.done = torch.zeros((args["batch_size"], 1))
self.size = 0
def __len__(self):
return self.size
def clear(self):
self.size = 0
def store(self, s, a, a_log_prob, r, s_, done):
self.s[self.size] = s
self.a[self.size] = a
self.a_log_prob[self.size] = a_log_prob
self.r[self.size] = r
self.s_[self.size] = s_
self.done[self.size] = done
self.size += 1
def get_data(self):
return self.s, self.a, self.a_log_prob, self.r, self.s_, self.done