Initialize replay memory
Initialize action-value function
Initialize target action-value function
For episode=
Initialize sequence
For
With probability
otherwise select
Execute action
Set
Store transition
Sample random minibatch of transitions
Set
Perform a gradient descent step on
Every
End For
End For
We first initialized a neural net to use for the deep q-network algorithm and ran it to see the average rewards per episode of this initialized, non-learned net. Next we started the training of the neural net for the deep q-network to update the weights to minimize the loss function from the pseudocode above. While doing so, we updated the target network to match the same weight parameters as the network we use to train every so often, in regular intervals. We stopped the training once it hit an average reward per episode of 200 for the last 100 episodes. The graph below shows the rewards collected per episode during the training process along with the average reward per episode before training and after training.
Although in the graph shown above, there seems to be a very quick learning process towards the intended target average rewards, this is not always the case. Running with the same hyperparameters gives a decently fast convergence towards the intended target average rewards (< 200 episodes), but other times, the network seems to get stuck in a local minimum and unable to get out within the set episode limit.
Initialize
Generate one episode
For t=
Estimate the return
End For
We first initialized a neural net to use for the REINFORCE algorithm and ran it to see the average rewards per episode of this initialized, non-learned net. Next we started the training of the neural net for the REINFORCE algorithm and updated the weights by the equation in the pseudocode above. We stopped the training once it hit an average reward per episode of 200 for the last 100 episodes. The graph below shows the rewards collected per episode during the training process along with the average reward per episode before training and after training.
There seems to be a much higher variance in the rewards collected after each episode for REINFORCE compared to DQN. It also seems to take much longer for the parameters in the neural net to learn the best policy.
This is for the Actor-Critic in the AC.py file.
Initialize
For t=
Sample reward
Then sample the next action
Update policy parameters:
Compute the correction for action-value at time
and use it to update value function parameters:
Update
End For
We first initialized the actor and critic networks to use for the AC algorithm. We then ran it to see the average rewards per episode of this initialized, non-learned actor net. Next we started the training of the actor and critic nets for the AC algorithm by calculating the losses and then using the Adam optimizer to calculate the gradients to update the parameters instead of directly updating the network parameters like in the pseudocode above. This was done mostly because we were not able to get a direct translation of the above pseudocode to work so we went this alternate method. We stopped the training once it hit an average reward per episode of 200 for the last 100 episodes. The graph below shows the rewards collected per episode during the training process along with the average reward per episode before training and after training.
Actor-Critic seems to work much better when gamma discount is above 0.99 (best if 0.995 or above). There also seems to be a lot more cases where the amount of rewards collected between episodes have a big drop off or gain, more extreme than the graph found in the REINFORCE algorithm. Although in the graph above it appears that the network was able to learn the parameters very quickly, this is often not the case as there is a huge variance in how many episodes it takes to the reach the benchmark of 200 average rewards per episode. However, compared to REINFORCE and DQN, it does appear to be able to reach the maximum reward of 500 more often between different run trials while also appearing to diverge more frequently than the other two. Below are two other instances of running the Actor-Critic Algorithm script: