Hello! Welcome to the sixth lesson in the "Artificial Intelligence: Search and Reasoning" module.
In our last lesson, we tackled adversarial games with the Minimax algorithm. You learned to find the optimal move in deterministic, perfect-information games like Tic-Tac-Toe, where every action has a single, predictable outcome.
Today, we're stepping out of that predictable world and into one filled with uncertainty. What if an action doesn't always lead to the same result? This lesson addresses that very question. Our goal is to learn how to model sequential decision-making problems using Markov Decision Processes (MDPs). This framework is the mathematical foundation for much of modern reinforcement learning and is essential for creating agents that can make smart decisions in complex, probabilistic environments.
1. From Deterministic Games to Probabilistic Worlds
In Minimax, the world is straightforward. If you move a piece to a square, it lands on that square. Your opponent's move is the only uncertainty, and Minimax handles that by assuming they play optimally against you.
But many real-world problems aren't so clean. Imagine programming a robot to navigate a room. You might command it to "move forward," but due to wheel slippage or an uneven floor, it might actually move forward 80% of the time, veer slightly left 10% of the time, and veer slightly right 10% of the time.
This is the core difference:
- Minimax: Deals with turn-based, deterministic environments. The solution is the single best move to make now.
- MDPs: Handle sequential, probabilistic environments. The solution is a policy, a complete plan telling the agent what to do for every possible situation it might encounter.
2. The Agent-Environment Interaction Loop
To formalize this, we introduce the concept of an agent operating within an environment. The interaction is a continuous loop:
- The agent observes the current state of the environment.
- Based on the state, the agent chooses an action.
- The environment processes the action, transitions to a new state, and gives the agent a reward.
- The loop repeats.
This interaction is the heart of reinforcement learning.

To understand the core components of this loop, let's watch a short video that introduces the framework.
How to solve problems with Reinforcement Learning | Markov Decision Process
The video 'How to solve problems with Reinforcement Learning' by CodeEmporium clearly explains the key players in this framework: the agent, environment, states, actions, and rewards.
Please watch the section from 01:46 to 03:43. Focus on how the agent and environment interact and the definition of each component in the cycle.
A crucial concept mentioned in the video is the Markov Property. In simple terms, it means the future is independent of the past, given the present. All the information needed to make the best decision is contained in the current state s. We don't need to know the entire history of how we got to s. This assumption dramatically simplifies the problem of modeling the world.
3. The Five Components of an MDP
To use the MDP framework, we must precisely define the problem. An MDP is formally described by a tuple of five components: . As a computer science student, you'll appreciate how this formal structure allows us to apply general algorithms to specific problems.
Let's break down each component, using the excellent Gibberblot article as a guide.
The article 'Markov Decision Processes — Mastering Reinforcement...' provides a clear, formal definition of an MDP and its components. We'll use it to understand each piece of the puzzle.
Read the section under the heading 'Markov Decision Processes', which starts with 'Definition – Markov Decision Process'. Focus on the definitions of the state space, actions, transition probabilities, rewards, and the discount factor.
Let's summarize those key components:
-
: State Space
- The set of all possible states the agent can be in. A state is a snapshot of the world containing all relevant information.
- Example: In a GPS navigation app, a state could be your current (latitude, longitude) coordinates.
-
: Action Space
- The set of all possible actions the agent can take. This can be specific to a state, e.g., .
- Example: From a given intersection, your actions might be {Turn Left, Go Straight, Turn Right}.
-
: Transition Probability Function
- defines the probability of transitioning to state if the agent takes action in state . This is the "uncertainty" part of the model. The sum of probabilities for all possible next states must equal 1.
- Example: If you choose "Go Straight" () at an intersection (), the probability of ending up in the next block () might be 0.9, but there might be a 0.1 probability you get stuck in traffic and remain in the same state ().
-
: Reward Function
- is the immediate reward the agent receives after transitioning from state to by taking action . The agent's goal is to maximize the cumulative reward over time, not just the next immediate reward.
- Example: Reaching your destination gives a large positive reward (+100). Each minute spent driving gives a small negative reward (-1) to encourage efficiency.
-
: Discount Factor
- A number between 0 and 1 that determines the importance of future rewards. A reward received
ksteps in the future is only worth times what it would be worth now. - This models the idea that immediate rewards are often better than future rewards. It also ensures that our math works out for infinite sequences of rewards.
- A number between 0 and 1 that determines the importance of future rewards. A reward received
This graphical representation can help you visualize how these components connect.

