I understand that this is the update for the parameters of a policy in REINFORCE:
$$ \Delta \theta_{t}=\alpha \nabla_{\theta} \log \pi_{\theta}\left(a_{t} \mid s_{t}\right) v_{t}, $$ where $v_t$ is usually the discounted future reward and $\pi_{\theta}\left(a_{t} \mid s_{t}\right)$ is the probability of taken the action that the agent took at time $t$. (Tell me if something is wrong here)
ButHowever, I don't understand how that is passed intoto implement this with a neural network for backpropagation.
Let's say that probs = policy.feedforward(state)
returns the probabilities of taking each action, like [0.6, 0.4]
.
action = choose_action_from(probs)
will return the index of the probability chosen. For example, if it chose 0.6, the action would be 0.
When it is time to update the parameters of the policy network, what should we havedo? Should we do something like the following?
gradient = policy.backpropagate(total_discounted_reward*log(probs[action])
policy.weights += gradient
Is this the right way to calculate the derivative of the loss and backpropagate it? And I only backpropagate this through one output neuron?
If not, whichWhich loss function should I use in REINFORCE, and what arethis case? What would the labels be?
If you need more explanation, I have this question on SO.