<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.10.0">Jekyll</generator><link href="https://dillonmsandhu.github.io/feed.xml" rel="self" type="application/atom+xml" /><link href="https://dillonmsandhu.github.io/" rel="alternate" type="text/html" /><updated>2026-09-27T22:58:05+00:00</updated><id>https://dillonmsandhu.github.io/feed.xml</id><title type="html">Dillon Sandhu’s Website</title><entry><title type="html">Non-linear Value Learning</title><link href="https://dillonmsandhu.github.io/deep/rl/2026/09/25/nonlinear-value-learning.html" rel="alternate" type="text/html" title="Non-linear Value Learning" /><published>2026-09-25T00:00:00+00:00</published><updated>2026-09-25T00:00:00+00:00</updated><id>https://dillonmsandhu.github.io/deep/rl/2026/09/25/nonlinear-value-learning</id><content type="html" xml:base="https://dillonmsandhu.github.io/deep/rl/2026/09/25/nonlinear-value-learning.html"><![CDATA[<script>
  MathJax = {
    tex: {
      inlineMath: [['$', '$'], ['$$', '$$'], ['\\(', '\\)']],
      displayMath: [['$$', '$$'], ['\\[', '\\]']]
    }
  };
</script>

<script src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js" async=""></script>

<style>
  .post-abstract {
    background-color: #fcfcfc;
    border-left: 5px solid #2a7ae2;
    padding: 20px;
    margin: 30px 0;
    font-style: italic;
    font-size: 0.95em;
    color: #444;
    line-height: 1.6;
  }
</style>

<div class="post-abstract">
I explain the difference between non-linear value function learning for RL, and show the trajectories taken by each algorithm on the spiral MDP, an environment created by <a href="https://www.mit.edu/~jnt/Papers/J063-97-bvr-td.pdf">Tsitsiklis and Van Roy (1997)</a> to break non-linear TD learning.
</div>

<p>A key concept in RL is learning the value function with <em>bootstrapping</em>. But there are several objectives that all make use of bootstrapping, all of which differ in subtle but important ways. For instance, we have <em>Bellman Error Minimization</em>, <em>TD Learning</em>, <em>Partially Fitted Value Iteration</em>, not to mention <em>Mean Squared Projected Bellman Error</em>, <strong>oh my</strong>…</p>

<p>Making things more confusing, standard treatment of these algorithms (e.g. from Sutton and Barto) uses linear value function estimation. In that case, the span of the tangent line of the value estimate is the same as the hypothesis class itself. As we shall see, when the value estimate is not linear in its parameters, intuitions from linear RL break down.</p>

<p>In this post, I demonstrate the behavior of the following <em>non-linear</em> value function learning methods on the spiral MDP:</p>
<ul>
  <li><em>Fitted Value Iteration (FVI)</em></li>
  <li><em>TD Learning</em></li>
  <li><em>Bellman Error Minimization</em></li>
  <li><em>Projected Bellman Error Minimization</em></li>
  <li><em>Monte Carlo / Supervised Value Learning</em></li>
</ul>

<h3 id="the-spiral-mdp">The Spiral MDP</h3>

<p>Tsitsiklis and Van Roy devised a counterexample to demonstrate that TD learning fails on-policy with non-linear function approximation. As we will see, the spiral MDP also breaks fitted value iteration.</p>

<p>The problem is a Markov Reward Process (MRP) and value function estimator. The MRP has three states, thus the value function estimate, called \(v_\theta\), outputs a three-dimensional vector that depends on a single parameter \(\theta\). The reward is zero everywhere, meaning the true value is \(V^\pi = \mathbf{0}\). The magnitude of the estimate \(v_\theta\) approaches zero as \(\theta \rightarrow -\infty\).</p>

<p>The value function, and its estimate are in three dimensions. However, \(v_\theta\) will always live in a two-dimensional subspace. We visualize that subspace in <strong>Figure 1</strong>. The spiral shows our function class – all possible values of \(v_\theta\) (projected to the 2-D subspace). The sinusoidal curves show the value function as the \(\theta\) changes - with each color representing a different state value.</p>

<div style="text-align: center; margin: 30px 0;">
  <img src="/assets/images/blog_post_4/image-5.png" alt="The Spiral MDP" style="max-width: 100%; border-radius: 4px;" />
  <p style="color: gray; font-size: 0.85em; margin-top: 5px;"><em>Figure 1: The Spiral MDP.</em></p>
</div>

<p>What’s nasty about this MRP – at least from the point of view of TD learning and friends – is that the Bellman Operator points towards the true value center, but when <em>fitting it as a stationary target</em> (like most bootstrapping methods), \(v_\theta\) fits the Bellman Estimate of the value, yet it diverges from \(V^\pi\).</p>

<p>A few technical details. First, the Bellman Operator is closed in this 2D space. For those who are curious why: \(\mathbf{1} =(1,1,1)^\intercal\) is a left eigenvector of \(P\) with eigenvalue 1. This implies that for any vector \(v\) orthogonal to \(\mathbf{1}\), \(Pv\) remains orthogonal to \(\mathbf{1}\), since \(\mathbf{1}^\intercal P v = \mathbf{1}^\intercal v = 0\).</p>

<p>Technical detail 2: The state-visitation distribution in the spiral MDP is exactly one third times the identity. Thus the on-policy weighted distance reduces to a constant scalar times the Euclidean distance. Technically, all inner products should be weighted by the on-policy distribution (stored in the matrix \(D\) in my earlier posts), but because \(D = \frac{1}{3}I\), I ignore it in this post. See the final section of the <a href="https://www.mit.edu/~jnt/Papers/J063-97-bvr-td.pdf">original paper</a> for the description of the MRP.</p>

<div style="text-align: center; margin: 30px 0;">
  <img src="/assets/images/blog_post_4/image-7.png" alt="Bellman Operator" style="max-width: 65%; border-radius: 4px;" />
  <p style="color: gray; font-size: 0.85em; margin-top: 5px;"><em>Figure 2: Bellman Operator.</em></p>
</div>

<h3 id="algorithm-1-partially-fitted-value-iteration-fvi">Algorithm 1: (Partially) Fitted Value Iteration (FVI)</h3>

<p>(Partially) Fitted Value Iteration (FVI) is the most common value learning algorithm in deep RL. For example, DQN and PPO both perform FVI. Generally, FVI is thought of as a batch algorithm. It repeatedly fits the Bellman Operator. In expectation, it works as follows:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Algorithm: FVI
Repeat:
0. Initialize Target Network u &lt;- v.
1. Estimate Tu = R + γPu.
2. Compute v by minimizing the length of Tu-v.
</code></pre></div></div>

<p>The distinction between batch FVI and PFVI lies entirely in the final step, when a new value estimate is obtained as \(v_\theta \gets \operatorname{argmin}_{v_\theta} \|Tu - v_\theta\|^2\). In classic linear FVI, the best fit for \(\theta\) can be obtained using least squares regression.</p>

<p>Deep variants perform gradient descent on \(\theta\). But for how many gradient updates? If we fit \(\theta\) for just one step of gradient descent, we get TD learning. If we run gradient descent until convergence, we get full batch FVI. The crux of the problem is that gradient descent doesn’t give us a global minimum. And the local optimum obtained is unfortunately worse than what we started with.</p>

<p>I run FVI on the spiral problem, with 200 gradient steps per Bellman update. The learning dynamics shown are in <strong>Figure 3</strong>. The left panel shows the parameter value with each update – notice that it is diverging away from the best estimate \(\theta^* = -\infty\). The middle panel shows the trajectory on the spiral. The trajectory appears to be going in the wrong direction, despite a better fit being available in the function class. How can this be? As the right panel shows: the loss landscape is non-convex. The global minimum estimator appears to be far to the right, around \(\theta=-5\). But there is a different local minimum in the other direction. Because the loss landscape is non-convex, each round of FVI gets further away from \(Tv\).</p>

<div style="text-align: center; margin: 30px 0;">
  <img src="/assets/images/blog_post_4/image-8.png" alt="Learning Dynamics of FVI" style="max-width: 100%; border-radius: 4px;" />
  <p style="color: gray; font-size: 0.85em; margin-top: 5px;"><em>Figure 3: Learning Dynamics of FVI.</em></p>
</div>

<p>Because our \(v_\theta\) is non-convex, fitting the Bellman operator can lead to a worse value estimate, breaking the contraction argument for why standard exact value iteration converges. In short, the “fitted” component of FVI breaks the guarantee of value iteration. <strong>Figure 4</strong> shows a longer run. Note that the parameters traverse the fixed loss landscape, since the loss changes with each application of \(T\) (but I only show the first loss).</p>

