To better understand Q-Learning, let’s take a simple example:
The reward function goes like this:
To train our agent to have an optimal policy (so a policy that goes right, right, down), we will use the Q-Learning algorithm.
So, for now, our Q-table is useless; we need to train our Q-function using the Q-Learning algorithm.
Let’s do it for 2 training timesteps:
Training timestep 1:
Because epsilon is big = 1.0, I take a random action, in this case, I go right.
By going right, I’ve got a small cheese, so , and I’m in a new state.
We can now update using our formula.
Training timestep 2:
I take a random action again, since epsilon is big 0.99 (since we decay it a little bit because as the training progress, we want less and less exploration).
I took action down. Not a good action since it leads me to the poison.
Because I go to the poison state, I get , and I die.
Because we’re dead, we start a new episode. But what we see here is that with two explorations steps, my agent became smarter.
As we continue exploring and exploiting the environment and updating Q-values using TD target, Q-table will give us better and better approximations. And thus, at the end of the training, we’ll get an estimate of the optimal Q-function.