我试图了解使用 TensorFlow 实现基本策略梯度 (REINFORCE) 方法。我想我几乎得到了一切。唯一仍然困扰我的是损失函数的实现。
从理论来看,我们有在所有的操作之后,得分函数的梯度是
在这个Cartpole示例中,与损失函数相关的部分是
neg_log_prob = tf.nn.softmax_cross_entropy_with_logits_v2(logits = NeuralNetworkOutputs, labels = actions)
loss = tf.reduce_mean(neg_log_prob * discounted_episode_rewards_)
在这一点上,我不明白上面的定义如何转换为代码。
据我了解,功能
tf.nn.softmax_cross_entropy_with_logits_v2(logits = NeuralNetworkOutputs, labels = actions)
返回
log(softmax(NeuralNetworkOutputs))*actions
然后乘以贴现回报
log(softmax(NeuralNetworkOutputs))*actions*discounted_episode_rewards_
在这个表达式中,我不明白我们为什么要将一个看起来像我们想要的损失函数的表达式乘以动作的值。