Overview

6 Tabular Reinforcement Learning

This chapter builds the core intuition behind tabular reinforcement learning by showing how agents can learn from experience without knowing the environment’s true dynamics. It starts with temporal-difference learning as the key bridge between dynamic programming and practical learning: instead of waiting for final outcomes, an agent updates its estimates step by step using the gap between what it expected and what it observed. The chapter connects this idea to prediction-error signals in neuroscience, then illustrates it with a simple restaurant scheduling problem where the agent learns when to seat customers immediately and when to wait for a better opportunity.

The discussion then develops the distinction between on-policy and off-policy learning. On-policy methods learn from the same behavior they use to act, while off-policy methods learn about an optimal target policy even while behaving differently. This leads naturally to the two main tabular control algorithms: SARSA, which updates from the action actually taken and is therefore more cautious, and Q-learning, which updates from the best possible next action and is more aggressive. Both are represented in a tabular form, where each state-action pair has a stored value, making the method simple, interpretable, and suitable for problems with manageable state spaces.

Finally, the chapter extends one-step temporal-difference learning to TD(λ) and eligibility traces, which distribute credit backward through recently visited states and actions. This gives a practical way to balance the speed of TD learning with the broader credit assignment of Monte Carlo methods. The chapter ends with a larger gas-station inventory control example, where the agent must decide daily whether to order fuel under uncertain demand and delivery delays. In this setting, the tabular methods are shown to learn useful inventory policies, with SARSA, Q-learning, and their trace-based variants revealing tradeoffs among reward, stability, risk, and operational reliability.

Like cooking, we use feedback from error to update parameters step by step.
Like cooking, we use feedback from error to update parameters step by step.
The formula shows how each update moves the old value toward a better one.
The formula shows how each update moves the old value toward a better one.
Convergence behavior of Temporal difference learning algorithm.
Convergence behavior of Temporal difference learning algorithm.
illustration of problem of aligning within the TD framework
illustration of problem of aligning within the TD framework
SARSA Algorithm Flowchart.
SARSA Algorithm Flowchart.
Q-learning Algorithm Flowchart.
Q-learning Algorithm Flowchart.
Comparison of TD(0), Monte Carlo and TD(λ) methods.
Comparison of TD(0), Monte Carlo and TD(λ) methods.
Update mechanism of temporal difference learning with eligibility traces.
Update mechanism of temporal difference learning with eligibility traces.
integrating eligibility trace in SARSA framework: SARSA(λ).
integrating eligibility trace in SARSA framework: SARSA(λ).
Integrating eligibility traces with Q-learning using Watkins's Q(λ) method.
Integrating eligibility traces with Q-learning using Watkins's Q(λ) method.
Tabular Reinforcement Learning Curves and Performance Analysis.
Tabular Reinforcement Learning Curves and Performance Analysis.

Summary

  • In model-based learning, the agent has access to the full dynamics of the environment—the transition probabilities P(s'|s,a) and reward function R(s,a). Dynamic Programming is a model-based approach.
  • In model-free learning, the agent does not know these dynamics and must learn directly from experience tuples (s, a, r, s') gathered through trial and error. Temporal difference learning, Q-learning, and SARSA are all model-free.
  • In offline learning, the agent is trained on a fixed, pre-collected batch of data and does not learn during interaction.
  • In online learning, the agent updates its knowledge continuously during interaction with the environment, learning step-by-step as new experience arrives. All the temporal difference methods discussed in this chapter are online learners.
  • In on-policy learning, the agent learns to improve the same policy it is using to make decisions. It learns from its own "lived experience." SARSA is on-policy.
  • In off-policy learning, the agent can learn about a different policy (the target policy, typically the optimal one) than the one it is using to generate behavior (the behavior policy, typically an exploratory one). Q-learning is off-policy.
  • Temporal-Difference learning is one of the two pillars of reinforcement learning, enabling agents to learn from raw experience without a model of the environment.
  • The core idea of temporal difference learning is to update your predictions based on the error between your current guess and a slightly better guess one step into the future.
  • This process of updating estimates using other estimates is called bootstrapping, and it allows learning to happen online, after every single step.
  • The TD error (δ) is the learning signal, quantifying the "surprise" or difference between what you expected and what you observed.
  • Temporal difference learning is the bridge between Dynamic Programming (which needs a full model) and Monte Carlo methods (which must wait for an episode to end).
  • For an agent to make decisions in a model-free world, it must learn action values (Q(s,a)), not just state values (V(s)).
  • Tabular methods represent the value function as a lookup table or spreadsheet, with a distinct entry for every state-action pair.
  • Q-learning is the quintessential off-policy algorithm; it learns about the optimal greedy policy while behaving according to a different, more exploratory policy.
  • Because Q-learning uses the max Q-value for its update, it is considered optimistic and often converges faster to the optimal policy.
  • SARSA is the quintessential on-policy algorithm; it learns about the same policy it is using to make decisions, including all its exploratory actions.
  • Because SARSA's updates use the Q-value of the actual next action taken, it is considered more realistic or conservative, learning a policy that is robust in the face of its own exploration.
  • The credit assignment problem asks how to distribute credit for a reward among the many actions that may have led to it, especially when rewards are delayed.
  • Eligibility traces (TD(λ)) are the solution, creating a short-term memory that allows the TD error to be propagated backward to all recently visited state-action pairs.
  • The λ parameter controls how far back credit is assigned, providing a tuneable spectrum between one-step TD (λ=0) and Monte Carlo (λ=1).
  • SARSA(λ) is a highly effective on-policy algorithm that combines the stability of SARSA with the learning speed of eligibility traces.
  • Watkins's Q(λ) adapts traces for off-policy learning by resetting the traces to zero whenever a non-greedy (exploratory) action is taken.

FAQ

What is temporal-difference (TD) learning, and why is it important in reinforcement learning?

Temporal-difference learning updates value estimates from experience by using the difference between a prediction and a bootstrapped target. It is important because it enables online, incremental learning without needing a full model of the environment or waiting until an episode ends.

How does TD learning differ from dynamic programming and Monte Carlo methods?

Compared with dynamic programming, TD learning does not require known transition probabilities or a complete model. Compared with Monte Carlo, TD learning updates before the episode ends, which makes it more efficient and suitable for online learning, though it uses bootstrapping instead of full-return estimates.

What is the TD error, and how is it used in value updates?

The TD error is the gap between the observed target and the current estimate. In state-value form, the update uses V(s) ← V(s) + αδ, where δ measures how much the estimate should be adjusted toward the new experience.

What does it mean for reinforcement learning to be on-policy or off-policy?

On-policy learning evaluates and improves the same policy that is generating actions. Off-policy learning evaluates a target policy while following a different behavior policy, allowing more exploratory behavior during data collection while learning a greedy or optimal policy.

What is the main difference between SARSA and Q-learning?

SARSA is an on-policy method that updates using the next action actually taken: Q(s', a'). Q-learning is off-policy and updates using the maximum next-state action value: max_a Q(s', a). SARSA tends to be more conservative, while Q-learning is more optimistic.

Why are tabular methods called “tabular,” and when are they useful?

They are called tabular because they store values in lookup tables, with one entry per state or state-action pair. They are useful when the state space is small enough to represent explicitly and visit many times during training.

What is a Q-table, and what does each entry represent?

A Q-table stores action-value estimates for every state-action pair. Each cell represents the expected return of taking a specific action in a specific state and then following the learned policy afterward.

What problem do eligibility traces solve?

Eligibility traces address the credit assignment problem by spreading TD error backward across recently visited states or actions. This helps earlier decisions receive some credit for later rewards, improving learning in delayed-reward tasks.

What is the difference between accumulating traces and replacing traces?

Accumulating traces add to the trace value each time a state-action pair is revisited, so traces can exceed 1. Replacing traces set the trace to 1 on revisit, which can be more stable and prevents overcounting repeated visits.

Why might SARSA(λ) or Q(λ) behave differently from their one-step versions?

They use eligibility traces to propagate learning updates over multiple past steps, which can speed up learning on delayed-reward problems. However, the extra credit assignment can also add complexity, and in some environments it may not outperform the simpler one-step methods.

pro $24.99 per month

  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose one free eBook per month to keep
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime

lite $19.99 per month

  • access to all Manning books, including MEAPs!

team

5, 10 or 20 seats+ for your team - learn more


Close
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Applied Reinforcement Learning Applied Reinforcement Learning ebook for free
Close
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Applied Reinforcement Learning Applied Reinforcement Learning ebook for free