TL;DR
A value function answers one question: how good is this situation? For a state, it gives the expected total discounted reward an agent collects from there onward, if it keeps following its current policy. For a state and action pair, it gives the same expectation given that the agent takes that action first. Once you have good values, choosing well is mostly a matter of comparing them.
Values are judgements about the future, not the present. A state can have a small immediate reward and still a high value, because it leads to good states later.
Where you'll see it: as the critic in actor-critic methods, as the baseline that reduces variance in policy-gradient training, and as the table that a Q-learning agent fills in while it plays.
Intuition
A score for every position
Think of a chess position. Material on the board is a partial picture, but a strong player has a feeling for whether the position is winning. That feeling is a value: a number for the position that summarises the games likely to follow. Two positions with identical material can have very different values, because one has a dangerous attack coming and the other does not.
A value function does the same job for an agent. It assigns every state a number that reflects its long-term prospects under a given way of behaving. The number is not a fact about the state alone. It depends on the policy, since a careless player and a careful player face different futures from the same board. That dependence is why the notation always carries the policy.
Why bother storing it
An agent that knows only rewards must look ahead by simulating futures, which is expensive and often impossible. An agent that stores a value for each state can decide with one comparison. Standing in state , it asks which neighbouring state or action has the highest value, and goes there. The value function compresses an unbounded future into one number per state, which is why almost every practical RL method learns one.
The math
Setting
As in the Markov decision process lesson, the environment has states , actions , transition probabilities , and rewards , where denotes the expected immediate reward for taking action in state . A policy gives the probability of each action in each state. The discount factor lies between 0 and 1. The return from time is
Everything below is an expectation of under the policy and the environment.
State-value function
The state-value function under policy is
Read it as: start in , follow forever, average the discounted rewards over all the random paths. The subscript marks the policy, and is the expectation over paths generated by it.
Action-value function
The action-value function, or Q-function, fixes the first action:
The two are linked by averaging over the policy's choice:
So says what each action is worth, and is the average over actions weighted by how often the policy picks them.
The recursive form (Bellman expectation equation)
The return satisfies . Taking expectations gives a relation between the value of a state and the values of its successors:
This is the Bellman expectation equation. It says the value of is the average, over actions and next states, of the immediate reward plus the discounted value of where you land. It is a system of linear equations in the unknowns , one per state. For a finite problem you can solve it directly, or iterate it from any starting guess until the numbers stop changing. The Bellman equation lesson covers the optimal version, where the sum over actions becomes a maximum.
Optimal values
The optimal value function is the best value any policy can achieve:
An optimal policy picks, in each state, an action that maximises . Knowing therefore gives a complete plan with no further search.
- value of reward 1 forever
Worked examples
An agent sits in a state that pays reward 1 on every step, forever. Use .
- Write the value as a sum: .
- This is a geometric series with first term 1 and ratio 0.9, so the sum is .
- Check with partial sums: after 3 terms the total is ; after 20 terms it is about 8.78. It creeps toward 10.
- Interpretation: a stream of 1s is worth ten times its immediate payoff, because each future step is discounted but there are infinitely many of them.
From state the reward is 0, and then with probability 0.5 the agent moves to state and with probability 0.5 to state . Both and are terminal, meaning the episode ends there. From the reward is 2 and then the episode ends. From the reward is 0 and then the episode ends. The policy is fixed, there is one action, and .
- Each terminal state pays its reward once and then nothing more, so and .
- Apply the Bellman expectation equation at : .
- Substitute: .
- The value of is 0.9 even though the immediate reward is 0. The state is worth something because it leads to a coin flip with a good outcome half the time.
A taxi driver at a station must decide whether to take a fare now or wait. Take a fare: the reward is 5 now, and the driver ends downtown, where the value is . Wait: the reward is 0, and the driver ends at the airport, where the value is . Use .
- Action values: .
- .
- Compare: , so taking the fare has the higher action value.
- Note that the airport state is more valuable than downtown, yet taking the fare still wins because its reward is immediate and certain. Action values combine both effects, which a state value alone cannot separate.
Tradeoffs and failure modes
Value functions are the backbone of many RL methods, but they come with costs. A table-based value function needs one entry per state, which is infeasible for images or long text. A neural network can generalise across states, but then the values it learns are approximate, and errors can spread from state to state. Values also depend on the policy, so when the policy changes, old estimates can become stale.
| Situation | What goes wrong | Better choice |
|---|---|---|
| Few states, known transitions | Nothing, a table is exact and fast | Dynamic programming on the Bellman equation |
| Many states, unknown transitions | A table cannot be filled in | Function approximation with a neural network |
| The policy changes often | Old value estimates describe a policy you no longer follow | On-policy methods that re-estimate, or off-policy methods that learn the optimal values directly |
| You need the best action only | Learning a full wastes effort | Learn instead, so action choice needs no model of transitions |
| The estimates are noisy | Policy-gradient updates have high variance | Subtract a baseline such as the state value (see the [[advantage-function |
A subtle trap is confusing with . The state value cannot tell you which action to take without knowing the transitions. If the agent has no model of the environment, it needs .
History
The idea comes from Richard Bellman's work on dynamic programming in the 1950s, which framed sequential decisions in terms of a function over states that satisfies a recursive equation. Bellman's book on the subject appeared in 1957. Ronald Howard's policy iteration in 1960 gave a practical method for finding optimal policies by alternately evaluating a policy's value and improving the policy.
In reinforcement learning, Richard Sutton's work in the late 1980s on temporal-difference learning showed how to estimate values from experience without a model of the environment. Chris Watkins's 1989 thesis introduced Q-learning, which learns action values directly. Sutton and Barto's textbook, first published in 1998, made these ideas the standard vocabulary. Later, the rise of deep networks made it possible to approximate value functions over images and other large inputs, which is what made the approach practical for games and robotics.
Check yourself
QuestionRecall: what is the difference between a state-value function and an action-value function?Show answer
The state-value function gives the expected return from state when following policy . The action-value function gives the expected return when the agent takes action in first and then follows . The state value is the policy-weighted average of the action values, .
QuestionComputation: a state pays reward 2 on every step forever, with . What is its value?Show answer
The value is . Each reward is 2, so the constant part contributes , the sum of the geometric series times the reward.
QuestionWhy: why does a value function let an agent choose actions without simulating the whole future?Show answer
Because the value already summarises the expected return of every future from that state. The agent only needs to compare the values of the options available to it, which costs one lookup or one comparison, rather than rolling out every possible sequence of moves. The price is that the value must have been learned from experience or computed from a model beforehand.
QuestionApplied: a recommendation system stores a value for each user state and a policy that changes every day. Why might yesterday's values mislead it, and what could help?Show answer
The values were computed for the policy that was in use when they were estimated. If the policy changes, the expected returns change too, since the future actions are different. Yesterday's values therefore describe a policy the system no longer follows. Helpful responses include re-estimating values with recent data, weighting recent experience more heavily, or using off-policy learning, which estimates values for the target policy from data collected under another policy. Each has trade-offs: re-estimating costs compute, and off-policy estimates can have high variance when the two policies differ a lot.
Sources
- Sutton and Barto, Reinforcement Learning: An Introduction, 2nd ed. (2018), Chapter 3: http://incompleteideas.net/book/the-book-2nd.html
- Value function, Wikipedia: https://en.wikipedia.org/wiki/Value_function
- Markov decision process, Wikipedia: https://en.wikipedia.org/wiki/Markov_decision_process