TL;DR
A policy is the rule an reinforcement learning agent uses to choose its next action from the state it is in. It can be a fixed choice, such as "always move right at this cell", or a probability over the available actions, such as "move right 80 percent of the time". Reinforcement learning is mostly the search for a policy that earns high reward over time, so the policy is the thing that gets learned and deployed.
Builds on: Markov Decision Process · Leads to: Value Function, Policy Gradient
Where it's used
Robot control. A robot arm reads its joint angles and camera image (the state) and picks one motor command (the action) every fraction of a second. The mapping from readings to commands is its policy. Learned policies have been used to make arms grasp and place objects that were not hand-programmed.
Game-playing agents. Agents for games such as Go and Atari titles pick a move or a button press from the current board or screen. In systems trained by self-play, the policy outputs a probability for each legal move, and the agent samples from those probabilities during play.
Fine-tuning language models. In reinforcement learning from human feedback, the language model is the policy: the state is the text so far, and the action is the next token. The model's output probabilities are its policy, and training adjusts them toward responses that people prefer.
How it works
Take a corridor with three cells: Left, Middle and Right. The agent starts in Left. Entering Right gives a reward of 1, and Right ends the episode. Moving left from Left is not possible, and the moves are otherwise certain, except where a policy says it may choose either move.
A policy is a lookup table from state to action probabilities:
| State | Probability of moving right | Probability of moving left |
|---|---|---|
| Left | 1.0 | 0.0 |
| Middle | 0.8 | 0.2 |
-
Read the state. The agent is in Left. Its policy row for Left says right with probability 1.0, so it has no real choice. Check: 1.0 + 0.0 = 1.0, so the row is a valid probability distribution.
-
Act. The agent moves right into Middle. The reward for this move is 0, because only entering Right pays. Check: Middle is one cell to the right of Left.
-
Read the new state and sample an action. In Middle, the policy says right with probability 0.8 and left with 0.2. Suppose the agent draws right. It moves into Right and collects the reward of 1. The episode ends. Check: the chance of this route, right then right, is 1.0 × 0.8 = 0.8.
-
Notice what the randomness does. If the draw had been left (probability 0.2), the agent would have returned to Left and tried again. The policy is a probability, so the same starting state can lead to different paths, and the expected reward is the average over those paths. Check: 0.8 + 0.2 = 1.0, so every draw is accounted for.
flowchart LR L["Left (start)"] -->|"right, prob 1.0"| M["Middle"] M -->|"right, prob 0.8, reward 1"| R["Right (end)"] M -->|"left, prob 0.2"| L
The math
A policy gives, for each state , a probability distribution over the actions : is the probability of taking action in state . A deterministic policy is the special case , where the probability of one action is 1 and the rest are 0.
Step 1 in symbols: the table
The table in the walkthrough is , and . Each row must satisfy
The bar in means "given that", a Conditional Probability. Each row is a Probability Mass Function over actions.
Step 2 in symbols: the chance of a route
A route is a sequence of states and actions. The probability of a route is the product of the policy's action probabilities and the environment's transition probabilities , which here are all 1:
Step 3 in symbols: the value of a policy
The return from time is the discounted sum of future rewards, , where is the discount factor (see Geometric Series and Expected Value). The value of a state under is the expected return when the agent follows from that state:
For the corridor, let . Entering Right pays 1 and ends the episode. Moving from Middle to Right has reward 1 at that step; moving from Middle to Left has reward 0. Moving from Left to Middle has reward 0. Write for and for . Then
Substituting the second equation into the first gives , so . Then . These relations are the one-step form of the Bellman Equation.
Worked examples
Forget the table for a moment. Suppose a different policy that always moves right, in Left and in Middle. Start in Left and compute the return with .
- The first move, Left to Middle, has reward .
- The second move, Middle to Right, has reward .
- The return is .
Interpretation: the reward of 1 arrives one step after the first move, so the discount factor 0.9 shrinks it to 0.9 when counted from the start. The further away a reward is, the more the discount shrinks it.
Policy A is the table above. Policy B always moves left in Middle.
- Under policy A, and , as computed in Step 3.
- Under policy B, moving from Middle always goes to Left with reward 0. From Left, the agent returns to Middle with reward 0. So and , which gives . The only solution is .
- The two values differ: about 0.955 against 0.
Interpretation: a policy that never reaches the goal has value 0, however reasonable it looks. Changing one row of the table changes the value of the whole policy.
A robot controller takes the state and outputs one score per motor command. Four commands get scores (2.0, 1.0, 0.0, -1.0). The policy turns the scores into probabilities with Softmax:
- Exponentiate each score: , , , .
- Add them: .
- Divide each by the total: , , , .
- Check: .
Interpretation: the controller picks the top command about 64 percent of the time, and still tries the others sometimes. Those occasional tries are how it discovers better options.
Try it: a controller has two commands with scores (1, 0). What is the probability of the first command? Answer: .
Common mistakes and tradeoffs
It is tempting to confuse the policy with the value. In fact the policy says what to do in each state, and the value says how good it is to be there under that policy. The policy is the choice; the Value Function is the score of the choice. A change in the policy changes the value, and the goal is to find the policy with the highest value.
It is tempting to think the best policy must always be deterministic. In fact an optimal policy for a fully known MDP can be deterministic, but learning often needs probabilities. Stochastic policies keep trying alternatives, which is exploration, and gradient-based methods such as Policy Gradient need probabilities to take derivatives at all. An Epsilon-Greedy Policy is a simple structured way to keep some randomness while mostly taking the best-known action.
It is tempting to think a policy can depend on everything that happened so far. In fact in an MDP the policy depends only on the current state. This is possible because the state is assumed to contain everything that matters for the future. When the agent cannot see the full state, it has to use its history, as in a Partially Observable Markov Decision Process.
It is tempting to think the policy must be a table. In fact a table works only for small state spaces; large problems use a function, such as a neural network, that maps states to action probabilities. Tables are easy to inspect and exact. Functions generalise to states never seen before, but they can be harder to train and interpret.
When to learn a policy directly: when the action space is large or continuous, or when a stochastic policy is needed. When to plan with a value function instead: when the model of the environment is known and the state space is small enough to evaluate.
History
Richard Bellman's work in the 1950s on dynamic programming and sequential decisions laid the foundations, and his equation is the basis of value-based methods. Ronald Howard's 1960 book on dynamic programming and Markov processes introduced policy iteration, the method of alternately evaluating a policy and improving it. The idea that a policy could be learned from reward alone, without a model of the world, grew through the 1980s and 1990s in work on temporal-difference learning. Ronald Williams's 1992 REINFORCE method made it possible to improve a stochastic policy directly with gradients, which is now the basis of modern policy-gradient methods.
Recap
- A policy maps each state to a probability distribution over actions. A deterministic policy is the special case with probability 1.
- The probability of a route is the product of the policy's action probabilities along it.
- A policy's Value Function is the expected discounted return from each state under that policy.
- Changing the policy changes the values, and reinforcement learning searches for the policy with the highest value.
- Read next: Value Function to see how a policy is scored, Bellman Equation for the one-step relations, and Policy Gradient for learning the probabilities directly.
Check yourself
QuestionWhat must each row of a policy's table sum to, and why?Show answer
Each row must sum to 1, because for each state the policy gives a probability distribution over the actions. The agent has to take exactly one action, so the probabilities must cover all the possibilities.
QuestionIn the corridor with γ = 0.9, what is the return G_0 for the route Left, Middle, Right, when the reward is 0 on the first move and 1 on entering Right?Show answer
G_0 = 0 + 0.9 × 1 = 0.9.
QuestionWhy is a policy that always moves left in Middle worth 0 in the corridor, even though it is a valid policy?Show answer
It never reaches Right, so it never collects the reward of 1. Every route from Left and Middle earns 0, so the expected discounted return is 0.
QuestionA policy outputs probabilities 0.6 for action A and 0.4 for action B, and the agent is trained by gradients. Why might the designers prefer this stochastic policy to always choosing A?Show answer
A stochastic policy keeps trying action B sometimes, so the agent can find out whether B is better, which is exploration. Gradient methods also need probabilities that change smoothly with the parameters, which a fixed choice does not provide.