<div style="text-align: center; margin: 30px 0;">
  <img src="/assets/images/blog_post_4/image-10.png" alt="Longer Run of FVI" style="max-width: 100%; border-radius: 4px;" />
  <p style="color: gray; font-size: 0.85em; margin-top: 5px;"><em>Figure 4: Longer Run of FVI.</em></p>
</div>

<h3 id="algorithm-2-td-learning">Algorithm 2: TD Learning</h3>
<p>Tsitsiklis and Van Roy’s original 1997 paper analyzed TD learning. As mentioned above, TD learning takes a single gradient step to fit the Bellman Operator before updating the value function. A single gradient step is a <em>locally linear</em> approximation to the true optimal direction. As such, each step of TD learning can be understood as taking a small step towards <em>the projection of</em> \(Tv_\theta\) onto <em>the space orthogonal to the tangent line of</em> \(v_\theta\).</p>

<p><strong>Figure 5</strong> shows the dynamics of TD learning. Again, a single application of the Bellman Operator to the starting value estimate is shown in purple. The green line shows the projection of \(Tv_\theta\) onto the span of \(\nabla_\theta v\) (a length 3 vector with entries \(\frac{dv}{d\theta}(s_i)\) for each state). Notice that this line points away from the center due to the direction of the spiral and angle of \(T\).</p>

<div style="text-align: center; margin: 30px 0;">
  <img src="/assets/images/blog_post_4/image-11.png" alt="TD Learning" style="max-width: 100%; border-radius: 4px;" />
  <p style="color: gray; font-size: 0.85em; margin-top: 5px;"><em>Figure 5: TD Learning.</em></p>
</div>

<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">def</span> <span class="nf">td_update</span><span class="p">(</span><span class="n">θ</span><span class="p">,</span> <span class="n">v</span><span class="p">,</span> <span class="n">dv</span><span class="p">,</span> <span class="n">α</span><span class="p">):</span>
    <span class="n">δ</span> <span class="o">=</span> <span class="n">T</span><span class="p">(</span><span class="n">v</span><span class="p">)</span> <span class="o">-</span> <span class="n">v</span>
    <span class="n">θ</span> <span class="o">=</span> <span class="n">θ</span> <span class="o">+</span> <span class="n">α</span> <span class="o">*</span> <span class="n">dv</span><span class="p">.</span><span class="n">T</span> <span class="o">@</span> <span class="n">δ</span>
    <span class="k">return</span> <span class="n">θ</span>
</code></pre></div></div>

<p>Note that in the linear case, the span of the tangent line <em>is</em> the space of representable functions. In this case, FVI and TD learning have the same fixed point.</p>

<h3 id="algorithm-3-bellman-error-minimization-bem">Algorithm 3: Bellman Error Minimization (BEM)</h3>
<p>Bellman Error Minimization (Baird, L. (1995)) solves \(\min_{\theta} \|Tv_\theta - v_\theta\|_2^2\). This looks <em>a lot</em> like TD learning and FVI. The key difference is that BEM differentiates both \(v_\theta\) AND \(T v_\theta\) with respect to \(\theta\). Whereas TD learning and FVI fix \(T v_\theta\) (e.g. with a target network).</p>

\[\begin{align}
\nabla_\theta \|Tv_\theta - v_\theta\|_2^2 &amp;= 2(Tv_\theta - v_\theta)^\intercal \nabla_\theta (Tv_\theta - v_\theta) \\
&amp;= 2 \delta^\intercal (\nabla_\theta T v_\theta - \nabla_\theta v_\theta)
\end{align}\]

<p>The presence of \(\nabla_\theta T v_\theta\) means that BEM techniques must incorporate information about how \(Tv\) changes with \(v\). More precisely, BEM methods must estimate \(P \nabla_\theta v_\theta\) – the expected value of the gradient one step into the future – as well as \(\delta\), and take their product. Since the expectation of a product does not equal the product of expectations, a naive sample-based update requires two independent transitions from the same state (the <em>double sampling issue</em>). However, just as in GTD methods, one can circumvent double sampling by introducing an auxiliary weight vector to estimate the expected future gradient product without requiring two next-state samples. In our experiments on the spiral problem, we can compute all terms in the gradient exactly.</p>

<p>Results are shown in Figure 6. Note that BEM succeeds on this problem.</p>

<div style="text-align: center; margin: 30px 0;">
  <img src="/assets/images/blog_post_4/image-15.png" alt="Bellman Error Minimization" style="max-width: 100%; border-radius: 4px;" />
  <p style="color: gray; font-size: 0.85em; margin-top: 5px;"><em>Figure 6: Bellman Error Minimization.</em></p>
</div>

<h3 id="algorithm-4-mean-squared-projected-bellman-error-mspbe">Algorithm 4: Mean Squared Projected Bellman Error (MSPBE)</h3>
<p>The MSPBE is the length of the green vector in Figure 5. Letting \(\Pi_\theta\) be the linear projection onto the span of \(\nabla_\theta v\), we have:</p>

\[\text{MSPBE} = \| \Pi_\theta (T v_\theta - v_\theta) \|^2 = \| \Pi_\theta \delta_\theta \|^2 = \delta_\theta^\intercal \Pi_\theta \delta_\theta\]

<p>Since we have just one parameter, \(\Pi_\theta\) is the \(3\times3\) matrix:</p>

\[\Pi_\theta = \frac{1}{\|\nabla_\theta v\|^2} (\nabla_\theta v) (\nabla_\theta v)^\intercal\]

<p>Plugging this in, we the squared TD learning update, divided by the squared length of the tangent vector \(\|\nabla_\theta v\|^2\):</p>

\[\begin{align}
\text{MSPBE} &amp;= \frac{1}{\|\nabla_\theta v\|^2}  (\delta_\theta^\intercal \nabla_\theta v)^2.
\end{align}\]

<p>There are numerous issues minimizing this quantity. For one, the gradient of the MSPBE contains the product of value network Hessians. Secondly, it once again requires estimating \(P \nabla_\theta v_\theta\) – in other words, it must know how $v_\theta$ changes as a local function of \(\theta\). This also requires addressing the double sampling issue. Methods that minimize the MSPBE avoid double sampling by training an estimator to predict the Bellman error.</p>

<p>For our toy problem, we can compute the gradient of the MSPBE exactly - and find that it works! At each step, it can be thought of as changing \(\theta\), re-applying the Bellman operator, and measuring the length of the green line. The right panel shows the true MSPBE - or the length of the green vector - as learning progresses.</p>

<div style="text-align: center; margin: 30px 0;">
  <img src="/assets/images/blog_post_4/image-12.png" alt="MSPBE Minimization" style="max-width: 100%; border-radius: 4px;" />
  <p style="color: gray; font-size: 0.85em; margin-top: 5px;"><em>Figure 7: MSPBE Minimization.</em></p>
</div>

<h3 id="algorithm-5-monte-carlo">Algorithm 5: Monte Carlo</h3>
<p>Removing all sampling noise, Monte Carlo value learning is just supervised learning of the center of the circle. Does this suffer from a highly non-convex landscape like FVI?</p>

<p>It does not. As \(\theta\) decreases, the error monotonically decreases as well, leading to a convex loss landscape. Note that its loss, shown in the fourth panel of Figure 8, has quite a similar shape to the MSPBE error, which is shown in the third panel.</p>

<div style="text-align: center; margin: 30px 0;">
  <img src="/assets/images/blog_post_4/image-13.png" alt="Value Error Minimization" style="max-width: 100%; border-radius: 4px;" />
  <p style="color: gray; font-size: 0.85em; margin-top: 5px;"><em>Figure 8: Monte Carlo / Value Error Minimization.</em></p>
</div>

<h3 id="summary">Summary</h3>
<p>In short, all one-step methods either fail (TD and FVI), or face the double sampling issue (BEM and MSPBE minimization). In our experiments, we take advantage of access to the true transition matrix and reward function to bypass the double sampling issue. Additionally, we get strong performance from multi-step methods like MC / VEM, due to the absence of sampling variance.</p>]]></content><author><name></name></author><category term="deep" /><category term="RL" /><summary type="html"><![CDATA[]]></summary></entry><entry><title type="html">Symmetrized TD Learning</title><link href="https://dillonmsandhu.github.io/representation/learning/2026/07/07/symmetrized-td-learning.html" rel="alternate" type="text/html" title="Symmetrized TD Learning" /><published>2026-07-07T00:00:00+00:00</published><updated>2026-07-07T00:00:00+00:00</updated><id>https://dillonmsandhu.github.io/representation/learning/2026/07/07/symmetrized-td-learning</id><content type="html" xml:base="https://dillonmsandhu.github.io/representation/learning/2026/07/07/symmetrized-td-learning.html"><![CDATA[<script>
  MathJax = {
    tex: {
      inlineMath: [['$', '$'], ['\\(', '\\)']],
      displayMath: [['$$', '$$'], ['\\[', '\\]']]
    }
  };
</script>

<script src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js" async=""></script>

<style>
  .post-abstract {
    background-color: #fcfcfc;
    border-left: 5px solid #2a7ae2;
    padding: 20px;
    margin: 30px 0;
    font-style: italic;
    font-size: 0.95em;
    color: #444;
    line-height: 1.6;
  }
</style>

<div class="post-abstract">
I continue examining when deep TD learning fits the value function, following up on the theoretical results of Tang and Munos (2023). Since the symmetry of the "key" matrix $A\doteq D(I-\gamma P)$ is crucial to the equivalence between supervised value learning and TD learning, I consider whether TD learning can be modified to use the symmetric portion of $A$ only. In the end, I have some empirical results testing the "symmetrized" TD learning. Unfortunately, the symmetrized TD learning is not of obvious practical value, since it requires using $A^{-1}$, which amounts to solving the MDP. 

Still, this post provides a concise derivation of the key results, and empirical validation.
</div>

<h2 id="refresher">Refresher</h2>
<p>The last post derived theoretical conditions for when TD learning fits the value function. Earlier theoretical results (Tang and Munos (2023)), found that if the Markov Chain is <em>reversible</em> ($\mu_i P_{ij} = \mu_j P_{ji}$), then TD-Learning is the exact same as gradient descent on a symmetrized value error. Let our estimate be $v_\theta$  and the value error vector be $e=V-v_\theta$. Finally, recall the definition of the <em>key matrix</em> $A=D(I-\gamma P)$. Then, the value error is the following:</p>

\[\begin{align}
E(v) &amp;\doteq \frac{1}{2} e^T A e \\
&amp;= \frac{1}{2} e^\top S e
\end{align}\]

<p>Where $S = \frac{1}{2}(A + A^\top)$, and the second line follows from the fact that $E$ is quadratic, meaning only the symmetric part of $A$ matters. Since $E$ is a (weighted) norm, it can only be zero if $e=0$. This implies the typical value error $\overline{VE}^2 = e^\top D e^\top$ and $E$ have the same minimum.</p>

<h3 id="td-learning">TD Learning</h3>
<p>TD learning is based on bootstrapping. Its update is proportional to:</p>

\[\dot{\theta} \propto (D\delta) \nabla v_\theta\]

<p>Next, I show that $Ae = D \delta$, giving us the form:</p>

\[\dot{\theta} \propto \begin{aligned} (D\delta) \nabla v_\theta &amp;= Ae \nabla v_\theta\end{aligned}\]

<p>Proof that $Ae = D \delta$.</p>

\[\begin{align}
Ae &amp;= D(I-\gamma P)(V - v_\theta) \quad \text{definition}\\
&amp;= D(R - (I-\gamma P)v_\theta) \quad \text{since } (I-\gamma P)V = R\\
&amp;= D(R  + \gamma Pv_\theta - v_\theta) \\
&amp;= D\delta \\
\end{align}\]

<p>The takeaway is that the update $\theta$ due to TD learning is proportional to $Ae \nabla v_\theta$. Also, note that $A$ is positive semi-definite since the bellman operator $T$ is a contraction on $| \cdot |_D$.<sup id="fnref:1" role="doc-noteref"><a href="#fn:1" class="footnote" rel="footnote">1</a></sup>.</p>

<h3 id="gradient-descent-on-e">Gradient Descent on E</h3>
<p>This is <em>almost</em> the same as the direction followed by direct gradient descent on $E$, which follows the negative gradient of $E$:</p>

\[\begin{align}
- \nabla_\theta E &amp;= -\nabla(e^\top A e) \\
&amp;= -\nabla(e^\top S e) \\
&amp;= -\nabla \cdot (V-v_\theta)^\top S (V-v_\theta) \\
&amp;= Se\nabla v_\theta
\end{align}\]

<p>Tang and Munos used the near equivalence of these two expressions to show that TD learning is the same as gradient descent on $E$ exactly when $S = A$ (the MDP is reversible).</p>

<h3 id="symmetrized-td-learning">Symmetrized TD Learning</h3>
<p>However, in general, $A$ is not symmetric, and $A = S + K$, with skew-symmetric component $K \doteq \frac{1}{2}(A-A^\top)$. This means that the skew-symmetric component is what can derail TD learning. The natural question is if we can remove the skew-symmetric component. Then, the TD learning update would take a step in the direction of $\nabla_\theta E$. We can rewrite $Se$ as $S(I-\gamma P)^{-1} \delta$. This yields an update of the following form, weighting the TD error by $S(I-\gamma P)^{-1}$ that will minimize $E$.</p>

\[\dot{\theta} \propto S(I-\gamma P)^{-1} \delta \nabla v_\theta\]

<h2 id="whirlpool-experiments">Whirlpool Experiments</h2>

<p>To test this symmetrized TD learning, I compare to <em>exact</em> TD learning. Exact TD learning makes applies the expected update due to TD, rather than constructing the an unbiased estimate from samples. This removes the noise in TD learning. Notice it doesn’t depend on a sampled batch: instead it computes $\delta$ for all states, and then weights it by $\mu$ in the final loss.</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>def td_loss(params):
	v = network.apply(params, ALL_STATES) # length N vector
	TD_targets = R_π + λ * P_π @ v
	td_errors = v - stop_gradient(TD_targets)
	loss = 0.5 * jnp.sum(mu * (td_errors ** 2))
return loss
</code></pre></div></div>

<p>For all experiments, I train a convolutional network to evaluate a fixed policy. I use a fixed policy due to training PPO to near convergence. The  I also train with <em>exact</em> Monte Carlo (i.e. gradient descent on $e^\top D e$), removing the variance due to noisy estimates of $V$ and noisy gradient estimates. Perhaps unsurprisingly, I find the symmetrized obtains much better value error with a neural network compared to TD learning. More suprisingly, I find it has better value erro than Monte Carlo. In the following experiment, I train a policy to near convergence with PPO.</p>

<p>Symmetric TD found a significantly stronger policy than exact MC (regression on $V$) or exact TD.</p>

<div style="text-align: center; margin: 30px 0;">
  <img src="/assets/images/blog_post_3/Percent%20Greedy%20Correct%20FourRooms.png" alt="Misaligned_TD" style="max-width: 100%; border-radius: 4px;" />
  <p style="color: gray; font-size: 0.85em; margin-top: 5px;"><em>Figure 1: Exact Algorithms performing policy evaluation of a strong policy on Four Rooms.</em></p>
</div>

<p>Surprisingly, gradient descent on $E$ found the strongest policy, suggesting there is something useful about weighting errors by $S$…</p>

<h3 id="whirlpool-environment">Whirlpool Environment</h3>
<p>To “stump” TD, I created a more asymetric environment: a whirlpool with a reward in the center. The start state is a random state in the outer ring, and the transition function pushes the agent clockwise 90% of the time, with the agents intended action succeeding 10% of the time. The value function is the following (note the reward is given on the transition <em>into</em> the center state, following the standard Gym API, leading to the terminal state having zero value.)</p>

<div style="text-align: center; margin: 30px 0;">
  <img src="/assets/images/blog_post_3/whirlpool_val.png" alt="Misaligned_TD" style="max-width: 100%; border-radius: 4px;" />
  <p style="color: gray; font-size: 0.85em; margin-top: 5px;"><em>Figure 2: Value of the whirlpool MDP. Note it is radially symmetric.</em></p>
</div>
<p>On this environment, TD was much weaker than the other methods, while gradient descent on $E$ and symmetric TD were the strongest.</p>

<div style="text-align: center; margin: 30px 0;">
  <img src="/assets/images/blog_post_3/whirlpool_ve.png" alt="Misaligned_TD" style="max-width: 100%; border-radius: 4px;" />
  <p style="color: gray; font-size: 0.85em; margin-top: 5px;"><em>Figure 3: Value Error on of the whirlpool MDP for exact methods (lower is better).</em></p>
</div>

<div style="text-align: center; margin: 30px 0;">
  <img src="/assets/images/blog_post_3/whirlpool_greedy_acc.png" alt="Misaligned_TD" style="max-width: 100%; border-radius: 4px;" />
  <p style="color: gray; font-size: 0.85em; margin-top: 5px;"><em>Figure 4: Greedy Policy prediction accuracy on of the whirlpool MDP for exact methods (higher is better).</em></p>
</div>

<h3 id="practical-issues">Practical issues</h3>
<p>Symmetric TD uses $(I-\gamma P)^{-1}$, essentially requiring solving the Bellman equation.</p>

<h3 id="penalizing-skew-symmetric-portion">Penalizing Skew-Symmetric Portion</h3>
<p>A related idea is as follows: subtract $Ke \nabla V$ from the TD update. This is because the difference between the TD update $(Ae \nabla v)$ and gradient of $E$  $(Se \nabla v)$ is exactly $Ke$:</p>

\[\dot{\theta} - \nabla_\theta E = (Ae - Se) \nabla v = Ke \nabla v\]

<p>This implies that $\dot{\theta} - Ke \nabla = \nabla_\theta E$. To make the TD update gradient descent on $E$, simply add $Ke \nabla v$ to the $TD$ update. However, this too requires a value oracle to get $e$, or Monte Carlo to estimate it, removing the advantage of TD learning.</p>

<hr />
<div class="footnotes" role="doc-endnotes">
  <ol>
    <li id="fn:1" role="doc-endnote">
      <p>Specifically, it holds that $x^\top S x \geq (1-\gamma)|x|_D^2$ for all $x$. The proof is as follows. Expanding $x^\top A x = x^\top D x - \gamma x^\top D P x$, we see that the first term is $|x|_D^2$ and the second is at most $ \gamma |x|_D |Px|_D$ by the Cauchy-Shwartz inequality. Since $T$ is a contraction in $| \cdot |_D$, $|Px|_D \leq |x|_D$, implying the second term is at most $\gamma |x|_D^2$. Thus, we have $x^\top S x = x^\top A x \geq (1-\gamma) |x |_D^2$. <a href="#fnref:1" class="reversefootnote" role="doc-backlink">&#8617;</a></p>
    </li>
  </ol>
</div>]]></content><author><name></name></author><category term="representation" /><category term="learning" /><summary type="html"><![CDATA[]]></summary></entry><entry><title type="html">How reinforcement learning with TD learning depends on the inherent symmetry of the problem</title><link href="https://dillonmsandhu.github.io/representation/learning/2026/06/09/when-does-td-learning-improve-representations.html" rel="alternate" type="text/html" title="How reinforcement learning with TD learning depends on the inherent symmetry of the problem" /><published>2026-06-09T00:00:00+00:00</published><updated>2026-06-09T00:00:00+00:00</updated><id>https://dillonmsandhu.github.io/representation/learning/2026/06/09/when-does-td-learning-improve-representations</id><content type="html" xml:base="https://dillonmsandhu.github.io/representation/learning/2026/06/09/when-does-td-learning-improve-representations.html"><![CDATA[<script>
  MathJax = {
    tex: {
      inlineMath: [['$$', '$$'], ['\\(', '\\)']],
      displayMath: [['$$', '$$'], ['\\[', '\\]']]
    }
  };
</script>

<script src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js" async=""></script>

<style>
  .post-abstract {
    background-color: #fcfcfc;
    border-left: 5px solid #2a7ae2;
    padding: 20px;
    margin: 30px 0;
    font-style: italic;
    font-size: 0.95em;
    color: #444;
    line-height: 1.6;
  }
</style>

<div class="post-abstract">
  Deep Temporal Difference (TD) learning is a standard technique for Reinforcement Learning (RL), but its stability is fragile. Previous work has shown that if an environment is perfectly reversible, TD learning amounts to supervised learning of the true value function. But about practical problems, where the dynamics can be highly asymmetric? In this post, I extend previous theory of TD dynamics and define exact conditions for representation improvement. I find that, if the transition function is symmetric enough, TD learning will update the hidden layers of a neural network to fit the value function. In other words, I find mathematical condtions for when we get alignment. At the end, I try to provide intuition for when this condition will hold.
</div>

<p>(This is a follow-up to my previous post <a href="https://dillonmsandhu.github.io/representation/learning/2026/05/20/will-deep-td-learning-result-in-quality-representations.html">Will Deep TD Learning Result in Quality Representations?</a>)</p>

<p>Deep temporal difference learning is the primary method for estimating the value function in reinforcement learning. The goal of TD learning is to minimize the average squared value error, averaged over a state distribution \(\mu\):</p>

\[\overline{VE}(v, \mu) = \sum \mu(s) (V(s)-v(s))^2 = 
(V-v)^\intercal D (V-v)\]

<p>where \(V\) is the true value function, \(v\) is estimate, and \(D = \text{diag}[\mu]\). The value estimate, obtained from a neural network, is the dot product of the state-features and value weights: \(v(s) = \phi(s)^\intercal w\). Since the value is not directly observable, TD learning uses bootstrapping: fitting the value network towards a target based on its own predictions.</p>

<p>In the last post, I provided a geometric intuition and showed that deep TD learning can adjust the features in the <em>wrong direction</em> – raising the inherent value error \(VE\) for the best weights. This happened when the TD target and true value function are on opposite sides of the feature space, which I call <em>misalignment</em>. An example is pictured below.</p>

<div style="text-align: center; margin: 30px 0;">
  <img src="/assets/images/blog_post_2/misaligned_td_learning.svg" alt="Misaligned_TD" style="max-width: 100%; border-radius: 4px;" />
  <p style="color: gray; font-size: 0.85em; margin-top: 5px;"><em>Figure 1: An example where 
  misalignment of the bellman target Tv and true value function V hurts the features.</em></p>
</div>

<p>Is misalignment a problem in practice? For evaluating the random policy on Four Rooms, I found it was not. But does it become an issue in challenging domains like math or robotics?</p>

<p>The literature has explored how deep TD learning will adjust the features. [Tang and Munos 2023] showed that, under the property that the MDP is reversible (\(D P = P^\top D\)), the TD learning update happens to perform gradient descent on \(V\). This sounds great, however, reversibility is extremely unlikely to hold in practice: It says that the probability transition \(Ds_1 \rightarrow s_2\) equals the probability of \(s_2 \rightarrow s_1\). Yet, on most tasks, strong policies don’t go backwards.</p>

<p>In this post, I extend the results of <a href="https://arxiv.org/abs/2305.18491">Tang and Munos 2023</a>. Reinforcing the importance of alignment, I show that alignment is a necessary and sufficient condition for the value error to decrease. I also show that an <em>almost reversible</em> property is enough to guarantee alignment.  Before that, I walk us through their original proof, which answers the important question of when TD learning is doing the right thing. So let’s go!</p>

<h3 id="main-result-of-tang-and-munos-2023">Main Result of Tang and Munos (2023)</h3>
<p>This work considers a continuous-time variant of TD learning, described by the following system of differential equations:</p>

\[\begin{align}
\dot{w}_t &amp;= \eta_w \cdot \Phi_t^\top D(Tv_t - v_t)\\
\dot{\Phi}_t &amp;= \eta_\Phi \cdot D(Tv_t-v_t) w^\top_t
\end{align}\]

<p>The dot indicates the time derivative: (\(\dot{x}_t = \frac{dx}{dt}\) for a function \(x(t)\)). These equations describe the dynamics of TD learning when discrete algorithmic updates are brought into continuous time. For the purposes of this blog post, I’ll assume that the weights are a fixed value \(w_t = w\).</p>

<p>The key question is how the value error changes with each update. We analyze this in terms of the time-derivative of the value error, \(E\) (defined below).</p>

<p>We now define the value error. For theoretical convenience, Tang and Munos consider a loss that weights states slightly differently. They define a value error \(E\)  that weights by the “key” matrix \(A = D(I-\gamma P)\):</p>

\[\begin{align}
E(\Phi, w) &amp;\doteq \frac{1}{2} (\Phi w - V)^T A (\Phi w - V)
\end{align}\]

<p>Though it doesn’t appear in the standard value error, the key matrix is of massive importance for the stability of TD learning. The dynamics of the features can be rewritten in terms of the key matrix.</p>

\[\begin{align}
\dot{\Phi}_t &amp;= \eta_\Phi \cdot D(R + (I-\gamma P)v_t) w^\top\\
&amp;= \eta_\Phi \cdot (DR + Av_t) w^\top
\end{align}\]

<p>The true value function doesn’t appear directly. A key insight is that the Bellman equation implies \(DR = D(I-\gamma P)  = AV\), allowing the above equation to be rewritten in terms of the true value function \(V\). This is an imporant move that is crucial to the results discussed in this post.</p>

