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

Change sampling method from randint to choice in Replay and robustify policy networks in SAC #111

Merged
merged 5 commits into from
Aug 10, 2020
Merged
Show file tree
Hide file tree
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
8 changes: 7 additions & 1 deletion rlkit/data_management/simple_replay_buffer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from collections import OrderedDict

import numpy as np
import warnings

from rlkit.data_management.replay_buffer import ReplayBuffer

Expand All @@ -13,6 +14,7 @@ def __init__(
observation_dim,
action_dim,
env_info_sizes,
replace = True,
):
self._observation_dim = observation_dim
self._action_dim = action_dim
Expand All @@ -35,6 +37,8 @@ def __init__(
self._env_infos[key] = np.zeros((max_replay_buffer_size, size))
self._env_info_keys = env_info_sizes.keys()

self._replace = replace

self._top = 0
self._size = 0

Expand All @@ -59,7 +63,9 @@ def _advance(self):
self._size += 1

def random_batch(self, batch_size):
indices = np.random.randint(0, self._size, batch_size)
indices = np.random.choice(self._size, size=batch_size, replace=self._replace or self._size < batch_size)
if not self._replace and self._size < batch_size:
warnings.warn('Replace was set to false, but is temporarily set to true because batch size is larger than current size of replay.')
batch = dict(
observations=self._observations[indices],
actions=self._actions[indices],
Expand Down
2 changes: 1 addition & 1 deletion rlkit/torch/sac/policies.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def forward(
action,
pre_tanh_value=pre_tanh_value
)
log_prob = log_prob.sum(dim=1, keepdim=True)
log_prob = log_prob.sum(dim=-1, keepdim=True)
else:
if reparameterize is True:
action = tanh_normal.rsample()
Expand Down