Reinforcement Learning: Deep SARSA and Q Learning
The Evolution of Reinforcement Learning: From Tables to Deep Q-Networks (DQN).
We have walked a long road to reach this point.
First, we had a table. Every state–action pair had its own little drawer in memory, and we updated one number at a time. Then the table became too large, and we replaced it with tiles. The value was no longer stored. it was computed:
Then even the tiles became too rigid. Instead of hand-designed features, we let a neural network learn them. The update changed from nudging a few tile weights to nudging an entire parameter vector through gradients:
At each step, the pattern remained the same:
Only the representation of “old” changed.
Until now, SARSA and Q-learning were described either in tabular form or with simple function approximators. But modern reinforcement learning systems like game-playing agents, robotic controllers, recommendation systems do not operate in tiny grids. They see images, raw pixels, high-dimensional sensor streams. A table cannot hold that. Even tile coding collapses under that scale.
So what happens when we plug a deep neural network into SARSA or Q-learning?
Bridging the Gap
Up to now, most of our story was built around
and that means we were always asking a very particular kind of question:
“How good is this state?”
That question is useful, but it quietly assumes something else is already handling the choice of action. A state-value tells us the value of being at an intersection, but it does not by itself tell us whether we should go left, right, up, or down. It gives a single number for the whole situation.
Imagine our drone is hovering above one city block. If we are told
we know the situation is fairly promising. But promising under what behavior? If the drone moves north, maybe it reaches the destination quickly. If it moves south, maybe it flies into a windy corridor and loses time. A single scalar for the whole state hides those differences.
That is exactly why control methods like SARSA and Q-learning do not stop at state values. They move one level deeper and ask a sharper question:
“What is the value of taking a particular action in this state?”
Now the object is no longer
but
This looks like a tiny change in notation, but conceptually it is a major upgrade. Instead of one number per state, we now want one number for each action available in that state.
If there are four actions, then the state no longer maps to one scalar. It maps to four scalars:
You can think of this as replacing one opinion about the state with four separate “what if” estimates:
“What if I go up from here?”
“What if I go down from here?”
“What if I go left?”
“What if I go right?”
In the tabular world, this was easy to picture. Each state–action pair had its own entry in the table. In the function approximation world, the idea is still the same, but now those values are produced instead of stored.
Earlier, with neural value prediction, we wrote
which means a network takes a state as input and emits one scalar. For SARSA or Q-learning, we simply ask the network to emit more than one scalar. The input is still the state, but the output becomes a collection of action-values:
If the action set is finite, the most natural design is to let the network take in and output a vector:
So in one forward pass, the network evaluates every action at once.
Deep SARSA: The Same Idea, Larger Capacity
Imagine again our Grid City drone. But now instead of representing a state as a number like 13, suppose the drone sees a grayscale image of the city from above. That image is the state. Every state is now a vector of 4096 numbers. A table indexed by images is impossible. Tile coding over pixels is absurd.
So we define a neural network:
that takes as input the image of the city and outputs a value for each possible action. Suppose there are four actions: UP, DOWN, LEFT, RIGHT. The network outputs:
all computed in one forward pass. Now we replay what SARSA used to do in the tabular world.
At time step , the drone is in state . It chooses action using -greedy on the network’s outputs. It receives reward , lands in , and selects the next action again using -greedy policy.
In tabular SARSA, the update was:
Now replace the table entry with the network output . Define the TD error:
Just like before.
But we cannot directly overwrite a number in a table. We must adjust parameters so that the network’s output for moves closer to the target. So we define a loss:
And then we perform gradient descent:
This is Deep SARSA.
Conceptually, nothing changed. It is still on-policy. It still bootstraps from the action actually taken. It still learns the value of the -greedy policy it follows. The only difference is that the Q-function is now represented by a deep neural network instead of a table.
But something subtle and dangerous has entered the story.
Remember earlier when we discussed how TD targets are already “moving targets”? Even in simple neural TD learning, the target
depends on , the same parameters we are updating.
In tabular SARSA, this coupling was mild. Updating one entry in the table did not drastically affect others. But in a deep network, changing slightly changes all Q-values for all states, because they share parameters.
Deep Q-Learning and the Moving Target Problem
Now imagine what happens in Deep Q-learning. Q-learning’s target is:
So the TD error becomes:
and we again minimize squared TD error. This is Deep Q-Learning in its most naive form.
At first glance, it looks almost identical to Deep SARSA. Just replace with . But now notice something unsettling.
The network parameters appear in three places:
- Inside
- Inside
- Inside the max operator
So the network is chasing a target that it itself is producing, while the target shifts every time the parameters shift. Imagine trying to shoot at a target that moves every time you adjust your aim and worse, the target moves because you adjusted your aim.
In small problems, sometimes this works. But with large nonlinear networks, training becomes unstable. Q-values can explode. Learning can diverge. To understand why, imagine a simple numeric example. Suppose initially:
So the max is 6.
The target becomes:
Now suppose a small gradient update slightly increases both values to 5.5 and 6.5. The target increases too. The update chases it upward again. If the network systematically overestimates values due to noise, the max operator amplifies that bias.
This is known as overestimation bias in Q-learning.
Stabilizing Deep Q-Learning: Replay and Target Networks
This is why modern Deep Q-Learning introduced two stabilizing ideas.
-
Experience replay.
Instead of updating the network immediately using the latest transition, we store transitions:
in a replay buffer. During training, we sample random mini-batches from this buffer.
Why does this help?
Because consecutive transitions are highly correlated. If the drone is flying north for ten steps, those ten states are similar. Training on them sequentially makes the network chase local correlations. Random sampling breaks this correlation and makes training behave more like standard supervised learning.
-
Target networks.
We create a second network with parameters , initially copied from . When computing the target:
we use the frozen target network parameters , not the current parameters .
The online network is updated every step. The target network is updated only occasionally, say every few thousand steps, by copying .
Now the target moves slowly. It is no longer chasing itself at every tiny gradient step.
With both ideas included, the Deep Q-Learning update becomes:
This combination of deep network, replay buffer, target network is what made Deep Q-Networks (DQN) capable of learning directly from high-dimensional inputs like raw pixels.
Deep SARSA can also be implemented with replay and target networks, though historically DQN popularized the approach in off-policy learning.
The Unchanging Backbone
Step back now and look at the pattern across everything we have done.
Monte Carlo:
SARSA:
Q-learning:
Deep SARSA:
Same SARSA target, but is a neural network.
Deep Q-learning:
Same Q-learning target, but stabilized with replay and target networks.
Across all of them, the backbone remains:
Only two ingredients ever change:
- What is the target?
- How is the value function represented?
When we replaced tables with tiles, and tiles with neural networks, we did not change the soul of reinforcement learning. We only changed its capacity.
But now a new tension emerges.
Deep Q-learning is off-policy and value-based. Deep SARSA is on-policy and value-based. Both estimate Q-values and derive policies from them. But what if we do not want to infer a policy indirectly from Q-values? What if we want to learn the policy directly?
That question opens the door to policy gradients, actor–critic methods, and eventually to algorithms like PPO and SAC where value functions and policies coexist inside deep networks in a more delicate balance.
And just like before, the core ideas will look surprisingly familiar once we watch one update at a time. stay tuned!!