\[\begin{align}
\dot{\Phi}_t &amp;= -\eta_\Phi \cdot A(\Phi_t w-V) w^\top_t
\end{align}\]

<p>We’d like to understand how \(E\) changes as TD learning progressively updates the features. Essentially this boils down to comparing \(\dot{\Phi}_t\) with \(-\partial_\Phi E(\Phi, w)\). If they point in the same direction, then TD learning decreases the value error.</p>

<p><strong>Theorem (Tang and Munos 2023, Theorem 3):</strong>
<em>Assume that</em> \(A\) <em>is symmetric (i.e. \(DP = P^\top D\)). Then, the TD learning update is the same as gradient descent on \(E\), i.e.:</em></p>

\[\dot{\Phi}_t \propto - \partial_{\Phi_t}E(\Phi_t).\]

<p>The conclusion is TD learning is effectively supervised learning of the value function. Sounds great! However, the premise that \(A\) is symmetric is unlikely to hold. It occurs when the Markov chain is reversible, meaning the probability of the transition \(s_1 \rightarrow s_2\) is the same as \(s_1 \leftarrow s_2\). Still, disregarding this result because the premise is too strong would be a mistake. As we will see, the proof of this theorem ties TD learning and value error minimization together in a way that can be extended, allowing us to write down exact mathematical conditions for when deep TD learning will and won’t work.</p>

<p>To start, I provide the proof of this theorem. Then I’ll relax the reversibility condition to show our main result.</p>

<p><strong>Proof of Tang and Munos Theorem 3:</strong>
Define the error vector \(e_t \doteq \Phi_t w - V^\pi\), which is a function of \(\Phi\). The value error is then:
\(E(\Phi_t) = \frac{1}{2} e_t^T A e_t\)
Since \(E\) is quadratic, it can be rewritten as \(e_t^\top (A + A^\top) e_t\), retaining only the symmetric portion of \(A\) (this is discussed more in the next section). From there, we have:</p>

\[\begin{aligned} \partial_{\Phi_t} E &amp;= \frac{1}{2} (A + A^\top) e_t w^\top\end{aligned}\]

<p>Now let’s consider the change in features due to TD learning. Plugging \(e_t\) into the expression \(\dot{\Phi}_t = -\eta_\Phi \cdot A(\Phi_i w_i-V) w^\top_i\) from earlier gives the following similar formula.</p>

\[\begin{aligned} \dot{\Phi}_t &amp;= -\eta_\Phi Ae_tw^\top\end{aligned}\]

<p>Comparing these formulations shows that if \(A\) is symmetric (\(A^\top = A\)), then TD learning gives the same feature update as gradient descent on \(E\).</p>

<h3 id="new-result-when-exactly-do-we-have-alignment">New Result: When exactly do we have alignment?</h3>
<p>For the TD learning update to be beneficial, we don’t need complete alignment of \(\dot{\Phi}_t\) and \(\partial_{\Phi_t} E\), only that \(\dot{E} &lt; 0\). The chain rule gives \(\dot{E} = \langle \partial_\Phi E, \dot{\Phi} \rangle_F\) where \(\langle A, B\rangle_F \doteq \text{Tr}(A^\top B)\) is the Frobenius inner product. The takeaway is that \(E\) will decrease if \(\dot{\Phi}\) points in a direction of high alignment with \(-\partial_{\Phi_t} E\).</p>

<p>The main result of this post is the following, which says exactly when TD learning benefits the features.</p>

\[\boxed{
\begin{align} 
\dot{E}(\Phi_t) &lt; 0 \iff e_t^\top (A + A^\top ) A  e_t &gt; 0 \\ 
\end{align}
}\]

<p>We can further simplify the inequality on the right. Let \(S\) and \(K\) denote the symmetric and skew-symmetric portions of \(A\). That is, \(A = S + K\) where \(S = \frac{1}{2}(A+ A^\top)\) and \(K = \frac{1}{2}(A- A^\top)\). Then, the inequality on the right is equivalent to:</p>

\[\boxed{
\begin{aligned}
e_t^\top  S^2e_t  &gt; -\frac{1}{2}e_t^\top (SK - K S) e_t
\end{aligned}
}\]

<p>In other words, TD learning lowers the value error if and only if the key matrix \(A\) is symmetric enough, in the sense of the above equation.</p>

<h4 id="interpretation">Interpretation</h4>
<p>How do we interpret the condition? Let’s first examine the terms of \(K\), and then connect this to the reversibility of the MDP.</p>

<p>The key matrix \(A = D(I-\gamma P)\) has off-diagonal terms like \(-\gamma \mu_i P_{ij}\). This leads to \(K\) having elements \(K_{ij} = \frac{\gamma }{2}(\mu_j P_{ji} - \mu_i P_{ij})\), which measure the extent to which the transition is non-reversible. When \(K_{ij}\) is zero, flow between the two states is equal (Tang and Munos’s theorem requires all elements of \(K\) are zero).</p>

<p>Intuitively, if the value error exists only in a region where the agent wanders back and forth equally, then TD learning will reduce \(E\) exactly like gradient descent.</p>

<p>However, in a one-way region, TD learning can raise \(E\) for certain values of \(e_t\). For example, an irreversible transition \(s_1 \rightarrow{} s_2\), where \(\phi(s_1)^\top \phi(s_2) \neq 0\) will see TD Learning update the features such that the value at \(s_1\) satisfies its own Bellman Equation, but it won’t take into account how changing these features affects the value of \(s_2\). This can create problems if \(v(s_2)\) is inaccurate. In contrast, gradient descent on \(E\) adjusts both \(\phi(s_1)\) and \(\phi(s_2)\).</p>

<p>Consider my previous experiment – evaluating the random policy on four rooms. It turns out that this is a highly symmetric Markov chain. Thus, it’s possible that my last example was inadvertently cherry-picked for TD learning to work. In an upcoming post, I’ll take a look at how easy it is to cherry pick highly non-reversible MDPs that make deep TD learning fail, even on-policy.</p>

<p>The resembelence of any such MDPs to practical problems may expose an area where we should be cautious using TD learning.</p>

<h4 id="proof-of-main-result">Proof of Main Result</h4>
<p>To start the proof, apply the previously mentioned decomposition of \(A\) into symmetric and <a href="https://en.wikipedia.org/wiki/Skew-symmetric_matrix">skew-symmetric</a> parts.</p>

\[\begin{align}
A &amp;= (1/2)(A + A^\top) + (1/2)(A - A^\top)\\
&amp;= S + K
\end{align}\]

<p>Note that for the skew-symmetric part \(K\), we have that \(u^\top K u=0\) for any vector \(u\).<sup id="fnref:1" role="doc-noteref"><a href="#fn:1" class="footnote" rel="footnote">1</a></sup> This yields:</p>

\[E(\Phi_t, w) = e_t^\top S e_t\]

<p>From the symmetry of \(S\), we have the following expression for \(\dot{E}(\Phi_t)\).</p>

\[\dot{E}(\Phi_t) = \frac{1}{2} \left(\dot{e}_t^\top S e_t + e_t S\dot{e}_t \right) = e_t^\top S \dot{e}_t = e_t^\top S \dot{\Phi}_t w\]

<p>To get this into the form of a Frobenius inner product, take the trace. For a scalar \(r\), \(\text{Tr}(r)=r\). Then apply the cyclic property of the trace: \(Tr(ABC) = Tr(CAB)\). Chaining these two together and then applying definition of the inner product, we get:</p>

\[\begin{align}
\dot{E}(\Phi_t) &amp;= \text{Tr}(e_t^\top S \dot{\Phi}_t w) \\
&amp;= \text{Tr}(w e_t^\top S \dot{\Phi}_t)\\
&amp;= \langle S e_tw ^\top, \dot{\Phi}_t\rangle_F\\
&amp;= \langle \partial_\Phi E, \dot{\Phi} \rangle_F
\end{align}\]

<p>The last step follows since \(\partial_\Phi E$ = S e_t w^\top\), which can be seen from the first step of the Tang and Munos proof, or the chain rule definition of \(\dot{E}(\Phi_t)\). Notice that the improvement in \(E\) is synonymous with the following notion of alignment:</p>

\[\text{Alignment} =-\langle \partial_\Phi E, \dot{\Phi}\rangle_F\]

<p>Next we determine when \(\dot{E}\) is negative (i.e. when alignment occurs). Starting from the trace expression above, and plugging in \(\dot{\Phi}_t = -\eta_\Phi A e_t w^\top\) allows us to pull out scalars:</p>

\[\begin{align}
\dot{E}(\Phi_t) &amp;= - \eta_\Phi \cdot \text{Tr}\left(w e_t^\top S A  e_t w^\top\right) \\
&amp;= - \eta_\Phi \cdot \text{Tr}\left(w^\top w e_t^\top S A  e_t \right) \\
&amp;= - \eta_\Phi \cdot \|w \|_2^2 \cdot \text{Tr}\left(e_t^\top S A  e_t \right) \\
\end{align}\]

<p>Since the scalar on the outside are negative, for the update to be beneficial, the argument to the trace must be positive. That is, the following guarantees alignment:</p>

\[\boxed{
\begin{align} e_t^\top S A  e_t &gt; 0 \\ 
\end{align}
}\]

<p>In other words, the TD learning update is guaranteed to help if the matrix \(SA = (A + A^\top)A\) is positive definite.<sup id="fnref:2" role="doc-noteref"><a href="#fn:2" class="footnote" rel="footnote">2</a></sup> Expanding the above expression:</p>

\[\begin{align}
e_t^\top S A  e_t &amp;= e_t^\top S (S+K)  e_t \\
&amp;= e_t^\top S^2e_t +  e_t^\top SK e_t \\
\end{align}\]

<p>Next, apply symmetrization of \(SK = \frac{1}{2}(SK + S^\top K^\top) + \frac{1}{2}(SK - S^\top K^\top)\), the fact that \(K^\top = -K\), and the property of skew-symmetric matrices that \(v_t K v_t = 0\) for any vector \(v\).</p>

\[\begin{align}
&amp;= e_t^\top S^2e_t + \frac{1}{2}e_t^\top (SK + K^\top S^\top) e_t + \frac{1}{2} e_t^\top (SK - K^\top S^\top) e_t
\end{align}\]

\[\begin{align}
&amp;= e_t^\top S^2e_t + \frac{1}{2}e_t^\top (SK - KS) e_t + \frac{1}{2} e_t^\top (SK + KS) e_t \\
&amp;= e_t^\top \left( S^2 + \frac{1}{2} (SK - KS) \right) e_t
\end{align}\]

<p>The last term is a quadratic with skew-symmetric weight (since \((SK + KS)^\top = -(KS-SK)\)), and is therefore \(0\). 
Also, we have that \(K^\top = -K\), which simplifies the second term. Re-arranging gives the final condition for when \(\dot{E}&lt;0\), completing the proof.</p>

\[\boxed{
\begin{aligned}
e_t^\top S^2e_t  &gt; -\frac{1}{2}e_t^\top (SK - K S) e_t
\end{aligned}
}\]

<p>Note that the left hand side is always positive, since \(S\) is positive definite. The term on the right can be positive, negative, or zero, since \(SK-KS\) is indefinite (\(\text{Tr}(SK-KS)=Tr(SK)-Tr(KS)=0\)). This means that a beneficial update cannot be guaranteed for all error vectors \(e_t\), unless the symmetric portion of \(A\) dominates its skew-symmetric portion in the sense of the above equation.</p>

<p>Thanks for reading!</p>

<hr />
<div class="footnotes" role="doc-endnotes">
  <ol>
    <li id="fn:1" role="doc-endnote">
      <p>\(u^\top K u= (u^\top K^\top u)^\top = u^\top K^\top u = \frac{1}{2}u^\top (A^\top - A)  u = - u^\top K u\). The only way for this \(K\)-weighted inner product to equal its negative is for it to be zero.\ <a href="#fnref:1" class="reversefootnote" role="doc-backlink">&#8617;</a></p>
    </li>
    <li id="fn:2" role="doc-endnote">
      <p>Matrix \(B\) is positive definite if for any vector \(x\), \(x^\top B x &gt;0\). <a href="#fnref:2" class="reversefootnote" role="doc-backlink">&#8617;</a></p>
    </li>
  </ol>
</div>]]></content><author><name></name></author><category term="representation" /><category term="learning" /><summary type="html"><![CDATA[]]></summary></entry><entry><title type="html">Will Deep TD Learning Result in Quality Representations?</title><link href="https://dillonmsandhu.github.io/representation/learning/2026/05/20/will-deep-td-learning-result-in-quality-representations.html" rel="alternate" type="text/html" title="Will Deep TD Learning Result in Quality Representations?" /><published>2026-05-20T00:00:00+00:00</published><updated>2026-05-20T00:00:00+00:00</updated><id>https://dillonmsandhu.github.io/representation/learning/2026/05/20/will-deep-td-learning-result-in-quality-representations</id><content type="html" xml:base="https://dillonmsandhu.github.io/representation/learning/2026/05/20/will-deep-td-learning-result-in-quality-representations.html"><![CDATA[<script>
  MathJax = {
    tex: {
      inlineMath: [['$', '$'], ['\\(', '\\)']],
      displayMath: [['$$', '$$'], ['\\[', '\\]']]
    }
  };
</script>

<script src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js" async=""></script>

<p>This post investigates Deep Temporal Difference (TD) learning as used to fit the value function in RL. It first provides a geometric explanation of deep TD learning. This highlights that deep TD learning does not directly optimize its representation to predict the true value function. Instead, it predicts a moving Bellman target​. Whether this indirectly improves representation depends on how aligned those two objectives are.</p>

<p>The main question of this post is:</p>

<p><em>Does TD learning improve the representation’s ability to represent the true value function?</em></p>

<p>I make a set of idealized assumptions, under which <em>the value predictions due to deep TD learning are guaranteed to improve</em>. I show, however, that adjusting the features to fit the Bellman target does not necessarily improve the representation. A simple geometric argument shows that the quality of the final representation depends on the alignment between the TD target and the true value function.</p>

<p>I show with a simple experiment on four rooms that the alignment isn’t always an issue, and TD learning can still succeed! But, another experiment has poor alignment and signfiicantly worse value learning.</p>

<p>Along the way, I frame the process of deep TD learning geometrically, visualizing the state space, where the true value lives, and the smaller subspace to which the estimate is confined. We’ll end with a closer look at a real example. So let’s go!</p>
<h2 id="setup">Setup</h2>
<p>It’s instructive to decompose the value network into two parts: the last linear layer, with weights by $w$, and all prior layers, parametrized by $\theta$.</p>

<div style="text-align: center; margin: 30px 0;">
  <img src="/assets/images/blog_post_1/network.svg" alt="Network Architecture Diagram" style="max-width: 100%; border-radius: 4px;" />
  <p style="color: gray; font-size: 0.85em; margin-top: 5px;"><em>Figure 1: Decomposing the value network into representation layers $\theta$ and a linear layer $w$.</em></p>
</div>

<p>Features $\phi_\theta(s)$ are obtained by passing the state through the network, stopping at the last layer. The final value estimate is:</p>

\[\begin{aligned} \hat{v}(s) = \phi(s)^\top w \end{aligned}\]

<p>where $\hat{v}$ is parameterized by neural network weights $(\theta, w)$. The feature representation $\phi$ is a function, which takes any state (or more generally, any object in the state space) and returns a vector of length $k$.</p>
<h2 id="linear-value-function-learning">Linear Value Function Learning</h2>
<p>Before diving in to the full complexity of deep learning, let’s consider what we obtain when holding the features constant – that is, if we were to freeze $\phi$ and update $w$ only.</p>

<p>Let $\Phi$ be the matrix obtained by stacking the feature representations for all $N$ states. Thus, $\Phi$ is an $N \times k$ matrix where $k$ is the length of each feature vector.  In general there are many more states than features, making $\Phi$ a “tall and skinny” matrix.</p>

<p>The space of all possible value functions we can represent is the column space of $\Phi$, also called $\text{span}(\Phi)$. In other words, all possible value estimates are of the form $\hat{v} = \Phi w$.</p>

\[\Phi = \begin{bmatrix}
\longleftarrow &amp; \phi(s_1)^T &amp; \longrightarrow \\
\longleftarrow &amp; \phi(s_2)^T &amp; \longrightarrow \\
               &amp; \vdots      &amp;                 \\
\longleftarrow &amp; \phi(s_N)^T &amp; \longrightarrow
\end{bmatrix}\]

<h2 id="best-linear-fit-with-the-projection-matrix">Best Linear Fit with the Projection Matrix</h2>
<p>Suppose we had access to the true value function $V$ – a length $N$ vector where each element denotes a state value. Least squares theory tells us that the “best fit” that can be represented by $\Phi w$ for some $w$ would be given by:</p>

\[\hat{v}_{best} = \Pi V\]

