Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shuffle samples to generate each mini-batch at Replay.get_batch. #59

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions tensorforce/core/memories/replay.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
from __future__ import print_function
from __future__ import division

from random import randrange
from six.moves import xrange
import numpy as np

Expand Down Expand Up @@ -62,20 +61,14 @@ def get_batch(self, batch_size):
"""
Samples a batch of the specified size by selecting a random start/end point and returning
the contained sequence (as opposed to sampling each state separately).

Args:
batch_size: Length of the sampled sequence.

Returns: A dict containing states, rewards, terminals and internal states

"""
end = (self.index - randrange(self.size - batch_size + 1)) % self.capacity
start = (end - batch_size) % self.capacity
if start < end:
indices = list(xrange(start, end))
else:
indices = list(xrange(start, self.capacity)) + list(xrange(0, end))

indices = np.random.permutation(self.size)[:batch_size]
return dict(
states={name: state.take(indices, axis=0) for name, state in self.states.items()},
actions={name: action.take(indices, axis=0) for name, action in self.actions.items()},
Expand Down