4. Modeling a Problem: Grid World
Let's make this concrete by modeling a classic AI problem called Grid World. Imagine an agent on a grid, trying to reach a goal.
The Computerphile video below does an excellent job of building up from a simple deterministic problem (like we've seen before) to a full probabilistic MDP, using a daily commute as an analogy.
Markov Decision Processes - Computerphile
In 'Markov Decision Processes', the Computerphile channel explains how uncertainty transforms a simple shortest-path problem into an MDP. This will help you understand why we need this new framework.
Watch the segment from 01:44 to 03:18 to see the introduction of uncertainty. Then, watch from 04:37 to 08:09, where the full commuting problem is modeled as an MDP graph. Notice how actions can lead to different outcomes with different probabilities and costs (rewards).
Now, let's define our own Grid World MDP based on the example in the Gibberblot article you read earlier:
- Environment: A 4x3 grid. One cell is a wall, one is a goal (+1 reward), and one is a pit (-1 reward).
- States (S): The set of all (x, y) coordinates for the cells the agent can be in. E.g., (0,0), (0,1), ... (3,2).
- Actions (A): {Up, Down, Left, Right}.
- Transition Probabilities (P): This is the core of the model. If the agent chooses 'Up':
- 80% chance it moves one cell up.
- 10% chance it 'slips' and moves one cell left.
- 10% chance it 'slips' and moves one cell right.
- If a move would take it into a wall or off the grid, it stays in the same cell.
- Rewards (R):
- A small negative reward for every step (e.g., -0.04) to encourage finding the shortest path.
- A large positive reward for entering the goal cell (+1).
- A large negative reward for entering the pit cell (-1).
- Discount Factor (): Let's say 0.9, meaning we value future rewards but prefer them sooner rather than later.
By defining these five components, we have successfully modeled the Grid World problem as an MDP. We haven't solved it yet, but we have translated a vague goal ("get to the green square") into a precise mathematical structure that an algorithm can work with.
Test your understanding!
Let's use the student example from the ML@B Blog. A student can be in one of three states: {Studying, Sleeping, Socializing}. From any state, they can choose an action: {Message a friend, Read a book, Eat a snack}.
Imagine you are in the state Studying and you choose the action Message a friend. What might be a reasonable definition for the Transition Probabilities P and Rewards R for this (state, action) pair? There's no single right answer; the goal is to think through the modeling process.
Show answer
Here's one possible way to model this:
Transition Probabilities :
- P(Socializing | ...): 0.6 (It's very likely that messaging a friend leads to a longer conversation).
- P(Studying | ...): 0.3 (You might quickly reply and get back to studying).
- P(Sleeping | ...): 0.1 (Maybe the conversation is so boring it makes you tired!).
(Notice these probabilities sum to 1.0)
Rewards :
Let's assume the student's main goal is to do well in school.
- r(Socializing | ...): +2 (A nice short break, but not directly contributing to the main goal).
- r(Studying | ...): +5 (You took a mini-break and got back to work, which is good).
- r(Sleeping | ...): -3 (You fell asleep while studying, which is not productive).
The key is that you have to define the probabilities of outcomes and assign values (rewards) that reflect the agent's goals. This act of defining P and R is the process of modeling.
5. The Solution to an MDP: A Policy
So, if the solution isn't a single move or a single path, what is it? The solution to an MDP is a policy, denoted by .
A policy is a complete strategy that tells the agent which action to take in every single state.
- Policy :
A good policy will tell the agent in the Grid World "if you are at (0,0), go Right," and "if you are at (2,1), go Up." The goal of reinforcement learning algorithms is to find the optimal policy (), which is the policy that maximizes the expected cumulative discounted reward.
Markov Decision Processes - Computerphile
The Computerphile video concludes by explaining this exact point: the solution to an MDP isn't a path, but a policy.
Please watch from 08:09 to 11:10. Pay close attention to the distinction between a 'path' and a 'policy'.
Conclusion
In this lesson, you have learned how to bridge the gap from deterministic problems to the more realistic world of uncertainty. You can now take a sequential decision-making problem and structure it as a formal Markov Decision Process.
Key Takeaways:
- MDPs are a framework for modeling sequential decision-making problems where outcomes are probabilistic.
- An MDP is defined by five components: States (), Actions (), Transition Probabilities (), Rewards (), and a Discount Factor ().
- The Markov Property simplifies modeling by assuming the current state contains all necessary information about the past.
- To model a problem as an MDP, you must define all five components based on the problem's characteristics and the agent's goals.
- The solution to an MDP is not a single move but a policy (), which is a complete plan specifying the best action to take in any given state.
Preview of the Next Lesson:
We have now formally defined the problem. The natural next question is, "How do we find that optimal policy?" The next lesson, "Explain core reinforcement learning concepts: states, actions, rewards, and policies," will serve as a bridge. We'll solidify the concepts you learned today and begin to explore the fundamental ideas behind the algorithms, like Value Iteration and Policy Iteration, that are used to solve MDPs and find that all-important optimal policy.