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

I really don't quite understand what the logits means in a2c.py #2

Open
Huixxi opened this issue Jun 12, 2019 · 3 comments
Open

I really don't quite understand what the logits means in a2c.py #2

Huixxi opened this issue Jun 12, 2019 · 3 comments

Comments

@Huixxi
Copy link

Huixxi commented Jun 12, 2019

Thanks your great work, I was reading your amazing blog recently. Maybe a stupid issue, I don't really understand the logits means in your code. I only know that it is the raw output of the last Dense layer. But how can it be put into the tf.random.categorical(logits, 1) directly without any preprocessing? I mean it at least should be pass into a softmax layer to convert it to a probability distribution right? Or the softmax is an inner operation of tf.random.categorical(logits, 1) and so that we can pass the logits directly into that function to pick an action based on its probability? I tried to track its source code but failed.
Another question, what the logits means, q-values of each action or just their probability? As far as I know that layer should be a policy-based operation, so ... I think there is nothing to do with q-value or value-function.

@inoryy
Copy link
Owner

inoryy commented Jun 13, 2019

Generally, the logits are simply unnormalized log probabilities.

Mathematically, you would want to work with probability distributions in most cases, but numerically it often makes more sense to work directly with the logits - not only because you do fewer ops, but also because it can be more computationally efficient under the hood (e.g. random sampling from generic categorical distribution is usually implemented with log of probabilities anyway).

Specifically, indeed tf.random.categorical works directly with logits. You can read the python source code here, though it eventually traces back to internal bindings.

@Huixxi
Copy link
Author

Huixxi commented Jun 14, 2019

Yes, thanks for your reply, I tried to track their source code from the same link you provided. But I failed at line 392. So I still can't get how they deal with the raw logits. Now I just assume that tf.random.categorical has the convert logits to probability inner operation.

@Huixxi
Copy link
Author

Huixxi commented Jun 15, 2019

Another question, I think there is no need to x = tf.convert_to_tensor(inputs, dtype=tf.float32), I've checked that the input is already a tensor(but I don't know how it does), so I comments it and the code works well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants