Skip to content

2.3 Policies, Values, and Returns

The previous section used the MDP tuple to describe a sequential decision problem. and specify what the agent can encounter and do; and specify how the environment changes and what immediate reward it provides; specifies the weight of future rewards.

These objects are enough to record one CartPole interaction. At each step, the agent observes the current state, pushes left or right, receives a reward, and enters the next state. Repeating this process produces a trajectory. Once the pole falls, we can calculate the return from every time step along that trajectory.

Decision making requires an estimate before the trajectory ends. From an intermediate state, the agent needs to know the average future return from continuing, and how that outcome changes if it chooses one action first. A single return describes one realized trajectory, while repeated visits to the same state can produce different actions, transitions, and returns.

This section therefore follows the notation from Section 2.2: first a policy produces a trajectory, then return measures that trajectory, and finally expected return defines the state value and action value . This moves us from recording an interaction to evaluating states and actions before acting.

Policies and Decision Rules

Consider one decision in CartPole. At each step, the environment returns four numbers: cart position, cart velocity, pole angle, and pole angular velocity. Suppose we observe

This four-dimensional vector is one concrete state. The cart is near the center and almost stationary. The pole is tilted by radians and is still rotating at radians per second.

Another run might produce

This is a different state because all four measurements may differ. Collecting every state that CartPole can produce gives the state space :

The calligraphic capital denotes the whole set, while lowercase denotes one member of that set. Thus, reads “ belongs to the state space .” Because the CartPole state changes continuously, contains many four-dimensional vectors, not just the two above.

CartPole has only two available actions. Its action space is

The calligraphic capital denotes all available actions, while lowercase denotes the action selected at one step. For example, and .

The agent receives a state and must select an action from . The rule that turns a state into a choice is a policy, written as the Greek letter , pronounced “pi.” Policies have two common forms.

A deterministic policy directly returns one action for each state:

The arrow means “maps from the expression on the left to the expression on the right.” Therefore, says that the policy accepts a state from the state space and returns an action from the action space.

To make the mapping concrete, consider three states and a simple teaching policy. This is not claimed to be an optimal CartPole controller.

Input state Pole motionPolicy output
tilted in the positive direction and still rotating that waypush right
tilted in the negative direction and still rotating that waypush left
nearly uprightpush right

The first row can be written as

is the input, and “push right” is the output. If the same is passed to this deterministic policy again, the output remains “push right.” A complete deterministic policy specifies one action for every state.

A stochastic policy returns action probabilities instead of immediately fixing one action:

means “the set of all probability distributions over the action space .” Because CartPole has two actions, one such distribution can be written as

For example, assigns probability to pushing left and to pushing right. The vectors , , and are also valid distributions in .

Input state Probability of leftProbability of rightPolicy output

For , the policy returns . If the agent encounters many times, it will push left about of the time and right about of the time.

In , the vertical bar reads “given,” so the expression refers to action probabilities given the current state . The dot stands for every candidate action. The symbol means “sample according to the distribution on the right.” Thus, says to sample the actual action from the probabilities produced by the policy.

The full path is now explicit: is a concrete member of ; the stochastic policy maps it to the concrete distribution in ; sampling that distribution produces a concrete action in .

A deterministic policy is a special case. The distribution assigns probability to pushing right, so every sample returns the same action. Policy-gradient methods commonly learn stochastic policies directly, whereas value-based methods such as DQN often derive a deterministic greedy policy from action values.

python
# A simple stochastic policy for CartPole
import torch
import torch.nn as nn

class CartPolePolicy(nn.Module):
    def __init__(self):
        super().__init__()
        self.net = nn.Sequential(
            nn.Linear(4, 32), nn.Tanh(),
            nn.Linear(32, 2)  # Logits for the two actions
        )

    def forward(self, state):
        logits = self.net(state)
        return torch.distributions.Categorical(logits=logits)

    def act(self, state):
        dist = self.forward(state)
        action = dist.sample()
        return action.item(), dist.log_prob(action)

If we pass torch.tensor([0.00, 0.00, 0.08, 0.15]) to this network, the first layer receives the four state values. The final layer outputs two logits, one for pushing left and one for pushing right. Categorical converts those scores into action probabilities, and sample() draws action or . log_prob(action) records the log-probability of the sampled action, which policy-gradient methods later use to adjust the network parameters.

The Optimal Policy

Once policies have been defined, we need a way to compare them. Suppose policy A controls CartPole for episodes and survives for steps on average, while policy B survives for steps on average. Because CartPole gives for each surviving step, policy B has the larger average long-term return.

The policy with the largest expected long-term return among all candidates is called an optimal policy, written :

The star marks an optimal quantity. means “find the policy that makes the expression on the right as large as possible,” and means averaging over the different outcomes that the policy may produce. DQN, PPO, and SAC represent and update policies differently, but all aim to improve this expected return.

Returns and Trajectory Evaluation

Consider a trajectory with only three steps. The agent starts in , selects , receives , and reaches . It then selects and receives . Finally, it selects , receives , and the task ends. Written in order, this experience is a trajectory:

is the Greek letter tau and denotes the whole trajectory. The subscripts on states and actions mark decision times; is the feedback received after the action at time . One complete run from the initial state to a terminal state is usually called an episode.

A trajectory contains several one-step rewards. To evaluate the entire future from a particular time, we combine those rewards into a return:

is the return from time . is the reward received after the current action, counts how many steps into the future a reward lies, and means to add all of these terms.

The Role of the Discount Factor

is the discount factor. It determines how much weight future rewards retain. Smaller values reduce the weight quickly; values close to preserve more of the distant reward.

For the three-step trajectory above, let . The return from the beginning is

All three rewards equal , but the second has weight and the third has weight . If we change to , the same trajectory has return . The more distant rewards now matter less.

For infinite-horizon tasks with bounded rewards, choosing also keeps the discounted sum finite. For a finite-horizon task with a clear terminal time, may be appropriate when all rewards should have equal weight. The choice of is part of the task objective.

γ valueMeaningApplications
0Immediate rewards only (greedy)Rarely used
0.9Short horizon (about 10 steps)Board games, recommender systems
0.99Medium horizon (about 100 steps)Atari, CartPole
0.999Long horizon (about 1,000 steps)Long-term tasks, robot navigation
1.0No discountingFinite-horizon tasks

Returns in CartPole

CartPole gives a reward of 1 at every step while the pole remains upright. An episode ends when the pole falls or the cart leaves the permitted range. The return is

where is the number of steps in the episode. When and , . If the pole survives for only steps, then . Under the same reward rule, surviving longer produces a larger return.

Value Functions and Long-Term Benefit

The same state can lead to different outcomes. Suppose we restart CartPole from state three times, follow the same policy, and obtain returns , , and . Their average is

With enough repetitions, this average approaches the expected return from the state under the policy. A value function estimates this average future return before the future trajectory has actually happened.

State Value

stands for value, and the superscript reminds us that the value depends on the policy followed afterward. The vertical bar means “given.” Thus, is the average of given that the current state is and future actions follow policy .

Action Value

additionally fixes the first action. Suppose repeated trials from the same state have average return when the first action is push left and when it is push right. Then

Both numbers assume that after this first action, the agent continues with policy . They refine the question “how good is this state?” into “how good is a particular first action in this state?”

The Relationship Between V and Q

This equation says that is the probability-weighted average of the action values. If the policy pushes left with probability and right with probability , then

means to visit every action and add the resulting terms. is the probability of action , and is its long-term value when taken first.

How the V–Q formula follows from the definitions

The two definitions already distinguish what is known before the first action. The state value conditions only on the current state:

The action value conditions on the current state and on a chosen first action:

Under policy , that first action is still random: is drawn from . The expectation of can therefore be grouped by which first action occurred. This is the law of total expectation from Section 2.1: the overall mean equals each group's probability times the mean inside that group.

The first line is the definition of . The second line expands the same expectation over the possible first actions. The third line replaces each inner conditional expectation with .

With two CartPole actions this is the arithmetic above:

Here and are and , while and are the two action values. If the policy is deterministic, one probability is and the others are , so equals the of that single action.

A Numerical GridWorld Example

Consider a corridor with three nonterminal states. The policy always moves right, entering the terminal state gives reward , every other transition gives reward , and :

S0 ──→ S1 ──→ S2 ──→ terminal
0.81   0.90   1.00      0

Starting from , the next move gives , so . Starting from , that reward arrives one step later, so . Similarly, . States closer to the terminal reward have larger values because the same reward is discounted fewer times.

The Advantage Function and Action Evaluation

The advantage function measures how much better action is than the average action:

  • : action is better than average
  • : action is worse than average
  • : action is average

Continue with . Pushing right has action value , so

The positive value says that pushing right is return units better than the policy's average choice. Pushing left has advantage , so it is below average. Advantage measures relative quality, which is why positive and negative values can appear in the same state.

The advantage function is central to policy-gradient methods (Chapter 6) and Actor-Critic methods (Chapter 7).

A Preview of the Bellman Equation

Value functions satisfy the Bellman equation, a recursive relationship that expresses in terms of :

First consider one term inside the brackets. Suppose action in state gives immediate reward and reaches . If and , the immediate reward plus discounted future value is

The full equation also accounts for every action the policy may choose and every next state the environment may produce. The outer sum averages over action probabilities, while the inner sum averages over transition probabilities. Chapter 3: Value Functions and Bellman Equations develops this equation from concrete examples.

Section Summary

Policies, returns, and value functions are three core concepts in an MDP:

  1. Policy : the agent's decision rule; the stochastic policy is the most general form
  2. Return : the discounted cumulative reward from time step onward,
  3. Value functions: is the state value and is the action value; the advantage measures relative quality

These objects can describe what happens along a trajectory, but return is available only after the trajectory unfolds. When an agent must act from an intermediate state, it needs to estimate the long-term outcome in advance. Chapter 3 begins with this problem and develops value functions and Bellman equations as the solution.

Hands-on Modern Reinforcement Learning