MLCrack

    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-PolicyOff-Policy
    ExampleSARSA, PPO, A2CQ-learning, DQN, SAC
    Data sourceCurrent policyAny policy (replay buffer)
    Sample efficiencyLowerHigher (reuse old data)
    StabilityMore stableCan be unstable
    ExplorationTied to learning policyDecoupled

    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 actions

    Off-policy methods can use experience replay buffers, making them more sample-efficient but potentially less stable.