Introduction, chapter 1 · 20 min read

Introduction

Learning by trial and error

What reinforcement learning is, how it differs from supervised and unsupervised learning, the elements of an RL system, and a tic-tac-toe player that improves from its own play.

Reinforcement learning

Learning from interaction is among the most basic forms of learning. An infant waving its arms or a cyclist finding balance has no explicit teacher, yet receives a constant stream of feedback about the consequences of its actions.

Reinforcement learning (RL) is the computational study of this kind of learning: learning what to do, that is, how to map situations, or states , to actions , so as to maximize a numerical reward signal. The learner is not told which actions to take. It must discover which actions yield the most reward by trying them.

Formally, the agent searches for a policy , a rule that maps each state to an action, that maximizes the total reward it collects. Hover over or tap any symbol to see what it means.

Two features distinguish RL from other kinds of learning. Trial-and-error search: the correct action is never given and must be found by experimentation. Delayed reward: an action affects not only the immediate reward but also the next situation, and through it all subsequent rewards.

RL is the third paradigm of machine learning. Supervised learning learns from labeled examples of correct behavior. Unsupervised learning finds hidden structure in unlabeled data. RL has neither: it learns from its own experience, guided only by reward. It also faces a trade-off that the other two do not, between exploiting actions known to work and exploring others that might work better.

Classify each case below.

Examples

The agent and its world

Sutton and Barto's examples range from a chess master choosing a move and a gazelle calf that runs within half an hour of birth, to an adaptive controller tuning a refinery in real time. Recent applications include AlphaGo, robot control, targeted advertising, treatment selection and autonomous driving.

All share one structure. An agent interacts with an environment over discrete time steps. At each step it observes a state , selects an action , and receives a reward together with the next state. Because actions change future states, a correct choice must take delayed consequences into account.

Select an example and step through the interaction loop:

Agent
action
new state and reward
Environment
Time step 0

The agent's objective in one sentence (hover over the underlined terms):

Learn to make optimal sequences of decisions in an unknown environment by trial and error.

Elements of reinforcement learning

Policy, reward, value and model

Beyond the agent and the environment, an RL system has four main elements. Each is illustrated below with Zero, the dog from the home page.

Policy

A mapping from perceived states to actions. It may be a lookup table, a function or an extensive search, and it may be stochastic, assigning a probability to each action. The policy alone determines behavior.

Zero: “When I hear ‘Sit!’, I usually sit.”

Reward signal

A single number sent by the environment at each time step. It defines the goal: the agent's sole objective is to maximize total reward over the long run.

Zero: “A treat is good. ‘No!’ is bad.”

Value function

The total reward the agent can expect to accumulate, starting from a state. Reward indicates what is good immediately; value indicates what is good in the long run.

Zero: “The kitchen is a great place to be. Food tends to appear there.”

Model (optional)

A predictor of the environment: given a state and an action, it returns the likely next state and reward. Models enable planning. Methods that use them are model-based; pure trial-and-error methods are model-free.

Zero: “If I bring the leash, a walk will probably follow.”

Reward and value can disagree. Below, Zero stands in a corridor with a small reward (+1) one step to the left and a large reward (+10) four steps to the right. The discount factor γ sets how much a future reward counts today: a reward k steps away is weighted by γk. Adjust γ and compare the values.

0.90

The number under each cell is its value under the best policy, and the arrows show the best action. With a small γ the near reward dominates; with a large γ the agent passes it for the larger, later one. Sutton and Barto call efficient value estimation arguably the most important thing learned about RL in six decades. It is central to almost every method in this book.

Limitations and scope

What this book covers, and what it leaves out

RL relies heavily on the concept of state: the information available to the agent about its environment at a given time. This book treats the state signal as given and concentrates on decision making, that is, which action to take as a function of the state, rather than on how the state representation is constructed.

Not every method estimates value functions. Evolutionary methods, such as genetic algorithms and simulated annealing, evaluate many fixed policies, keep the best and vary them. They can be effective when the policy space is small or easy to search, but they ignore the structure of the problem: which states were visited and which actions were taken within each episode.

The methods in this book learn during interaction, from individual steps, which usually makes far more efficient use of experience. The next example shows how.

An extended example: tic-tac-toe

A player that teaches itself

Consider a tic-tac-toe player that learns to exploit an imperfect opponent, with no strategy programmed in.

Keep a table with one number per board position: the current estimate of the probability of winning from that position, its value . Positions with three Xs in a row have value 1, lost or drawn positions have value 0, and all others start at 0.5.

To move, X examines every position it can reach and usually selects the one with the highest value, a greedy move. Occasionally it selects a random move instead, an exploratory move, to gain information about positions it would otherwise never see.

After each greedy move, the value of the earlier position is moved a fraction of the way toward the value of the later one:

One update, worked through with concrete numbers:

This is a temporal-difference (TD) learning method: the update is driven by the difference between estimates at two successive times. Play against X, train it against a random opponent, then play again.

Train X

The percentage on each empty square is X's estimated probability of winning if it plays there. All estimates start at 50%. After training, X has learned which moves win against a careless opponent, from nothing but its own play.

Summary

Four key characteristics

  1. Optimization

    The agent maximizes a measurable reward. The reward is a design choice: change it and the learned behavior changes, as when Zero is rewarded for spinning.

  2. Exploration vs. exploitation

    Obtaining reward requires exploiting actions known to work; finding them requires exploring. Neither can be pursued exclusively without failing at the task.

  3. Delayed reward

    Actions affect future states, so a greedy choice now can be costly later. Value functions account for these long-term consequences.

  4. Generalization

    Most real problems have far too many states to visit each one. Backgammon has about 1020 positions, so the agent must generalize from experienced states to unseen ones.

Part I treats problems small enough for tabular methods, such as tic-tac-toe. Part II covers large problems, where tables are replaced by function approximators such as neural networks.

Early history of reinforcement learning

Three threads that came together

Trial and error in animals

Rooted in animal psychology. Thorndike's Law of Effect (1911), drawn from cats escaping puzzle boxes, states that actions followed by satisfying outcomes become more likely to recur. Zero's training on the home page follows the same principle.

Optimal control

In the 1950s Richard Bellman developed dynamic programming and the Bellman equation for controllers that optimize behavior over time in a known system. Value functions and Markov decision processes originate here.

Temporal-difference learning

Learning driven by the difference between successive estimates appears in Arthur Samuel's checkers program (1959) and was formalized as a general method by Richard Sutton (1988).

Chris Watkins's Q-learning (1989) unified the three threads and marks the beginning of modern reinforcement learning. The milestones timeline continues the story.