What Is Reinforcement Learning?
Learning to act from trial, error and reward.
Suppose you had to teach a skill without ever showing the right move, only handing out points afterward. That is the deal in reinforcement learning, and it has produced champion game players, controllers for fusion plasma and the final polish on chat assistants. You start this lesson as the learner yourself, then watch agents plan, explore and learn, and finish with a map of the whole course.
What you’ll learn
- Explain what makes reinforcement learning different from learning from labeled examples: the feedback is a score, it is often delayed, and it depends on the learner's own actions.
- Use the words of the agent–environment loop correctly: state, action, reward, return, policy and value.
- Compute a discounted return and explain why rewards further in the future count less.
- Explain the exploration–exploitation dilemma, and the difference between planning with a model and learning from experience.
- Place the ten topics of this course on one map and say which question each one answers.
You are the agent
Here are five slot machines. Each one pays a point with its own fixed probability, and nobody will tell you which is best. There is no manual and no teacher, only the points you collect. Pull a few dozen times and try to win as much as you can.
Learning to act from a score, by trial and error, is reinforcement learning (RL). In a moment you will name what you just did. First, play.
Think first On every pull you faced the same choice. What was it, and why is there no free lunch?
Pull the machine with the best record so far, or try one you know less about. The first is exploitation: cashing in on what you know. The second is exploration: paying a little now for information that may pay off later. Explore too little and you can lock onto a mediocre machine forever; explore too much and you waste pulls on machines you already know are bad. This exploration–exploitation dilemma appears in every RL problem, and slot machines, the multi-armed bandit, are its purest form.
After a few pulls, machine A has paid 6 times out of 7 and machine B once out of 3. What is the soundest conclusion?
- A is certainly better, so B should never be pulled again
- B is due for a win, so pull B next
- A looks better, but three pulls of B say little: B could still be the best machine, so trying it again has value
- Pull A and B in strict alternation from now on
Show the answer
C. A looks better, but three pulls of B say little: B could still be the best machine, so trying it again has value
Three pulls cannot pin down B's rate: a machine that pays 60% of the time still pays only once in three pulls about 29% of the time. Estimates from few tries are uncertain, and good strategies keep exploring in proportion to that uncertainty. Thompson sampling does exactly that, which is why its regret curve flattens while greedy's can keep climbing.
The agent–environment loop
Every RL problem has the same shape. An agent, the learner and decision maker, interacts with an environment, which is everything else, in discrete steps. At step the agent observes the state and chooses an action ; the environment answers with a number, the reward , and a new state . Then it repeats.
The agent's rule for choosing actions is its policy, written : in each state it says which action to take, or with what probabilities. The goal is not the next reward but the total collected over the long run, the return. That is what makes RL hard: a move can look bad now and turn out brilliant later.
| Problem | State | Actions | Reward |
|---|---|---|---|
| Go | The board position | Legal moves | for a win, for a loss, 0 until the game ends |
| A robot arm picking up a cup | Joint angles, a camera image | Motor commands | when the cup is lifted |
| Heating and cooling a building | Temperatures, occupancy, weather | Heater and chiller settings | Minus the energy cost, minus a penalty for discomfort |
| Video recommendations | The user's recent history | Which video to show | Watch time, a stand-in for satisfaction |
| Fine-tuning a chat assistant | The conversation so far | The next piece of text | A score from a model of human preferences |
Compare this with learning from labeled examples, the supervised learning behind spam filters and image classifiers, where every example comes with the right answer. In RL:
- the feedback is a score, not an answer: a reward of 3 says how well things went, never what you should have done;
- the feedback is delayed: a game is won or lost only at the end, so the agent must work out which of its many moves deserve the credit, the credit assignment problem;
- the data depend on the agent: what it sees next depends on what it chose, so a timid agent never learns what lies beyond its comfort zone.
Which of these is a reinforcement learning problem?
- Predicting tomorrow's temperature from ten years of weather records
- Labeling photos as cats or dogs, given 10,000 labeled photos
- Grouping customers by their shopping habits
- Learning when to heat and cool a building, judged only by the energy bills and comfort complaints that follow
Show the answer
D. Learning when to heat and cool a building, judged only by the energy bills and comfort complaints that follow
The building controller's choices change what happens next and are judged only by a delayed score, with no one saying which setting would have been right. The other three are prediction from labeled data (the first two) or finding structure without labels (the third).
Rewards, returns and the price of waiting
If an agent simply added up all its future rewards, a task that never ends could have an infinite total. RL usually discounts instead: a reward steps ahead is multiplied by , where the discount factor is a number between 0 and 1.
There are three reasons to discount:
- the future is uncertain: if the world might end, or change, at each step with probability , a reward steps away arrives only with probability ;
- sooner is more useful: a reward now can be put to work, just as money now earns interest;
- the math stays finite: with rewards of at most 1, the return is at most .
That last number says roughly how far ahead the agent looks, its effective horizon: 10 steps for , 100 steps for .
A robot pays a cost of 1 for every step (a reward of ) and reaches its charger, worth , on the third step: its rewards are . With , what is its return ?
Show the answer
6.2
. A route that reached the charger one step sooner would be worth : the step costs and the discount both reward getting there quickly.
Rewards are how you tell an agent what you want, not how to do it. Sutton and Barto's example: reward a chess program for winning, not for capturing pieces. Rewarded for captures, it may learn to win material and lose games. An agent optimizes exactly the number you give it, and it finds loopholes you did not imagine.
Policies and values: planning with a map
How should an agent choose? The key quantity is value: the expected return from a state when you follow a given policy from there on. A state can be valuable without paying anything itself, because of where it leads. If you know the rules of the world, how each action moves you and what it pays, you can compute values without taking a single real step. That is planning with a model, and its classic method is dynamic programming, developed by Richard Bellman in the 1950s.
The whole idea fits in one sentence, the Bellman equation: the value of where you stand is the reward of your best move plus the discounted value of where that move takes you (averaged over the possible landing places when moves can slip). Value iteration repeats that calculation for every state, sweep after sweep, and each sweep carries news of the rewards one cell further.
Think first With no living reward, the exit is five moves from the start, and . Why is the start worth only about 0.49?
Moves slip sideways 20% of the time, so the trip takes more than five moves on average, and every extra move multiplies the eventual by another 0.9. (Bumping into a wall costs nothing but that lost step.) The optimal route keeps away from the pit, so the barely enters. Set the noise to 0 and the start is worth exactly .
Learning from experience
Real agents rarely get the map. A robot does not know its own exact physics, and a recommender cannot write down how people will respond. Two families of methods cope:
- Model-based RL learns a model of how the world works from experience, then plans with it.
- Model-free RL skips the model and learns values or a policy directly from experience.
Q-learning (Watkins, 1989) is the classic model-free method. For every state and action it keeps an estimate of the return, an action value. After each step it compares that estimate with what it just saw, the reward plus its own estimate of the best next action, and moves part of the way toward it.
In the maze below the goal pays , moves never slip, and the shortest route from the start takes 13 moves. With , what value should the start's best action settle at once the agent has learned a shortest route?
Show the answer
0.25
: the loses a factor of 0.9 for each move. After training, read the start cell's largest Q-value. It climbs toward 0.25 as the agent's route becomes a shortest one.
A short history, and RL at work
| Where | What RL does there | The honest caveat |
|---|---|---|
| Games | Expert or superhuman play in backgammon, Go, chess, Atari games and StarCraft II, mostly learned through self-play | Needs a perfect simulator and an enormous amount of play |
| Robotics | Legged locomotion, dexterous manipulation and drone racing, usually trained in simulation | Transfer from simulation to the real machine (sim-to-real) is fragile, and real trials are slow and can break hardware |
| Control of physical systems | Shaping the plasma in an experimental fusion reactor, a tokamak (2022), and steering stratospheric balloons (2020) | Built on accurate simulators and safety checks: landmark demonstrations, not yet routine practice |
| Recommendation | Choosing what to show next to raise long-term engagement | The reward is a proxy (clicks, watch time) that can drift from what users value, and most learning is from logged data |
| Language models | RL from human feedback and from checkable answers fine-tunes pretrained models | How much RL adds beyond pretraining is debated, and optimizing a learned reward can exploit its flaws (reward hacking) |
The map of this course
This course is a state space with ten regions, each explored on three levels. Exploration lessons like this one build intuition with live agents. Bootstrapping lessons give the algorithms, the math and the code. Fixed Point lessons prove the theorems and reach the research frontier.
| Topic | The question it answers |
|---|---|
| What problem do all RL methods solve, and in what language? (You are here.) |
| How much should you experiment before you commit, when every trial costs something? |
| If you know the rules of the world, how do you compute the best behavior? |
| How do you learn values from samples alone, without the rules? |
| How do you generalize when there are far too many states to visit, as in Atari from pixels? |
| How do you improve behavior directly, by following the gradient of the expected return? |
| How do you learn how the world works, and then plan, search or practice inside that model? |
| How do you learn from experts and from logged data, without trial and error? |
| What changes when several learners share one world, from poker to traffic? |
| How is RL used to train language models, keep agents safe and within bounds, organize behavior into reusable skills, and build agents that learn to learn? |
The rest of this topic has four Bootstrapping lessons. Agents, Environments & Rewards makes the interaction loop, returns and time limits precise. Markov Decision Processes builds the formal model of states, actions and transition probabilities. Value Functions & the Bellman Equations derives the equations that pin values down and solves them. The Map of RL Algorithms lays out the families you will meet, value-based or policy-based, model-free or model-based, on- or off-policy, online or offline, and when to reach for each.
A hospital wants a better treatment policy, but it can only learn from the records of past patients: no new trials are allowed. Which topic addresses this?
- Bandits & the Explore–Exploit Dilemma
- Learning from Demonstrations & Data
- Multi-Agent RL & Games
- Planning with a Model: Dynamic Programming
Show the answer
B. Learning from Demonstrations & Data
Learning a policy from a fixed log of past decisions, without new interaction, is offline RL. It belongs to Learning from Demonstrations & Data, together with imitation learning and estimating a new policy's value from old records.
Key takeaways
- Reinforcement learning learns to act from rewards: feedback that scores outcomes instead of naming the right action, often arrives late, and depends on what the agent chose.
- The loop: observe a state, act, receive a reward and a new state. A policy picks the actions; the goal is the return, the discounted sum of rewards.
- Discounting by makes later rewards count less, keeps returns finite, and sets an effective horizon of about steps.
- Every agent must balance exploration (gaining information) against exploitation (using it).
- Values measure long-run worth. With a model they can be computed by planning (dynamic programming); without one they are learned from experience (Q-learning), at the price of many samples.
- Rewards specify what to achieve, not how, and agents exploit every loophole in a badly specified reward.
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
A program learns chess from a database in which every position is labeled with a grandmaster's move. Why is this not reinforcement learning?
- Because chess is a game
- Because it is told the correct move for each position instead of learning from a score of its own play
- Because it does not use a neural network
- Because chess has too many positions
Show the answer
B. Because it is told the correct move for each position instead of learning from a score of its own play
Being told the right action is supervised learning, here imitation of an expert. RL gets only evaluative feedback, such as winning or losing, on actions it chose itself, and must discover which moves were responsible.
Plan A pays 10 right away. Plan B pays nothing now and 15 one step later. For which discount factors does plan B have the larger return?
- For every
- For
- For
- For no below 1
Show the answer
C. For
Plan B is worth and plan A is worth 10, so B wins when . A patient agent (large ) waits for the bigger reward; an impatient one takes the 10.
What does the value of a state measure?
- The reward received on entering it
- The number of steps to the nearest exit
- How often the agent has visited it
- The expected return from that state onward, when following a given policy
Show the answer
D. The expected return from that state onward, when following a given policy
Value looks ahead: it is the expected discounted sum of all future rewards from the state under a policy. In the gridworld, most cells pay nothing themselves yet have positive value because of where they lead.
Once the maze agent has reached the goal a few times, why does it still need some random moves?
- Its estimates come only from routes it has tried, so a shorter or safer route can be found only by trying actions its current estimates do not favor
- Random moves make the Q-values on the route it already knows converge faster
- Without random moves the agent would stop moving
- Random moves are needed to make the rewards random
Show the answer
A. Its estimates come only from routes it has tried, so a shorter or safer route can be found only by trying actions its current estimates do not favor
Exploitation follows the best route known so far, which need not be the best route. A little exploration keeps testing alternatives, and good exploration strategies (the Bandits topic) aim it where the agent is most uncertain.
Which statement correctly contrasts value iteration and Q-learning?
- Value iteration learns by trial and error; Q-learning needs the transition probabilities
- Both need the full rules of the world
- Value iteration needs the rules (a model) but no experience; Q-learning needs experience but no model
- Q-learning works only in games
Show the answer
C. Value iteration needs the rules (a model) but no experience; Q-learning needs experience but no model
Value iteration is planning: it computes values from known transition probabilities and rewards. Q-learning is model-free learning: it estimates action values from the transitions it experiences. Model-based RL sits in between, learning a model from experience and planning with it.
Go deeper
- Agents, Environments & Rewards · The interaction loop, rewards and returns: the problem every RL method solves.
- Markov Decision Processes · States, actions and transition probabilities: the mathematical model of sequential decisions.
- Value Functions & the Bellman Equations · What states and actions are worth, and the recursive equations that pin values down.
- The Map of RL Algorithms · Model-free or model-based, value or policy, on- or off-policy, online or offline.
Further reading
- R. S. Sutton & A. G. Barto, Reinforcement Learning: An Introduction, ch. 1 and 3 (MIT Press, 2nd ed., 2018).
- D. Silver et al., "Mastering the game of Go with deep neural networks and tree search," Nature 529, 484–489 (2016).