Markov Decision Processes
A Markov decision process is the formal interface between an agent and its environment: at each step the agent reads a state, chooses an action, and receives a reward and a next state. We fix that loop, the dynamics function that governs it, and the Markov property that makes the state sufficient; then turn goals into a scalar reward and rewards into a discounted return, with one notation that covers both episodic and continuing tasks.
╌╌╌╌
A bandit has one state. You pull an arm, you collect a reward, and the next pull faces exactly the same choice — nothing you did changed the situation. That is the assumption that makes bandits easy and also the assumption that makes them a toy. Almost every problem worth calling reinforcement learning breaks it: the move you make now alters the board you face next, so a good action is not the one that pays most immediately but the one that steers you toward states from which more reward is reachable. The Markov decision process (MDP) is the formalism that adds this missing piece — a state that the agent's actions can change — and it is the frame for the rest of the subject.1
The agent–environment interface
Split the world in two. Everything the learner controls and does its learning inside is the agent; everything outside, which it can only influence through its actions, is the environment. They meet at an interface of three signals, exchanged at each of a sequence of discrete time steps :
- the state , the environment's representation handed to the agent;
- the action , the agent's choice, possibly restricted by the current state;
- the reward , a single number the environment returns one step later, together with the next state .
Running the loop produces a trajectory, the alternating record of everything that happened:
Two conventions are worth fixing now, because they thread through every later equation. First, the reward for taking in is written , not — the subscript emphasizes that the reward and the next state are jointly determined by the environment, one step after the action. Second, , , and are random variables: capital letters for the random quantity, lower-case (, , ) for particular values they might take.
The split is not the physical boundary of a robot's body. The rule is control: anything the agent cannot change at will is part of the environment. A robot's motors and sensors, even the code that computes its reward, sit on the environment side — the agent may know how the reward is computed, but it cannot alter that computation, and that is what keeps the reward an honest yardstick.2
The Markov property
For the loop to be tractable we need the state to be sufficient: the future must depend on the past only through the present state. Formally, the probability of the next state and reward may depend on and , but not on anything that came before.
This is best read as a restriction on the state, not on the process. If the
outcome genuinely depends on some earlier fact — a velocity, a card already
played, a counter — then that fact belongs in the state. A chess position is
Markov because the arrangement of pieces (plus castling and en-passant flags) is
all you need to reason about the game; the sequence of moves that produced it is
irrelevant. We assume the Markov property throughout, and treat design a good state
as the work of making it hold.
For example, suppose a robot's state is the single
number position on a track,
and the reward depends on where it will be next.
Position alone is not Markov: from a given position the next one depends on
whether the robot is moving left or right, a fact the past encodes but the
present state omits. The remedy is to
augment the state to the pair (position, velocity). With velocity included, the
next position is a function of the current state and action alone, and the Markov
property is restored. This is the standard move: whenever the future leaks
information from the past, fold that information into the state.
The dynamics function
When the sets , , and are all finite, the process is a finite MDP, and its entire behavior is captured by one four-argument function.
The symbol marks a definition, not a derived identity. Because is a probability distribution over for each fixed , it normalizes:
In plain terms, is a giant lookup table: for every situation you could be in and every move you could make, it lists the chances of each thing that could happen next and the reward that comes with it. Nothing about the environment is left out.
This one function completely characterizes the environment. Everything else you might want to know is a marginal or expectation of it. The state-transition probabilities drop the reward argument,
the expected reward for a state–action pair sums out the next state,
and the expected reward for a full triple divides by the transition probability,
The four-argument is the master object; the rest are conveniences. The
framework is general. Time steps need not be seconds — they can
be arbitrary stages of decision making. Actions range from motor voltages to
whether to go to graduate school.
States range from raw sensor readings to
symbolic descriptions of a room. Any goal-directed learning-from-interaction
problem reduces to three signals crossing the interface: actions (the
choices), states (the basis for the choices), and rewards (the goal).
Goals and the reward hypothesis
The agent's purpose enters through exactly one channel: the reward. At each step the environment sends a number , and the agent's entire goal is to maximize the total it collects — not the immediate reward, but the accumulated reward over the long run. Sutton and Barto elevate this to a hypothesis about all purposive behavior.3
Formalizing goals with a single scalar looks restrictive and turns out not to be. A robot learning to walk gets reward proportional to its forward motion; an agent escaping a maze gets per step, so hurrying minimizes the penalty; a game-player gets for a win, for a loss, otherwise. In each case the agent that maximizes reward is the agent that does what we wanted.
Reward is what, not how
The single most common way to break an RL system is to reward the method instead of the goal. A chess agent should be rewarded only for winning — never for subgoals like capturing pieces or controlling the center. Reward a proxy and the agent will find a way to maximize the proxy without achieving the real aim: it learns to grab material even at the cost of the game.4
The reward's residence on the environment side of the boundary is what enforces this: the agent cannot rewrite its own objective, so the objective stays a faithful statement of the task.
Returns
Maximize cumulative reward
needs a precise target. If the rewards after step
are , the agent maximizes the expected return, some function of that reward sequence. The simplest choice is the plain sum
up to a final step :
This is well defined whenever there is a natural final step — when the interaction breaks into episodes.
The alternative is a task that never resets. A process-control loop or a long-lived robot goes on continually, without limit; these are continuing tasks, and the plain-sum return is useless for them because would make the sum run away. A reward of every step already gives an infinite return, and infinities cannot be compared or maximized.
Discounting
The fix is to weight rewards by how soon they arrive, discounting the far future geometrically. The agent chooses to maximize the discounted return:
where is the discount rate. It sets the present value of a future reward: a reward steps ahead is worth only of what the same reward would be worth now. The parameter tunes the agent's horizon.
- — the agent is myopic, caring only about ; it maximizes each immediate reward in isolation.
- — the agent is farsighted, weighing distant rewards nearly as heavily as near ones.
If and the reward sequence is bounded, the infinite sum is finite. The constant-reward case makes this concrete: if every equals , then
the familiar geometric series. So discounting buys a well-defined objective for continuing tasks at the cost of one extra parameter.
A worked comparison shows what the discount rate actually decides. Two reward streams: stream pays every step forever; stream pays for the first four steps, then once, then forever. Which does the agent prefer? It depends entirely on .
| return of = | return of = | preferred | |
|---|---|---|---|
| (near reward) | |||
| , but pays /step | (delayed payoff) |
At the future is discounted so hard that a reward five steps away is worth of its face value, so the big-but-late payoff of counts for little. Raising toward lets the distant count for more, but a steady stream of small rewards still wins here because it never stops. The last row flips the comparison: shrink the steady reward and the delayed payoff wins. The discount rate sets how the agent trades near reward against far reward, and every value in the subject is computed relative to a chosen .
The recursive form
The return starting now is the next reward plus the discounted return starting one step later, so the infinite tail never has to be summed — it is deferred to the next step. Peeling off the first term makes this exact; it is the most-used identity in reinforcement learning.
The return from now is the immediate reward plus the discounted return from the next step. This recursion holds for every , and if we define at termination it holds there too.
It is the basis of the Bellman equations and of
every bootstrapping method — dynamic programming,
Monte Carlo,
and temporal-difference learning
all lean on it. We build the value functions
that formalize expected return from a state
in the next lesson; this recursion is
what makes them computable.
Pole-balancing: episodic or continuing
The same task can be framed either way, and the choice of return shows how. In pole-balancing a cart moves along a track and must keep a hinged pole upright; failure is the pole tipping past a fixed angle or the cart leaving the track, after which the pole resets.5
Two framings, same behavior:
| Framing | Reward | Return | Goal it induces |
|---|---|---|---|
| Episodic | per step, at failure | steps until failure | balance forever return |
| Continuing (discounted) | at failure, elsewhere | , steps to failure | push failure far off return |
Both returns are maximized by keeping the pole up as long as possible. The episodic framing counts successes; the continuing framing, with discounting, penalizes the next failure less the further away it is pushed. The task is the same; only the bookkeeping differs.
Unified notation
Two return definitions — a finite sum for episodic tasks, an infinite discounted sum for continuing ones — is one too many. A single trick collapses them: treat episode termination as entering an absorbing state.
Starting from the reward sequence is ; summing the first rewards or the whole infinite tail gives the same return, and this stays true with discounting. So we write one return for both worlds,
allowing (continuing) or (episodic, all episodes terminate) — but not both at once. We also drop the explicit episode index: stands in for , the state at step of episode , because we almost always reason about a single generic episode. With one dynamics function , one reward hypothesis, and one return, the finite MDP frames every problem in the subject.
Worked example: the recycling robot
A concrete finite MDP ties the pieces together.6 A mobile robot collects soda cans, running on a rechargeable battery whose charge is either or , so . In each state it can for cans, for someone to bring one, or (only when ) :
Searching collects more cans than waiting (expected rewards ) but drains the battery, and if it drains while searching from the robot must be rescued — a reward of . A search from keeps the charge with probability ; a search from keeps it with probability and otherwise depletes it. The full dynamics is a small table:
Every row is a outcome with its probability and expected reward, and the probabilities out of each state–action pair sum to — a complete, if tiny, Markov decision process. This is the object the next lessons learn to solve: what to search or wait or recharge from each charge level, so as to maximize the discounted return.
Solving the recycling robot with real numbers
Put numbers on it. Fix (a search from usually keeps the charge high), (a search from usually drains it), , , and . The expected reward of searching from is the rescue-weighted average
so a search from a low battery loses reward on average — the rescue is common enough to make it a bad bet. Now evaluate a sensible policy : always when , always when . Its two Bellman equations are
the second line because recharging moves deterministically to for reward . Substituting the second into the first and using the numbers,
so , giving and . Check the first equation directly: . It holds exactly, which is the whole point of the Bellman equation — the two values are not independent numbers but a pair determined jointly by one-step consistency.
Is this policy the best one? Running the same recursion with a over actions instead of the fixed choice (value iteration, taken up in dynamic programming) converges to , — the very same values. The optimal action-values from are , , , so recharging is best and searching (expected reward ) is worst. Our hand-picked policy was already optimal for these numbers. That coincidence is the exception; the reason the next several lessons exist is that reading the optimal policy off the equations is easy only for a two-state toy.
Partial observability, reward design, and average reward
The finite MDP assumes the agent sees a Markov state. Three extensions matter enough in modern practice to name here, each relaxing one of the lesson's clean assumptions.
When the state is hidden. Real agents often observe not the state but a noisy, incomplete observation — a camera frame, a sensor reading — from which the true state must be inferred. This is a partially observable MDP (POMDP), formalized by Kaelbling, Littman, and Cassandra (1998).7 The standard result is that a POMDP is again an MDP, but over a different state: the belief state, a probability distribution over the underlying states, updated by Bayes' rule as observations arrive. The belief is Markov even when the raw observation is not, so all the theory of this lesson applies to it — at the cost that the belief space is continuous even when the underlying MDP is finite. In deep RL the same problem is met by feeding a history of observations into a recurrent network, letting it learn an approximate belief; this is why Atari agents stack the last four frames rather than acting on a single image.
Designing the reward is the hard part. The lesson warns that rewarding a subgoal invites the agent to satisfy the proxy and skip the goal. Modern systems hit this constantly, under the name reward hacking or specification gaming: a boat-racing agent trained by OpenAI (2016) learned to spin in circles collecting respawning bonus targets rather than finish the race, scoring high while losing every race.8 There is one principled tool for adding guidance without changing the optimal policy: Ng, Harada, and Russell (1999) proved that a shaping reward of the form , for any state potential , leaves the set of optimal policies unchanged.9 Such potential-based shaping can speed learning by making progress toward the goal immediately rewarding, while the telescoping form guarantees the extra reward sums to zero along any path back to the start, so it cannot be farmed. This is the safe way to inject prior knowledge that the reward hypothesis otherwise forbids.
Continuing tasks without discounting. Discounting is not the only way to make an infinite return finite. For continuing tasks one can instead maximize the average reward per step, , and measure a state's value by how much its returns exceed that average (the differential value). Sutton and Barto develop this setting later, under function approximation, and Mahadevan (1996) surveyed the earlier average-reward algorithms; it is the natural criterion when there is no principled reason to discount and every step counts equally, as in a long-running server or queueing system.10
Footnotes
- Sutton & Barto, Reinforcement Learning: An Introduction (2nd ed.), Ch. 3 — Finite Markov Decision Processes: MDPs as the formalization of sequential decision making, where actions influence not just immediate rewards but subsequent states and, through them, future rewards. ↩
- Sutton & Barto, §3.1 — The Agent–Environment Interface: the boundary is the limit of the agent's absolute control, not the physical body; anything the agent cannot change arbitrarily, including the reward computation, is part of the environment. ↩
- Sutton & Barto, §3.2 — Goals and Rewards: the reward hypothesis, that goals and purposes can be framed as maximizing the expected cumulative scalar reward, and the flexibility of scalar rewards across walking, maze-escape, and game-playing. ↩
- Sutton & Barto, §3.2 — Goals and Rewards: the reward signal communicates what to achieve, not how; rewarding subgoals (capturing pieces, controlling the center) lets the agent satisfy the proxy while missing the true objective. ↩
- Sutton & Barto, §3.3 — Returns and Episodes, Example 3.4 (Pole-Balancing): the same balancing task framed episodically ( per step) or as a continuing discounted task ( at failure), both maximized by balancing as long as possible. ↩
- Sutton & Barto, §3.1 — The Agent–Environment Interface, Example 3.3 (Recycling Robot): a two-state finite MDP with search / wait / recharge actions, its transition probabilities , and its rewards specified as a table of and expected rewards. ↩
- Kaelbling, L. P., Littman, M. L. & Cassandra, A. R. (1998),
Planning and acting in partially observable stochastic domains
, Artificial Intelligence 101(1–2), 99–134 — the POMDP framework and the reduction to a belief-state MDP, where the agent acts on a Bayes-updated probability distribution over hidden states. ↩ - Clark, J. & Amodei, D. (2016),
Faulty reward functions in the wild
, OpenAI blog — the CoastRunners boat-racing agent that maximized a proxy score by looping through respawning targets instead of finishing the race, a widely-cited example of specification gaming / reward hacking. ↩ - Ng, A. Y., Harada, D. & Russell, S. (1999),
Policy invariance under reward transformations: theory and application to reward shaping
, Proceedings of the 16th International Conference on Machine Learning (ICML), 278–287 — the proof that potential-based shaping preserves the set of optimal policies for any potential . ↩ - Mahadevan, S. (1996),
Average reward reinforcement learning: foundations, algorithms, and empirical results
, Machine Learning 22(1–3), 159–195 — a survey of the average-reward optimality criterion and differential value functions as an alternative to discounting for continuing tasks. ↩
╌╌ END ╌╌