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

Sampling from replay buffer with bias? #33

Open
tangwentlw opened this issue Apr 23, 2024 · 0 comments
Open

Sampling from replay buffer with bias? #33

tangwentlw opened this issue Apr 23, 2024 · 0 comments

Comments

@tangwentlw
Copy link

Hi,

Thank you for the excellent implementation. I have a quick question regarding sampling from the replay buffer. In the following code from LazyMemory class, you added a bias term to the randomly generated index when the replay buffer is full (bias = -self._p if self._n == self.capacity else 0). Is there any particular reason for doing this? My understanding is that, since the indexes are uniformly generated, adding a bias term would not make any difference compared to not adding the bias. Am I right? Or is there anything that I missed?

    def sample(self, batch_size):
        indices = np.random.randint(low=0, high=len(self), size=batch_size)
        return self._sample(indices, batch_size)

    def _sample(self, indices, batch_size):
        bias = -self._p if self._n == self.capacity else 0

        states = np.empty(
            (batch_size, *self.state_shape), dtype=np.uint8)
        next_states = np.empty(
            (batch_size, *self.state_shape), dtype=np.uint8)

        for i, index in enumerate(indices):
            _index = np.mod(index+bias, self.capacity)
            states[i, ...] = self['state'][_index]
            next_states[i, ...] = self['next_state'][_index]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant