Introduction
What does Machine Learning (ML) learn? It took me a while to answer this question but the answer is actually straightforward. Machine learning always learns a function: .
- In supervised learning, you show it examples of inputs with the right answers , and it learns to predict from .
- In unsupervised learning, you only show it inputs, and it finds structure in them: clusters, directions, a compressed description.
But Reinforcement learning (RL) learns something else: how to act. An agent looks at its situation, takes an action, sees what happens, and does it again, step after step. Nobody tells it which action was right. It only receives a number, a reward, after each step, which can be: points in a game, a penalty for falling, a bonus for reaching the goal. Its job is to find a way of acting, a policy, that collects as much reward as possible in the long run.
This setting covers a lot of ground: an agent learning to play Atari games from the pixels and the score, a simulated body learning to walk without falling, AlphaGo beating Lee Sedol at Go, AlphaZero mastering chess and shogi by self-play, language models fine-tuned from human preferences. Each time, a sequence of decisions, each one changing what the next one will face, and a score that says how well it went.
Two questions run through the whole subject:
- What is the best way to act? It needs a precise answer: best for which score, over how long, and when the world is random.
- How do we find it? When the rules of the world are known, we can compute the best behaviour without ever acting: this is planning. When they are not, the agent must learn it from experience, it is called learning and is the true purpose of RL.
This page is about the first case: planning with a model. This is the beginning of the story of Reinforcement Learning. It builds the framework that all of RL rests on, we’ll see:
RL framework:
- Sequential decisions and the return, the score of a whole trajectory.
- Markov decision processes, the model of the world.
Evaluating a decision:
- Value functions and the Bellman equations: how good a state is, and how we can link them by a one-step recursion.
Taking better decisions:
- Optimal values and policies: the best one can do, and the Bellman optimality equation that characterizes it.
Then Part 2, Planning with a Model turns these equations into algorithms that solve them exactly: policy evaluation, policy iteration and value iteration. These are required steps before switching to Part 3, Learning from experience, which removes the model and uses Monte Carlo, temporal-difference learning, SARSA and Q-learning to learn the same values from sampled interactions only. Everything they do is an approximation of what Parts 1 and 2 compute exactly.
A word on notation, which follows Sutton and Barto’s book.
- means “is defined as”.
- True values are lowercase, , , , , and so are the successive approximations of dynamic programming, ; the estimates learned from experience in Part 3 are uppercase, and .
- A star means optimal.
1. Sequential decisions
Taking good decisions starts with being able to evaluate the impact of a decision in a given situation. This section describes the framework that is used to describe: 1) the impact of a decision and 2) the quality of this decision.
1.1 Decisions in stages
In sequential decision making, a decision maker takes successive decisions, each one based on what it observes of the effect of the previous ones. Picture a decision tree: from the current situation, each possible action leads to a new situation, from which new actions branch out, and so on. A good decision maker finds a good path through this tree.
The framework is called sequential because time is discrete: there is a first decision, a second one, a third one. But the framework says nothing about how long a step lasts: a millisecond for a robot’s motor, a day for a stock portfolio. And only time is discrete: the actions themselves can be a choice among a few options (left, right) or a real number (the torque of a joint).
Think about it for a second, this can cover a large portion of real-world problems.
In RL, a decision maker, the agent, interacts with its environment, everything distinct from itself. They talk in a loop. At each step , the agent observes the state and picks an action ; the environment answers with a reward and a new state . One interaction produces a trajectory:
Note the index of the reward: is the reward that follows action , received together with .
This is a sequential decision making framework, with a reward describing how good an action, from a given state, is.
1.2 Optimal means optimal for a score
What does being optimal mean?
Being optimal is always being optimal with regard to a cost or a score. To illustrate this concept, here is the running example of this page, a tiny map with four places at different altitudes:
| S (start) · 0 m | A · 10 m |
| B · 40 m | G (goal) · 5 m |
A hiker starts at and wants to reach with as little effort as possible, the effort being the total altitude change along the way. Two routes:
- right, then down: , an effort of m;
- down, then right: , an effort of m.
Both reach , but the first route is five times cheaper. “Best” only means something with respect to a score computed along the whole trajectory. Control theory usually minimizes a cost ; RL maximizes a sum of rewards . They are the same thing with : on our map, the reward of a move will be minus the absolute altitude change.
In RL, the reward is a step signal: a single number handed to the agent after each step, not a grade computed once at the end. The agent does not see the reward structure in advance; it discovers it one step at a time. Sutton and Barto state the bet behind the whole field as the reward hypothesis: all goals can be described as the maximization of the expected cumulative reward.
Ideally, the reward would be:
- for success;
- otherwise.
In practice, such a sparse signal is often too hard to learn from, and designers add intermediate rewards to guide the agent, at the risk of rewarding something other than what they meant.
1.3 The return and the discount factor
The quantity the agent actually maximizes is not the reward directly but rather the return, the sum of the discounted rewards to come, from step on:
The number is the discount factor: a reward received steps from now counts times as much as the same reward received now. Like money, cash now is worth more than potential money later. With close to , the agent is said to be myopic: only the next rewards matter. With close to , it is said to be far-sighted.
The discount also keeps the sum finite. When the task never ends (a continuing task) and the rewards are bounded, , the geometric series gives
When the task stops after a finite number of steps (an episodic task, like a game or our hike), the sum is finite anyway, and is allowed.
On our map, the route right-then-down gives and , then the episode ends. With , ; with , : the second step is discounted, the first never is.
For a task that never ends, with a reward of at every step, the return is a geometric series: . That is with , with , and no finite value with : roughly, the agent looks steps ahead.
Play with on a few reward sequences:
One identity will matter more than any other on this page. Take the first reward out of the sum, factor out of the rest, and shift the index with :
What remains is the return of the next step:
Stated differently, the return is the next reward plus the discounted return from the next step on.
Exercise 1.3 Returns from a reward sequence
- An episode. With , an episode gives the rewards , , , , , then ends at (so ). Compute .
- A task that never ends. With , the rewards are , followed by an infinite sequence of s: . Compute , then .
- The sequence of question 2 never ends. Why is still a finite number?
Hint
Work backwards, from , with : each return is one reward plus the discounted return you just computed.
Hint
For question 2, is a geometric series: for .
Checkpoint what you should get
In question 1, ; in question 2, and .
Solution
-
Backwards, with :
Forwards gives the same result, , with more work.
-
From on, the reward is always : , and .
-
Because : the weights form a convergent geometric series, and with bounded rewards . Here the bound is reached exactly. With , the sum would diverge.
The backward recursion computes all the returns of an episode in one pass, each from the next one. This is how Monte Carlo methods compute returns in Part 3, and the same split, one reward plus the rest, is the seed of the Bellman equations of section 3.
2. Markov decision processes
The previous section showed what taking decisions looks like. But before applying this to real problems, we need another brick: how can we model the world as a decision tree?
2.1 The Markov property
Do we need to know all the past to take a good decision?
The past is the history, everything the agent has seen so far: observations, actions, rewards. The state is what we keep of it to decide what comes next. Keeping everything works, but it grows without end; the goal is to use the smallest summary that loses nothing useful for predicting the future.
A state is said to be Markov when it has the following property: knowing is enough to predict , and the rest of the history adds nothing,
In words: the future is independent of the past, given the present. For a point mass pushed by a force, position and velocity form a Markov state: the next position and velocity follow from them and from the force applied, whatever path led there. Position alone would not be Markov.
We often get to choose the state, and a common trick is to put a bit of history in it to make it Markov. In the Atari game, DeepMind used the last four frames of images as the state.
2.2 The model of the world
A Markov decision process (MDP) is the mathematical model of a sequential decision problem. It is made of:
- a set of states , and for each state a set of actions ;
- the dynamics , which says where an action leads and what it rewards;
- a discount factor .
The dynamics is a single function describing the joint probability of the next state and of the reward, given the current state and action:
For each pair , it is a probability distribution over the pairs : after taking in , the agent lands somewhere and collects some reward, so .
Other functions follow from , for instance the probability of landing in and the expected reward:
A function would only describe a world where the same action always has the same effect. Real environments are often random: a wheel slips, a die is rolled, another player moves. A probability covers all these cases at once, and a deterministic world is just the case where one outcome has probability . The reward is in the same distribution because it can be random too, and it often depends on where the agent lands.
On our 2×2 map example:
Here is our map framed as an MDP with some design choices:
- The states are , , and .
- The reward of a move is minus the altitude change, .
- Nothing forces the hiker onward: from and , they can also go back to , or stay where they are, at a small cost of .
- is terminal: no action is taken there, the episode ends, and its value is by convention.
Each cell gives the next state and the reward of an action taken in a state ; a dash means the action is not available there.
| right | down | left | up | stay | |
|---|---|---|---|---|---|
| , | , | – | – | – | |
| – | , | , | – | , | |
| , | – | – | , | , |
This environment is deterministic: for each pair , a single pair has probability , for instance , and every other pair has probability . The sum over is still , not because the world is deterministic, but because is a probability distribution.
Vocabulary:
The process is Markov because conditions on the last state and action only. It is stationary if does not change over time, which we assume. And it is finite when there are finitely many states, actions and rewards: is then a table of numbers, the case of this whole page.
2.3 Policies
Last, how do we describe a behaviour compared to another?
A policy is the agent’s decision rule: it describes which action to take in which state. In general it is a probability law, a probability distribution over the actions for each state:
A deterministic policy, , is the special case where all the probability sits on one action.
Two policies on our map will come back in the exercises:
- , deterministic: right at , down at , right at . In the general form, and .
- , stochastic at : and ; the same as at and .
Both sum to at , which is what makes them policies. The normalization holds state by state.
Once a problem is written as an MDP, there is a well-defined notion of best behaviour: an optimal policy is the decision rule that maximizes the expected return.
The MDP is the model of the problem; the policy is its solution. The next section makes “maximizes the expected return” precise.
3. Value functions and the Bellman equation
Now that we know how to define our environment and what taking decisions means, we will study how to compare policies and find the best actions.
3.1 How good is a state, how good is an action
To compare policies, and to improve them, we need to know how good each situation is. The state-value function of a policy is the expected return when starting in and following :
The action-value function is the expected return when starting in , taking action first, then following :
is the expectation of the return, under a certain policy. Since our environment and our policies might be stochastic, the return has to be evaluated on average, to compare between policies.
The expectation is over everything random: the actions drawn from and the outcomes drawn from . Both functions score the same return; just conditions on one more piece of information, the first action. ranks states; ranks the moves available in a state. In discrete cases, these expectations are expressed as sums directly.
On our 2×2 example, take the policy that flips a coin at , right or down with probability each, then heads straight for , with .
From the return is , from it is , and from it is or depending on the coin ( on average), leading to:
At , the first two moves give and : already, says that right is the better move. The whole table of , one row per state, one column per action: each entry is the reward of the first move plus the value of where it lands.
| right | down | left | up | stay | |
|---|---|---|---|---|---|
| – | – | – | |||
| – | – | ||||
| – | – |
And averaging the action values over the policy’s own choices gives back the state value (weighted by the probability of each action):
For instance on :
3.2 The Bellman expectation equation
Computing from its definition means averaging the return over every trajectory that starts in . Their number explodes with the length of the episode, and it is infinite as soon as the process can run forever, as on our map, where the hiker can walk back and forth.
Bellman’s idea is to never enumerate trajectories. Any trajectory from is one step, followed by a trajectory from the next state, and the value of “the rest” is again, one step later.
Think of the hike. You don’t need to walk every route from to know what is worth: if you already know that is worth , the move is worth , and nothing beyond matters. The value of a state is written with the values of its neighbours, and theirs with their neighbours’, and this is a consistency that the table should verify everywhere:
Using and the expectation taken given , we obtain:
Written with the policy and the dynamics, first the choice of the action, then the outcome:
From the inside out: is what one outcome is worth; the inner sum averages it over what the environment may do; the outer sum averages over what the policy may choose.
This is the Bellman expectation equation. Read it as a picture, a backup diagram: from the state , the policy branches over the actions; from each action, the environment branches over the outcomes ; each leaf is worth its reward plus the discounted value of where it lands. The same reasoning for puts the outcome first and the next action second:
The equation turns an infinite sum over trajectories into a one-step, self-referential relation. In a finite MDP, it is one linear equation per state, so equations for the unknowns : a linear system, which can be solved directly. For on our map, with , one equation per state:
Four equations, four unknowns. Here the system is even triangular: gives and , which give .
Another way to see it: is a fixed point. Replace every value by the one-step look-ahead of its neighbours, the right-hand side of the equation, and the table does not change.
Optional Where the Markov property is used: deriving the Bellman equation
The equation is not as straightforward as it might look: it takes two lines of conditioning, and one assumption.
From to . Split the expectation along the first action, whose probability given is (law of total expectation): .
From to . Write and split along the outcome , whose probability is :
The last expectation is where the Markov property enters: given the present state , the future does not depend on how the agent got there, so this expectation is just . Substituting one relation into the other gives both Bellman equations.
Without the Markov property, the value of would depend on the path that led to it, “the value of a state” would not be defined, and there would be no Bellman equation: no dynamic programming, and none of the learning methods of Part 3.
Exercise 3.2 Value functions on the altitude map
Take the altitude map of section 2.2, with , and the two policies of section 2.3.
- By backward substitution from , where , compute , then , then .
- Compute , , and .
- Compare with the values and of the coin-flipping policy of section 3.1. Are they equal? Why, since the two policies differ?
- Compute as an average of action values, . Is it closer to or to ?
- Check your result with the Bellman expectation equation of at .
Hint
The map is deterministic and , so each value is one reward plus the value of where you land: . For , the first action is the one you are given, whatever the policy says.
Hint
fixes the action at , then follows from the next state on. Which states does it look at, and what do the policies do there?
Checkpoint what you should get
, , and .
Solution
- , then . goes right at , so .
- and . Then and : going back pays the climb from to a second time.
- They are equal. By definition, fixes the action at : it ignores and depends on the policy only through what it does at the next states, and . There, the two policies agree (down at , right at ), so they have the same .
- For the same reason, , since differs from only at . So , much closer to : puts 70% of its probability on the expensive move.
- . The same computation as in question 4, expanded one step further, from into .
is an average of the , so it always lies between the smallest and the largest of them, here between and . And compares actions without caring what the policy does in the current state: this is what makes the improvement step of Part 2 (section 2) possible.
4. Optimality: the best policy
Wrapping everything up, how do we define the best strategy? What properties does this strategy satisfy?
4.1 Optimal values and optimal policies
The best achievable values, over all policies, are the optimal value functions:
A policy is optimal if in every state.
That a single policy can be best everywhere at once is not obvious; it is a theorem. For a finite MDP with bounded rewards (and , or episodes that end), the theorem states that:
- there always exists an optimal policy, and at least one of them is deterministic;
- it can be read from : ;
- and are unique, but optimal policies may not be: when two actions tie for the max, both are optimal.
So once is known, acting optimally is a table lookup, and there is no need to search among stochastic policies.
Acting from is also possible, , but it needs the model ; acting from does not. This is why the model-free methods of Part 3 will learn rather than .
The optimal values satisfy their own Bellman equations, the Bellman optimality equations. An optimal agent puts all its probability on a best action, so the average over the actions becomes a max:
No policy is left in these equations: the max is the optimal policy.
Note what changed and what did not: max over what the agent controls (the action), expectation over what it does not (the outcome).
On our 2×2 map, with , one equation per state again, each value tied to those of its neighbours:
Because of the max, the system is no longer linear, and there is no closed-form solution in general. Part 2 (sections 1 to 3) solves it by iteration; on this small map, Exercise 4.1a solves it by hand.
The optimal policy also depends on . Take a task that never ends, where the agent only decides in one state, : left pays now and on the way back, right pays now and on the way back. Which loop is better?
Exercise 4.1a The optimal policy of the altitude map
On the altitude map, with :
- At , three actions are available: down, left and stay. Explain why stay and left are never optimal, and deduce . Do the same at and deduce .
- Deduce , by comparing right and down from .
- Plug the three values back into the Bellman optimality equations at , and , and check that they hold.
- Deduce . Compare it with and .
Hint
Start from the equation of in the system above, . Can the last term ever be the max, for a finite ?
Hint
For left: from , going down costs and every later reward is , so it is worth at most ; going right is worth , which is at least (go down to from ). So . What does that give for ?
Checkpoint what you should get
, , .
Solution
-
Stay gives , which is strictly less than : it can never be the max. (Staying forever would return .) Left gives : going back pays the climb between and twice, for nothing. Only down is left: . At , stay loses for the same reason, and up gives ; right gives , so .
-
, reached by right.
-
With :
- ;
- ;
- .
is a fixed point of the optimality equations: one more update changes nothing.
-
, , : this is , and indeed (Exercise 3.2). It is deterministic, as the theorem promises, and unique here because no two actions tie. The stochastic only gets .
Mixing in a bad action never helps once you know : randomness is useless for acting in a known MDP. It becomes useful for learning, when the agent must try actions to find out what they are worth (Part 3).
Exercise 4.1b The discount factor decides the optimal policy
A continuing task: from the state , the agent chooses left, which pays and leads to , or right, which pays and leads to . From , the only action returns to with reward ; from , the only action returns to with reward . The agent decides only in : there are two deterministic policies, and .
- Write the infinite reward sequence seen from under each policy.
- Show that and .
- Which policy is optimal for ? For ? For ?
- For which are the two policies equally good?
Hint
Each policy cycles through every two steps. Group the rewards by pairs: the sum is a geometric series of ratio .
Hint
Or, with the Bellman equation over one cycle: under , .
Checkpoint what you should get
Left is optimal at , right at ( against ), and they tie at , both worth .
Solution
- : and :
- Under , the reward is at the even steps and at the odd ones: . Under , at the odd steps: . With the Bellman equation: and give the same results.
- Since , compare the numerators, and :
- : against , left is optimal (only the next reward counts);
- : against , right is optimal;
- : both are worth , an exact tie.
- .
In section 1.3, only reweighted the rewards of a fixed trajectory. Here it changes the argmax: which policy is optimal. is not a tuning knob, it is part of the problem statement, like the rewards. Check your answers on the figure above.
4.2 How to choose a reward? The rewards are part of the problem
All the rewards of the altitude map are negative. Is that an arbitrary choice? Why not add a constant to make them positive, and maximize a “score” instead of minimizing an effort? The answer differs between continuing and episodic tasks.
Exercise 4.2 Do the signs of the rewards matter?
Fix a constant and shift every reward of an MDP: . Write for the values in the shifted MDP.
- Continuing task, . Show that , with a constant that depends neither on nor on . Give . Does the shift change which policy is optimal?
- Episodic task, . Let be the (random) time at which the episode ends. Show that . Why is this different from question 1?
- On the altitude map (), shift every reward by . Compare the return from of (two steps to ) with the return of the policy that goes to , plays stay times, then goes to . What is ?
- For which values of does the shifted map keep the same optimal behaviour, reaching along the cheapest route?
Hint
Question 1: ; split the sum in two.
Hint
Question 3: with the shift, a step to pays , the last step , and each stay .
Hint
Question 4: look at what one more stay adds to the return, , and what the last step costs, . Be careful with the policy that stays at forever.
Checkpoint what you should get
; with , returns and dawdling times returns , so ; the optimal behaviour survives only for .
Solution
-
, on every trajectory. Taking the expectation, with , the same for every state and every policy, because every trajectory is infinitely long. All policies move by the same amount: their ranking, and , do not change. In a continuing task, only the differences between rewards matter, not their sign.
-
Now , so (for policies that end the episode). The shift depends on the policy, through the expected length of the episodes it produces: adding to every reward puts a price on time, per step, and policies differ in how much time they take.
-
: (check: ). Staying times at : (check: ). Each extra stay now pays : the longer the agent dawdles, the better, without limit, so and no policy is optimal. The least-effort problem has become “stay out as long as possible”.
-
Each extra stay adds :
- : staying still costs something, the reasoning of Exercise 4.1a still holds, and is unchanged, with ;
- : staying is free. Dawdling a finite number of times ties with , at , but parking at forever returns and never pays the of the last step: the optimal agent never reaches ;
- : staying pays, and .
The map stays a least-effort problem only for . This is why stay costs : a free stay is exactly the case .
In an episodic task, the level of the rewards is part of the specification: a reward of per step says “time is free”, a negative one says “hurry”, a positive one says “take your time”. A robot rewarded at the goal and elsewhere, with , scores the same whether it arrives fast or slowly.
4.3 Some useful vocabulary
Solving the Bellman optimality equation is the whole problem: from or , the optimal policy is found from it. We might solve it from different approaches in various cases.
Each one answers a question with one of two opposite terms:
Every algorithm of the course can be placed on each of the two axes.
Let’s focus a bit on the last line. Every agent faces a trade-off that a planner does not: explore to find out more about the environment, or exploit what it already knows to collect reward. It is a trade-off, not a choice made once: an agent that only exploits can settle on a mediocre action it never questions, and one that only explores never uses what it has learned. A good learner explores a lot at first, and less as it learns.
4.4 Wrap-up: the 2×2 map, solved
Everything on this page fits on our four-state map. Pick a policy, or build your own one state at a time, and read its values: each one is the Bellman expectation equation of its state, numbers included.
Click on a state to see the values or change its policy:
What to look at in the figure above
- πA reaches everywhere: it is optimal, as in Exercise 4.1a. πB loses at by going down 70% of the time.
- Stay when you can, with : and are worth , the hiker never reaches . Lower and the values become finite: discounting makes an endless task finite, as in section 1.3.
- The optimal policy depends on . Staying forever at is worth , against for going down to : below , the optimal hiker parks at instead of finishing. At , where finishing costs , this happens below . A short-sighted agent finds the end of the hike too expensive.
An eye to what’s next 👀
On four states, everything can be solved by hand. But in real problems, solving the Bellman equations exactly is rarely possible. It needs the dynamics, which robots, cars or robots do not hand out; the computing power to handle every state, while Go has about legal positions; and the Markov property.
The rest of the course is about approximate solutions, learned from interaction. We’ll first study problems with a model (model-based) before switching to problems with no access to a model (model-free).
Part 2, Planning with a Model, does find approximate solutions on any finite MDP, with iterative algorithms: evaluate a policy, improve it toward the optimal value function, and repeat, until the policy is optimal.
Extra exercises
Exercise E.1 The v*, q*, π* dictionary
Four one-line relations, used constantly from Part 2 on. Give each, and justify it in a sentence.
- in terms of .
- in terms of and the dynamics .
- in terms of .
- in terms of and .
- Compare 3 and 4: to act optimally from , what must you know about the environment? And from ?
Hint
An optimal agent puts all its probability on a best action: the average of section 3.1 collapses to a max.
Hint
For 2, the agent chooses , but not the outcome: the sum over stays an expectation.
Checkpoint what you should get
, and : acting from needs no model.
Solution
- : an optimal agent puts all its probability on a maximizing action, so the average over the actions becomes a max.
- : take , then act optimally. The sum over stays an expectation, since the agent does not choose the outcome.
- . Membership, not equality: when several actions tie, any choice among them, or any mixture of them, is optimal.
- Substituting 2 into 3: .
- From , nothing: read the row , take the largest entry, act. From , the model , to look one step ahead for each candidate action before comparing them.
is what you can act on without a model. Dynamic programming (Part 2) may work with , because the model is given; Monte Carlo, SARSA and Q-learning (Part 3) never know , so they estimate .
Exercise E.2 The same equations in three-argument notation
Much of the literature does not use , but the two functions of section 2.2, and .
- Show that, for any function of the states, Which property of the bracket makes this work?
- Deduce the four Bellman equations, for , , and , written with and only.
- In one sentence: what is lost, and what is gained, in this notation?
Hint
Split the sum in two. In the second term, does not depend on : it comes out of the sum over .
Checkpoint what you should get
The bracket is affine in and in . Only the mean of the reward survives: its distribution is lost.
Solution
- Split the sum: The first sum is by definition; in the second, does not depend on , and summing out of gives . It works because the bracket is affine in and in .
- Applying 1 to each equation:
- Gained: compactness, sums over the states only, and is often what a simulator hands out. Lost: everything about the distribution of the reward, of which only the mean survives.
Losing the distribution is harmless here: the Bellman equations depend on the reward only through its expectation. It is fatal as soon as you care about risk or about the spread of the return, which is why risk-sensitive and distributional RL keep the four-argument form.
Exercise E.3 Episodic or continuing?
- The dynamics of section 2.2 satisfy . In an episodic task, which set must range over for this to hold? Where does the agent land on the last step of an episode?
- Pole-balancing, as an episodic task with discounting: every reward is , except when the pole falls, which ends the episode. Let be the number of steps from until the fall. Give .
- The same task as a continuing one: the pole is put back up after each fall, and the task never ends. The falls happen steps after . Give , and say how it differs from question 2.
- Check in both cases that maximizing the return means “balance the pole as long as possible”.
Hint
Question 2: a single reward is nonzero, , and it carries the weight .
Checkpoint what you should get
Episodic: . Continuing: .
Solution
- Over the states and the terminal state. On the last step, the agent lands in the terminal state; leaving it out of the sum would lose that probability, and the total would fall short of . The condition still only concerns the non-terminal , since no action is taken from a terminal state: the agent acts from the non-terminal states and lands anywhere, terminal included.
- Only the fall contributes: (a fall at the very next step, , gives ).
- Every future fall contributes, each discounted by how far away it is: . The episodic return only sees the next fall, what comes after belongs to another episode; the continuing return adds up the whole infinite future.
- In both cases the return is a sum of terms , which increase with when : pushing every fall further away increases the return, and an agent that never lets the pole fall reaches the best possible return, .
Here the rewards are or negative and , so “maximize the return” and “last as long as possible” coincide. Exercise 4.2 showed how easily this breaks when the level of the rewards changes.
Exercise E.4 Limits of the MDP framework
No computation, and no single answer.
- Is the MDP framework enough to represent every goal-directed learning task? Propose at least two counterexamples, and say in each case what exactly breaks.
- Consider driving a car. The actions could be the accelerator, the steering wheel and the brakes; or one level below, the driver’s muscles; or one level above, the choice of a route. Where should the boundary between agent and environment be drawn? Is there a single right answer? What rule of thumb would you propose?
Solution
Some directions, not a complete answer.
- The state may not be observable: a poker player does not see the other hands, and the observation is not Markov (section 2.1). The goal may not fit in one number: several objectives that cannot be traded against each other, or constraints that must never be violated. Other agents may learn at the same time, so the dynamics are no longer stationary. And the reward may simply not be available, or be too sparse to learn from (section 1.2).
- There is no single answer; Sutton and Barto’s rule is that the boundary separates what the agent can change arbitrarily from what it cannot. Anything it cannot control directly belongs to the environment, even its own body. In practice, the boundary is chosen at the level where the decisions of interest are taken: the route for navigation, the pedals and the wheel for driving, the muscles for motor control.