5 State Abstraction
\[ \newcommand{\E}{\mathbb{E}} \newcommand{\R}{\mathbb{R}} \newcommand{\Prob}{\mathbb{P}} \newcommand{\BR}{\operatorname{BR}} \newcommand{\eps}{\varepsilon} \newcommand{\given}{\,\vert\,} \newcommand{\argmax}{\operatorname*{arg\,max}} \newcommand{\argmin}{\operatorname*{arg\,min}} \newcommand{\sm}{\setminus} \newcommand{\defeq}{\equiv} \]
In Chapter 3’s Q-learning update, a transition \((s_t,a_t,r_{t+1},s_{t+1})\) revises the estimate \(q_t(s_t,a_t)\). The row that changes is the one for \(s_t\). Giving several states one row reduces the number of entries to estimate and lets visits to any of those states update that row. We want to know when these shared estimates can recover the optimal action values and when they suffice to choose an optimal action.
We use the finite discounted MDP of Chapters 1–3, with state space \(\mathcal S\), the same finite action set \(\mathcal A\) at every state, bounded rewards \(r_{t+1}\), and discount factor \(0<\gamma<1\). Call a state \(s\) of this MDP a full state.
Definition 5.1 (State abstraction) A state abstraction maps each full state \(s\) to a label \(x=\phi(s)\), called an abstract state. Write \(\overline{\mathcal S}\) for the set of labels and \(\mathcal S_x=\{s\in\mathcal S:\phi(s)=x\}\) for the group with label \(x\).
Like the feature map in Chapter 3, \(\phi\) represents a state in a form that the learner uses to estimate values. Here the label selects one row, giving a table with \(|\overline{\mathcal S}|\,|\mathcal A|\) entries. The definition follows Li, Walsh, and Littman (2006), §3.1.
5.1 Q-learning on abstract states
Write \(x_t=\phi(s_t)\) and let \(\bar q_t(x,a)\) be the table indexed by abstract state and action. In Equation 3.9, replace the two state arguments with \(x_t\) and \(x_{t+1}\). Let \(\alpha_t(x,a)\) be the step size for entry \((x,a)\). The TD error \(\delta_t\) and the update are
\[ \begin{aligned} \delta_t &=r_{t+1}+\gamma\max_{b\in\mathcal A}\bar q_t(x_{t+1},b)-\bar q_t(x_t,a_t),\\ \bar q_{t+1}(x_t,a_t) &=\bar q_t(x_t,a_t)+\alpha_t(x_t,a_t)\delta_t . \end{aligned} \tag{5.1}\]
Two full states with the same label now update the same entry for a given action. To see when those updates agree in expectation, first compute the probability of the next label \(y\). It is the sum of the transition probabilities to the full states in its group,
\[ p_\phi(y\given s,a) =\sum_{s'\in\mathcal S_y}p(s'\given s,a). \tag{5.2}\]
For a given table \(\bar q\), write \(g_{\bar q}(s,a)\) for the expected TD target conditional on \(s_t=s\) and \(a_t=a\). The reward \(r(s,a)\) is the conditional mean of \(r_{t+1}\). Grouping the possible next states by their label gives
\[ \begin{aligned} g_{\bar q}(s,a) &=r(s,a)+\gamma\sum_{s'\in\mathcal S}p(s'\given s,a) \max_{b\in\mathcal A}\bar q(\phi(s'),b)\\ &=r(s,a)+\gamma\sum_{y\in\overline{\mathcal S}} p_\phi(y\given s,a)\max_{b\in\mathcal A}\bar q(y,b). \end{aligned} \tag{5.3}\]
This is the expectation in the Q-learning Bellman equation with the continuation value taken from the shared table.
5.2 When the abstract state is Markov
Let \(h_t\) be the history of observed labels, actions, and rewards through the current label \(x_t=x\), before taking action \(a_t\). Conditional on that history and the current action, the next label has distribution
\[ \Prob(x_{t+1}=y\given h_t,a_t=a) =\sum_{s\in\mathcal S_x}\Prob(s_t=s\given h_t,a_t=a)\,p_\phi(y\given s,a). \tag{5.4}\]
The abstract state is Markov for prediction under a given action if the current label and action suffice to predict the next label. A condition for one transition law valid from every full starting state is
\[ \begin{gathered} p_\phi(y\given s_1,a)=p_\phi(y\given s_2,a)\\ \text{for all }x,y,a\text{ and }s_1,s_2\in\mathcal S_x. \end{gathered} \tag{5.5}\]
If the condition holds, the common probability comes outside the sum in Equation 5.4. The weights sum to one, so the result depends only on \(x\) and \(a\). For necessity, start separately from \(s_1\) and \(s_2\) and take the same action. Their first-step distributions over labels must agree if one law is to apply to both starts. For a particular initial distribution the mixtures in Equation 5.4 may agree across histories even if some of their terms differ.
To preserve the model used by the Bellman update, also require the expected reward \(r(s,a)\) to agree within each group for every action. Together these conditions make Equation 5.3 agree within the group for every table \(\bar q\). Conversely, if the targets agree for every table, setting \(\bar q=0\) gives equality of expected rewards. To check the transition to a particular label \(y\), set every action value at \(y\) to one and all other entries to zero. After canceling the expected rewards, equality of the targets gives equality of \(\gamma p_\phi(y\given s,a)\).
The transition condition compares the total probability of reaching each group. The probabilities of reaching particular full states inside that group may differ. Reproducing the reward draws together with the labels would require equality of their joint distribution. Li, Walsh, and Littman, Definition 3(1).
Under a fixed policy
The forecast in Equation 5.4 conditions on the current action. Under a fixed stationary policy \(\pi(a\given s)\), we can instead predict the next label before seeing the action. Chapter 2 averages over the action to get \(r_\pi(s)\) and \(p_\pi(s'\given s)\) (Definition 2.1). Applying Equation 5.2 to \(p_\pi\) gives the transition probability to label \(y\),
\[ \sum_{s'\in\mathcal S_y}p_\pi(s'\given s) =\sum_{a\in\mathcal A}\pi(a\given s)\,p_\phi(y\given s,a). \]
By the same starting-state argument, one transition law under \(\pi\) applies from every start exactly when this sum agrees across \(s\in\mathcal S_x\) for every \(x,y\). To preserve the expected reward under \(\pi\), check \(r_\pi(s)\) within each group as well. The policy averages can agree even when the probabilities differ for an individual action. When the policy uses only \(x\), the per-action conditions also give agreement after averaging over the policy. A policy on full states can use different action probabilities within a group, so its averages have to be checked using its own action probabilities.
If both policy averages agree, they define a reward and transition on the labels. Solve the policy evaluation equation there and assign its value at \(x\) to every \(s\in\mathcal S_x\). Substituting this assignment into the full policy evaluation equation in Chapter 2 gives equality at every full state. Uniqueness of that equation’s solution therefore gives \(v_\pi(s)\) on the labels. To compute \(q_\pi(s,a)\), take the reward and transition under the forced first action \(a\), then use \(v_\pi\) as the continuation. For a policy that uses only \(x\), the per-action conditions make both terms agree across the group, so \(q_\pi\) also fits on the labels.
5.3 An MDP on abstract states
We can construct an MDP on the labels by choosing a distribution \(w_x(s)\) over the full states in each group \(\mathcal S_x\). Keep the same actions and discount factor, and define its reward and transition probability by
\[ \begin{aligned} \bar r(x,a)&=\sum_{s\in\mathcal S_x} w_x(s)\,r(s,a),\\ \bar p(y\given x,a)&=\sum_{s\in\mathcal S_x} w_x(s)\,p_\phi(y\given s,a). \end{aligned} \tag{5.6}\]
The second expression averages probability distributions, so it defines a probability distribution for each \((x,a)\). Under the per-action conditions on reward and transition, every term in each average agrees and the weights do not affect the result. In general the weights here are fixed by construction. The weights in Equation 5.4 describe which full state we occupy given the history and action, so they can change from one observation to the next. Li, Walsh, and Littman, Definition 1.
The Bellman optimality operator \(\bar T\) for the averaged MDP applies the right-hand side of the Q-learning Bellman equation to the current table. From Equation 5.6 and Equation 5.3,
\[ \begin{aligned} (\bar T\bar q)(x,a) &=\bar r(x,a)+\gamma\sum_{y\in\overline{\mathcal S}}\bar p(y\given x,a) \max_{b\in\mathcal A}\bar q(y,b)\\ &=\sum_{s\in\mathcal S_x}w_x(s)\,g_{\bar q}(s,a). \end{aligned} \tag{5.7}\]
The operator contracts by \(\gamma\). A change of at most \(\varepsilon\) in each table entry changes a maximum by at most \(\varepsilon\) and the discounted average by at most \(\gamma\varepsilon\). Its unique fixed point \(\bar q^*\) is the optimal action-value function of the averaged MDP.
Convergence with a fixed sampling distribution
Choose the entry \((x_t,a_t)\) and its step size before drawing the reward \(r_{t+1}\) and next state \(s_{t+1}\). Let \(\mathcal H_t\) record the history through those choices, including the current table. The sampled TD target is \(Z_t=r_{t+1}+\gamma\max_b\bar q_t(x_{t+1},b)\). Let \(\bar q_{\mathrm{ref}}\) be a fixed candidate limit and write \(\Delta_t=\bar q_t-\bar q_{\mathrm{ref}}\) for the error table. A sufficient condition on the target at the updated entry is
\[ \left|\E[Z_t\given\mathcal H_t]-\bar q_{\mathrm{ref}}(x_t,a_t)\right| \leq\gamma\|\Delta_t\|_\infty . \tag{5.8}\]
Suppose each entry has step sizes in \([0,1]\) and, almost surely, an infinite sum and a finite sum of squares. Under Equation 5.8, the shared table converges almost surely to \(\bar q_{\mathrm{ref}}\).
Subtract \(\bar q_{\mathrm{ref}}(x_t,a_t)\) from the Q-learning update. The result has the form of Equation 3.6, with both step sizes equal to \(\alpha_t(x_t,a_t)\) and noise term \(Z_t-\bar q_{\mathrm{ref}}(x_t,a_t)\). Set the step sizes and noise to zero at every other entry. The step sizes are fixed by \(\mathcal H_t\), and Equation 5.8 bounds the conditional mean of the noise. Bounded rewards and \(\|\bar q_t\|_\infty\leq\|\bar q_{\mathrm{ref}}\|_\infty+\|\Delta_t\|_\infty\) bound its conditional variance by a constant times \((1+\|\Delta_t\|_\infty)^2\). Thus Theorem 3.2 applies.
For the fixed sampler, select \((x_t,a_t)\) and the step size, draw \(s_t\) from \(w_{x_t}\), then sample the transition under \(a_t\) in the full MDP. This gives \(\E[Z_t\given\mathcal H_t]=(\bar T\bar q_t)(x_t,a_t)\) by Equation 5.7. The contraction of \(\bar T\) gives Equation 5.8 with \(\bar q_{\mathrm{ref}}=\bar q^*\).
Along a trajectory, changing the behavior policy can change which full states supply updates to a shared entry. With the current table held fixed by the learner’s history, the expected target averages Equation 5.3 over the conditional distribution of \(s_t\) in that history, as in Equation 5.4.
5.4 Preserving values and decisions
Optimal action values
The full optimal action values \(q^*(s,a)\) fit in one table on the labels exactly when they agree within every group for each action. Preserving the expected reward and transition for each action suffices. Start value iteration for the full Q-table at zero. If an iterate agrees within each group, its Bellman update is given by Equation 5.3 and also agrees under these conditions. The full Bellman operator contracts by the same argument as \(\bar T\), with each full state in its own group. Its iterates therefore converge to \(q^*\), which still agrees within groups.
Now suppose only that \(q^*(s,a)\) agrees within each group. Define a table by \(\bar q(\phi(s),a)=q^*(s,a)\). Substituting this table into Equation 5.3 gives \(g_{\bar q}(s,a)=q^*(s,a)\) by the full Bellman equation. Consequently every weighted average in Equation 5.7 returns the same entry \(\bar q(x,a)\). This table is the fixed point \(\bar q^*\) for any choice of weights. Here the targets need to agree at just one table. Change the next-label probabilities from one member of a group and subtract the resulting change in the discounted continuation term in Equation 5.3 from its reward. The table still solves the full Bellman equation while the next-label probabilities can differ within that group.
The same equality explains why Q-learning can recover \(q^*\) without a fixed mix of full states. At the table representing \(q^*\), the expected TD error is zero conditional on each full pair \((s,a)\). For any other table \(\bar q\),
\[ \big|g_{\bar q}(s,a)-\bar q^*(\phi(s),a)\big| \leq \gamma\|\bar q-\bar q^*\|_\infty . \]
On a trajectory, choose the entry \((\phi(s_t),a_t)\) and step size before drawing \((r_{t+1},s_{t+1})\). Include the full \(s_t\) in \(\mathcal H_t\) for the proof. Conditional on this history, the target mean is \(g_{\bar q_t}(s_t,a_t)\). The bound above gives Equation 5.8 with the table representing \(q^*\) as \(\bar q_{\mathrm{ref}}\). With the same per-entry step size bounds and sums, the shared table converges almost surely to this limit. The bound holds for each full state, so it also holds when the frequencies of those states within an abstract entry change. Li, Walsh, and Littman, Definition 3(3), Theorem 4(1).
An optimal policy
A policy \(\bar\pi(a\given x)\) on the labels acts in the full MDP by choosing actions with probabilities \(\pi(a\given s)=\bar\pi(a\given\phi(s))\). Such a policy can be optimal from every full state exactly when each group has an action that is optimal for all its members,
\[ \bigcap_{s\in\mathcal S_x}\argmax_{a\in\mathcal A}q^*(s,a)\ne\varnothing \qquad\text{for every }x. \tag{5.9}\]
Under an optimal policy, averaging \(q^*(s,a)\) over its action probabilities gives the maximum. Any action with positive probability at \(x\) must therefore lie in the intersection. Conversely, choose an action from each intersection. The optimal state value \(v^*(s)=\max_{a\in\mathcal A}q^*(s,a)\) then satisfies the Bellman equation of that policy, hence is its value. The condition requires a common maximizing action. Its value may vary across states in the group. Li, Walsh, and Littman, Definition 3(5).
When solving the averaged MDP gives an optimal policy
Suppose each group has both a common optimal action and a common optimal state value \(v^*(s)=\bar v(x)\) for \(s\in\mathcal S_x\). The return from taking action \(a\) in the averaged MDP and using \(\bar v\) for the continuation is
\[ \bar r(x,a)+\gamma\sum_{y\in\overline{\mathcal S}}\bar p(y\given x,a)\,\bar v(y) =\sum_{s\in\mathcal S_x}w_x(s)\,q^*(s,a) \leq \bar v(x). \tag{5.10}\]
A common optimal action attains equality, so \(\bar v\) solves the averaged Bellman equation and the left side of Equation 5.10 equals \(\bar q^*(x,a)\). If every full state in the group has positive weight, any action attaining equality maximizes \(q^*(s,a)\) at every full state in the group. Thus every greedy policy from the averaged MDP is optimal in the full MDP. A zero weight can hide a strict inequality, letting an action that is suboptimal at that full state tie in the average. Under the fixed sampler above, Q-learning converges to the values in the averaged MDP, even when suboptimal action values vary within the group. In Li, Walsh, and Littman’s Figure 1(a), both merged states have optimal value 4. The other action is worth 1 in one state and 2 in the other. Figure 1(c) shows that action’s estimate fluctuating as the behavior policy switches between favoring one action and favoring the other. Li, Walsh, and Littman, Definition 3(4), Theorems 3 and 4(2), Figure 1(a,c).
If the common action has different values at different full states, a policy can still choose it throughout the group. In the counterexample of Li, Walsh, and Littman, Figure 1(b), two actions from a state kept in its own group lead to different full states \(s'_1,s'_2\) in one next group. Their expected immediate rewards are \(r_1,r_2\). The averaged MDP uses the same continuation for both, so the first action wins when \(r_1>r_2\). In the full MDP the second action wins if \(r_1-r_2<\gamma[v^*(s'_2)-v^*(s'_1)]\).
At the terminal state, both actions loop with zero reward, so continuation there is zero. Complete the diagram by sending the unshown action 1 from each merged state to the terminal state with zero reward. Action 2 is then optimal at both merged states, with values \(1\) and \(2\). The initial rewards are \(r_1=0.5\) and \(r_2=0\), so for \(\gamma>0.5\) the rankings reverse. With the fixed sampler, the learned greedy policy takes the suboptimal action 1 at the initial state. Li, Walsh, and Littman, Theorems 3 and 4(3), Figure 1(b).
5.5 State abstraction in Krusell–Smith
Krusell and Smith find that mean capital gives accurate forecasts despite inexact aggregation, with small utility gains from richer forecasts. They also vary initial wealth dispersion in a two-period model. Here we use one pair of distributions to compare next-state laws under a common action and measure the loss from sharing one saving action. Krusell and Smith (1998), §III.C and Krusell and Smith (2006), §4.1.
Two distributions with the same aggregate capital
The household’s full state is \(s=(k,e,z,\Gamma)\), where \(k\) is its capital, \(e\) its employment status, \(z\) aggregate productivity, and \(\Gamma\) the joint distribution of capital and employment. The abstract state \(x=(k,e,z,K)\) keeps only mean capital \(K=\int k\,d\Gamma\) from the distribution. In the benchmark, \(z\) fixes the employment share, so current prices depend on \(K\) and \(z\). At a common \(x\) the household therefore has the same current resources \(m>0\). Saving \(a=k'\) gives the same reward \(\log(m-a)\) for any common feasible action \(0\leq a<m\). Krusell and Smith (1998), §§II.A–B.
Starting from one simulated cross-section \(\Gamma_A\), form \(\Gamma_B\) by moving weight from the middle of the employed capital distribution to both tails, keeping mean capital and the employment shares fixed. In both states, \(K=37.3509\) and employment is 90 percent. Keep the same employed household and productivity state, and fix the benchmark population saving rule \(g(k,e,z,K)\). The household is a price taker with zero weight in the population. Its action sets its own next capital. The population saves before the next shocks, so the next abstract state in case \(i\) is
\[ x'_i=(a,e',z',K'_i),\qquad K'_i=\int g(k,e,z,K)\,d\Gamma_i(k,e),\qquad i\in\{A,B\}. \tag{5.11}\]
The shock law for \((e',z')\) is common to the two cases. The event that next mean capital equals \(K'_A\) has probability one in state A and zero in state B because \(K'_A\ne K'_B\) in Table 5.1. This fails the transition test in Equation 5.5. The redistribution matters because saving per additional unit of capital varies across employed households. With a constant slope, total saving by that group would depend only on its mass and total capital, both of which are held fixed. Krusell and Smith (1998), §III.D.
One-step saving decisions
Use the same numerical continuation \(v_{\mathrm{ref}}\) in both cases. For each \((e',z',K')\), integrate \(R/c_{\mathrm{ref}}\) in own capital, where \(R\) is the gross capital return and \(c_{\mathrm{ref}}\) is consumption under the benchmark rule. The Bellman objective for \(0<a<m\) is
\[ q_i(a)=\log(m-a)+\gamma\,\E\big[v_{\mathrm{ref}}(a,e',z',K'_i)\given z,e\big]. \tag{5.12}\]
Only the continuation differs across the two objectives. The script checks that \(c_{\mathrm{ref}}\) is nondecreasing in own capital at the successor states, so the continuation is concave and the log reward makes each \(q_i\) strictly concave. At zero saving, next-period unemployment can leave the household with no consumption, giving \(q_i(0)=-\infty\). With \(\Gamma\) observed, the household can choose its maximizer \(a_i^*\). With only \(x\), the best shared action \(a_S\) under equal weights maximizes \((q_A+q_B)/2\). Its loss in state \(i\) is \(q_i(a_i^*)-q_i(a_S)\).
| Quantity | \(\Gamma_A\) | \(\Gamma_B\) |
|---|---|---|
| Next mean capital \(K'\) | 37.2600 | 37.2778 |
| Best saving action \(a_i^*\) | 33.03745 | 33.03693 |
| Loss at shared action \(a_S=33.03719\) | \(4.482\times10^{-9}\) | \(4.483\times10^{-9}\) |
A higher \(K'\) lowers the next rental rate and raises the next wage for a given \(z'\). These prices enter the marginal continuation value of saving. The common-maximizer test in Equation 5.9 fails for the two one-step objectives. At either interior optimum the derivative with respect to saving is zero, so a small deviation has no first-order utility cost. The reported losses concern one decision at these two states, with the population rule and continuation fixed.
Reproduce the calculation
The script uses the pinned course notebook for the calibrated saving rule and simulation. Tightening the household solver tolerance from \(10^{-8}\) to \(10^{-10}\) changes the \(K'\) gap by less than \(10^{-9}\), each action by less than \(3\times10^{-7}\), and each loss by less than \(3\times10^{-15}\).
Download ks_abstraction.py and run the following commands in its directory.
python3.12 -m venv .venv
source .venv/bin/activate
python -m pip install jax==0.9.0 jaxlib==0.9.0 \
numpy==2.3.5 scipy==1.17.0 matplotlib==3.10.8
python ks_abstraction.py