Skip to content

Commit

Permalink
Merge pull request #41 from The-Bread/master
Browse files Browse the repository at this point in the history
Fix for RuntimeError for Environments with single continuous actions.
  • Loading branch information
nikhilbarhate99 authored Apr 12, 2021
2 parents d83918a + d5e73e5 commit 4c1a27b
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion PPO.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,18 @@ def evaluate(self, state, action):

if self.has_continuous_action_space:
action_mean = self.actor(state)

action_var = self.action_var.expand_as(action_mean)
cov_mat = torch.diag_embed(action_var).to(device)
dist = MultivariateNormal(action_mean, cov_mat)

# For Single Action Environments.
if self.action_dim == 1:
action = action.reshape(-1, self.action_dim)

else:
action_probs = self.actor(state)
dist = Categorical(action_probs)

action_logprobs = dist.log_prob(action)
dist_entropy = dist.entropy()
state_values = self.critic(state)
Expand Down

0 comments on commit 4c1a27b

Please sign in to comment.