-
Notifications
You must be signed in to change notification settings - Fork 728
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
Add comment on the use of categorical cross entropy in REINFORCE and a2c #54
Comments
Yes, categorical cross entropy can not be used for policy gradient generally. I have changed the cross entropy to one hot vector and multiplied with advantage function which is also one hot vector. So the categorical cross entropy became object function for the policy gradient. I did this because I want to use model.fit() to policy gradient because it is simple! I will make some explanation for this. Thank you |
Categorical cross entropy is defined |
Thank you! Your explanation is clear enough to understand easily. I will add explanation about this soon |
Shall I make a pull request? |
@fredcallaway |
Hello, I am confused as to why "all other p_i are zero" if p's are advantages and softmax is applied. Is this the answer? "You correctly pointed out that the softmax numerator should never have zero-values due to the exponential. However, due to floating point precision, the numerator could be a very small value, say, exp(-50000), which essentially evaluates to zero." from https://stackoverflow.com/questions/39109674/the-output-of-a-softmax-isnt-supposed-to-have-zeros-right |
Softmax is not applied to the advantages (the Note that |
I printed out the advantages array:
So the final line H(p, q) = -(A * log(policy(s,a)) means the cross-entropy loss is the negation of advantage * log probability of the policy? (I kept seeing the negation everywhere cross-entropy is explained so wanted to include it). It's still magical to me how the network outputs probabilities but you can use the advantages like this. Is this a hack? If so I think it is very ingenious but I also prefer to learn it the plain vanilla way. Is Karpathy's pong example the best for that? |
Good point regarding the negation. Your correct that the loss has the negation. However, we are actually trying to maximize I definitely agree that it's a bit confusing, but I think the idea of this library is not so much to teach you the math, but rather to give you some code to play around with to test the effects of hyperparameters and apply the algorithms to different environments. |
I was surprised to see this loss function because it is generally used when the target is a distribution (i.e. sums to 1). This is not the case for the advantage estimate. However, I worked out the math and it does appear to be doing the right thing which is neat!
I think this trick should be mentioned in the code.
The text was updated successfully, but these errors were encountered: