Skip to content

Commit

Permalink
Merge pull request tensorflow#5058 from raymond-yuan/patch-1
Browse files Browse the repository at this point in the history
minor bug fix
  • Loading branch information
MarkDaoust authored Aug 30, 2018
2 parents d988d71 + e9dbef6 commit 2aec950
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions research/a3c_blogpost/a3c_cartpole.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,13 +347,11 @@ def compute_loss(self,
value_loss = advantage ** 2

# Calculate our policy loss
actions_one_hot = tf.one_hot(memory.actions, self.action_size, dtype=tf.float32)

policy = tf.nn.softmax(logits)
entropy = tf.reduce_sum(policy * tf.log(policy + 1e-20), axis=1)
entropy = tf.nn.softmax_cross_entropy_with_logits_v2(labels=policy, logits=logits)

policy_loss = tf.nn.softmax_cross_entropy_with_logits_v2(labels=actions_one_hot,
logits=logits)
policy_loss = tf.nn.sparse_softmax_cross_entropy_with_logits(labels=memory.actions,
logits=logits)
policy_loss *= tf.stop_gradient(advantage)
policy_loss -= 0.01 * entropy
total_loss = tf.reduce_mean((0.5 * value_loss + policy_loss))
Expand Down

0 comments on commit 2aec950

Please sign in to comment.