File tree Expand file tree Collapse file tree 1 file changed +4
-9
lines changed Expand file tree Collapse file tree 1 file changed +4
-9
lines changed Original file line number Diff line number Diff line change 6363import numpy as np
6464import matplotlib
6565import matplotlib .pyplot as plt
66- from collections import namedtuple
66+ from collections import namedtuple , deque
6767from itertools import count
6868from PIL import Image
6969
115115class ReplayMemory (object ):
116116
117117 def __init__ (self , capacity ):
118- self .capacity = capacity
119- self .memory = []
120- self .position = 0
118+ self .memory = deque ([],maxlen = capacity )
121119
122120 def push (self , * args ):
123- """Saves a transition."""
124- if len (self .memory ) < self .capacity :
125- self .memory .append (None )
126- self .memory [self .position ] = Transition (* args )
127- self .position = (self .position + 1 ) % self .capacity
121+ """Save a transition"""
122+ self .memory .append (Transition (* args ))
128123
129124 def sample (self , batch_size ):
130125 return random .sample (self .memory , batch_size )
You can’t perform that action at this time.
0 commit comments