Value Functions
A value function is a single number per situation: how much future reward you can expect from here on. It turns far-off consequences into a choice you can make right now.
Why Does This Exist?
An agent that chases immediate reward walks into traps: the tasty move now leads to disaster later. The goal is the total future reward, but totals arrive too late to steer by. You need a number, available now, that already contains the future.
Value functions are that number. Each state, or each state action pair, maps to the expected return from there on, so choosing well means picking the neighbour with the highest value. Planning far ahead collapses into comparing a few numbers.
This page defines the two value functions and the discount, with one hand-computed backup chain. The recursion they satisfy is Bellman equations, the setup they live in is basic concepts, and the networks that learn them are deep Q-networks.
The one idea you need first
The return is the sum of discounted future rewards from step : onward. The discount in shrinks later rewards, so the sum stays finite and sooner rewards count more. Values are expectations of this return.
Think of It Like This
A chess player who prices positions, not pieces
Capturing a pawn feels good now. A strong player ignores that feeling and prices the position: this board is worth a likely win, that one a likely loss. They will sacrifice a whole knight for a position that forces checkmate in five moves, because the position's price already includes those five moves.
State values are position prices. Action values price each candidate move from the current position. Once every reachable position has a price tag, the player stops calculating variations and simply steps toward the highest tag.
Where the analogy stops: chess ends, so prices can be settled by working backward from checkmate. Many agent tasks never end, which is why the discount exists: without it, infinite futures would have infinite prices.
How It Actually Works
The state value is the expected return from state while following policy thereafter. Here is the agent's rule for picking actions, and the expectation averages over the randomness of the world and the policy:
The action value fixes the first move to and follows after that. The difference matters for control: with you act by picking the highest number, no world model needed. With only you must predict which action leads to the best next state, which requires knowing how the world responds.
The optimal values and belong to the best achievable policy. Most of reinforcement learning is a hunt for one of these two objects, and values are never absolute: change the policy and every number moves, except at the optimum.
Worked example
Three states in a chain, , with rewards , , and on the last step, and . Start all values at zero and apply three times.
Sweep 1: only sees reward, . Others stay zero.
Sweep 2: . still sees only zeros.
Sweep 3: .
Final values: , , . The reward needed one sweep per step to travel backward, which is exactly why one-step methods learn slowly over long delays.
Code
The backup chain in plain Python, with type hints, matching the numbers above:
values: dict[str, float] = {"S0": 0.0, "S1": 0.0, "S2": 0.0, "End": 0.0}transitions: dict[str, tuple[str, float]] = { "S0": ("S1", 0.0), "S1": ("S2", 0.0), "S2": ("End", 100.0),}gamma = 0.9
for _ in range(3): values = { s: 0.0 if s not in transitions else transitions[s][1] + gamma * values[transitions[s][0]] for s in values }
print(f"V(S0) {values['S0']:.1f}") # -> V(S0) 81.0print(f"V(S1) {values['S1']:.1f}") # -> V(S1) 90.0print(f"V(S2) {values['S2']:.1f}") # -> V(S2) 100.0Watch Out For
Reading V as if it tells you what to do
prices the situation under the current policy, but it never names a move. Agents wired to "take the action with the best V" are stuck, because V has no action slot. The symptom is a planner that evaluates positions beautifully and then picks moves at random.
Fix it by matching the object to the job: learn for model-free control, or pair with a model that predicts next states so you can compare them.
Forgetting values belong to a policy
There is no true value of a state on its own, only the value under some way of behaving. Improve the policy and yesterday's values are stale; evaluate a new policy with old numbers and the agent defends positions its new behavior has abandoned. The symptom is evaluation scores that disagree with actual rollouts after every policy change.
Fix it by re-estimating values whenever the policy moves, and by treating as the only policy-free object on the page.
The Quick Version
- A value function turns the whole future into one number per state or state action pair: the expected discounted return from there.
- prices the situation under a policy; prices one move first, which is what model-free control needs.
- The discount keeps infinite futures finite and makes sooner rewards count more.
- In the worked chain, reward 100 with discount 0.9 backs up to values 81.0, 90.0 and 100.0, one sweep per step.
- Values belong to a policy, so they go stale the moment behavior changes; only the optimal values are policy-free.