State-value and action-value functions
Overview
The state-value function and action-value function are the core tools for quantifying "how good" a state or action is under a given policy. They convert the abstract goal of "maximize future rewards" into concrete numbers we can compute and optimize.

[!intuition] Why do we need value functions?
An agent in state wants to know: "Should I stay or should I go?" But the answer depends on:
- Immediate reward from actions available now
- Future rewards from states we'll visit later
- The policy we're following (which actions we tend to take)
Value functions compress the infinite future into a single number: the expected cumulative reward from this point forward. This lets us compare states and actions numerically.
The key insight: Instead of simulating thousands of possible futures every time, we learn a function or that memorizes "how good is this situation?"
[!definition] State-value function
The state-value function is the expected return when starting in state and following policy thereafter:
where is the discounted return.
Breaking it down:
- : expectation over trajectories sampled by following policy
- : sum of future rewards, discounted by
- : we condition on starting in state
What this tells us: answers "If I'm in state and keep following my current policy , what's my expected total reward?"
[!definition] Action-value function
The action-value function (or Q-function) is the expected return when starting in state , taking action , and then following policy :
The difference from :
- : "How good is this state under policy ?"
- : "How good is taking action in state , then following ?"
gives us action-level granularity. We can compare different actions in the same state.
[!formula] Relationship between and
Deriving from
If we know for all actions, we can compute by averaging over the policy's action distribution:
Why this works:
- is the expected return when following from state
- Policy gives us a probability distribution over actions:
- For each action , the return is
- Expected value over actions: weight each by its probability
Intuition: is the weighted average of all action-values, where weights are the policy's action probabilities.
Deriving from
We can express in terms of using the one-step dynamics:
where is the environment's transition probability.
Derivation from first principles:
Start with the definition:
Expand the return :
Separate immediate and future rewards:
The immediate reward depends only on from the environment:
The future return depends on where we land. Condition on :
But by definition!
Combine:
Why this step? We're using the law of iterated expectation and the Markov property: the future return from depends only on , not on how we got there.
[!formula] Bellman expectation equations
These are recursive consistency conditions that value functions must satisfy.
Bellman equation for
Derivation:
- Start with (averaging over actions)
- Substitute
- Result: expressed in terms of for successor states
Intuition: The value of state equals the immediate reward plus the discounted value of wherever you land next, averaged over your policy's action choices.
Bellman equation for
Derivation:
- Start with
- Substitute
- Result: in terms of
Why recursive? Both equations express value functions in terms of themselves at successor states. This is the bootstrapping principle: we can solve for value functions iteratively.
[!example] Example 1: Gridworld state values
Consider a gridworld. Agent starts anywhere, goal is top-right corner . Actions: up, down, left, right. Deterministic. Reward: per step, at goal. . Policy : move right if possible, else move up.
Let's compute for state (center).
Step-by-step:
-
Identify policy action: From , says go right with probability 1.
-
Next state: (one step from goal)
-
Immediate reward:
-
Bellman equation:
-
Compute : From , policy goes up to (goal).
-
At goal: (terminal state, no future rewards)
-
Back-substitute:
Why this step? Each application of the Bellman equation propagates value backward from the goal. The negative values reflect the cost of reaching the goal (each step incurs ).
[!example] Example 2: Action values in a two-action state
State , two actions: (safe), (risky). Stochastic outcomes.
(safe):
- 100% chance: next state , reward
(risky):
- 70% chance: next state , reward
- 30% chance: next state , reward
Assume , , . (undiscounted).
Compute :
Why? Deterministic transition, so the sum colapses to a single term.
Compute :
Why this step? We weight each outcome by its probability. The risky action has higher expected value despite the negative outcome possibility.
Comparison: . If we're trying to improve the policy, we'd prefer in state .
[!example] Example 3: Computing from with a stochastic policy
State , actions{a_1, a_2, a_3}$. Known Q-values:
Policy :
Compute :
Why this step? The policy is stochastic, so we take a weighted average. has the highest Q-value but only 30% probability, so it contributes to the overall value.
Insight: Even though is best, is less than because the policy sometimes choses suboptimal actions.
[!mistake] Common mistake: Confusing and in policy improvement
Wrong reasoning: "I'll compute for all states, then pick the action that leads to the state with highest ."
Why it feels right: We want to go to valuable states, so picking the action that takes us to the highest-value next state seems logical.
Why it's wrong:
- already averages over the policy's action distribution. It doesn't tell you which action is best.
- An action might lead to a high-value state but have a low immediate reward, making it worse overall.
- The transition might be stochastic—you can't just "choose" the next state.
The fix: Use for action selection! Compute: for each action, then pick .
Why this works: already accounts for:
- Immediate reward
- Stochastic transitions via the sum over
- Future value via
Steel-man the mistake: The confusion arises because in deterministic environments with zero immediate reward, and collapse to similar meanings. But in general, they're distinct!
[!mistake] Common mistake: Ignoring the policy in value function notation
Wrong statement: "The value function ."
Why it's wrong: Value functions are policy-dependent! Different policies lead to different values for the same state.
The fix: Always write or specify which policy you mean. For the optimal policy , write .
Example:
- Random policy :
- Optimal policy :
Same state, different values!
Why this matters: In policy evaluation, we compute for a fixed . In policy optimization, we search for the that maximizes .
[!recall]- Explain to a 12-year-old
Imagine you're playing a video game. You're at certain level (state). You want to know: "How good is my situation right now?"
is like a score for your current level. It tells you, "If you keep playing the way you normally play, here's how many total points you'll probably get from now until the game ends." It's a single number that sums up your future.
is like a score for each possible move. It says, "If you press the jump button right now, here's how many points you'll get." Then, "If you press the shoot button, here's how many points you'll get." It helps you compare different moves.
The key difference: tells you how good your position is if you keep doing what you usually do. tells you how good each specific choice is, so you can pick the best one!
Why we need both: Sometimes you want to know "Am I in a good spot overall?" (use ). Other times you want to know "Which button should I press?" (use ).
[!mnemonic] Remember V vs Q
V = "Value of a Vacation spot"
- You're in Hawaii . How good is being here overall? That's .
- Depends on your plans (policy): if you like beaches, Hawaii is great. If you hate sun, not so much!
Q = "Quality of a Quest"
- You're in Hawaii and deciding: swim, hike, or surf? Each choice has a quality score: , , .
- Pick the highest for the best experience.
V is where you are. Q is what you do.
Connections
- 5.1.03-Returns-and-episodes: Value functions compute the expected return
- 5.1.05-Optimal-policiesand-optimal-value-functions: Optimal and are value functions for the best policy
- 5.2.01-Dynamic-programming-policy-evaluation: Iterative algorithms solve Bellman equations for
- 5.2.02-Policy-iteration: Uses and to improve policies
- 5.3.01-Monte-Carlo-prediction: Estimates from sampled episodes
- 5.4.01-Temporal-difference-learning: Updates and using bootstrapping from Bellman equations
#flashcards/ai-ml
What is the state-value function ? :: The expected return (cumulative discounted reward) starting from state and following policy thereafter:
What is the action-value function ?
How do you compute from ?
How do you compute from ?
What is the Bellman expectation equation for ?
What is the Bellman expectation equation for ?
Why are value functions policy-dependent?
What does "bootstrapping" mean in the context of Bellman equations?
If and , which action should you prefer under policy improvement?
Why can't you just pick the action that leads to the highest for policy improvement?
Concept Map
Hinglish (regional understanding)
Intuition Hinglish mein samjho
Dekho, reinforcement learning mein agent ko yeh samajhna hota hai ki koi state ya action kitna "acha" hai. Value functions yeh kaam karte hain — woh future rewards ko ek single number mein summarize kar dete hain.
State-value function bolta hai: "Agar main is state mein hoon aur apni current policy follow karta rahoon, toh total kitna reward milegा?" Yeh state ki overall "goodness" measure karta hai. Action-value function thoda aur specific hai — yeh bolta hai: "Agar main state mein action loon, phir policy follow karoon, toh total kitna reward milegا?" Matlab, har action ke liye alag score.
Dono ke bech ka difference samajhna zaroori hai. already policy ke actions ko average kar leta hai, isliye woh bata hai state overall kitna valuable hai. Lekin agar tumhe action choose karna hai, toh chahiye, kyunki woh explicitly har action ko compare karta hai. Bellman equations yeh guarantee dete hain ki value functions recursive tareke se consistent rahein — matlab current state ka value next states ke values se connected hota hai. Yeh bootstrapping principle RL algorithms ka backbone hai, jaise dynamic programming aur TD learning.Agar yeh concepts clear ho jayein, toh baki RL topics jaise policy improvement aur Q-learning automatically samajh ayenge!