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 63
63
import numpy as np
64
64
import matplotlib
65
65
import matplotlib .pyplot as plt
66
- from collections import namedtuple
66
+ from collections import namedtuple , deque
67
67
from itertools import count
68
68
from PIL import Image
69
69
115
115
class ReplayMemory (object ):
116
116
117
117
def __init__ (self , capacity ):
118
- self .capacity = capacity
119
- self .memory = []
120
- self .position = 0
118
+ self .memory = deque ([],maxlen = capacity )
121
119
122
120
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 ))
128
123
129
124
def sample (self , batch_size ):
130
125
return random .sample (self .memory , batch_size )
You can’t perform that action at this time.
0 commit comments