Chapter 1: Introduction to Reinforcement Learning
Build the mental model behind reinforcement learning: an agent that learns by interacting with an environment, guided only by reward. Understand how RL differs from supervised learning, formalize the agent-environment loop, and meet the core ideas — rewards, returns, policies, value functions, and the exploration-exploitation tradeoff.
- Topics
- 5
- Videos
- 5
- Min read
- 16
Chapter Overview
Reinforcement learning (RL) is the study of how an agent should act in an environment to maximize a cumulative reward signal. Unlike supervised learning, there is no labeled dataset telling the agent the correct action — instead the agent must discover which actions are good by trying them and observing the consequences.
This trial-and-error loop, combined with the idea that actions can have delayed effects, is what makes RL both powerful and challenging. A move in a game, a trade in a market, or a torque applied to a robot joint may only reveal whether it was wise many steps later.
This chapter establishes the vocabulary you will use for the rest of the plan. You will learn to describe any sequential decision problem in terms of states, actions, and rewards; understand why we discount future reward; and see how policies and value functions let an agent reason about long-term consequences. We close with the exploration-exploitation dilemma — the fundamental tension at the heart of every RL algorithm.
This chapter covers:
- What is RL: Learning from interaction versus learning from labels
- The Agent-Environment Interface: States, actions, rewards, and the interaction loop
- Rewards & Returns: The reward hypothesis and discounted return
- Policies & Value Functions: Mapping states to actions and estimating long-term value
- Exploration vs Exploitation: Why an agent must sometimes act sub-optimally to learn
Chapter Roadmap
Click any topic to jump in
What is RL
Learning by interaction: an agent maximizes cumulative reward with no labeled answers, only feedback from the environment.
Agent-Environment Loop
At each step the agent observes a state, picks an action, and receives a reward and next state — the canonical RL interaction.
Policies choose actions; value functions score how much return a state or action is worth.
Rewards & Returns
Goals are encoded as a scalar reward. The return is the discounted sum of future rewards the agent actually tries to maximize.
Policies & Values
A policy maps states to actions; value functions estimate the expected return, letting the agent reason about the long term.
Exploration vs Exploitation
To find the best actions the agent must explore unknown options, while still exploiting what it already knows works.
Topics
5 topics in this chapter
Reinforcement learning sits between supervised and unsupervised learning, but the difference is not a matter of degree — it is a different kind of feedback entirely. In supervised learning a teacher supplies the correct label for every input, so the learner is told what it should have done. In unsupervised learning there are no labels at all, only structure to discover. Reinforcement learning has feedback, but that feedback is evaluative rather than instructive: a reward says how good the chosen action was without ever revealing which action would have been best. Two further complications follow from that. The data is not a fixed dataset handed to you in advance — it is generated by the agent's own choices, so an agent that never tries an action never learns anything about it. And the reward may arrive many steps after the decision that earned it, leaving the agent to work out which of its past actions deserve the credit. Those three properties — evaluative feedback, self-generated data, and delayed consequences — are what make reinforcement learning its own field rather than a variant of supervised learning.
Definition
Reinforcement learning is the study of how an agent should choose actions in an environment so as to maximize cumulative reward over time. The agent is never told the correct action; it receives only a scalar reward signal, and must discover a good policy by trying actions and observing their consequences.
In this topic
- 1Learning From Interaction
- 2Evaluative vs Instructive Feedback
Learning From Interaction
An RL agent learns a behaviour by repeatedly interacting with an environment. At each step it takes an action, the environment responds with a new situation and a numerical reward, and the agent revises its strategy to earn more reward over time. The crucial structural difference from supervised learning is that there is no fixed training set: the data the agent learns from is generated by its own choices. That creates a feedback loop with no analogue in supervised learning: a poor policy visits poor states, collects uninformative data, and stays poor. Good exploration is not a refinement here, it is a precondition for learning anything at all.
RL optimizes an objective over trajectories: maximize , the expected total reward, where the expectation is taken over the agent's own action choices and the environment's dynamics.
Why can't we treat learning to play a game as a standard supervised-learning problem where each board position is labeled with the 'correct' move?
Evaluative vs Instructive Feedback
Instructive feedback names the correct action, so a single example fully determines what the learner should do at that input. Evaluative feedback only scores the action that was actually taken, which means a reward of is uninformative in isolation — you cannot tell whether an unchosen alternative would have scored or . The only way to find out is to try it, and trying it costs whatever the alternative was worth. This is precisely why exploration is a structural requirement of reinforcement learning rather than a heuristic: without it, the value of every untried action stays permanently unknown.
If is the best action, supervised learning observes directly, while RL only observes for the chosen and must infer from samples.
Related Problems on PixelBank
The agent-environment interface is the formal skeleton on which every algorithm in this course hangs. At each discrete timestep the agent observes a state, selects an action, and one step later receives a reward together with the next state. Everything the agent can control lies on one side of that boundary; everything it cannot lies on the other. Drawing the boundary is a modelling decision with real consequences, and the standard convention surprises people: it is placed at the limit of the agent's absolute control, not at the physical body of a robot. A robot's motors and joints belong to the environment, because the agent cannot command a torque and be certain of the resulting motion — friction, wear and load all intervene. What belongs to the agent is only the decision itself. This convention keeps the formalism honest: anything the agent cannot change arbitrarily is part of the problem to be solved, not part of the solver.
Definition
The agent-environment interface is the boundary across which a state passes to the agent, an action passes back, and a reward and next state return. The boundary is drawn at the limit of the agent's absolute control, not at any physical or intuitive division.
In this topic
- 1States, Actions, and Rewards
- 2The Markov Property
States, Actions, and Rewards
A state is whatever the agent observes and conditions its decision on; an action is any decision it can make; a reward is the scalar score the environment returns. The reward is deliberately a single number rather than a vector, because comparing candidate behaviours requires a total ordering — with two competing objectives there is no fact of the matter about which policy is better without a weighting that collapses them into one. Note the indexing convention: the action taken in state produces reward , not . The reward is indexed by when it arrives, which keeps the timing unambiguous once discounting is introduced.
The interaction generates a trajectory The environment is characterized by transition dynamics .
The Markov Property
A state is Markov if it summarizes everything from the history that matters for the future — formally, the distribution of the next state and reward depends on the current state and action alone. This is what makes a value function well defined, because it licenses attaching a single number to a state rather than to an entire history. Crucially the property belongs to the state representation rather than to the world: the same environment is Markov or not depending on what you choose to observe. Almost all of the theory in this course assumes it, so understanding when it fails tells you when the guarantees stop applying.
Formally, . Conditioning on the whole history collapses to conditioning on the last state and action. Position-only robots break this because also depends on velocity, which lives in .
A robot's sensor only reports its current position but not its velocity. Is 'position alone' a Markov state for predicting where the robot goes next?
The reward is a single scalar arriving at every timestep, and the agent's objective is not to maximize it but to maximize the return: the accumulated reward over the future. That distinction is the whole of long-term planning. An agent that maximized immediate reward would take the chocolate now; an agent that maximizes return can accept a negative reward this step because it unlocks a far larger one later. Formalizing the return raises an immediate problem in tasks that never terminate, where an infinite sum of positive rewards diverges and every policy scores infinity — making them indistinguishable and the objective useless. Discounting solves this by weighting a reward steps away by , which keeps the sum finite whenever . It also encodes a genuine preference for sooner rewards and bounds how far consequences must be tracked. Because different discount factors can make different policies optimal, belongs to the problem specification, not to the solver.
Definition
The return is the total discounted reward accumulated from time onward, written . The discount factor controls how heavily rewards further into the future are counted, and choosing it below one keeps the sum finite even in tasks that carry on forever.
In this topic
- 1The Reward Hypothesis
- 2Discounted Return
The Reward Hypothesis
The reward hypothesis is the claim that every goal can be expressed as the maximization of expected cumulative reward. It is an assumption rather than a theorem, and it is the load-bearing one in the whole framework: accept it and goal-directed behaviour becomes an optimization problem. The practical consequence is that designing the reward is designing the goal, and the agent will optimize precisely what you wrote rather than what you meant. Rewarding a cleaning robot for collected dust invites it to dump dust and re-collect it — specification gaming, which is a reward-design failure rather than a learning failure.
The reward hypothesis: any goal can be expressed as maximization of the expected value of the cumulative sum of a received scalar signal, .
Discounted Return
Discounting weights a reward arriving steps in the future by , which serves three purposes simultaneously. It keeps the return finite in continuing tasks, it expresses a real preference for sooner rewards, and it bounds the horizon over which consequences must be tracked. A useful rule of thumb is that produces an effective horizon of roughly steps: rewards much beyond that contribute almost nothing. Small therefore yields myopic agents that converge quickly; near one yields far-sighted agents whose value estimates carry much higher variance and converge much more slowly.
The return obeys the recursion , which is the seed of every Bellman equation. With rewards bounded by the sum is bounded by . The horizon rule follows from : a reward ten steps out at is weighted , and a reward a hundred steps out at is weighted .
With rewards of +1 at every step and gamma = 0.9, what is the return of an infinitely long episode?
A policy is the agent's behaviour: a mapping from states to actions, possibly stochastic. A value function is the agent's judgement: how much return it expects from a state, or from a state-action pair, assuming it continues to follow a particular policy. Almost every algorithm in this course maintains both and improves each using the other, so it is worth being precise about what each one is for. The policy answers what to do; the value function answers how good it would be. There are two value functions rather than one, and the difference matters more than it first appears. The state-value function scores a state under the policy, while the action-value function commits to an action first and follows the policy afterwards. Acting greedily from requires only comparing stored numbers, whereas acting greedily from requires knowing the environment's dynamics — which is exactly why model-free control algorithms all learn .
Definition
A policy is a probability distribution over actions given the current state. The state-value function gives the return expected from that state when the agent follows the policy, while the action-value function gives the return expected from committing to one action first and following the policy from the next step onward.
In this topic
- 1Policies
- 2State-Value and Action-Value Functions
Policies
A deterministic policy maps each state to one action; a stochastic policy gives a distribution over actions. A basic theorem covered in Chapter 2 says every finite MDP has an optimal policy that is deterministic, so randomness is never required to attain the optimum. Stochastic policies remain essential in practice for three separate reasons: they drive the exploration without which evaluative feedback teaches nothing, they are differentiable in a way an arg-max is not, and they are genuinely optimal in partially observable or adversarial settings where the theorem's assumptions fail. The theorem constrains the final answer, not the path taken to reach it.
A stochastic policy is , a probability distribution over actions for each state.
State-Value and Action-Value Functions
Both functions are expectations of the same return, differing only in what is fixed at the first step. averages over the policy's action choice; pins that first action and averages afterwards. The asymmetry that matters is practical rather than theoretical. Selecting the best action from is an arg-max over stored numbers, whereas selecting it from requires evaluating each action's expected next state — which needs the transition dynamics. The action-value function has effectively cached the model's contribution inside the learned quantity, which is why it can be estimated from samples alone.
The two functions are tied by : the state value is the policy-weighted average of the action values. At the optimum the average becomes a maximum, , so the greedy action is exactly the one that attains .
If you know the optimal action-value function q*, how do you act optimally without any further planning?
Because feedback is evaluative, an agent only learns the value of an action by taking it. That creates a tension with no counterpart in supervised learning: at every step the agent must choose between exploiting the best action it currently knows and exploring an alternative that might be better. Exploiting yields the highest immediate expected reward given current knowledge; exploring may cost reward now but buys information that improves every future decision. Neither extreme works. A purely greedy agent commits to whatever looked best first and never discovers anything better, because the actions it rejected stay untried and their estimates stay frozen at whatever early noise produced them. A purely exploratory agent gathers excellent information and never acts on it. The practical resolution is to explore persistently but sparingly, and usually to explore less as estimates become trustworthy. Every algorithm in this course makes some choice here, whether through an explicit , an entropy bonus, or optimistic initialization.
Definition
The exploration-exploitation tradeoff is the choice at each step between taking the action currently believed best (exploitation) and taking another action to improve the estimates (exploration). It arises because feedback is evaluative: the value of an action is only learned by taking it.
In this topic
- 1The Dilemma
- 2Epsilon-Greedy Action Selection
The Dilemma
The tension is that information and reward are collected by the same actions, so acquiring one costs the other. What makes it genuinely hard rather than merely awkward is that early estimates are noisy, and a greedy agent's mistakes are self-sealing: an action that happened to yield a poor sample is never retried, so its estimate is never corrected. The damage is permanent rather than transient. This is also why exploration cannot simply be front-loaded into an initial phase in non-stationary environments, where the best action can change and a converged agent must retain some capacity to notice.
Regret formalizes the cost of not always playing optimally: , the gap between the best mean reward and the rewards actually earned.
Epsilon-Greedy Action Selection
The standard mechanism takes the greedy action with probability and a uniformly random action otherwise, guaranteeing every action retains positive probability forever. Its appeal is simplicity and the fact that it satisfies the exploration condition convergence proofs require. Its weakness is that exploratory moves are uniform: a clearly terrible action is sampled exactly as often as a promising untried one, so the cost of exploring scales badly with the number of actions. Smarter schemes such as optimistic initialization or upper-confidence bounds direct exploration toward genuinely uncertain actions instead.
With actions, -greedy gives the greedy action probability and every other action , because the uniform draw can also land on the greedy action. At and that is 0.91 for the greedy action and 0.01 for each of the other nine.
Why might you decay epsilon from 1.0 toward 0.05 over training rather than keeping it fixed?