<p>where $\Pi = \Phi (\Phi^\top \Phi)^{-1} \Phi^\top$.</p>

<div style="text-align: center; margin: 30px 0;">
  <img src="/assets/images/blog_post_1/best_linear_fit.png" alt="Least Squares Projection" style="max-width: 80%; border-radius: 4px;" />
  <p style="color: gray; font-size: 0.85em; margin-top: 5px;"><em>Figure 2: Geometric view of the best linear fit $\Pi V$ in the feature subspace $\text{span}(\Phi)$.</em></p>
</div>

<p>The above formulation treats all states equally. If we care about the value error differently across states, we can define a weighting distribution $\mu(s)$, and let $D = \text{diag}[\mu(s_1), \dots, \mu(s_N)]$ be a $N \times N$ square weighting matrix. This changes the projection matrix to:</p>

<p>\(\Pi = \Phi (\Phi^\top D \Phi)^{-1} \Phi^\top D\).</p>

<p>Note we still have $\hat{v}_{best} = \Pi V$.</p>

<p>The best linear fit provides a measure of the quality of our features.  That is, the value error of $\hat{v}_{best}$ (the blue dotted line in the image) gets smaller exactly when our feature space $\text{span}(\Phi)$ gets closer to the true value function. Informally,  $\text{Good Features} \iff \text{Best fit has low value error}$.</p>

<p>The value error vector $VE$, is defined as the difference between our fit and the true value function. For $v_{best}$ it is equal to the blue vector:</p>

\[VE(v_{best}) = V - \Pi V\]

<p>The length of this vector (weighting each state by $\mu$) gives us an overall estimate of the quality of our fit. The average value error – $\overline{VE}$ – is minimized by $v_{best}$.</p>

\[\overline{VE}(v) = \sum_s \mu(s) (V(s) - v(s))^2 =  \|V - v\|_\mu^2\]

<p>This post focuses on TD learning, which refines a value estimate using its own current value. TD learning can be done by fitting targets based on a single transition, and is therefore much less noisy, generally leading to the strongest policy for most applications. However, it comes with complications. First, it introduces bias, because our target will generally not be the exact value function. Second, it doesn’t fit the ground truth, but instead a one-step refinement of its current guess.</p>

<h3 id="the-td-learning-solution">The TD Learning Solution</h3>
<p>TD Learning uses the Bellman operator, which, for any vector $v \in \mathbb{R}^N$, is $Tv = R + \gamma P v$.
The Bellman operator is a contraction, and its fixed point is the true value function $V$. The fixed point equation is true only at the true value function $V$:</p>

\[TV = V \quad (\text{system of N equations})\]

<p>For other value functions $v$, we have a difference $Tv - V$. The contraction property implies that infinite application of $T$ will shrink this difference to zero:</p>

\[T^\infty v = V\]

<p>TD Learning attempts to fit the value function incrementally, starting with $v_0$ and repeatedly fitting $v_{i+1} \approx Tv_i$. In the linear case, this is done by approximating $T v_i$ with the best linear fit, yielding:</p>

\[v_{i+1} = \Pi T v_i\]

<p>where $\Pi$ is the same projection matrix from before. The following picture shows this process of first applying the Bellman operator, followed by the projection matrix:</p>
<div style="text-align: center; margin: 30px 0;">
  <img src="/assets/images/blog_post_1/linear_td.svg" alt="TD Operator Application" style="max-width: 100%; border-radius: 4px;" />
  <p style="color: gray; font-size: 0.85em; margin-top: 5px;"><em>Figure 3: One step of linear TD: applying the Bellman Operator $T$, followed by the projection $\Pi$.</em></p>
</div>
<p>Under some assumptions<sup id="fnref:1" role="doc-noteref"><a href="#fn:1" class="footnote" rel="footnote">1</a></sup>, for fixed $\Phi$, repeated application of $\Pi T$ will, converge to a fixed point 
value estimate $v_{TD}$:</p>

\[v_{TD} = \Pi T v_{TD}\]

<p>Note that $v_{TD} \neq v_{best}$ in general.</p>
<h2 id="deep-td-learning">Deep TD Learning</h2>

<p>Deep TD learning generalizes this procedure: repeatedly approximating $v_{i+1} \approx Tv_i$,  with both $w$ and $\phi$ as free parameters. Both the target and representation evolve simultaneously.</p>

<p>Deep TD learning aims to reduce the length the following error, called the Bellman residual.</p>

\[(\text{sg}(Tv_{i}) - v_i)\]

<p>This is pink vector in the above images. The stop gradient, $sg(\cdot)$, is used since bootstrapping in this manner presents problem for gradient descent. In effect, TD learning drops the gradient $\nabla T v_i$, adjusting only $v_i$ –  <strong>not</strong> $T v_i$. The update for any parameter $\omega \in (w, \theta)$ is:</p>

\[\omega_{i+1} = \omega_i + \alpha (Tv_{i} - v_i) \cdot \nabla_\omega v_i\]

<p>Where $\alpha$ is a learning rate. Applying this rule, the expected change in weights and feature parameters at each round are:</p>

\[\begin{aligned} \Delta_ w &amp;\propto  \Phi^\top D  (Tv_{i} - v_i) \\
\Delta_\theta &amp;\propto  (\nabla_\theta \Phi w)^\top D (Tv_{i} - v_i)\
\end{aligned}\]

<p>Note that this treats $\theta$ as a column vector to keep the notation clean. At the linear fixed point $v_{TD}$, we have that $\Delta_w = 0$, since $\Phi$ is orthogonal to the TD error.  However, $\Delta_\theta \neq 0$ in general, leading the features $\Phi$ to tilt towards the fixed $Tv_i$. This is how representation learning occurs for standard deep RL.</p>

<p>We consider an idealized version of TD learning, where the weights are always the least squares fit of the Bellman target: $\Phi w_i = \Pi_{\Phi_i} T v_i$. This allows us to focus on the update to the features, rather than the final linear layer.</p>

<p>The following image breaks each update into three idealized steps. The first two steps are familiar from linear TD, but in the third step, the features change, adjusting $\Phi_1$ to $\Phi_2$ to shrink $Tv_i - \Pi T v_i$ .</p>

<div style="text-align: center; margin: 30px 0;">
  <img src="/assets/images/blog_post_1/deep_td_sketch.svg" alt="Deep TD" style="max-width: 100%; border-radius: 4px;" />
  <p style="color: gray; font-size: 0.85em; margin-top: 5px;"><em>Figure 4: One step of deep TD: features and weights both fit $Tv$</em></p>
</div>

<h3 id="does-deep-td-learning-improve-the-representation">Does Deep TD Learning Improve the Representation?</h3>
<p>Those dramatized images (that I made up) look pretty good! The final estimate $v_1$, which lives on the span of $\Phi_1$, is closer to both $T v_0$ and $V$! But looking at the image, we have no guarantee that $Tv_0$ and $V$ will be on the same side of the feature subspace. In that case, the update to $\Phi$ would actually be harmful for representing the true value function.</p>

<p>To more formally analyze this, let’s make some simplifying assumptions to help TD learning. First assume that $\mu$ corresponds to the on-policy distribution, which implies that  $T$ is a contraction in the $\mu$-weighted norm<sup id="fnref:2" role="doc-noteref"><a href="#fn:2" class="footnote" rel="footnote">2</a></sup>. Given enough data and network capacity, it should be possible to achieve a perfect fit: $v_{i+1}= Tv_i$, in which case standard contraction arguments can be used to show that $\overline{VE}(v_i) \rightarrow 0$. This means that deep TD learning is fundamentally sound – at least asymptotically and under perfect conditions.</p>

<p>More interesting is what happens to the feature quality in each round, as measured by $\overline{VE}(v_{best})$. As we have already suggested, the feature quality can get worse, as stated in the following result:</p>

<p><strong>Result:</strong> <em>TD Learning does not always improve the representation</em>: During update $i$ of Deep TD Learning, it’s possible that \(\|V - \Pi_{\Phi_i} V\|_\mu\) increases, even as \(\|Tv_i - \Pi_{\Phi_i} T v_i\|_\mu\) shrinks.</p>

<p>Geometrically, $\overline{VE}(v_{best})$ is made worse is when the true value function $V$ and $T v_i$ are on different sides of $\text{span}(\Phi)$. This is when the projection error on the Bellman target $\Pi Tv_i - Tv_i$ points in a different direction to the projection error for $v_{best}$. Algebraically, the condition:</p>

\[(\Pi V-V)^\top D (\Pi T v_i - Tv_i) &lt; 0\]

