baselines icon indicating copy to clipboard operation
baselines copied to clipboard

neglogac in a2c.py

Open shijcnju opened this issue 8 years ago • 1 comments

Why is neglogac in a2c.py defined as
neglogpac = tf.nn.sparse_softmax_cross_entropy_with_logits(logits=train_model.pi, labels=A)?

shijcnju avatar Jun 06 '18 01:06 shijcnju

Current implementation of a2c assumes discrete action spaces. Furthermore, train_model.pi outputs the unnormalized action probabilities given by policy (see here https://github.com/openai/baselines/blob/24fe3d6576dd8f4cdd5f017805be689d6fa6be8c/baselines/ppo2/policies.py#L98 and here https://github.com/openai/baselines/blob/24fe3d6576dd8f4cdd5f017805be689d6fa6be8c/baselines/common/distributions.py#L55)

So, what neglogpac in https://github.com/openai/baselines/blob/24fe3d6576dd8f4cdd5f017805be689d6fa6be8c/baselines/a2c/a2c.py#L33 actually computes is - log normalized probability of action taken. Softmax normalizes the policy-output action probabilities to sum to 1, and cross-entropy with action computes -log probability of action taken. Recall that cross entropy of p_i and q_i is - sum_i q_i log p_i. In our case q_i is zero for actions not taken, and 1 for action taken, and p_i is the softmax of the unnormalized policy output.

I hope that answers the question, if not, please reopen.

pzhokhov avatar Jun 06 '18 18:06 pzhokhov