State-Value and Action-Value Functions

Once returns are defined, we can ask how good a situation is before the episode is over. In a maze, some positions make high future return more likely even before the agent reaches the goal.

A policy is the agent's decision rule. We write π(as)\pi(a\mid s) for the probability of taking action aa in state ss. A deterministic policy puts all probability on one action. A stochastic policy spreads probability across actions.

The behavior we want to optimize is the policy. The optimal policy is written π=argmaxπEπ[Gt]\pi^*=\arg\max_\pi \mathbb{E}_\pi[G_t] In words: find the policy that maximizes expected return.

Notation Map

  • ss: the current state at time tt.
  • st+1s_{t+1}: the sampled next state produced by the environment.
  • ss': a symbol ranging over possible next states.
  • aa: the action taken in state ss.
  • aa': a candidate next action.
  • π(as)\pi(a\mid s): the policy's probability of taking action aa in state ss.

A state-value function evaluates being in a state and then following a policy:

Vπ(s)=Eπ[GtSt=s]V^\pi(s)=\mathbb{E}_\pi[G_t\mid S_t=s]

Read this as: the value of state ss under policy π\pi is the expected return, assuming the agent starts in state ss at time tt and follows π\pi afterward. The expectation is necessary because the policy may be stochastic and the environment may be uncertain.

An action-value function evaluates one first action and then following the policy:

Qπ(s,a)=Eπ[GtSt=s,At=a]Q^\pi(s,a)=\mathbb{E}_\pi[G_t\mid S_t=s,A_t=a]

Read this as: how good it is to be in state ss, take action aa now, and then follow policy π\pi afterward. The difference is practical: QQ answers "what if I take this action first?" while VV answers "how good is this state if I behave according to this policy?"

V versus Q

Two different questions at the same state

At the fork, Q asks about one named first action. V asks about the state under the policy's usual behavior.

Situation

The agent is at one fork in a maze. It can take a shortcut or a safe path.

Q question

What if the first action is shortcut?

Q(s, shortcut) = 2.0

Q question

What if the first action is safe path?

Q(s, safe) = 5.0

Choose the policy pi(a | s)

V question

If the agent follows this policy from the fork, how good is the state on average?

Vπ(s)=(0.5)(2)+(0.5)(5)=3.5V^\pi(s)=(0.5)(2)+(0.5)(5)=3.5

The Q values stay fixed. The V value changes because the policy changes which action is more likely.

Q is action-specific. V is policy-specific. If the policy changes, V can change even when the action-values stay the same.

The two QQ values are action-specific: shortcut has one value, safe path has another. The VV value is the average return from the state if the policy chooses actions with its usual probabilities.

That is why VV is policy-dependent. The action-values can stay fixed while the state-value changes, because a different policy changes how often each action is chosen.

The relationship is Vπ(s)=aπ(as)Qπ(s,a)V^\pi(s)=\sum_a \pi(a\mid s)Q^\pi(s,a) This is a weighted average. Each Qπ(s,a)Q^\pi(s,a) is counted in proportion to how often policy π\pi takes action aa in state ss.

When Q Is Especially Useful

If the agent must choose an action now, Qπ(s,a)Q^\pi(s,a) is directly comparable across actions. A state-value summarizes how good the state is under the policy.

Choosing the Highest-Q Action

Because Q(s,a)Q(s,a) scores a specific action in a specific state, an agent can choose the action with the highest Q-value:

a=argmaxaQ(s,a)a^*=\arg\max_a Q(s,a)

In the maze example, suppose Q(s,shortcut)=4.2Q(s,\text{shortcut})=4.2 and Q(s,safe path)=6.8Q(s,\text{safe path})=6.8. A greedy agent chooses the safe path because it has the higher estimated return from the current state.

This rule is called greedy action selection. It is useful when the Q-values are reliable, but early in learning the highest current Q-value may simply reflect a lucky estimate. That is why later sections introduce exploration.

Checkpoint

Why can Vπ(s)V^\pi(s) change when the policy changes even if the environment and rewards stay fixed?