Equations · Watkins, “Learning from Delayed Rewards” (PhD thesis, 1989); Watkins and Dayan, “Q-learning” (1992)
The Q-learning update rule, explained
Q-learning learns the value of each action in each state from experience, one transition at a time. It nudges the current estimate toward the reward received plus the best value available from the next state. Deep Q-networks (DQN) use the same target with a neural network in place of the table.
Term by term
The current estimate of the action value: the expected return from taking action in state and acting well afterwards. Not the query matrix of attention.
Action-value function Q · State s and action a · Subscript (index or label)
Assignment: overwrite the stored value. This is an update rule, not an equation.
The learning rate, between 0 and 1: how far to move toward the target.
The TD target: the reward received plus the discounted value of the best action in the next state. The max is what makes Q-learning learn the optimal policy's values whatever policy collected the data (off-policy).
Reward r · Gamma · Max and min
The TD error, often written : target minus current estimate. Zero when the estimate already agrees with the target.
A small worked example
, reward , the best action in the next state has , , . Target: . TD error: . New value: . At the end of an episode the target is just .
In code
import numpy as np
def q_update(Q, s, a, r, s2, done, alpha=0.1, gamma=0.99):
# Q: (num_states, num_actions) table
target = r if done else r + gamma * Q[s2].max()
Q[s, a] += alpha * (target - Q[s, a])Every symbol in it
Other equations
- Scaled dot-product attention
- Softmax
- Cross-entropy loss
- Adam update
- Layer normalization
- RMSNorm
- The ELBO
- KL divergence
- Backpropagation through one layer
- LoRA
- GELU
- Dropout
- Batch normalization
- Rotary position embedding (RoPE)
- Multi-head attention
- PPO clipped objective
- DPO loss
- Policy gradient (REINFORCE)
- Bellman equation
- InfoNCE contrastive loss
- Diffusion forward process
- DDPM simplified loss
- VAE reparameterization trick
- GAN minimax objective
- AdamW
- Cosine learning-rate schedule
- Perplexity
- Logistic regression
- Normal equation (linear regression)
- Singular value decomposition (SVD)
- Principal component analysis (PCA)