The diagram shows why TD works: at each step, we get new information (the actual reward Rt+1) that makes our estimate more accurate than it was before.
The three estimates in play:
Old estimate:V(St) — what we thought before taking action
Actual sample: We observe Rt+1 — real, experienced data
TD target:Rt+1+γV(St+1) — combines real reward with our current best guess about the future
Why this is smarter than Monte Carlo:
MC waits until episode end to see Gt=Rt+1+γRt+2+γ2Rt+3+⋯
TD substitutes V(St+1) for the infinite sum Rt+2+γRt+3+⋯
This reduces variance because we're estimating less (only one step of randomness)
But introduces bias because V(St+1) is not the true value (yet)
Recall Feynman Explanation (Explain to a 12-year-old)
Imagine you're walking home from school, and you want to guess how long it will take. You could:
Monte Carlo way: Walk all the way home, check your watch, and then say "Oh, it took 20 minutes." Only update your guess after you're done.
TD way: After each block, update your guess. "I thought it'd take 20 minutes total, but I just walked one block in 2 minutes, and I think the rest will take 17 more minutes. So my new guess is 2 + 17 = 19 minutes."
TD is smarter because:
You learn during the walk, not just at the end
If something unexpected happens (like hitting traffic), you update your guess right away
By the time you're halfway home, you already have a pretty good estimate
The "temporal difference" is the difference between what you thought would happen and what actually happened. Every time reality surprises you (good or bad), you adjust your guess a little bit.
Why the fancy math?Rt+1+γV(St+1)−V(St) is just:
Rt+1 = what just happened (like walking one block)
V(St+1) = your guess for the rest of the journey
V(St) = your old guess for the full journey
The difference tells you if your old guess was too high or too low!
Bias-variance tradeoff: TD has lower variance than MC but introduces bias from bootstrapping
Faster propagation: Values spread backward through state space more efficiently than MC
#flashcards/ai-ml
What is the fundamental idea behind Temporal Difference learning? :: TD learning updates value estimates immediately after each step by comparing the current prediction with a new prediction based on the actual reward received plus the estimated value of the next state (bootstrapping). It learns from incomplete episodes.
What is the TD(0) update rule?
V(St)←V(St)+α[Rt+1+γV(St+1)−V(St)], where the bracketed term is the TD error measuring how much our prediction was off.
What is the TD error formula and what does it represent?
δt=Rt+1+γV(St+1)−V(St). It represents the difference between our improved estimate (TD target: Rt+1+γV(St+1)) and our old estimate V(St). It tells us how wrong we were.
What is the TD target?
The TD target is Rt+1+γV(St+1). It's our improved estimate combining the actual observed reward Rt+1 with our current best guess about future value γV(St+1).
What is bootstrapping in the context of TD learning?
Bootstrapping means updating an estimate based on other estimates rather than waiting for actual final outcomes. TD uses V(St+1) (an estimate) to update V(St), rather than waiting for the true return Gt.
What are the three key differences between TD and Monte Carlo?
1) TD updates online (each step) vs MC updates after episode; 2) TD bootstraps from estimates vs MC uses actual returns; 3) TD is biased but lower variance vs MC is unbiased but higher variance.
Why does TD learning have lower variance than Monte Carlo?
TD only depends on one step of randomness (R_{t+1} and S_{t+1}), then uses an estimate. MC depends on the randomness of all remaining steps in the episode. Fewer random variables = lower variance.
Why does TD learning have bias while Monte Carlo does not?
TD uses V(St+1) which is an estimate (not the true value) to compute the target. This introduces bias. MC uses the actual return Gt, which is an unbiased sample of the true value.
Is TD learning model-free or model-based and why?
Model-free. TD learns from sampled experience (transitions) without needing to know the transition dynamics P(s′∣s,a) or reward function R(s,a). We observe (St,At,Rt+1,St+1) directly from environment interaction.
What properties must the learning rate α satisfy for TD convergence?
For guaranteed convergence: ∑t=1∞αt=∞ (sufficient learning) and ∑t=1∞αt2<∞ (decreasing step sizes). Example: αt=1/t or αt=1/n(s) where n(s) is state visit count.
How does TD learning propagate value information through state space?
Backward propagation: states near rewards learn first, then their predecessors learn from them, creating a value gradient. Each state "teaches" its predecessor through bootstrapping, allowing faster propagation than MC.
What happens if you set α=1 in TD learning?
With α=1, you get V(St)←Rt+1+γV(St+1), completely replacing the old estimate with a single noisy sample. This causes wild oscillations and prevents convergence—no smoothing over multiple experiences.
What are the advantages of TD over Dynamic Programming?
TD is model-free (doesn't require knowing P(s′∣s,a) or R(s,a)), learns from actual experience, and naturally handles stochastic environments without neding to compute expectations over all possible transitions.
Why might TD error never reach zero even with perfect value estimates?
Due to stochasticity in the environment. Even with correct values, random rewards and transitions cause TD error to fluctuate around zero. Only the expected TD error E[δt] converges to zero, not individual samples.
What is the relationship between TD(0) and the Bellman equation?
TD(0) is a stochastic approximation to the Bellman equation. The TD target Rt+1+γV(St+1) is a sampled estimate of the right side of the Bellman equation E[Rt+1+γV(St+1)∣St].
Temporal Difference learning ko samajhne ke liye ek simple examplete hain. Maan lo tum school se ghar jaa rahe ho aur tumhe guess karna hai kitna time lagega. Monte Carlo method mein tum pora walk complete karte ho, tab jake update karte ho—"Oh, 20 minute laga." Lekin TD learning smart hai—har block ke bad tum apna guess update karlete ho: "Ek block mein 2 minute laga, baki ka 17 minute lagega, toh total 19 minute." Real-time learning hai ye.
TD ka core idea hai bootstrapping—matlab tum apne hi estimates seekhte ho. Formula dekho: V(St)←V(St)+α[Rt+1+γV(St+1)−V(St)]. Yahan Rt+1 actual reward hai jo tumne dekha, aur V(St+1) tumhara next state ka estimate hai. Dono ko combine karke "TD target" banta hai, jisko tum apne purane estimate V(St) se compare karte ho. Jo difference ata hai, usko "TD error" bolte hain—ye bata hai ki tumhara prediction kitna galat tha.
Ye approach powerful kyon hai? Pehla, episodes incomplete bhi hon tab bhi kaam karta hai—khelne ke bech mein hi seekh lete ho, wait nahi karna padta. Dosra, values jaldi propagate hoti hain backwards—goal ke pas wale states pehle seekhte hain, phir unke pehle wale, aur aise hi chain reaction hoti hai. Monte Carlo mein har state ko khud puri episode khelni padti hai value seekhne ke liye, lekin TD mein ek state apne neighbor seekh leta hai.
Ek common confusion: log sochte hain ki TD error zero ho jayega jab learning complete hogi. Galat! Environment stochastic hai—random rewards aur transitions hain. Toh individual TD errors fluctuate karte rahenge, lekin average zero ke around hoga. Aur learning rate alpha ko carefully choose karna padta hai—zyada b toh values oscillate karenge, bohot chhota toh learning slow hogi. TD learning reinforcement learning ki backbone hai—Q-learning, SARSA, sabhi isi foundation pe khade hain.