Notes taken from my Reinforcement Learning module at university. The ideas and concepts are taken from both the module’s learning materials and the first 6 chapters of the course textbook “Reinforcement Learning: An Introduction” by Sutton and Barto.

Dynamic programming and Monte Carlo methods are both classes of methods within reinforcement learning used to solve sequential decision problems.

Temporal-Difference (TD\text{TD}) learning methods combine the core ideas of the two. Like Monte Carlo methods, they learn purely from the agent’s experience without relying on a model of the agent’s environment. However unlike Monte Carlo methods, they do not require full episodes of experience in order to learn. Instead, they use bootstrapping (learning estimates of value functions based on the estimates of other state’s value functions), like Dynamic Programming methods, to learn from shorter fragments of experience.

Looking at the simplest version, TD(0)\text{TD(0)}, otherwise known as one step TD\text{TD} learning, for an agent that starts in state StS_{t}, takes action AtA_{t} according to its policy π\pi, transitions to state St+1S_{t+1} and earns reward Rt+1R_{t+1}, performs the following update:

V(St)←V(St)+α[Rt+1+γV(St+1)−V(St)]V(S_{t}) \leftarrow V(S_{t}) + \alpha[R_{t+1} + \gamma V(S_{t+1}) - V(S_{t})]

Comparing the backup diagrams:

Dynamic ProgrammingMonte CarloTD(0)StStSt↙↓↘↓↓ (1 step)◯◯◯◯St+1 (bootstraps!)(all possible futures)⋮■ (Terminal)\begin{array}{ccc} \textbf{Dynamic Programming} & \textbf{Monte Carlo} & \textbf{TD(0)} \\[6pt] S_t & S_t & S_t \\ \swarrow \quad \downarrow \quad \searrow & \downarrow & \downarrow \text{ \scriptsize (1 step)} \\ \bigcirc \quad \bigcirc \quad \bigcirc & \bigcirc & S_{t+1} \text{ \scriptsize (bootstraps!)} \\ \text{\scriptsize (all possible futures)} & \vdots & \\ & \blacksquare \text{ \scriptsize (Terminal)} & \end{array}

In TD(0)\text{TD}(0), the bracketed term is the TD error (δt\delta_t), which measures the gap between our old estimate and the new one-step reality:

δt=Rt+1+γV(St+1)−V(St)\delta_t = R_{t+1} + \gamma V(S_{t+1}) - V(S_t)

TD\text{TD} control methods extend this exact same error-driven update to action-value functions.

Advantages of TD Learning

  • Learns straight from raw experience so no transition probabilities needed (model-free).
  • Updates after a single step instead of waiting for an episode to end, so it can learn quicker.
  • Faster convergence as it usually beats Monte Carlo on stochastic tasks because bootstrapping links states together, allowing TD\text{TD} methods to implicitly exploit the environment’s Markov structure without storing a full transition matrix.

Sarsa and Q-Learning

State values V(s)V(s) only tell us how good a state is; without a model, we need action values Q(s,a)Q(s, a) to pick actions (control):

St→  At  Rt+1,  St+1→  At+1  Q(St+1,At+1)S_t \xrightarrow{\;A_t\;} R_{t+1},\; S_{t+1} \xrightarrow{\;A_{t+1}\;} Q(S_{t+1}, A_{t+1})
  • Sarsa (On-Policy): Evaluates and improves the same policy the agent is currently following (e.g. ε\varepsilon-greedy), updating from the quintuple (St,At,Rt+1,St+1,At+1)(S_t, A_t, R_{t+1}, S_{t+1}, A_{t+1}): Q(St,At)←Q(St,At)+α[Rt+1+γQ(St+1,At+1)−Q(St,At)]Q(S_t, A_t) \leftarrow Q(S_t, A_t) + \alpha\big[R_{t+1} + \gamma Q(S_{t+1}, A_{t+1}) - Q(S_t, A_t)\big]
  • Q-Learning (Off-Policy): Directly approximates the optimal action-value function q∗q_* by bootstrapping off the best possible next action, regardless of whatever exploratory move the agent actually took: Q(St,At)←Q(St,At)+α[Rt+1+γmax⁡aQ(St+1,a)−Q(St,At)]Q(S_t, A_t) \leftarrow Q(S_t, A_t) + \alpha\big[R_{t+1} + \gamma \max_{a} Q(S_{t+1}, a) - Q(S_t, A_t)\big]

nn-Step and Planning Methods

TD(0)\text{TD}(0) and Monte Carlo sit at opposite ends of a single spectrum:

TD(0)⏟n=1⟷n-step TD⏟1<n<∞⟷Monte Carlo⏟n=∞\underbrace{\text{TD}(0)}_{n = 1} \longleftrightarrow \underbrace{n\text{-step TD}}_{1 < n < \infty} \longleftrightarrow \underbrace{\text{Monte Carlo}}_{n = \infty}
  • nn-Step TD\text{TD}: Collects nn real rewards before bootstrapping from V(St+n)V(S_{t+n}), using the nn-step return: Gt(n)=Rt+1+γRt+2+⋯+γn−1Rt+n+γnV(St+n)G_t^{(n)} = R_{t+1} + \gamma R_{t+2} + \dots + \gamma^{n-1} R_{t+n} + \gamma^n V(S_{t+n}) Methods like TD(λ)\text{TD}(\lambda) blend multiple nn-step returns together using eligibility traces.
  • Planning (e.g. Dyna): TD\text{TD} isn’t restricted to real experience. An agent can use real transitions to learn an environment model, then run the exact same TD\text{TD} updates (like Q-learning) on simulated transitions from that model to speed up learning.

References

  • Sutton, R. S., & Barto, A. G. Reinforcement Learning: An Introduction. The MIT Press.