Understanding the mathematical foundation of temporal difference learning
Q-learning is a model-free reinforcement learning algorithm that learns the value of an action in a particular state (Q-value) without requiring a model of the environment. The core of Q-learning lies in its temporal difference (TD) update rule, which combines the current estimate with new information from the environment.
The Q-value represents the expected cumulative reward when taking action a in state s and following the optimal policy thereafter:
Rt+1: Immediate reward
γ: Discount factor (0 ≤ γ ≤ 1)
maxa' Q(st+1, a'): Maximum future reward
The Q-value is updated using the temporal difference error, which is the difference between the current estimate and the new target value:
α: Learning rate (0 ≤ α ≤ 1)
TD Error: [Rt+1 + γ maxa' Q(st+1, a') - Q(st, at)]
←: Update operation
Immediate Reward (Rt+1)
Direct feedback from the environment after taking action at
Discount Factor (γ)
Determines importance of future rewards (0 = myopic, 1 = far-sighted)
Learning Rate (α)
Controls how much new info overrides old info
The key innovation in Q-learning is the use of temporal difference (TD) error, which represents the difference between the current Q-value estimate and the newly computed target value:
This error term drives the learning process by indicating how much the current estimate needs to be adjusted.
Q-learning uses bootstrapping, where current estimates are used to update other estimates. This is evident in the term maxa' Q(st+1, a'), which uses the current Q-table to estimate future rewards.
This bootstrapping approach allows Q-learning to learn from incomplete episodes, making it more sample-efficient than Monte Carlo methods.
Q-learning is an off-policy algorithm because it learns the optimal policy while following an exploration policy (like ε-greedy). The update rule uses the maximum Q-value of the next state, regardless of the action actually taken next.
Under the following conditions, Q-learning is guaranteed to converge to the optimal Q-function:
Initialize Q(s, a) arbitrarily
for each episode do
Initialize state s
for each step in episode do
Choose action a from s using policy (ε-greedy)
Take action a, observe R, s'
Q(s, a) ← Q(s, a) + α[R + γ maxa' Q(s', a') - Q(s, a)]
s ← s'
until s is terminal
end for
Q(s,a) ← Q(s,a) + α[R + γ max Q(s',a') - Q(s,a)]
Learning Rate (α)
Typically starts between 0.1 and 0.5, then annealed over time
Discount Factor (γ)
Close to 1 for long-term planning (e.g., 0.9, 0.99)
Exploration Rate (ε)
Starts high (1.0), decays to small value (0.01)
Memory Limitations
Q-table grows with state-action space (curse of dimensionality)
Sparse Rewards
Delayed rewards make learning difficult
Exploration-Exploitation
Balancing new actions vs. known good actions