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

fix: correct irrelevant factor 0.25 in td3 loss #78

Merged
merged 1 commit into from
Sep 6, 2022
Merged
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
9 changes: 6 additions & 3 deletions qdax/core/neuroevolution/losses/td3_loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def _policy_loss_fn(
q_value = critic_fn(
critic_params, obs=transitions.obs, actions=action # type: ignore
)
q1_action = q_value[:, 0]
q1_action = jnp.take(q_value, jnp.asarray([0]), axis=-1)
policy_loss = -jnp.mean(q1_action)
return policy_loss

Expand Down Expand Up @@ -83,9 +83,12 @@ def _critic_loss_fn(
q_error = q_old_action - jnp.expand_dims(target_q, -1)

# Better bootstrapping for truncated episodes.
q_error *= jnp.expand_dims(1 - transitions.truncations, -1)
q_error = q_error * jnp.expand_dims(1.0 - transitions.truncations, -1)

# compute the loss
q_losses = jnp.mean(jnp.square(q_error), axis=-2)
q_loss = jnp.sum(q_losses, axis=-1)

q_loss = 0.5 * jnp.mean(jnp.square(q_error))
return q_loss

return _policy_loss_fn, _critic_loss_fn