EDIT: The linked questions do not answer my question. My question is, how is reward incorporated into the following algorithm to make it improve iteratively When the target reward is random.
Following are the steps specified for deep Q learning in the book 'Deep Reinforcement Learning Hands-On' by 'Maxim Lapan'. These steps are based on the original deepmind paper, I think.
- Initialize the parameters for ππ(π π , ππ) and ππΜ(π π , ππ) with random weights, ππ β 1.0, and empty the replay buffer.
- With probability ππ, select a random action, a; otherwise, ππ = arg maxππ ππ(π π , ππ).
- Execute action a in an emulator and observe the reward, r, and the next state, s'.
- Store transition (s, a, r, sβ²) in the replay buffer.
- Sample a random mini-batch of transitions from the replay buffer.
- For every transition in the buffer, calculate target y = r if the episode has ended at this step, or π¦π¦ = ππ + πΎπΎ max ππβ²βπ΄π΄ ππΜ(π π β² , ππβ² ) otherwise.
- Calculate loss: β = (ππ(π π , ππ) β π¦π¦)2.
- Update Q(s, a) using the SGD algorithm by minimizing the loss in respect to the model parameters.
- Every N steps, copy weights from Q to ππΜ.
- Repeat from step 2 until converged.
Essentially you start with a two random networks Q and Q_hat and use Q_hat to generate labels to train Q. After a while you migrate all params from Q to Q_hat and this continues.
Essentially, you start with random network (say Q_hat_0), so labels (values for each state/action pair) created by that network is probably random. And then you train Q against those random labels. After a while, Q is probably good at creating those 'random' labels at which point you copy params from Q to Q_hat (let's call this q_hat_1). Now Q_hat_1 is no longer random, but it is good at creating labels that were 'probably wrong' in the first place. And then you re-start this cycle.
This looks like cheating, but I know it is not as it works. I like to understand how this works and if possible, some kind of mathematical proof that this system converges to predict correct values for state/action pairs.