Skip to content

Instantly share code, notes, and snippets.

@DavidSanwald
Created November 18, 2016 12:37
Show Gist options
  • Save DavidSanwald/2a6d7dbebd82304afe3ffcbfbe4d703f to your computer and use it in GitHub Desktop.
Save DavidSanwald/2a6d7dbebd82304afe3ffcbfbe4d703f to your computer and use it in GitHub Desktop.
DQN with experience replay and target network
from collections import deque
from random import sample
class ReplayMemory:
def __init__(self, capacity):
self.samples = deque([], maxlen=capacity)
def store(self, exp):
self.samples.append(exp)
pass
def get_batch(self, n):
n_samples = min(n, len(self.samples))
samples = sample(self.samples, n_samples)
return samples
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment