ai theory
Reinforcement Learning Basics (3) — The MDP as a Problem Statement
Junyoung Park · 2024-03-29 · 14 min
Introduction
The second article described a state not as merely the screen visible now, but as a summary containing the history needed to judge the future. We called it the Markov property when, once the current state is known, older history provides no additional information for predicting the next state.
Defining one good state is not enough to complete a reinforcement-learning problem. We must also specify which next states the agent can reach, how often each transition occurs, which rewards it receives, and which actions it can choose.
Attaching these pieces in order gives a Markov Decision Process, or MDP.
When I first encountered the term MDP, it sounded like another algorithm. I thought there was a learning method named MDP beside Q-Learning. An MDP, however, is not an algorithm for solving a problem. It is closer to a mathematical format for writing down a reinforcement-learning environment.
In a Sudoku analogy, the MDP is the puzzle sheet and its rules. Q-Learning and policy gradient are methods for solving that puzzle. Separating the problem statement from the solution makes later algorithms much less confusing.
Rather than defining an MDP all at once, this article assembles it in three stages.
- A Markov process containing only states and transitions
- A Markov reward process that adds rewards and a discount factor
- A Markov decision process that adds the agent's actions
Markov Process: States Move According to Probabilities
A Markov process is also called a Markov chain. It is a stochastic process in which states satisfying the Markov property continue over time.
We need two elements to define this process.
- : the set of possible states
- : the transition probabilities between states
For example, suppose I can be in one of the following places just before leaving work.
When the current state is DESK, the probability that the next state is CAFE is written as
is the current state and is the next state. The prime does not create a different kind of variable; it simply points to the next position in the same state set.
With a concrete value,
In words: “given that the current state is DESK, the probability that the next state is CAFE is .”
In the figure, the probabilities leaving DESK are for CAFE, for HOME, and for GYM. The next state must be one of these three, so the probabilities sum to .
In general, the probabilities of every possible next state from current state also sum to .
Collecting one such row for every current state produces a state-transition matrix.
Each row corresponds to one current state, and each column to one next state. Every row therefore sums to .
There is no agent and no action yet. I do not choose whether to go from DESK to CAFE or HOME; the next state appears according to the fixed probabilities. Despite the word “process,” nothing is being learned. This is only a description of the probabilistic rule by which states follow one another.
Is a Transition Wrong If Its Probability Is Not 1?
In early reinforcement-learning examples, arrows labeled or can make the environment seem imprecise. If I pressed a HOME button, should I not simply go HOME? Why do we need a probability?
Many environments can produce different outcomes from the same current situation.
- A robot walks forward but may slide sideways on a slippery floor.
- A game character attacks but can miss with some probability.
- A recommendation system shows the same item, but the user may click or ignore it.
- The same commute can take different amounts of time depending on traffic.
A transition probability does not mean the agent is indecisive. It represents uncertainty in the environment's outcome even under the same conditions.
Not every transition must be stochastic. In a simple environment where HOME always leads to SLEEP, the probability is . We call such a transition deterministic. It is still included in the transition-probability framework as the special case with probability .
Markov Reward Process: Attaching Scores to Transitions
A Markov process tells us how states change, but not which states are good. We still have no numerical basis for deciding whether CAFE or GYM is preferable.
Adding a reward function and discount factor gives a Markov Reward Process, or MRP.
Two new elements have appeared.
- : the expected immediate reward in each state
- : the discount factor that determines how strongly future rewards affect the present
Following the notation in David Silver's lecture, the reward function of state is
Read this as “the average reward received next when the current state is .”
Expectation can look excessive in an environment where a reward is always the same number. But even in the same CAFE state, the wait may be short or an order may be wrong. Actual rewards can vary, so the reward function records what we receive on average over repeated experience.
The return from the first article appears again here.
In an MRP, the state sequence follows transition probabilities and rewards accumulate along that path. Even from the same DESK state, one day may pass through CAFE on the way HOME, while another may go directly to GYM. The actual return can therefore differ between episodes.
We do not yet calculate the average return of a state. That average is the value, the subject of the next article. For now, remember that an MRP describes where states move and which rewards appear along those transitions.
Why Reward Notation Differs Between Sources
Reinforcement-learning materials write the reward function in several forms.
Some define reward using only the current state. Others include the state and action, or the next state as well.
In a maze that gives for hitting a wall, it is natural to describe the reward by “which action was taken and where the agent arrived” rather than by the current state alone. If simply remaining in a state determines the score, is enough.
Different notation does not describe different kinds of reinforcement learning. It only makes a different amount of the reward's conditioning explicit. Following David Silver's lectures, this series uses for an MRP and for an MDP.
Markov Decision Process: Adding the Agent's Choice
Now we add the final piece, actions. Adding an action set from which the agent can choose turns an MRP into a Markov Decision Process.
In words, each symbol answers a question.
| Component | Question answered in an MDP |
|---|---|
| Which situations can the agent occupy? | |
| What can it choose in each situation? | |
| After an action, what is the probability of each next state? | |
| What reward is received on average after that action? | |
| How important are distant future rewards? |
Because actions now exist, the transition probability gains another condition.
In an MRP, the current state alone determined the next-state distribution. In an MDP, we must also know which action was selected.
The reward function includes the action in the same way.
In words: “the average reward received next after taking action in state .”
From the same DESK state, I can choose to study, go home, or work out. This choice is why the word “Decision” appears in the name.
Do not confuse an action with a next state. Even after selecting the action “go to GYM,” a blocked road or sudden closure might produce the next state HOME. The action is chosen by the agent. The next state is the outcome produced by the environment according to its transition probabilities.
Comparing MP, MRP, and MDP in One Table
Collecting the components we added one at a time makes the structure clearer.
| Name | Components | Agent action | Reward | Description |
|---|---|---|---|---|
| Markov Process | No | No | States move according to probabilities. | |
| Markov Reward Process | No | Yes | Rewards accumulate along a state sequence. | |
| Markov Decision Process | Yes | Yes | The agent's choice affects transitions and rewards. |
Rather than memorizing the long names, it is easier to think of them as
Attaching scores to state transitions gives an MRP. Adding the right to choose gives an MDP.
Fixing a Policy Turns an MDP Back into an MRP
The first article defined policy as the probability of choosing action in state .
An MDP leaves several actions open. Once we fix a policy, we determine the proportion with which the agent chooses them—for example, STUDY with probability , LEAVE with , and WORK OUT with at DESK.
We can then replace the action-specific probabilities with one transition probability mixed by the policy.
Read the right side in this order.
- Take the probability that the policy selects action .
- Multiply it by the probability of reaching after that action.
- Sum over every possible action.
We can average rewards in the same way according to the policy's action frequencies.
Thus, after fixing one policy in an MDP, the rule for the agent's choices is set and the resulting sequence of states and rewards can be viewed as one MRP.
This relationship matters because it turns policy evaluation into value calculation in an MRP. The question “how good is it to keep following this policy?” becomes the question of calculating the expected return in the MRP induced by the policy. The next article continues with that calculation.
Describing an MDP Does Not Mean Knowing Its Transition Matrix
Writing an MDP as does not mean that the agent initially knows every number in and .
In an environment with completely specified rules, such as a board game, transitions and rewards may be known in advance. We then say that the environment model is known. Dynamic programming begins with this assumption.
For a real robot or a game run for the first time, the agent may not know which outcomes its actions produce before trying them. The environment can still be represented as an MDP; the agent simply does not know that MDP's transitions and rewards.
Keep the distinctions clear.
- MDP: What states, actions, transitions, and rewards structure the environment?
- Model-based status: Does the agent know or learn the transition and reward rules?
- RL algorithm: How does it use unknown information and experience to find a policy?
The existence of a problem structure and the solver's knowledge of its numbers are separate matters.
Terminal States and Processes That Never End
Reinforcement-learning environments can be divided into episodic tasks with an ending and continuing tasks that keep running.
A game, maze escape, or completed order has a clear ending, so we define a terminal state. In the example above, SLEEP could mark the end of a day. Reaching the terminal state ends the episode, and the next episode begins from a new starting state.
A temperature-control system or continuously moving robot may run indefinitely. Such settings often use discounted returns with to keep the sum of rewards from growing without bound.
A terminal state is sometimes represented as an absorbing state that transitions to itself with probability .
The episode has already ended in practice. Mathematically, the self-loop keeps the row of transition probabilities summing to .
Common Points of Confusion
An MDP Is Not a Reinforcement-Learning Algorithm
An MDP is a format for expressing the problem. Keep it separate from methods such as Q-Learning, SARSA, and policy gradient that find a good policy.
An Action Does Not Necessarily Determine the Next State
The agent selects an action, but the environment's outcome may be stochastic. The same can produce different and rewards.
Reward and Value Are Different
A reward is a number received one step later. A value is the average future return expected when starting from a state. Writing beside a state in this article does not mean that the state's value is .
“Markov” Does Not Mean That the Past Was Never Needed
History may be used to construct a state. The property says that after a sufficient state has been constructed, the next transition and reward can be expressed conditional on that state.
What to Remember
The central idea of this article is
An MDP is the problem statement of reinforcement learning: it records which actions an agent can choose in each state and the probabilities with which next states and rewards follow.
More specifically:
- A Markov process represents stochastic state transitions as .
- An MRP adds rewards and a discount factor: .
- An MDP adds actions: .
- Even after an action is selected, the next state and reward may vary stochastically.
- Fixing a policy lets us view the resulting state and reward sequence in an MDP as an MRP.
- Defining an MDP is different from the agent knowing its transition and reward numbers.
All ingredients of the reinforcement-learning problem are now present. But we still do not know which of DESK, CAFE, and HOME is better in the long run. Comparing immediate rewards alone can miss distant consequences.
The next article distinguishes reward, return, and value, then examines the questions answered by the state value and action value . This is where reinforcement learning begins to predict the future in earnest.