-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
The compute_loss function is wrong for the Simplest Policy Gradient #414
Comments
I notice the same problem |
@alantpetrescu I think you are correct that the equation written differs from what is implemented in code, but only by a constant multiple. Since we multiply the gradient estimate by the learning rate when performing gradient ascent, the constant multiple doesn't really matter. |
I think the problem with this is that not all trajectories are of the same length. Some trajectories might be short (e.g. the game ends early), and some trajectories might be really long. This means that a single batch will most likely contain trajectories of different length. Imagine the following. You sample a batch:
Update according to the gradients. Sample another batch:
update according to the gradients. Now, for both batches, we divided the sum with roughly 1000, which could be reshuffled into the learning rate indeed, but the big problem is that batch by batch the denominator will most like change! It's equivalent to changing the learning rate for each batch, which surely will cause a problem. So @alantpetrescu I think this is still a bug. It might work with this because if the length of the episodes are roughly equal and do not vary too much batch by batch, this effect will not be observable too much, and can be thought of as a rescaled learning rate. But I'm not sure if we have such even length episodes, or any guarantee of that whatsoever. |
I have been reading the 3 parts from "Introduction to RL" section and I have observed in part 3 that the compute_loss function for the Simplest Policy Gradient returns the mean of the product between the log probabilities of the actions taken by the agent and the weights of those actions, in other words, the finite-horizon undiscounted returns of the episodes in which they were taken.
In the estimation of the Basic Gradient Policy above, the sums of products is divided by the number of trajectories, but in the implementation, when you return the mean, the sums of products is divided by the number of all the actions taken across all the trajectories from one epoch. Maybe I am understanding this wrong, but I wanted to get a clear picture on the implementation.
The text was updated successfully, but these errors were encountered: