Policies and Value Functions

Imagine a robot navigating a warehouse to fetch packages. At every aisle, it chooses whether to turn left, turn right, or wait. Every choice it makes is dictated by some rule. That rule maps what it currently perceives to what it does next. That rule is a policy. Understanding policies precisely is the hinge on which all of reinforcement learning turns. Once an agent commits to a policy, we can ask a deeper question. How much reward should we expect, on average, if the agent follows this policy from any given situation? Answering that question rigorously produces the value function. It is the single most important object for reasoning about long-term consequences of behavior. This matters far beyond toy robots. Recommendation engines decide which policy of content-serving maximizes long-term engagement. Autonomous vehicles evaluate policies over steering and braking. These must be safe over entire trips, not just the next instant. Game-playing agents, such as those that master Go or Atari, are at their core searches over policies. These searches are guided by estimates of value. In every one of these systems, the mathematical objects introduced here — policies and value functions — are the vocabulary in which the entire problem is posed. Building on the Markov Decision Process framework and the notion of Rewards and Returns, this article makes precise what it means for an agent to "behave." It also makes precise what it means for that behavior to be "good." We treat a policy not as vague intuition but as a well-defined mathematical mapping. We treat "goodness" as an expectation computed under the dynamics of the environment. Getting these definitions exactly right matters greatly. It is what allows later machinery — the Bellman Equations and the distinction between State-Value and Action-Value Functions — to be built without ambiguity. By the end, you should be able to write down a policy for a concrete MDP. You should be able to compute the expected return it induces from any state. Do this by hand for small examples. You should also understand precisely why value functions are the right currency for comparing different behaviors. This groundwork is what all of dynamic programming, Monte Carlo methods, and temporal-difference learning are built upon.

Key takeaways
  • A policy π is a mapping from states to a probability distribution over actions: π(a|s).
  • Policies can be deterministic (a single action per state) or stochastic (a distribution over actions).
  • Following a policy from a state generates a random trajectory of states, actions, and rewards, governed by both π and the MDP's transition dynamics.
  • The expected return under a policy is the expectation, over all such trajectories, of the cumulative discounted reward.
  • This expectation, as a function of the starting state, defines what will later be called the state-value function.
  • Comparing policies rigorously means comparing the expected returns they induce, state by state.
The core insight

A policy tells an agent how to act, and the value of a policy is nothing more than the expected long-run reward that acting this way produces.

The idea

Formally, given a Markov decision process with state space S\mathcal{S} and action space A\mathcal{A}, a policy is a function

π:S×A→[0,1],π(a∣s)=Pr⁡[At=a∣St=s],\pi : \mathcal{S} \times \mathcal{A} \to [0,1], \qquad \pi(a \mid s) = \Pr[A_t = a \mid S_t = s],

satisfying ∑a∈A(s)π(a∣s)=1\sum_{a \in \mathcal{A}(s)} \pi(a \mid s) = 1 for every state ss. This says: whenever the agent finds itself in state ss, it samples its next action AA from the distribution π(⋅∣s)\pi(\cdot \mid s). A policy is stationary if this mapping does not change with time step tt; unless otherwise stated, we always mean stationary policies, since for MDPs with an infinite or indefinite horizon, stationary policies suffice to achieve optimal behavior (a fact justified later via the Bellman optimality equations). Two important special cases deserve names. A policy is deterministic if for every state ss there is a single action a=π(s)a = \pi(s) with π(a∣s)=1\pi(a \mid s) = 1; we then abuse notation and write π(s)\pi(s) directly as an action rather than a distribution. A policy is stochastic if it assigns positive probability to more than one action in at least one state — useful for exploration, for handling partial observability, and for games with adversaries where randomized behavior is provably necessary for optimality (as in rock-paper-scissors-like MDPs). A policy alone does not determine what happens; it interacts with the environment's transition function p(s′∣s,a)p(s' \mid s, a) and reward function to generate a stochastic process. Starting from state S0S_0, we draw A0∼π(⋅∣S0)A_0 \sim \pi(\cdot \mid S_0), the environment responds with reward R1R_1 and next state S1∼p(⋅∣S0,A0)S_1 \sim p(\cdot \mid S_0, A_0), then we draw A1∼π(⋅∣S1)A_1 \sim \pi(\cdot \mid S_1), and so on. This produces a random trajectory

S0,A0,R1,S1,A1,R2,S2,…S_0, A_0, R_1, S_1, A_1, R_2, S_2, \ldots

The return GtG_t from time tt is the (typically discounted) sum of future rewards,

Gt=Rt+1+γRt+2+γ2Rt+3+⋯=∑k=0∞γkRt+k+1,G_t = R_{t+1} + \gamma R_{t+2} + \gamma^2 R_{t+3} + \cdots = \sum_{k=0}^{\infty} \gamma^k R_{t+k+1},

for discount factor γ∈[0,1)\gamma \in [0,1) (or a finite sum in episodic tasks with γ=1\gamma = 1). Because both the policy and the transition dynamics are stochastic, GtG_t is a random variable even conditional on the starting state. The single most important derived quantity in reinforcement learning is the expectation of this return, which is exactly what a value function measures:

vπ(s)=Eπ[Gt∣St=s].v_\pi(s) = \mathbb{E}_\pi[G_t \mid S_t = s].

This equation is the bridge between "a rule for acting" (the policy) and "a number worth optimizing" (the value). Everything that follows — the Bellman equations that make this expectation recursively computable, and the split into state-value versus action-value functions — is built on exactly this definition.

How it works

Mechanically, evaluating what a policy is worth means simulating (or analytically solving for) the expected return it produces. There are two complementary ways to think about "how it works": generating trajectories under a fixed policy, and computing the expectation of return in closed form for small, fully known MDPs.

Trajectory generation. Given an explicit policy and a known MDP, we can sample rollouts directly. This is the operational meaning of "following a policy," and it is exactly what a simulator or robot does at run time. ``` function GENERATE_EPISODE(policy π, MDP M, start_state s0, max_steps T): trajectory = [] s = s0 for t = 0 to T-1: sample a ~ π(· | s) # stochastic action choice sample (s', r) ~ M.step(s, a) # environment dynamics p(s', r | s, a) trajectory.append((s, a, r)) s = s' if M.is_terminal(s): break return trajectory function MONTE_CARLO_RETURN(trajectory, γ): G = 0 for (s, a, r) in reversed(trajectory): G = r + γ * G # accumulate discounted return backward return G ``` Running many episodes from a fixed start state and averaging the resulting GG values gives a Monte Carlo estimate of vπ(s0)v_\pi(s_0) — a direct, simulation-based reading of the definition vπ(s)=Eπ[Gt∣St=s]v_\pi(s) = \mathbb{E}_\pi[G_t \mid S_t = s].

Exact evaluation for small, known MDPs. When the transition and reward functions are fully known and the state space is small, we don't need sampling at all. The definition of vπv_\pi satisfies a self-consistency condition — the seed of the Bellman equation, though we state it here only as a direct consequence of expectations, not yet as the general recursive machinery: ``` function EVALUATE_POLICY_EXACTLY(policy π, MDP M, γ, tol):

# v is a table indexed by state, initialized arbitrarily (e.g., all zeros) v = { s: 0.0 for s in M.states } repeat: Δ = 0 for s in M.states: if M.is_terminal(s): continue old_v = v[s] total = 0 for a in M.actions(s): action_prob = π(a | s) expected_next = 0 for (s_next, r, p) in M.transitions(s, a): # p = p(s',r|s,a) expected_next += p (r + γ v[s_next]) total += action_prob * expected_next v[s] = total Δ = max(Δ, abs(old_v - v[s])) if Δ < tol: break return v ``` This is iterative policy evaluation: it repeatedly applies the expectation implied by π\pi and the MDP dynamics until the value estimates stop changing meaningfully. It is not yet the full Bellman equation (that formalism and its contraction-mapping proof of convergence belong to a dedicated treatment), but it is a direct computational unpacking of vπ(s)=Eπ[Gt∣St=s]v_\pi(s) = \mathbb{E}_\pi[G_t \mid S_t = s]: each state's value is the probability-weighted average, over the policy's action choices and the environment's transition randomness, of immediate reward plus discounted value of what comes next.

Figure
A policy as a mapping from states to action distributions, driving trajectories evaluated by expected return
Policy π: state → distribution over actions S₀ π(left|S₀)=0.7 π(right|S₀)=0.3 Environment dynamics p(s′,r | s,a) resolve the sampled action into a next state and reward S₁ reward R₁ S₂ reward R₂ … v_π(S₀) = E_π[ R₁ + γR₂ + γ²R₃ + … | S₀ ] — expectation over BOTH the policy's action sampling AND the environment's transitions

Complexity & correctness

Space. Storing a general stochastic policy over a finite MDP requires O(∣S∣⋅∣A∣)O(|\mathcal{S}| \cdot |\mathcal{A}|) numbers — one probability per state-action pair. A deterministic policy needs only O(∣S∣)O(|\mathcal{S}|) since one action index per state suffices. Storing the value table used in evaluation requires O(∣S∣)O(|\mathcal{S}|) real numbers.

Time for Monte Carlo estimation. Each simulated episode of length TT costs O(T)O(T) to generate and O(T)O(T) to compute its return, so NN episodes cost O(NT)O(NT). The estimator of vπ(s)v_\pi(s) from NN independent episodic returns starting at ss has variance shrinking as O(1/N)O(1/N) by the standard concentration of sample means — this is a direct consequence of Var[Gˉ]=Var[G]/N\mathrm{Var}[\bar G] = \mathrm{Var}[G]/N for i.i.d. samples, so Monte Carlo evaluation is unbiased but requires many episodes for tight estimates, especially when returns have high variance (long horizons, large γ\gamma, or high-variance rewards all increase the number of episodes needed for a fixed confidence interval).

Time for exact iterative evaluation. One full sweep over all states costs O(∣S∣⋅∣A∣⋅B)O(|\mathcal{S}| \cdot |\mathcal{A}| \cdot B) where BB bounds the branching factor (number of possible next states per state-action pair), since for each state we loop over actions and, for each action, over possible outcomes. The number of sweeps required to reach a fixed tolerance is where the deeper correctness argument lives.

Why iterative evaluation converges — the core argument. Define the update in the evaluation pseudocode as an operator TπT^\pi acting on any candidate value table vv:

(Tπv)(s)=∑aπ(a∣s)∑s′,rp(s′,r∣s,a)[r+γv(s′)].(T^\pi v)(s) = \sum_a \pi(a\mid s) \sum_{s', r} p(s', r \mid s, a)\big[r + \gamma v(s')\big].

Two facts, both provable directly from this definition, guarantee correctness: 1. vπv_\pi is the unique fixed point of TπT^\pi. Substituting the true expected-return function into the right-hand side and using linearity of expectation over the one-step decomposition of Gt=Rt+1+γGt+1G_t = R_{t+1} + \gamma G_{t+1} shows Tπvπ=vπT^\pi v_\pi = v_\pi exactly — this is the content of what becomes the Bellman equation for vπv_\pi, and uniqueness follows because TπT^\pi is a contraction (next point). 2. TπT^\pi is a γ\gamma-contraction in the max-norm. For any two value tables u,vu, v,

∥Tπu−Tπv∥∞≤γ∥u−v∥∞,\|T^\pi u - T^\pi v\|_\infty \le \gamma \|u - v\|_\infty,

because the difference (Tπu)(s)−(Tπv)(s)(T^\pi u)(s) - (T^\pi v)(s) is a π\pi- and pp-weighted average of terms γ(u(s′)−v(s′))\gamma\big(u(s') - v(s')\big), each bounded in magnitude by γ∥u−v∥∞\gamma \|u-v\|_\infty, and a weighted average of numbers cannot exceed the largest one in magnitude. Since γ<1\gamma < 1, the Banach fixed-point theorem guarantees that repeated application of TπT^\pi from any starting table converges to the unique fixed point vπv_\pi, and the error shrinks geometrically: after kk sweeps, ∥v(k)−vπ∥∞≤γk∥v(0)−vπ∥∞\|v^{(k)} - v_\pi\|_\infty \le \gamma^k \|v^{(0)} - v_\pi\|_\infty. This geometric shrinkage is what justifies stopping the loop once successive updates differ by less than a small tolerance — the true error is bounded by a known multiple of the observed change, so the number of sweeps needed for a target accuracy ε\varepsilon is O ⁣(log⁡(1/ε)/log⁡(1/γ))O\!\left(\log(1/\varepsilon) / \log(1/\gamma)\right), giving a total time complexity of

O ⁣(∣S∣ ∣A∣ B⋅log⁡(1/ε)log⁡(1/γ)).O\!\left(|\mathcal{S}|\,|\mathcal{A}|\,B \cdot \frac{\log(1/\varepsilon)}{\log(1/\gamma)}\right).

Tradeoffs. Exact evaluation requires full knowledge of p(s′,r∣s,a)p(s',r\mid s,a) and scales poorly as ∣S∣|\mathcal{S}| grows (the "curse of dimensionality"), while Monte Carlo evaluation needs no model of the environment at all but pays in variance and sample count. Both approaches, however, are computing the same mathematically well-defined object, vπ(s)=Eπ[Gt∣St=s]v_\pi(s) = \mathbb{E}_\pi[G_t \mid S_t = s] — the distinction is purely about how the expectation is realized, not what it means.

Worked example

Consider a tiny two-state MDP: a "Study" state SS and a "Rest" state RR, both non-terminal, with γ=0.9\gamma = 0.9. From each state the agent can choose action stay or switch. Dynamics (deterministic for simplicity):

StateActionNext stateReward
SstayS+2
SswitchR0
RstayR+1
RswitchS-1

Consider the stochastic policy π\pi: in state SS, choose stay with probability 0.8 and switch with probability 0.2; in state RR, choose stay with probability 0.5 and switch with probability 0.5. We run `EVALUATE_POLICY_EXACTLY` by hand. Initialize v(S)=v(R)=0v(S) = v(R) = 0.

Sweep 1:

v(S)=0.8[2+0.9⋅0]+0.2[0+0.9⋅0]=1.6v(S) = 0.8\big[2 + 0.9\cdot 0\big] + 0.2\big[0 + 0.9\cdot 0\big] = 1.6
v(R)=0.5[1+0.9⋅0]+0.5[−1+0.9⋅0]=0.0v(R) = 0.5\big[1 + 0.9\cdot 0\big] + 0.5\big[-1 + 0.9\cdot 0\big] = 0.0

Sweep 2: using v(S)=1.6, v(R)=0.0v(S)=1.6,\ v(R)=0.0 from sweep 1,

v(S)=0.8[2+0.9(1.6)]+0.2[0+0.9(0.0)]=0.8(3.44)+0=2.752v(S) = 0.8[2 + 0.9(1.6)] + 0.2[0 + 0.9(0.0)] = 0.8(3.44) + 0 = 2.752
v(R)=0.5[1+0.9(0.0)]+0.5[−1+0.9(1.6)]=0.5(1)+0.5(0.44)=0.72v(R) = 0.5[1 + 0.9(0.0)] + 0.5[-1 + 0.9(1.6)] = 0.5(1) + 0.5(0.44) = 0.72

Sweep 3: using v(S)=2.752, v(R)=0.72v(S) = 2.752,\ v(R) = 0.72,

v(S)=0.8[2+0.9(2.752)]+0.2[0+0.9(0.72)]=0.8(4.4768)+0.2(0.648)=3.58144+0.1296=3.71104v(S) = 0.8[2 + 0.9(2.752)] + 0.2[0 + 0.9(0.72)] = 0.8(4.4768) + 0.2(0.648) = 3.58144 + 0.1296 = 3.71104
v(R)=0.5[1+0.9(0.72)]+0.5[−1+0.9(2.752)]=0.5(1.648)+0.5(1.4768)=0.824+0.7384=1.5624v(R) = 0.5[1 + 0.9(0.72)] + 0.5[-1 + 0.9(2.752)] = 0.5(1.648) + 0.5(1.4768) = 0.824 + 0.7384 = 1.5624

The table below shows the trend over sweeps, converging geometrically (each error term shrinking by roughly the contraction factor γ=0.9\gamma = 0.9 per step, consistent with the correctness argument above):

Sweepv(S)v(R)
00.0000.000
11.6000.000
22.7520.720
33.7111.562
...→ 6.30→ 5.07

Continuing the recursion (or solving the two linear fixed-point equations directly, v(S)=0.8(2+0.9v(S))+0.2(0.9v(R))v(S) = 0.8(2+0.9v(S)) + 0.2(0.9 v(R)) and v(R)=0.5(1+0.9v(R))+0.5(−1+0.9v(S))v(R) = 0.5(1+0.9v(R)) + 0.5(-1+0.9v(S))) gives the exact fixed point around vπ(S)≈6.30v_\pi(S) \approx 6.30, vπ(R)≈5.07v_\pi(R) \approx 5.07. This confirms concretely: vπ(S)v_\pi(S) is strictly the expectation of discounted return starting in SS and always sampling actions from π\pi — no single trajectory realizes this exact number, but it is what a Monte Carlo average over many trajectories would converge to as well.

Common pitfalls & traps

PitfallWhy it happensFix
Confusing a policy with a planTreating π\pi as a fixed sequence of actions rather than a state-indexed ruleRemember π(a∣s)\pi(a\mid s) is defined for every state, not just those on one trajectory
Forgetting policies can be stochasticHabit of thinking in terms of deterministic control rulesAlways check whether π(⋅∣s)\pi(\cdot\mid s) sums to 1 over multiple actions before assuming determinism
Evaluating vπv_\pi using only one rolloutTreating a single sampled return GtG_t as if it equals vπ(s)v_\pi(s)vπ(s)v_\pi(s) is an expectation; use many episodes and average, or solve exactly if the model is known
Ignoring the discount factor's role in convergenceAssuming iterative evaluation always converges regardless of γ\gammaThe contraction argument requires γ<1\gamma < 1 (or a properly terminating episodic setting); check this before trusting convergence
Mixing up which distribution the expectation is overForgetting that both action and transition randomness contribute to GtG_t's randomnessState explicitly: expectation is over the joint randomness of π(a∣s)\pi(a\mid s) and p(s′,r∣s,a)p(s',r\mid s,a)

Pioneers & history

Origins · 1 minRichard Bellman and how this was discovered
RB
Richard Bellman
1920–1984 · Applied mathematician, RAND Corporation

Bellman formalized dynamic programming and the principle of optimality in the 1950s, providing the mathematical language — states, decisions, and expected returns — in which policies and value functions are still expressed today.

History
1950
s — Richard Bellman develops dynamic programming and formalizes sequential decision problems.
1957
— Bellman publishes the theory of Markov decision processes with rewards and the principle of optimality.
1960
— Ronald Howard develops policy iteration for Markov decision processes in operations research.
1988
— Sutton introduces temporal-difference learning, connecting value estimation to online, model-free learning.
1998
— Sutton and Barto's Reinforcement Learning: An Introduction standardizes the modern notation for policies and value functions used across the field today.

Where this matters

Every reinforcement learning algorithm — from tabular Q-learning to deep policy-gradient methods used in large-scale robotics and game-playing systems — is ultimately manipulating one of two objects: a policy or a value function derived from one. Recommendation systems at scale formalize "which content to show" as a policy over user states, and evaluate candidate policies via estimated expected long-term engagement, directly mirroring vπ(s)v_\pi(s). Autonomous driving stacks encode driving behavior as a policy over perceptual states and must certify that its expected return (safety-weighted) exceeds some threshold before deployment. Industrial control systems, from HVAC optimization to data-center cooling, are tuned by comparing policies through exactly the expected-return criterion introduced here. The distinction between policies (how to act) and value functions (how good acting that way is) is also the organizing principle behind actor-critic architectures in deep reinforcement learning, where one neural network represents π\pi and another approximates vπv_\pi or a related quantity.

Ask the tutor: How does policy improvement use the value function v_π to construct a strictly better policy π′?

Can a policy depend on the entire history of states and actions, not just the current state?

In principle, yes — a policy could be defined over full histories rather than just the current state. However, for a Markov decision process, the Markov property guarantees that stationary, state-dependent policies are sufficient: no additional value can be extracted by conditioning on history beyond what the current state already encodes, since the future is conditionally independent of the past given the present state. This is why the standard definition restricts π\pi to depend only on StS_t, simplifying both the theory and the algorithms built on it, without losing any achievable performance.

Is the value function part of the policy, or something computed from it?

The value function is derived from a policy, not part of its definition. A policy π\pi only specifies action probabilities per state; it says nothing directly about long-run reward. The value function vπ(s)=Eπ[Gt∣St=s]v_\pi(s) = \mathbb{E}_\pi[G_t \mid S_t = s] is a separate object computed by taking expectations over all the trajectories that π\pi, combined with the environment's dynamics, can generate. Two very different policies can, in principle, produce identical value functions, and conversely a single value function is meaningful only relative to the specific policy that generated it.

Why do we need the discount factor γ for the expected return to make sense?

Without discounting (γ = 1) in a task that can run indefinitely, the sum of infinitely many nonzero rewards can diverge, making the expectation Eπ[Gt]\mathbb{E}_\pi[G_t] undefined or infinite. Setting γ∈[0,1)\gamma \in [0,1) guarantees the geometric series of discounted rewards converges whenever rewards are bounded, since ∑kγkRmax⁡\sum_k \gamma^k R_{\max} is a finite geometric sum. In episodic tasks with guaranteed termination, γ = 1 is often fine since the sum is naturally finite; the choice of γ is really about ensuring the mathematical object vπ(s)v_\pi(s) is well-defined and finite.

How is a policy actually represented in a real reinforcement learning system?

In tabular settings with small, finite state and action spaces, a policy can be stored explicitly as a table of probabilities, one row per state. In large or continuous state spaces, this is infeasible, so policies are instead represented parametrically — for example, as a neural network that takes a state as input and outputs either action probabilities (for stochastic policies) or a single action (for deterministic policies). The core mathematical definition, π(a|s), remains identical; only the representation and the method for adjusting π change between tabular and function-approximation settings.

What is the difference between evaluating a policy and improving a policy?

Evaluating a policy means computing or estimating vπv_\pi for a fixed, unchanging π — this is the entire content of this article. Improving a policy means using that value information to construct a new, better policy π′, typically by acting greedily with respect to the computed values. These are two distinct operations that, when alternated, form the basis of policy iteration; but the concept of policy improvement itself and its correctness proof belong to later material building on the value functions introduced here.

Does every policy have a well-defined value function?

Yes, provided the expected return itself is finite — which holds automatically whenever rewards are bounded and either the discount factor satisfies γ < 1, or the task is episodic and guaranteed to terminate in finite expected time under π. If neither condition holds (for instance, an infinite-horizon undiscounted task where the policy never terminates and accumulates unbounded positive reward), the expectation defining vπ(s)v_\pi(s) can diverge, and the value function is not well-defined for that policy in that setting.

Why introduce the state-value function here rather than jumping straight to optimal policies?

Reasoning about optimal behavior requires first being able to compare any two policies, and the only rigorous way to compare them is through the expected returns they induce — exactly what vπv_\pi captures. Attempting to discuss "optimal" policies before defining value functions leaves no precise criterion for what "optimal" even means. This ordering — policy, then expected return, then value function, then optimality — mirrors how the Bellman Equations and the notion of an optimal policy are subsequently built directly on top of these definitions.

Before this

Where this leads