From 4fac5e3e5b41cc48a7ad39fcfa9561bb8d4cd0f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=A8=9C?= Date: Tue, 5 Aug 2025 02:35:24 +0000 Subject: [PATCH] =?UTF-8?q?=E5=BC=BA=E5=8C=96=E5=AD=A6=E4=B9=A0=E8=AE=AD?= =?UTF-8?q?=E7=BB=83=E6=97=B6=E5=AD=98=E5=82=A8=E5=8A=A8=E4=BD=9C=E5=92=8C?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E8=BD=AC=E7=A7=BB=20=E6=B0=B8=E8=BF=9C?= =?UTF-8?q?=E6=90=9E=E4=B8=8D=E6=B8=85=E6=A5=9Avstack=E5=92=8Chstack=20?= =?UTF-8?q?=E5=AF=BC=E8=87=B4=E6=95=B0=E7=BB=84=E4=B8=8D=E5=8C=B9=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 张娜 --- python/transition.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 python/transition.py diff --git a/python/transition.py b/python/transition.py new file mode 100644 index 0000000..27500f9 --- /dev/null +++ b/python/transition.py @@ -0,0 +1,17 @@ + def store_transition(self, s, a, r, s_): + transition = [] + transition.append(s) + transition.append(a) + transition.append(r) + transition.append(s_) + transitionn = np.array(transition, dtype=object) + if self.prioritized: # prioritized replay + #transition = np.hstack((s, [a, r], s_)) + self.memory.store(transitionn) # have high priority for newly arrived transition + else: # random replay + if not hasattr(self, 'memory_counter'): + self.memory_counter = 0 + #transition = np.hstack((s, [a, r], s_)) + index = self.memory_counter % self.memory_size + self.memory[index, :] = transitionn + self.memory_counter += 1 \ No newline at end of file -- Gitee