All Lessons

Discounted Returns and Value Functions

Sequential decisions require a precise way to combine immediate and delayed rewards. This lesson builds discounted returns, state values, action values, and the one-step consistency relation used throughout reinforcement learning.

AI Narration Press play to listen
0  / 6 paragraphs
Click any paragraph to jump · Scroll freely without breaking narration

A reinforcement-learning trajectory is a sequence $(s_t,a_t,r_{t+1},s_{t+1})$ containing a state, an action, the next reward, and the next state. The agent cannot judge an action only by $r_{t+1}$ because the action may change rewards far into the future. We therefore need one scalar target that summarizes the future while still giving earlier consequences greater influence.

For discount factor $0\leq\gamma<1$, the return from time $t$ is $$G_t=\sum_{k=0}^{\infty}\gamma^k r_{t+k+1}.$$ A reward one step away has weight $1$, a reward two steps away has weight $\gamma$, and later rewards receive successively smaller weights. In finite episodes the sum ends at termination, so $\gamma=1$ can also be valid when the undiscounted return is finite.

A policy $\pi(a\mid s)$ defines how actions are sampled. Its state-value function is $V^\pi(s)=\mathbb{E}_\pi[G_t\mid s_t=s]$, while its action-value function is $Q^\pi(s,a)=\mathbb{E}_\pi[G_t\mid s_t=s,a_t=a]$. The advantage $A^\pi(s,a)=Q^\pi(s,a)-V^\pi(s)$ measures whether an action is better or worse than the policy's typical action at that state.

The return separates into one observed reward and a remaining return: $G_t=r_{t+1}+\gamma G_{t+1}$. Taking conditional expectations gives the one-step consistency equation $$V^\pi(s)=\mathbb{E}_\pi[r_{t+1}+\gamma V^\pi(s_{t+1})\mid s_t=s].$$ This identity is the bridge between complete-trajectory targets and methods that update from a single transition.

The discount factor also defines an effective horizon. Since geometric weights sum to $1/(1-\gamma)$, a rough horizon is of that order: $\gamma=0.9$ emphasizes about ten steps, while $\gamma=0.99$ reaches roughly one hundred. This is only a scale, not a hard cutoff. Changing $\gamma$ changes the objective itself, so it should not be treated as merely a numerical tuning knob.

In implementation, distinguish true termination from an artificial time limit. A terminal state has no future value, so its bootstrap term is zero; a truncated trajectory may still require $V(s_{t+1})$. Log reward scale, return scale, episode length, and the fraction of truncated samples. These checks reveal many value-target errors before they become unstable policy updates.