In our previous lesson, we established the importance of the Markov property, which ensures that the current state provides a complete summary of the past. This property relates to the environment's dynamics. We will now turn our attention to the other side of the interaction: the agent. Specifically, we'll examine how an agent makes decisions.
This lesson focuses on defining the agent's decision-making rule, known as a policy. Our goal is to distinguish between the fundamental types of policies you will encounter: deterministic, stochastic, stationary, and time-dependent. Understanding these distinctions is crucial, as the type of policy we are looking for often dictates the algorithm we use to solve an MDP.
What is a Policy?
At its core, a policy, typically denoted by the Greek letter (pi), is the agent's strategy or "behavioral blueprint." It dictates what action the agent will take in any given state. For any state the agent finds itself in, the policy provides the answer to the question, "What should I do now?"
In the context of an MDP, where the future is governed by probabilities, it is natural to define a policy in probabilistic terms. A policy is a function that specifies the probability of taking action while in state :
This formalizes the agent's behavior. Given an MDP, if we also have a policy, the entire system's evolution becomes a stochastic process that we can analyze.
Let's watch a segment from David Silver's lecture that introduces the policy and its role in turning a Markov Reward Process (which lacks agency) into a full Markov Decision Process.
RL Course by David Silver - Lecture 2: Markov Decision Process
In his "RL Course by David Silver," watch the section where he formally introduces the concept of a policy.
Pay close attention to the segment from the policy definition. He defines a policy as a distribution over actions given states and explains why, for an MDP, we can often focus on policies that only depend on the current state (stationary policies), a point we will return to shortly.
As you saw, a policy completely defines the agent's behavior. However, policies can have different characteristics. They can be classified along two primary axes:
- Deterministic vs. Stochastic: Does the policy always choose the same action in a state, or does it choose actions according to a probability distribution?
- Stationary vs. Time-Dependent: Does the policy's rule change over time, or does it remain the same?
Let's break down these distinctions. For a precise and formal overview, we'll turn to a concise reference.
Introduction 1 Introduction to reinforcement learning
The following reading, from a University of Minnesota course, provides excellent formal definitions for the types of policies we're discussing.
Please read the short paragraph titled "Policy". This section cleanly defines deterministic, randomized (stochastic), and stationary policies.
Dimension 1: Deterministic vs. Stochastic
The first distinction concerns the nature of the choice itself.
-
A deterministic policy maps each state to a single, specific action. For any state , there is one action that the agent will always take. In this case, the probability is 1 for that specific action and 0 for all others. Think of it as a fixed lookup table: "If in state , do action ".
-
A stochastic (or randomized) policy maps each state to a probability distribution over the set of available actions. In a state , the agent might choose action with probability , action with probability , and so on. The policy can take values between 0 and 1, as long as for every state .
You might wonder why we would ever want a policy to be stochastic. Wouldn't the agent want to be decisive? One of the most important reasons is to balance exploration and exploitation. An agent might need to take actions it doesn't currently believe are the best, just to "explore" and see if they lead to unexpectedly high rewards.
Andrew Ng's lecture on MDPs provides a fantastic explanation of this trade-off and introduces the -greedy policy, a classic example of a simple stochastic policy used in reinforcement learning.
Lecture 17 - MDPs & Value/Policy Iteration | Stanford CS229: Machine Learning Andrew Ng (Autumn2018)
In his Stanford CS229 lecture, Andrew Ng explains the exploration vs. exploitation trade-off.
Watch the segment from exploration vs. exploitation. He introduces the idea of an \epsilon-greedy policy, where an agent usually picks the best-known action (exploits) but sometimes, with a small probability \epsilon, picks a random action (explores). This is a prime example of a stochastic policy in action.
Dimension 2: Stationary vs. Time-Dependent
The second distinction concerns whether the policy changes over time.
-
A stationary policy is time-independent. The rule for choosing actions is the same regardless of the time step . If the agent encounters state at time and again at , it will use the exact same logic (the same ) to choose an action. As David Silver mentioned in the first video, the Markov property of the state often makes it sufficient to consider only stationary policies.
-
A time-dependent (or non-stationary) policy changes with time. The policy is represented as a sequence , where is the rule used at time step . An agent following such a policy might act differently in the same state depending on whether it's early or late in the process. This is particularly relevant in problems with a finite, known horizon. For example, a strategy for the last minute of a basketball game is very different from the strategy in the first quarter.
To solidify these ideas, let's return to the UMN paper and its robot example.
Introduction 1 Introduction to reinforcement learning
This section provides concrete examples that illustrate the difference between stationary and non-stationary policies.
Read the paragraph starting just after the policy definitions you read earlier, from the robot examples. Notice how a stationary policy's rule depends only on the state (e.g., distance from the target), while a non-stationary policy can change over time based on new information or a change of mind.
The Four Policy Types and Their Importance
By combining these two dimensions, we get four general categories of policies:
- Stationary Deterministic: — A fixed rule mapping each state to one action.
- Stationary Stochastic: — A fixed probability distribution over actions for each state.
- Time-Dependent Deterministic: — A rule mapping each state to one action, where the rule can change with time .
- Time-Dependent Stochastic: — A probability distribution over actions for each state, where the distribution can change with time .
A remarkable result in the theory of MDPs, which greatly simplifies the search for a solution in many common scenarios, is that for an infinite-horizon discounted MDP, an optimal policy exists and it can be found within the class of stationary deterministic policies. This means we don't have to search through the vastly more complex space of time-dependent or stochastic policies to find the best possible long-term strategy.
The following reading from a Stanford course makes this crucial point.
3 Acting in a Markov decision process
These lecture notes formally define the policy types and then state the powerful result about the sufficiency of stationary policies.
First, read the section "MDP policies and policy evaluation" (Section 3.4.1). Note the formal notation \pi = (\pi_0, \pi_1, \dots) for a non-stationary policy. Then, read the paragraph immediately following Definition 3.1, starting with "The next result...". This highlights the critical insight that for infinite-horizon problems, our search for an optimal policy can be restricted to the much simpler class of stationary policies.
Conclusion
In this lesson, we have moved from the environment's dynamics to the agent's decision-making process. You have learned to define and differentiate the key types of policies that an agent can follow.
Here are the key takeaways:
- A policy is a mapping from states to actions (or distributions over actions), representing the agent's strategy.
- Deterministic policies specify a single action for each state, while stochastic policies specify a probability distribution over actions. Stochastic policies are particularly useful for encouraging exploration.
- Stationary policies are time-independent, applying the same rule at every time step. Time-dependent policies can change their rules over time.
- For the important class of infinite-horizon discounted MDPs, there is guaranteed to be an optimal policy that is both stationary and deterministic. This result dramatically simplifies the problem of finding the best way to act.
Now that we have defined both the environment (the MDP) and the agent's behavior (the policy), we can start to analyze what happens when they interact. In the next lesson, we will learn how to compute the probability of a specific sequence of states and actions—a trajectory—that results from an agent following a particular policy in an MDP.