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)
However, I don't understand how to implement this with a neural network.
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 do? Should we do something like the following?
gradient = policy.backpropagate(total_discounted_reward*log(probs[action])
policy.weights += gradient
And I only backpropagate this through one output neuron?
Which loss function should I use in this case? What would the labels be?
If you need more explanation, I have this question on SO.