<p>indicates that these two residuals point in different directions. This indicates that the update will improve feature quality if the the cosine similarity between these two vectors is higher, leading to the following <strong>alignment</strong> metric.</p>

\[\text{alignment} = \frac{(\Pi V-V)^\top D (\Pi T v_i - Tv_i)}{\| \Pi V-V\|_D \|\Pi Tv_i-Tv_i \|_D}\]

<p>This might explain why regularization techniques that controlling the size of the gradient update are helpful empirically: by overfitting a single application of $T$ to a single value estimate, the features could be updated to make the overall value function worse compared to just doing linear TD from the beginning. Regularization like value target clipping and gradient norm clipping prevent the features from changing too much based on just a single application of the Bellman operator.</p>

<p>Under our assumptions, eventually the TD learning process will converge to the true value. At that point, we’ll have that $Tv_i - V = \gamma P (v_i - V)$  is small, since $v_i \approx V$. In short, the closer the value estimate gets to the true value, the less of a problem alignment will be. That said, in practice, a lack of alignment may prevent $v_i \rightarrow V$.</p>

<p>In summary, we have that, when applying TD learning under these idealized assumptions:</p>
<ul>
  <li><strong>The Current Predictor Improves:</strong> The value error $|V - v_i|_\mu$ always shrinks.</li>
  <li><strong>The Representation Quality is not guaranteed to improve:</strong> The value error $|V-v_{best}|_\mu$ can grow if not aligned.</li>
</ul>

<p>We can also ask whether the <strong>TD Fixed Point</strong> itself can get worse: is $|V - v_{TD}|$ guaranteed to improve? The worsening representation is certainly a plausible mechanism by which $v_{TD}$ could become worse.</p>

<h4 id="does-overlinevev_best-even-matter">Does $\overline{VE}(v_{best})$ even matter?</h4>
<p>One might ask why we should care about this metric, if what we really care about is $\overline{VE}(v_i)$. The reason is that the final result of the optimization, assuming everything goes well, is the TD-fixed point. And, it is known that, as the representation improves, the TD-fixed point improves. It is known that if $V \in \text{span}(\Phi)$, the TD solution $v_{TD}$ will indeed be the true value function. Relatedly, a bound due to Scherrer 2010<sup id="fnref:3" role="doc-noteref"><a href="#fn:3" class="footnote" rel="footnote">3</a></sup> shows that when $\overline{VE}(v_{best})$ is small, $\overline{VE}(v_{TD})$ is controlled.</p>

<p>This motivates why $\overline{VE}(v_{best})$ is an important quantity, that standard deep TD learning may not optimize at each step.</p>

<h1 id="experiment">Experiment</h1>
<p>I perform online, batch TD learning to evaluate the random policy on Four Rooms. Four Rooms is a maze environment with $N =149$. I set the number of features $k=32$.</p>

<div style="text-align: center; margin: 30px 0;">
  <img src="/assets/images/blog_post_1/four_rooms_true.png" alt="Four Rooms" style="max-width: 100%; border-radius: 4px;" />
  <p style="color: gray; font-size: 0.85em; margin-top: 5px;"><em>Figure 5: True Value Function for Four Rooms</em></p>
</div>

<p>After each TD update, I compute the best solution $v_{best}$ for the current features and on-policy distribution, and compute the exact Bellman Error and Value Error. Recall the metrics:</p>
<ul>
  <li>Bellman Error: $|Tv_i - v_i|_\mu^2$, indicates the degree that deep TD learning is shrinking the bellman residual.</li>
  <li>Value Error: $|V - v_i|_\mu^2$, indicates whether deep TD learning is improving its fit of the value function.</li>
  <li>Value Error of $v_{best}$: $|V - \Pi V |_\mu^2$, indicates whether the features are improving their proximity to $V$</li>
</ul>

<h2 id="results">Results</h2>

<p>Asymptotically, the results are a success for TD learning. Given enough updates, we see that value error is brought extremely close to zero. This demonstrates that deep TD learning can indeed perform perfectly, even when introducing sampling and real-world deep learning dynamics.<sup id="fnref:4" role="doc-noteref"><a href="#fn:4" class="footnote" rel="footnote">4</a></sup></p>

<p>However, early in learning, there are some hiccups, where the representation quality actually gets worse. During this period (around $i=10$), the Bellman Error is being rapidly minimized, but the feature quality isn’t getting better.</p>

<div style="text-align: center; margin: 30px 0;">
  <img src="/assets/images/blog_post_1/bellman_error_no_ln.png" alt="Four Rooms" style="max-width: 100%; border-radius: 4px;" />
  <p style="color: gray; font-size: 0.85em; margin-top: 5px;"><em>Figure 6: VE and BE during learning</em></p>
</div>

<p>Interestingly, this bumpiness in $\overline{VE}(v_{best})$ happens when the alignment, as defined above, falls below zero, indicating that $Tv_i$ and $V$ are on opposite sides of the feature-space. However, for most of learning, they are on the same side!</p>

<div style="text-align: center; margin: 30px 0;">
  <img src="/assets/images/blog_post_1/alignment_with_ln.png" alt="Four Rooms" style="max-width: 100%; border-radius: 4px;" />
  <p style="color: gray; font-size: 0.85em; margin-top: 5px;"><em>Figure 6: VE alignment during learning</em></p>
</div>

<h3 id="an-ablation-that-that-emphasizes-caution">An ablation that that emphasizes caution</h3>
<p>The above results are really promising! The network’s value error reached a minimum and the alignment generally stayed positive. However, things don’t look as nearly so good when one architectural change is made. The layer norm operation operates on each feature vector $\phi(s)\in \mathbb{R}^k$, subtracting the mean feature $\mu = \frac{1}{k}\sum_{j=1}^k \phi_j(s)$ and dividing by the feature standard deviation, $\sigma = \sqrt{ \frac{1}{k}\sum_{j=1}^k (\phi_j - \mu)^2}$. The experiments above take the output of a CNN in $\mathbb{R}^k$ and then apply a layer norm. We can hypothesize the layer norm helps prevent features from representing correlated concepts, or helps improves the variance of the features, helping the optimization of the weights due to conditioning.</p>

<p>Rather than focus on the layer norm, I just want to highlight how different the results become when this one architectural detail is changed. Without the layer norm, the alignment is poor, meaning that the update is often pointing away from the ground truth value. The representation quality is hurt (although its hard to tell at the scale of the graph, the minimum value of $VE(v_{best})$ is five times higher without the layer norm), and the final value estimate is 40 times worse than the same learning process with a layer norm.</p>

<div style="text-align: center; margin: 30px 0;">
  <img src="/assets/images/blog_post_1/alignment_no_ln.png" alt="Four Rooms" style="max-width: 100%; border-radius: 4px;" />
  <p style="color: gray; font-size: 0.85em; margin-top: 5px;"><em>Figure 7: VE alignment during learning with no layer norm. </em></p>
</div>

<hr />
<div class="footnotes" role="doc-endnotes">
  <ol>
    <li id="fn:1" role="doc-endnote">
      <p><a href="https://arxiv.org/abs/2501.01774">Wu et al 2025</a> showed that for the TD fixed point to exist, a condition they call rank invariance must hold: $\text{Rank}(\Phi) = \text{Rank}(\Phi^\top D(I-\gamma P) \Phi)$.  They also showed that rank invariance is sufficient, in addition to being necessary for the TD fixed point to exist. <a href="#fnref:1" class="reversefootnote" role="doc-backlink">&#8617;</a></p>
    </li>
    <li id="fn:2" role="doc-endnote">
      <p>Tsitsiklis, J.N. and Van Roy, B. An analysis of temporal-diﬀerence learning with function approximation. IEEE Transactions on Automatic Control,42(5):674–690, 1997 <a href="#fnref:2" class="reversefootnote" role="doc-backlink">&#8617;</a></p>
    </li>
    <li id="fn:3" role="doc-endnote">
      <p><a href="https://arxiv.org/abs/1011.4362">Scherrer, Bruno, Should one compute the Temporal Difference fix point or minimize the Bellman Residual? The unified oblique projection view, ICML 2010</a> <a href="#fnref:3" class="reversefootnote" role="doc-backlink">&#8617;</a></p>
    </li>
    <li id="fn:4" role="doc-endnote">
      <p>Note that adding a layer norm after the output of the CNN was instrumental in achieving this very low value error. <a href="#fnref:4" class="reversefootnote" role="doc-backlink">&#8617;</a></p>
    </li>
  </ol>
</div>]]></content><author><name></name></author><category term="representation" /><category term="learning" /><summary type="html"><![CDATA[]]></summary></entry></feed>