REINFORCEMENT LEARNING · INTERVIEW QUESTION
Describe the difference between on-policy and off-policy learning.
🟡 intermediate · Fundamentals & MDPs
Hint: On-policy learns from its own actions; off-policy can learn from other agents' experiences.
Answer
On-policy: The agent learns about the policy it is currently using to make decisions.
Off-policy: The agent learns about a different (target) policy than the one generating data (behavior policy).
Comparison
| On-Policy | Off-Policy | |
|---|---|---|
| Example | SARSA, PPO, A2C | Q-learning, DQN, SAC |
| Data source | Current policy | Any policy (replay buffer) |
| Sample efficiency | Lower | Higher (reuse old data) |
| Stability | More stable | Can be unstable |
| Exploration | Tied to learning policy | Decoupled |
SARSA (On-Policy) vs Q-Learning (Off-Policy)
text
# Mathematical pseudocode (not executable Python)
# SARSA: uses action actually taken
Q[s,a] += α * (r + γ * Q[s', a'] - Q[s,a]) # a' from current policy
# Q-Learning: uses best possible action
Q[s,a] += α * (r + γ * max(Q[s', :]) - Q[s,a]) # max over all actionsOff-policy methods can use experience replay buffers, making them more sample-efficient but potentially less stable.
Related questions
- Explain the Bellman equation. How is it used in Q-learning?
- What is reinforcement learning, and how does it differ from supervised and unsupervised learning?
- Explain the exploration-exploitation tradeoff. What strategies address it?
- Define the terms: agent, environment, state, action, and reward in the context of reinforcement learning.
- Can you explain the concept of the Markov Decision Process (MDP) in reinforcement learning?