<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Mitansh Gor</title>
    <description>The latest articles on DEV Community by Mitansh Gor (@mitanshgor).</description>
    <link>https://dev.to/mitanshgor</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F999457%2F1e38e750-fe49-48f5-8f41-8b0a1ea57000.png</url>
      <title>DEV Community: Mitansh Gor</title>
      <link>https://dev.to/mitanshgor</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mitanshgor"/>
    <language>en</language>
    <item>
      <title>RL 3: Bellman Equations and Markov Decision Processes (1950s–1960s)</title>
      <dc:creator>Mitansh Gor</dc:creator>
      <pubDate>Fri, 18 Sep 2026 20:47:23 +0000</pubDate>
      <link>https://dev.to/mitanshgor/rl-3-bellman-equations-and-markov-decision-processes-1950s-1960s-2pp0</link>
      <guid>https://dev.to/mitanshgor/rl-3-bellman-equations-and-markov-decision-processes-1950s-1960s-2pp0</guid>
      <description>&lt;h2&gt;
  
  
  Where we left off
&lt;/h2&gt;

&lt;p&gt;Two quick reminders.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Thorndike (1898)&lt;/strong&gt; watched cats escape a puzzle box and gave us the &lt;strong&gt;Law of Effect&lt;/strong&gt;: do something, get a good result, do it again. Get a bad result, stop. Learning is bookkeeping over consequences.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Blog 2&lt;/strong&gt; turned that idea into hardware. Shannon's mouse ran a maze and remembered the route. Minsky's SNARC strengthened the wires that led to good outcomes.&lt;/p&gt;

&lt;p&gt;Both worked. Both were missing the same thing.&lt;/p&gt;

&lt;p&gt;Thorndike's cat knew &lt;em&gt;"pulling that loop felt good."&lt;/em&gt; It did &lt;strong&gt;not&lt;/strong&gt; know it was three moves from freedom. Shannon's mouse could replay a path, but it couldn't tell you why one path was better than another.&lt;/p&gt;

&lt;p&gt;Nobody had a word for this yet:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Value&lt;/strong&gt; — a number attached to a situation that says &lt;em&gt;how good does the future look from right here?&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That one missing number is what this whole post is about.&lt;/p&gt;




&lt;h3&gt;
  
  
  Side note: the biologists were chasing the same number
&lt;/h3&gt;

&lt;p&gt;Worth thirty seconds, because it makes the maths feel less alien.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Rescorla and Wagner (1972)&lt;/strong&gt; showed that animals don't learn from repetition. They learn from &lt;strong&gt;surprise&lt;/strong&gt;. If a bell already predicts food perfectly, adding a light next to the bell teaches the animal almost nothing about the light. There's no surprise left to learn from.&lt;/p&gt;

&lt;p&gt;Their rule, in plain English:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;new belief = old belief + (small step) × (what actually happened − what I expected)&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That last bracket — reality minus expectation — is called &lt;strong&gt;prediction error&lt;/strong&gt;. Hold onto it. It comes back in Blog 4 with a much bigger job.&lt;/p&gt;

&lt;p&gt;(Yes, 1972 is out of order here. I'm putting it early because it explains "value" better than a grid does.)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F98aodvd1bi2qni84k7q9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F98aodvd1bi2qni84k7q9.png" alt="Prediction error diagram" width="800" height="457"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Enter Richard Bellman
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F28nj9nvict7epd44gyk0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F28nj9nvict7epd44gyk0.png" alt="Richard Bellman" width="146" height="180"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In 1949, a mathematician named &lt;strong&gt;Richard Bellman&lt;/strong&gt; started working at &lt;strong&gt;RAND&lt;/strong&gt;, a US think tank. His job was a specific shape of problem: you make a choice, the world changes, then you have to choose again. Missile guidance. Supply planning. Anything where today's decision quietly reshapes tomorrow's options.&lt;/p&gt;

&lt;p&gt;He cracked it. Then he needed a name for it, So he picked two words that sounded harmless and industrial: &lt;strong&gt;Dynamic Programming&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;(The story has probably been tidied up over the years — the dates don't quite line up — but the name stuck, and it's now one of the most important terms in computer science.)&lt;/p&gt;

&lt;p&gt;Here's the problem he was actually solving.&lt;/p&gt;




&lt;h2&gt;
  
  
  The problem, in the form we'll use all post
&lt;/h2&gt;

&lt;p&gt;Forget missiles. Here's the setup we'll use for everything that follows.&lt;/p&gt;

&lt;p&gt;You're on a grid. You start in one corner. The goal is somewhere else. Every step costs you a little energy. Some cells are bad news. You want to reach the goal having collected as much reward as possible.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1cx1d3ep6pxzlra06vvm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1cx1d3ep6pxzlra06vvm.png" alt="grid" width="800" height="800"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Easy to describe. Genuinely nasty to solve &lt;em&gt;systematically&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;The obvious approach is to list every possible path and pick the best. That works right up until it catastrophically doesn't. Paths multiply exponentially with grid size. 10×10 is already unpleasant. 100×100 is hopeless. Bellman later gave this failure mode a name — &lt;strong&gt;the curse of dimensionality&lt;/strong&gt; — and we'll come back to it at the end, because it's the villain of the whole post.&lt;/p&gt;

&lt;p&gt;So he needed a fundamentally different kind of reasoning.&lt;/p&gt;




&lt;h2&gt;
  
  
  Dynamic Programming: solve it backward, and only solve it once
&lt;/h2&gt;

&lt;p&gt;Bellman's core insight is called the &lt;strong&gt;Principle of Optimality&lt;/strong&gt;. Here it is in his words:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;"An optimal policy has the property that whatever the initial state and initial decision are, the remaining decisions must constitute an optimal policy with regard to the state resulting from the first decision."&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That's a mouthful. In human:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;If the best route from A to C goes through B, then the B-to-C part of it must itself be the best route from B to C.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Because if it weren't — if there were a better way from B to C — you'd just swap it in and get a better A-to-C route. Contradiction. Done.&lt;/p&gt;

&lt;p&gt;Sounds trivial. It isn't, because of what it licenses you to do:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;You only ever have to solve each sub-problem once.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Once you know the best way from B onward, &lt;em&gt;every&lt;/em&gt; route that passes through B can reuse that answer for free. No recomputation. That's Dynamic Programming: chop a giant sequential problem into overlapping sub-problems, solve them from the end backward, and cache the answers.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9f9yzz0hsk9op7rj7817.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9f9yzz0hsk9op7rj7817.png" alt="stare-reardloop" width="799" height="356"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;backward&lt;/strong&gt; part is the counterintuitive bit and it's worth sitting with. Bellman didn't ask "what's my best first move?" He asked &lt;strong&gt;"what's my best &lt;em&gt;last&lt;/em&gt; move?"&lt;/strong&gt; Then second-to-last. Then third-to-last, propagating backward until every square on the board has an answer.&lt;/p&gt;

&lt;p&gt;This is &lt;strong&gt;backward induction&lt;/strong&gt;, and it's not a historical curiosity — it is still, structurally, how modern RL agents plan.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvoj8dzboblvy02ckek0h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvoj8dzboblvy02ckek0h.png" alt="backward induction" width="800" height="800"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Hold onto this:&lt;/strong&gt; the future is easier to reason about than the past, because the future has an ending you can anchor to.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Five nouns you need before the equation shows up
&lt;/h2&gt;

&lt;p&gt;So: five nouns first. Equation after. All five together are called a &lt;strong&gt;Markov Decision Process (MDP)&lt;/strong&gt; — the formal container the maths lives in.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F460d9r80ynde2ixbgf04.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F460d9r80ynde2ixbgf04.png" alt="MDP diagram" width="800" height="800"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. State — &lt;code&gt;s&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
Where you are. On the grid, "row 3, column 4." In chess, the board position. In a delivery robot, position &lt;em&gt;plus&lt;/em&gt; battery &lt;em&gt;plus&lt;/em&gt; whether it's holding a package. The full set of states is written &lt;code&gt;S&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Action — &lt;code&gt;a&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
What you can do from here. On the grid: up, down, left, right. The full set is &lt;code&gt;A&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Transition — &lt;code&gt;P(s' | s, a)&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
Read it as: &lt;em&gt;"the probability of landing in state &lt;code&gt;s'&lt;/code&gt;, given that I was in &lt;code&gt;s&lt;/code&gt; and did &lt;code&gt;a&lt;/code&gt;."&lt;/em&gt; The apostrophe just means "next."&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Reward — &lt;code&gt;R(s, a)&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
A number the environment hands you for doing &lt;code&gt;a&lt;/code&gt; in &lt;code&gt;s&lt;/code&gt;. This is where you, the designer, encode what "good" means. Reach the goal: +10. Take a step: −1. Fall in the pit: −100.&lt;/p&gt;

&lt;p&gt;Get this wrong and your agent will cheerfully optimise the wrong thing. Reward design is 90% of applied RL pain, and I'm not going to pretend otherwise.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Policy — &lt;code&gt;π&lt;/code&gt; (pi)&lt;/strong&gt;&lt;br&gt;
Your strategy. A rule that maps &lt;em&gt;state → action&lt;/em&gt;. "When in this square, go right." That's it. A policy isn't a plan or a path — it's a lookup table of what to do &lt;em&gt;anywhere&lt;/em&gt; you might find yourself.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;The whole field, in one sentence:&lt;/strong&gt; an MDP describes the world; a policy describes your behaviour in it; and the rest of RL is the search for the best policy.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbz9309bj0gu2w598yq1s.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbz9309bj0gu2w598yq1s.png" alt="Reinforcement Learning loop" width="800" height="375"&gt;&lt;/a&gt;&lt;/p&gt;


&lt;h2&gt;
  
  
  The one assumption holding all of this up
&lt;/h2&gt;

&lt;p&gt;There's a condition the whole framework quietly depends on, and it's called the &lt;strong&gt;Markov Property&lt;/strong&gt;:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;The future depends only on the present state — not on the history of how you got there.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0j3w2pfw16tjoscydeb1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0j3w2pfw16tjoscydeb1.png" alt="stateIsEnough" width="800" height="800"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;First reaction to this is usually: &lt;em&gt;that's obviously false, history matters all the time.&lt;/em&gt; Fair. But that's not quite what it says.&lt;/p&gt;

&lt;p&gt;It says &lt;strong&gt;history must already be baked into the state.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If your robot's battery level affects the next decision, then battery level belongs &lt;em&gt;in the state definition&lt;/em&gt;. Once it's in there, you don't need to replay the last 50 timesteps — you just look at where you are now.&lt;/p&gt;

&lt;p&gt;Two quick examples to make it concrete:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Chess is Markov.&lt;/strong&gt; The board position tells you everything. It doesn't matter whether you reached it through a brilliant sacrifice or a series of blunders — the position is the position.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Poker is not Markov if your state is just "my cards."&lt;/strong&gt; Whether your opponent has been bluffing all night genuinely changes what you should do. Fix it by expanding the state to include betting history. Now it's Markov again — and much bigger. (Notice the trade you just made. That's foreshadowing.)&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;The neat way to say it:&lt;/strong&gt; the &lt;em&gt;state&lt;/em&gt; is allowed to have memory. The &lt;em&gt;policy&lt;/em&gt; isn't.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This assumption is exactly what makes RL computable. Without it, an agent would have to carry and process its entire past at every step. With it, a policy is just a lookup: current state in, action out.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;One more assumption, and it's a big one.&lt;/strong&gt; For this entire post, the agent is assumed to already &lt;strong&gt;know&lt;/strong&gt; &lt;code&gt;P&lt;/code&gt; and &lt;code&gt;R&lt;/code&gt;. It knows the physics of the world and the reward structure before it takes a single step. That's called &lt;strong&gt;model-based&lt;/strong&gt; RL, and it's what makes the maths clean here.&lt;/p&gt;

&lt;p&gt;It is also completely unrealistic, and Blog 4 takes a sledgehammer to it.&lt;/p&gt;


&lt;h2&gt;
  
  
  Return and γ: why "how good" needs a definition
&lt;/h2&gt;

&lt;p&gt;One more thing before the equation. If value means "how promising is the future from here," we need to say what &lt;em&gt;the future&lt;/em&gt; means numerically.&lt;/p&gt;

&lt;p&gt;Add up all the reward you'll collect from now until the end. That total is called the &lt;strong&gt;return&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Except there's a problem: if the task never ends, that sum runs to infinity, and "infinity" is a terrible thing to compare against another infinity. So Bellman introduced a &lt;strong&gt;discount factor, &lt;code&gt;γ&lt;/code&gt; (gamma)&lt;/strong&gt;, a number between 0 and 1. Reward one step away is multiplied by γ. Two steps away, γ². Three steps, γ³. And so on.&lt;/p&gt;

&lt;p&gt;

&lt;/p&gt;
&lt;div class="katex-element"&gt;
  &lt;span class="katex-display"&gt;&lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord mathnormal"&gt;G&lt;/span&gt;&lt;span class="msupsub"&gt;&lt;span class="vlist-t vlist-t2"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mathnormal mtight"&gt;t&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-s"&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mrel"&gt;=&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord mathnormal"&gt;R&lt;/span&gt;&lt;span class="msupsub"&gt;&lt;span class="vlist-t vlist-t2"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mathnormal mtight"&gt;t&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-s"&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mbin"&gt;+&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;γ&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord mathnormal"&gt;R&lt;/span&gt;&lt;span class="msupsub"&gt;&lt;span class="vlist-t vlist-t2"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mtight"&gt;&lt;span class="mord mathnormal mtight"&gt;t&lt;/span&gt;&lt;span class="mbin mtight"&gt;+&lt;/span&gt;&lt;span class="mord mtight"&gt;1&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-s"&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mbin"&gt;+&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord mathnormal"&gt;γ&lt;/span&gt;&lt;span class="msupsub"&gt;&lt;span class="vlist-t"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mtight"&gt;2&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord mathnormal"&gt;R&lt;/span&gt;&lt;span class="msupsub"&gt;&lt;span class="vlist-t vlist-t2"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mtight"&gt;&lt;span class="mord mathnormal mtight"&gt;t&lt;/span&gt;&lt;span class="mbin mtight"&gt;+&lt;/span&gt;&lt;span class="mord mtight"&gt;2&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-s"&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mbin"&gt;+&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord mathnormal"&gt;γ&lt;/span&gt;&lt;span class="msupsub"&gt;&lt;span class="vlist-t"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mtight"&gt;3&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord mathnormal"&gt;R&lt;/span&gt;&lt;span class="msupsub"&gt;&lt;span class="vlist-t vlist-t2"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mtight"&gt;&lt;span class="mord mathnormal mtight"&gt;t&lt;/span&gt;&lt;span class="mbin mtight"&gt;+&lt;/span&gt;&lt;span class="mord mtight"&gt;3&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-s"&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mbin"&gt;+&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="minner"&gt;…&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/div&gt;


&lt;p&gt;Two things fall out of this, and both matter:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Mathematically:&lt;/strong&gt; the sum now converges. It's a geometric series. No infinities.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Behaviourally:&lt;/strong&gt; γ is a &lt;strong&gt;personality dial.&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;γ near &lt;strong&gt;0&lt;/strong&gt; — a myopic agent. Only right now exists. It will grab the nearest +1 and ignore a +100 two steps away.&lt;/li&gt;
&lt;li&gt;γ near &lt;strong&gt;1&lt;/strong&gt; — a patient agent. Happy to eat a −1 today for a +100 later.&lt;/li&gt;
&lt;li&gt;γ = 0.9 — a reasonable default that says "about ten steps of foresight."&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It's compound interest, run backward. A reward ten steps away at γ = 0.9 is worth about 35% of its face value today.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fivqu2yfy9rbo9lxbnlf8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fivqu2yfy9rbo9lxbnlf8.png" alt="Same grid solved three times" width="800" height="437"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Value: the number Thorndike's cat never had
&lt;/h2&gt;

&lt;p&gt;Now we can define the thing this whole post is chasing.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;V(s)&lt;/code&gt; — the value of state &lt;code&gt;s&lt;/code&gt; — is the expected return you'll collect if you start in &lt;code&gt;s&lt;/code&gt; and behave well from there on.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That's the number the cat didn't have. The cat knew &lt;em&gt;"this felt good."&lt;/em&gt; A value function knows &lt;em&gt;"this square is worth 7.1, that one's worth 5.4, so go left."&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;And that's the whole trick: &lt;strong&gt;once every square has a number, choosing an action stops being a search problem and becomes a comparison.&lt;/strong&gt; Look at the neighbouring numbers. Walk toward the big one. Done.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Bellman Equation
&lt;/h2&gt;

&lt;p&gt;In his 1957 book &lt;em&gt;Dynamic Programming&lt;/em&gt;, Bellman wrote down the recursion that ties all of this together:&lt;/p&gt;


&lt;div class="katex-element"&gt;
  &lt;span class="katex-display"&gt;&lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;V&lt;/span&gt;&lt;span class="mopen"&gt;(&lt;/span&gt;&lt;span class="mord mathnormal"&gt;s&lt;/span&gt;&lt;span class="mclose"&gt;)&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mrel"&gt;=&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mop op-limits"&gt;&lt;span class="vlist-t vlist-t2"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mathnormal mtight"&gt;a&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="mop"&gt;max&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-s"&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="minner"&gt;&lt;span class="mopen delimcenter"&gt;&lt;span class="delimsizing size4"&gt;[&lt;/span&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;R&lt;/span&gt;&lt;span class="mopen"&gt;(&lt;/span&gt;&lt;span class="mord mathnormal"&gt;s&lt;/span&gt;&lt;span class="mpunct"&gt;,&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;a&lt;/span&gt;&lt;span class="mclose"&gt;)&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mbin"&gt;+&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;γ&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mop op-limits"&gt;&lt;span class="vlist-t vlist-t2"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mtight"&gt;&lt;span class="mord mtight"&gt;&lt;span class="mord mathnormal mtight"&gt;s&lt;/span&gt;&lt;span class="msupsub"&gt;&lt;span class="vlist-t"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size3 size1 mtight"&gt;&lt;span class="mord mtight"&gt;&lt;span class="mord mtight"&gt;′&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="mop op-symbol large-op"&gt;∑&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-s"&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;P&lt;/span&gt;&lt;span class="mopen"&gt;(&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord mathnormal"&gt;s&lt;/span&gt;&lt;span class="msupsub"&gt;&lt;span class="vlist-t"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mtight"&gt;&lt;span class="mord mtight"&gt;′&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mrel"&gt;∣&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;s&lt;/span&gt;&lt;span class="mpunct"&gt;,&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;a&lt;/span&gt;&lt;span class="mclose"&gt;)&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;V&lt;/span&gt;&lt;span class="mopen"&gt;(&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord mathnormal"&gt;s&lt;/span&gt;&lt;span class="msupsub"&gt;&lt;span class="vlist-t"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mtight"&gt;&lt;span class="mord mtight"&gt;′&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mclose"&gt;)&lt;/span&gt;&lt;span class="mclose delimcenter"&gt;&lt;span class="delimsizing size4"&gt;]&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/div&gt;


&lt;p&gt;In one sentence:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;The value of where you are = the best immediate reward you can grab + the discounted value of wherever you end up next.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Every symbol is one of the five nouns you already know:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Piece&lt;/th&gt;
&lt;th&gt;Reading&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;V(s)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;how good it is to be here&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;max_a&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;you, choosing.&lt;/strong&gt; Try every action, keep the best&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;R(s, a)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;what you get right now&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;γ&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;how much you care about later&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;∑ P(s':s,a) · V(s')&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;the world, responding.Average over every place you might land, weighted by likelihood&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Two things I want to flag, because they're where people quietly lose the thread.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;First: &lt;code&gt;max&lt;/code&gt; and &lt;code&gt;∑&lt;/code&gt; are doing opposite jobs.&lt;/strong&gt; The &lt;code&gt;max&lt;/code&gt; is the agent &lt;em&gt;choosing&lt;/em&gt;. The &lt;code&gt;∑&lt;/code&gt; is the world &lt;em&gt;rolling dice&lt;/em&gt;. You control your action. You do not control the outcome. If the transitions were deterministic, that &lt;code&gt;∑&lt;/code&gt; would collapse to a single term and disappear — it only exists because the world is uncertain.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Second: &lt;code&gt;V(s)&lt;/code&gt; appears on both sides.&lt;/strong&gt; That's not sloppy notation, it's the entire idea. The equation is &lt;strong&gt;self-referential&lt;/strong&gt; — the value of a state is defined in terms of the values of &lt;em&gt;other&lt;/em&gt; states.&lt;/p&gt;

&lt;p&gt;Which raises the obvious question: if V is defined in terms of V, how do you ever compute it?&lt;/p&gt;

&lt;p&gt;You guess, then you improve. Start with V = 0 everywhere (a wrong but harmless guess), apply the equation, get better numbers, apply again. The values stop changing when they're all consistent with each other. Mathematicians call that a &lt;strong&gt;fixed point&lt;/strong&gt; — the place where applying the rule doesn't change anything anymore.&lt;/p&gt;

&lt;p&gt;That "keeps changing until it doesn't" process is the entire computational game. And it's easier to believe once you've watched it happen, so let's watch it happen.&lt;/p&gt;




&lt;h2&gt;
  
  
  Let's actually put numbers on the board
&lt;/h2&gt;

&lt;p&gt;Here's the smallest example that shows the real behaviour. A corridor, four squares, then the goal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[ S1 ][ S2 ][ S3 ][ S4 ][ GOAL ]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Rules:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Actions: move left or move right. Deterministic — no ice.&lt;/li&gt;
&lt;li&gt;Every move costs &lt;strong&gt;−1&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Stepping into GOAL pays &lt;strong&gt;+10&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;γ = &lt;strong&gt;0.9&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;GOAL is terminal, so &lt;code&gt;V(GOAL) = 0&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Work backward, exactly as Bellman said to.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;S4&lt;/strong&gt; is one step from GOAL: &lt;code&gt;V(S4) = −1 + 10 + 0.9 × 0 =&lt;/code&gt; &lt;strong&gt;9.00&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;S3&lt;/strong&gt; is one step from S4: &lt;code&gt;V(S3) = −1 + 0.9 × 9.00 =&lt;/code&gt; &lt;strong&gt;7.10&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;S2:&lt;/strong&gt; &lt;code&gt;V(S2) = −1 + 0.9 × 7.10 =&lt;/code&gt; &lt;strong&gt;5.39&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;S1:&lt;/strong&gt; &lt;code&gt;V(S1) = −1 + 0.9 × 5.39 =&lt;/code&gt; &lt;strong&gt;3.85&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[ 3.85 ][ 5.39 ][ 7.10 ][ 9.00 ][ GOAL ]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Look at what happened. &lt;strong&gt;The goal's reward leaked backward through the corridor and left a slope behind it.&lt;/strong&gt; The agent doesn't need a map, a plan, or a search. It just walks uphill. The value function turned a planning problem into a gradient you can follow like a scent trail.&lt;/p&gt;


&lt;div class="crayons-card c-embed text-styles text-styles--secondary"&gt;
    &lt;div class="c-embed__content"&gt;
      &lt;div class="c-embed__body"&gt;
        &lt;h2 class="fs-xl lh-tight"&gt;
          &lt;a href="https://drive.google.com/file/d/1zEZ-xmnFXWbNvPaQeYPOpUamLs6qBp62/view?usp=sharing" rel="noopener noreferrer" class="c-link"&gt;
            Animated_heatmap_of_the_x_gr.mp4 - Google Drive
          &lt;/a&gt;
        &lt;/h2&gt;
        &lt;div class="color-secondary fs-s flex items-center"&gt;
            &lt;img alt="favicon" class="c-embed__favicon m-0 mr-2 radius-0" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fssl.gstatic.com%2Fdocs%2Fdoclist%2Fimages%2Fdrive_favicon_2026_32dp.png" width="32" height="32"&gt;
          drive.google.com
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;



&lt;h3&gt;
  
  
  Now watch it converge from nothing
&lt;/h3&gt;

&lt;p&gt;That was the answer. Here's the &lt;em&gt;process&lt;/em&gt; — starting from V = 0 everywhere and sweeping the equation across all four states repeatedly:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Sweep&lt;/th&gt;
&lt;th&gt;V(S1)&lt;/th&gt;
&lt;th&gt;V(S2)&lt;/th&gt;
&lt;th&gt;V(S3)&lt;/th&gt;
&lt;th&gt;V(S4)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0.00&lt;/td&gt;
&lt;td&gt;0.00&lt;/td&gt;
&lt;td&gt;0.00&lt;/td&gt;
&lt;td&gt;0.00&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;−1.00&lt;/td&gt;
&lt;td&gt;−1.00&lt;/td&gt;
&lt;td&gt;−1.00&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;9.00&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;−1.90&lt;/td&gt;
&lt;td&gt;−1.90&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;7.10&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;9.00&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;−2.71&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;5.39&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;7.10&lt;/td&gt;
&lt;td&gt;9.00&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;3.85&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;5.39&lt;/td&gt;
&lt;td&gt;7.10&lt;/td&gt;
&lt;td&gt;9.00&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;3.85&lt;/td&gt;
&lt;td&gt;5.39&lt;/td&gt;
&lt;td&gt;7.10&lt;/td&gt;
&lt;td&gt;9.00&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Three things worth noticing here, and honestly this table is the most important object in the post:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Information travels exactly one square per sweep.&lt;/strong&gt; Sweep 1, only S4 knows the goal exists. Sweep 2, S3 finds out. It's a wavefront moving backward.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The early numbers are hilariously wrong.&lt;/strong&gt; At sweep 3, S1 thinks it's worth −2.71 — it can only see step costs and no payoff yet. It's a pessimist with incomplete information. It gets over it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;You don't need a stopping rule, you need a stopping &lt;em&gt;condition&lt;/em&gt;.&lt;/strong&gt; When a full sweep changes nothing, you're done. That's the fixed point, made of actual numbers.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fe8grw8sbri68uc9p8788.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fe8grw8sbri68uc9p8788.png" alt="bar chart per sweep" width="671" height="926"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Howard's Policy Iteration: from knowing values to having a strategy
&lt;/h2&gt;

&lt;p&gt;Bellman gave us the value of every square. But there's a subtly separate question: how do you systematically build the &lt;strong&gt;strategy&lt;/strong&gt; — the policy — that goes with it?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ronald Howard&lt;/strong&gt;, in his 1960 monograph &lt;em&gt;Dynamic Programming and Markov Processes&lt;/em&gt;, noticed the problem is circular:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;To compute &lt;code&gt;V(s)&lt;/code&gt;, you need to know which policy &lt;code&gt;π&lt;/code&gt; the agent is following.&lt;/li&gt;
&lt;li&gt;To find the best &lt;code&gt;π&lt;/code&gt;, you need to know &lt;code&gt;V(s)&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Classic chicken and egg. Howard's answer: &lt;strong&gt;stop trying to do both at once. Alternate.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs3xphu5bv5k6sxejgsjx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs3xphu5bv5k6sxejgsjx.png" alt="PE vs PI" width="800" height="800"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1 — Policy Evaluation: "how good is my current strategy?"
&lt;/h3&gt;

&lt;p&gt;Freeze the policy. Don't try to improve it. Just ask: &lt;em&gt;if I followed this exact strategy forever, what would each state be worth?&lt;/em&gt;&lt;/p&gt;


&lt;div class="katex-element"&gt;
  &lt;span class="katex-display"&gt;&lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord mathnormal"&gt;V&lt;/span&gt;&lt;span class="msupsub"&gt;&lt;span class="vlist-t"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mathnormal mtight"&gt;π&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mopen"&gt;(&lt;/span&gt;&lt;span class="mord mathnormal"&gt;s&lt;/span&gt;&lt;span class="mclose"&gt;)&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mrel"&gt;=&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;R&lt;/span&gt;&lt;span class="mopen"&gt;(&lt;/span&gt;&lt;span class="mord mathnormal"&gt;s&lt;/span&gt;&lt;span class="mpunct"&gt;,&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;π&lt;/span&gt;&lt;span class="mopen"&gt;(&lt;/span&gt;&lt;span class="mord mathnormal"&gt;s&lt;/span&gt;&lt;span class="mclose"&gt;))&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mbin"&gt;+&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;γ&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mop op-limits"&gt;&lt;span class="vlist-t vlist-t2"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mtight"&gt;&lt;span class="mord mtight"&gt;&lt;span class="mord mathnormal mtight"&gt;s&lt;/span&gt;&lt;span class="msupsub"&gt;&lt;span class="vlist-t"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size3 size1 mtight"&gt;&lt;span class="mord mtight"&gt;&lt;span class="mord mtight"&gt;′&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="mop op-symbol large-op"&gt;∑&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-s"&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;P&lt;/span&gt;&lt;span class="mopen"&gt;(&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord mathnormal"&gt;s&lt;/span&gt;&lt;span class="msupsub"&gt;&lt;span class="vlist-t"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mtight"&gt;&lt;span class="mord mtight"&gt;′&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mrel"&gt;∣&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;s&lt;/span&gt;&lt;span class="mpunct"&gt;,&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;π&lt;/span&gt;&lt;span class="mopen"&gt;(&lt;/span&gt;&lt;span class="mord mathnormal"&gt;s&lt;/span&gt;&lt;span class="mclose"&gt;))&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord mathnormal"&gt;V&lt;/span&gt;&lt;span class="msupsub"&gt;&lt;span class="vlist-t"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mathnormal mtight"&gt;π&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mopen"&gt;(&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord mathnormal"&gt;s&lt;/span&gt;&lt;span class="msupsub"&gt;&lt;span class="vlist-t"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mtight"&gt;&lt;span class="mord mtight"&gt;′&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mclose"&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/div&gt;


&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Notice the &lt;code&gt;max&lt;/code&gt; is gone.&lt;/strong&gt; There's no choosing here. &lt;code&gt;π(s)&lt;/code&gt; tells you what to do; you're just measuring the consequences. This isn't optimisation, it's &lt;em&gt;scorekeeping&lt;/em&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Step 2 — Policy Improvement: "could I do better?"
&lt;/h3&gt;

&lt;p&gt;Now take those scores and ask, at every state: &lt;em&gt;given what I now know things are worth, is there an action better than the one my policy currently prescribes?&lt;/em&gt; If yes, switch to it.&lt;/p&gt;


&lt;div class="katex-element"&gt;
  &lt;span class="katex-display"&gt;&lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord mathnormal"&gt;π&lt;/span&gt;&lt;span class="msupsub"&gt;&lt;span class="vlist-t"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mtight"&gt;&lt;span class="mord mtight"&gt;′&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mopen"&gt;(&lt;/span&gt;&lt;span class="mord mathnormal"&gt;s&lt;/span&gt;&lt;span class="mclose"&gt;)&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mrel"&gt;=&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mop"&gt;ar&lt;span&gt;g&lt;/span&gt;&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mop op-limits"&gt;&lt;span class="vlist-t vlist-t2"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mathnormal mtight"&gt;a&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="mop"&gt;max&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-s"&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="minner"&gt;&lt;span class="mopen delimcenter"&gt;&lt;span class="delimsizing size4"&gt;[&lt;/span&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;R&lt;/span&gt;&lt;span class="mopen"&gt;(&lt;/span&gt;&lt;span class="mord mathnormal"&gt;s&lt;/span&gt;&lt;span class="mpunct"&gt;,&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;a&lt;/span&gt;&lt;span class="mclose"&gt;)&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mbin"&gt;+&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;γ&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mop op-limits"&gt;&lt;span class="vlist-t vlist-t2"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mtight"&gt;&lt;span class="mord mtight"&gt;&lt;span class="mord mathnormal mtight"&gt;s&lt;/span&gt;&lt;span class="msupsub"&gt;&lt;span class="vlist-t"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size3 size1 mtight"&gt;&lt;span class="mord mtight"&gt;&lt;span class="mord mtight"&gt;′&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="mop op-symbol large-op"&gt;∑&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-s"&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;P&lt;/span&gt;&lt;span class="mopen"&gt;(&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord mathnormal"&gt;s&lt;/span&gt;&lt;span class="msupsub"&gt;&lt;span class="vlist-t"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mtight"&gt;&lt;span class="mord mtight"&gt;′&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mrel"&gt;∣&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;s&lt;/span&gt;&lt;span class="mpunct"&gt;,&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;a&lt;/span&gt;&lt;span class="mclose"&gt;)&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord mathnormal"&gt;V&lt;/span&gt;&lt;span class="msupsub"&gt;&lt;span class="vlist-t"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mathnormal mtight"&gt;π&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mopen"&gt;(&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord mathnormal"&gt;s&lt;/span&gt;&lt;span class="msupsub"&gt;&lt;span class="vlist-t"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mtight"&gt;&lt;span class="mord mtight"&gt;′&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mclose"&gt;)&lt;/span&gt;&lt;span class="mclose delimcenter"&gt;&lt;span class="delimsizing size4"&gt;]&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/div&gt;


&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;arg max&lt;/code&gt; vs &lt;code&gt;max&lt;/code&gt;, since this trips everyone up:&lt;/strong&gt; &lt;code&gt;max&lt;/code&gt; returns &lt;em&gt;the best value&lt;/em&gt;. &lt;code&gt;arg max&lt;/code&gt; returns &lt;em&gt;the action that achieved it&lt;/em&gt;. Evaluation wants the number; improvement wants the move.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  And repeat
&lt;/h3&gt;

&lt;p&gt;Evaluate. Improve. Evaluate. Improve. Stop when an improvement step changes nothing.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh0vlv9oo30xbnr0swsa5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh0vlv9oo30xbnr0swsa5.png" alt="Policy Eval and Improvement" width="800" height="555"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Howard proved two things about this loop that are genuinely reassuring:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The greedy step never makes the policy worse.&lt;/strong&gt; Every improvement is an improvement or a tie. It can't wander off toward a worse policy — the local, greedy move is globally safe here. (That's a strong guarantee, and one that quietly evaporates once we start using neural networks in later posts.)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;On a finite MDP, it terminates in a finite number of iterations.&lt;/strong&gt; There are only finitely many policies, you never repeat one, so you must stop. Usually in a handful of rounds.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj0n70gh4uwe9sqkz4sog.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj0n70gh4uwe9sqkz4sog.png" alt="Eval Improv General idea" width="799" height="695"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;And here's the part that should give you a small jolt:&lt;/strong&gt; that two-role split — one part measuring, one part deciding — is the direct ancestor of the &lt;strong&gt;Actor–Critic&lt;/strong&gt; architectures we'll get to in Blog 7. The Critic does Policy Evaluation. The Actor does Policy Improvement.&lt;/p&gt;

&lt;p&gt;That structure wasn't invented for deep learning. It was sitting in a 1960 operations research monograph the whole time.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy1sj0dabx5pxpe0c7fu0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy1sj0dabx5pxpe0c7fu0.png" alt="actor-critic" width="800" height="492"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Value Iteration: the impatient version
&lt;/h2&gt;

&lt;p&gt;Policy Iteration is a bit fussy. It insists on &lt;em&gt;fully&lt;/em&gt; evaluating a policy — running evaluation to convergence — before it'll consider improving anything.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Value Iteration&lt;/strong&gt; says: why wait? Fold the improvement directly into the update.&lt;/p&gt;


&lt;div class="katex-element"&gt;
  &lt;span class="katex-display"&gt;&lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;V&lt;/span&gt;&lt;span class="mopen"&gt;(&lt;/span&gt;&lt;span class="mord mathnormal"&gt;s&lt;/span&gt;&lt;span class="mclose"&gt;)&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mrel"&gt;←&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mop op-limits"&gt;&lt;span class="vlist-t vlist-t2"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mathnormal mtight"&gt;a&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="mop"&gt;max&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-s"&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="minner"&gt;&lt;span class="mopen delimcenter"&gt;&lt;span class="delimsizing size4"&gt;[&lt;/span&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;R&lt;/span&gt;&lt;span class="mopen"&gt;(&lt;/span&gt;&lt;span class="mord mathnormal"&gt;s&lt;/span&gt;&lt;span class="mpunct"&gt;,&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;a&lt;/span&gt;&lt;span class="mclose"&gt;)&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mbin"&gt;+&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;γ&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mop op-limits"&gt;&lt;span class="vlist-t vlist-t2"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mtight"&gt;&lt;span class="mord mtight"&gt;&lt;span class="mord mathnormal mtight"&gt;s&lt;/span&gt;&lt;span class="msupsub"&gt;&lt;span class="vlist-t"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size3 size1 mtight"&gt;&lt;span class="mord mtight"&gt;&lt;span class="mord mtight"&gt;′&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="mop op-symbol large-op"&gt;∑&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-s"&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;P&lt;/span&gt;&lt;span class="mopen"&gt;(&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord mathnormal"&gt;s&lt;/span&gt;&lt;span class="msupsub"&gt;&lt;span class="vlist-t"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mtight"&gt;&lt;span class="mord mtight"&gt;′&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mrel"&gt;∣&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;s&lt;/span&gt;&lt;span class="mpunct"&gt;,&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;a&lt;/span&gt;&lt;span class="mclose"&gt;)&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;V&lt;/span&gt;&lt;span class="mopen"&gt;(&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord mathnormal"&gt;s&lt;/span&gt;&lt;span class="msupsub"&gt;&lt;span class="vlist-t"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mtight"&gt;&lt;span class="mord mtight"&gt;′&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mclose"&gt;)&lt;/span&gt;&lt;span class="mclose delimcenter"&gt;&lt;span class="delimsizing size4"&gt;]&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/div&gt;


&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;The &lt;code&gt;max&lt;/code&gt; is back, and it's inside the loop.&lt;/strong&gt; Every single update implicitly re-decides the best action. No separate improvement phase exists.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fkisnepo5w1ik802tpuqo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fkisnepo5w1ik802tpuqo.png" alt="Value iteration code loop" width="800" height="431"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Value Iteration never stores a policy at all. It just hammers on the value function until it settles, and &lt;em&gt;then&lt;/em&gt; you read the policy off: stand in each state, look at the neighbours, take the action pointing at the biggest number.&lt;/p&gt;

&lt;p&gt;(That sweep table you looked at earlier? That was Value Iteration. You've already seen it run.)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fol3kxq76qxut4anbugrn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fol3kxq76qxut4anbugrn.png" alt="Value iteration diagram" width="800" height="110"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Policy Iteration vs Value Iteration, side by side
&lt;/h2&gt;

&lt;p&gt;Same equation, same destination, different temperament.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Policy Iteration is the coach who watches the entire game.&lt;/strong&gt; Films it. Writes a 40-page report. Rewrites the playbook from scratch before the next match. Few iterations, each one expensive and each one a big leap.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Value Iteration is the coach who stops play after every snap.&lt;/strong&gt; &lt;em&gt;"Stop — standing three feet left would've been worth two more points."&lt;/em&gt; Cheap per update, but it needs a lot of them. Constantly nudging everyone's understanding of the field.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;Policy Iteration&lt;/th&gt;
&lt;th&gt;Value Iteration&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Explicit policy?&lt;/td&gt;
&lt;td&gt;Yes, maintained separately&lt;/td&gt;
&lt;td&gt;No, implicit in the values&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;max&lt;/code&gt; in the update?&lt;/td&gt;
&lt;td&gt;Only in the improvement step&lt;/td&gt;
&lt;td&gt;Every update&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Cost per iteration&lt;/td&gt;
&lt;td&gt;High (full evaluation)&lt;/td&gt;
&lt;td&gt;Low (one sweep)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Iterations needed&lt;/td&gt;
&lt;td&gt;Few&lt;/td&gt;
&lt;td&gt;Many&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Terminates when&lt;/td&gt;
&lt;td&gt;Policy stops changing&lt;/td&gt;
&lt;td&gt;Values stop changing&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Best when&lt;/td&gt;
&lt;td&gt;State space is small and exact&lt;/td&gt;
&lt;td&gt;State space is large or approximate&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft67wzcfoyg1eg0yusm8x.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft67wzcfoyg1eg0yusm8x.png" alt="PI vs VI comparison" width="800" height="800"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Which should you use? Small, well-defined state space where you want exactness — Policy Iteration. Large or approximate — Value Iteration.&lt;/p&gt;

&lt;p&gt;And worth flagging for later: &lt;strong&gt;almost every modern RL algorithm is spiritually a descendant of Value Iteration.&lt;/strong&gt; They update values continuously and never wait for a full evaluation to finish. Q-learning is Value Iteration with the model ripped out. DQN is Q-learning with a neural network glued on.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fd58xk4wtaecldkdl8ny6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fd58xk4wtaecldkdl8ny6.png" alt="Convergence plot" width="800" height="531"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  The curse they named but couldn't escape
&lt;/h2&gt;

&lt;p&gt;Now the bad news, and Bellman himself is the one who delivered it.&lt;/p&gt;

&lt;p&gt;Both algorithms require sweeping over &lt;strong&gt;every state in &lt;code&gt;S&lt;/code&gt;&lt;/strong&gt;. Every single one. Every iteration.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;4-square corridor: 4 states. Trivial.&lt;/li&gt;
&lt;li&gt;10×10 grid: 100 states. Fine.&lt;/li&gt;
&lt;li&gt;Chess: roughly 10⁴⁴ positions.&lt;/li&gt;
&lt;li&gt;Go: more legal positions than there are atoms in the observable universe.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Bellman named this the &lt;strong&gt;curse of dimensionality&lt;/strong&gt;, in the same 1957 book that gave us the equation. Add one variable to your state description and the state space doesn't grow — it &lt;em&gt;multiplies&lt;/em&gt;. A robot tracking position, velocity, battery, and grip status doesn't have four problems. It has (positions × velocities × battery levels × grip states) problems.&lt;/p&gt;

&lt;p&gt;And remember the poker example from earlier? Fixing the Markov violation by stuffing betting history into the state made the state space explode. That's the curse arriving in person. &lt;strong&gt;Making a problem Markov and making it small are usually opposing goals.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs3xphu5bv5k6sxejgsjx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs3xphu5bv5k6sxejgsjx.png" alt="PE vs PI" width="800" height="800"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is why RL went quiet for decades after Bellman. It wasn't that the theory was shaky. &lt;strong&gt;The theory was perfect and the computer was too small.&lt;/strong&gt; Dynamic Programming solves the &lt;em&gt;structure&lt;/em&gt; of sequential decision-making completely — it just needs a table with one row per state, and sometimes that table can't exist.&lt;/p&gt;

&lt;p&gt;The escape route — stop storing &lt;code&gt;V(s)&lt;/code&gt; in a table and start &lt;em&gt;approximating&lt;/em&gt; it with a function — wouldn't properly arrive until DeepMind's DQN in 2013. But the problem was named here, in 1957. Nearly everything between then and now is an attempt to get around it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fldvjuox3yrc4hxi0ql3p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fldvjuox3yrc4hxi0ql3p.png" alt="Exponential blowup chart" width="800" height="478"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Why 1957 mathematics is running inside your 2026 chatbot
&lt;/h2&gt;

&lt;p&gt;It sounds like a stretch that equations written for missile guidance underpin modern reasoning models. It isn't.&lt;/p&gt;

&lt;p&gt;When a model like &lt;strong&gt;o1&lt;/strong&gt; or &lt;strong&gt;DeepSeek-R1&lt;/strong&gt; works through a hard problem, it isn't just emitting the most likely next token. It's exploring reasoning paths, &lt;em&gt;scoring&lt;/em&gt; how promising each one looks, and abandoning the ones heading toward a dead end.&lt;/p&gt;

&lt;p&gt;Read that again with this post's vocabulary loaded:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A partial chain of reasoning is a &lt;strong&gt;state&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;The next thing to write is an &lt;strong&gt;action&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;"Is this line of thinking going anywhere?" is a &lt;strong&gt;value estimate&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Backtracking out of a bad path is &lt;strong&gt;backward induction&lt;/strong&gt; — the same move Bellman made when he asked about the &lt;em&gt;last&lt;/em&gt; step instead of the first.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The state space changed from grid squares to token sequences. The tables became neural networks. The core question — &lt;em&gt;how good is this situation, really?&lt;/em&gt; — is unchanged since 1957.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjyhn54bk6dkq914dey11.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjyhn54bk6dkq914dey11.png" alt="timeline" width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Six things to keep
&lt;/h2&gt;

&lt;p&gt;If every equation falls out of your head by Thursday, keep these:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;The world is states and actions&lt;/strong&gt; — that's an MDP.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Rewards define what "good" means&lt;/strong&gt; — and you're the one writing them, so be careful.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Value is a score for how promising the future looks from here&lt;/strong&gt; — the number Thorndike's cat never had.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The Bellman Equation makes future reward flow backward&lt;/strong&gt; through states, leaving a slope you can climb.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A policy is just a rule for picking actions&lt;/strong&gt; — a lookup table, not a plan.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Iteration fixes the circularity.&lt;/strong&gt; Guess, measure, improve, repeat, stop when nothing changes.&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;p&gt;If Bellman clicks, the rest of RL is refinement.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fmu8z9j1hlh0zh5csusmj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fmu8z9j1hlh0zh5csusmj.png" alt="Glossary" width="800" height="546"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  What's coming next
&lt;/h2&gt;

&lt;p&gt;Everything in this post rested on one assumption I flagged and then leaned on hard: &lt;strong&gt;the agent already knows &lt;code&gt;P&lt;/code&gt; and &lt;code&gt;R&lt;/code&gt;.&lt;/strong&gt; It knows the physics. It knows the payoffs. It's not learning about the world — it's &lt;em&gt;calculating&lt;/em&gt; against a world it already has a complete map of.&lt;/p&gt;

&lt;p&gt;Real agents don't get that map.&lt;/p&gt;

&lt;p&gt;In &lt;strong&gt;Blog 4 — Early Heuristics and the Birth of Temporal Difference Learning (1959–1968)&lt;/strong&gt;, that assumption gets torn up. We'll meet a program that had to work out what positions were worth by &lt;em&gt;playing&lt;/em&gt;, not by computing — and we'll finally see what happens when you take Rescorla and Wagner's "learn from surprise" idea and let it fire on every single step instead of once per trial.&lt;/p&gt;

&lt;p&gt;Remember the prediction error term from the top of this post? It's about to get a job.&lt;/p&gt;

&lt;p&gt;The equation was ready. The machine was next.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Next: Blog 4 — Early Heuristics and the Birth of Temporal Difference Learning (1959–1968).&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Previously: Blog 1 — Biological Foundations and the Law of Effect (1898–1949) · Blog 2 — The First Machines.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>reinforcementlearning</category>
      <category>machinelearning</category>
      <category>ai</category>
      <category>history</category>
    </item>
    <item>
      <title>RL 2: The first physical and computational RL machines(1948–1954)</title>
      <dc:creator>Mitansh Gor</dc:creator>
      <pubDate>Sat, 12 Sep 2026 05:57:48 +0000</pubDate>
      <link>https://dev.to/mitanshgor/rl-2-the-first-physical-and-computational-rl-machines1948-1954-1amh</link>
      <guid>https://dev.to/mitanshgor/rl-2-the-first-physical-and-computational-rl-machines1948-1954-1amh</guid>
      <description>&lt;p&gt;&lt;strong&gt;Quick recap, if you're just arriving:&lt;/strong&gt; Blog 1 showed that every core idea in reinforcement learning was discovered by someone watching animals, not computers. Thorndike's cats taught us that learning is selection, not insight. Pavlov's dogs taught us that a signal can carry information about the future. Skinner's pigeons taught us that big behaviors are built from small rewarded steps. Hebb's neurons taught us that learning lives in the strength of a connection.&lt;/p&gt;

&lt;p&gt;Four beautiful observations. Not one of them tells you how to &lt;em&gt;build&lt;/em&gt; something that does this.&lt;/p&gt;

&lt;p&gt;This is the decade where people tried to build it anyway. What followed was ten years of beautiful, clunky, brilliant hardware — machines that stumbled through mazes, adjusted their own wiring, and learned, in the most primitive sense, from their mistakes. None of the people building them knew they were inventing Reinforcement Learning. They were just trying to make something move on its own.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Missing Link: Why "a signal predicts the future" Needed a Number
&lt;/h2&gt;

&lt;p&gt;Before we jump to the machines, one 20-second detour — because it's the cleanest bridge between Blog 1 and everything below.&lt;/p&gt;

&lt;p&gt;Pavlov noticed his dogs salivated at footsteps, before food even showed up. Nice story. But it doesn't tell you &lt;em&gt;how much&lt;/em&gt; the dog should update its expectation each time, or why the association eventually stops getting stronger.&lt;/p&gt;

&lt;p&gt;Decades later — 1972, well after everything in this post — psychologists Robert Rescorla and Allan Wagner finally wrote that down as a formula:&lt;/p&gt;

&lt;p&gt;

&lt;/p&gt;
&lt;div class="katex-element"&gt;
  &lt;span class="katex-display"&gt;&lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;Δ&lt;/span&gt;&lt;span class="mord mathnormal"&gt;V&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mrel"&gt;=&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;α&lt;/span&gt;&lt;span class="mord mathnormal"&gt;β&lt;/span&gt;&lt;span class="mopen"&gt;(&lt;/span&gt;&lt;span class="mord mathnormal"&gt;λ&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mbin"&gt;−&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;V&lt;/span&gt;&lt;span class="mclose"&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/div&gt;


&lt;p&gt;In plain words: &lt;em&gt;how much you learn from an event equals how surprising it was.&lt;/em&gt; &lt;code&gt;V&lt;/code&gt; is what you currently expect, &lt;code&gt;λ&lt;/code&gt; is what actually happened, and &lt;code&gt;(λ - V)&lt;/code&gt; is the surprise — the gap between prediction and reality. If a bell always predicts food, eventually there's no surprise left, and no more learning happens. That gap term is the whole engine.&lt;/p&gt;

&lt;p&gt;Why mention a 1972 psychology paper in a post about 1948–1954 engineering? Because the people you're about to meet — Wiener, Turing, Minsky, Shannon — independently backed into the exact same idea from a completely different direction: &lt;em&gt;engineering&lt;/em&gt;, not biology. None of them had read Pavlov's fine print. They just kept discovering, on their own, that intelligence seems to boil down to measuring a gap and closing it. Keep that gap-closing idea in your head — it's the thread connecting every section below.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Cybernetic Spark: Wiener's Feedback Loops (1948)
&lt;/h2&gt;

&lt;p&gt;In 1948, mathematician Norbert Wiener published &lt;em&gt;Cybernetics: Or Control and Communication in the Animal and the Machine&lt;/em&gt;, and made a claim that was radical for its time: the same mathematical principle governs both living organisms and machines — &lt;strong&gt;negative feedback&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwbuzb0pe19qif6xzu7na.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwbuzb0pe19qif6xzu7na.png" alt="Norbert Wiener" width="360" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Forget dogs and food for a second. Think of a thermostat. It doesn't "know" temperature in any deep sense — it just tracks one number obsessively: the gap between where it is and where it's supposed to be.&lt;/p&gt;


&lt;div class="katex-element"&gt;
  &lt;span class="katex-display"&gt;&lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;D&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mrel"&gt;=&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;T&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mbin"&gt;−&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;S&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/div&gt;


&lt;p&gt;Where &lt;code&gt;T&lt;/code&gt; is the target state and &lt;code&gt;S&lt;/code&gt; is the current state. If &lt;code&gt;D ≠ 0&lt;/code&gt;, the system fires a correction to close the gap. That's it. That's the whole idea.&lt;/p&gt;

&lt;p&gt;This is exactly the Rescorla-Wagner gap from above, just wearing an engineer's clothes instead of a psychologist's. &lt;code&gt;D&lt;/code&gt; here is the direct ancestor of the &lt;strong&gt;Temporal Difference (TD) error&lt;/strong&gt; you'll see in modern RL — the signal that tells an agent "something's off, adjust." Every gradient update in every deep RL system running today is, underneath the math, a Wiener-style error minimization.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fsiow833y4mu41qyc87l9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fsiow833y4mu41qyc87l9.png" alt="thermostat vs organism comparison" width="800" height="437"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Wiener's punchline:&lt;/strong&gt; Intelligence isn't magic. It's error minimization on a loop. If you can define a goal and measure your distance from it, a machine can "learn" to close that distance.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxvq6yd134hkpydroyxd6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxvq6yd134hkpydroyxd6.png" alt="Cybernetics Diagram" width="768" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So Wiener gave the field a &lt;em&gt;drive&lt;/em&gt; — a reason to move, a number to chase to zero. But a drive isn't a mechanism. It doesn't tell you what happens inside the machine when it's wrong versus when it's right. That's exactly what Alan Turing was working out, in the very same year, from a completely different angle.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Turing Blueprint: Pain, Pleasure, and the First Neural Network on Paper (1948)
&lt;/h2&gt;

&lt;p&gt;Turing's 1948 paper &lt;em&gt;Intelligent Machinery&lt;/em&gt; introduced the &lt;strong&gt;P-type (Pain-type) Unorganized Machine&lt;/strong&gt;, and reading it today feels like finding the first design document for a neural network, forty years too early.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnbcg2qdg8dv83jnwnck8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnbcg2qdg8dv83jnwnck8.png" alt="Alan Turing" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Turing's argument was blunt: a human infant's cortex is mostly a random, disorganized network that only becomes useful through experience. So why not build the machine equivalent? He proposed a network built from &lt;strong&gt;NAND gates&lt;/strong&gt; — think of these as the smallest possible decision units, each taking two inputs and spitting out one output based on a simple rule. Each gate could sit in one of two internal "configuration states," and that state is what determined how the gate behaved.&lt;/p&gt;

&lt;p&gt;The learning happened through two signals, and this is the part that matters:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pain&lt;/strong&gt; — when the machine got something wrong, the gates that had just fired got scrambled at random:&lt;/p&gt;


&lt;div class="katex-element"&gt;
  &lt;span class="katex-display"&gt;&lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord mathnormal"&gt;C&lt;/span&gt;&lt;span class="msupsub"&gt;&lt;span class="vlist-t vlist-t2"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mtight"&gt;&lt;span class="mord mtight"&gt;&lt;span class="mord mathit mtight"&gt;next&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-s"&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mrel"&gt;=&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord mathit"&gt;RandomSample&lt;/span&gt;&lt;/span&gt;&lt;span class="mopen"&gt;(&lt;/span&gt;&lt;span class="mord mathnormal"&gt;C&lt;/span&gt;&lt;span class="mclose"&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Pleasure&lt;/strong&gt; — when the machine got something right, those same configurations froze in place. No more random reshuffling:&lt;/p&gt;


&lt;div class="katex-element"&gt;
  &lt;span class="katex-display"&gt;&lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;P&lt;/span&gt;&lt;span class="mopen"&gt;(&lt;/span&gt;&lt;span class="mord"&gt;Δ&lt;/span&gt;&lt;span class="mord mathnormal"&gt;C&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mrel"&gt;∣&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord text"&gt;&lt;span class="mord"&gt;Pleasure&lt;/span&gt;&lt;/span&gt;&lt;span class="mclose"&gt;)&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mrel"&gt;=&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;0&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/div&gt;


&lt;p&gt;So: wrong answer, shake things up. Right answer, lock it in. It's almost embarrassingly simple — which is exactly why it's important.&lt;/p&gt;

&lt;p&gt;Turing also spotted the obvious problem immediately: pure random shuffling doesn't scale. If a machine has &lt;code&gt;n&lt;/code&gt; units, each with &lt;code&gt;k&lt;/code&gt; possible states, the number of configurations to search through is &lt;code&gt;k^n&lt;/code&gt; — a number that explodes into uselessness almost immediately, even for tiny machines.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F01nodr2ttwo9rz0ys009.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F01nodr2ttwo9rz0ys009.png" alt="search space explosion" width="800" height="437"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;His fix: bring in a &lt;strong&gt;teacher&lt;/strong&gt;. Instead of letting the machine flail randomly forever, a teacher hands out Pleasure signals early to nudge it toward useful sub-behaviors, and &lt;em&gt;then&lt;/em&gt; Pain prunes away the remaining mistakes. That's not just a clever patch — it's the seed of &lt;strong&gt;Supervised Fine-Tuning (SFT)&lt;/strong&gt; and &lt;strong&gt;Imitation Learning&lt;/strong&gt;, ideas that wouldn't get their modern names for another fifty-plus years. Turing had quietly moved the burden of "being smart" off the programmer's shoulders and onto the environment's.&lt;/p&gt;

&lt;p&gt;His paper sat mostly unread for decades. But look at the shape of it: a randomly wired network, shaped over time by reward and punishment, converging on useful behavior. Every RLHF pipeline running behind a modern chatbot is, structurally, still running Turing's 1948 loop.&lt;/p&gt;

&lt;p&gt;Wiener gave us the &lt;em&gt;why&lt;/em&gt; — close the gap. Turing gave us the &lt;em&gt;what happens inside&lt;/em&gt; — freeze on success, scramble on failure. What nobody had shown yet was a machine that could do this outside of a chalkboard, with actual physical parts that changed themselves. That's where Marvin Minsky comes in.&lt;/p&gt;




&lt;h2&gt;
  
  
  Minsky's SNARC: The First Machine That Rewired Itself (1951–1954)
&lt;/h2&gt;

&lt;p&gt;While Turing's ideas stayed on paper, Marvin Minsky and his Princeton colleague Dean Edmonds went to the workshop and actually built something.&lt;/p&gt;

&lt;p&gt;In 1951, they built the &lt;strong&gt;SNARC — Stochastic Neural Analog Reinforcement Calculator&lt;/strong&gt; — the first machine to physically implement Hebbian learning (remember Blog 1: neurons that fire together, wire together) combined with reinforcement, in real hardware. Minsky later wrote it up in his 1954 thesis.&lt;/p&gt;

&lt;p&gt;The SNARC simulated a rat finding its way through a maze using &lt;strong&gt;40 artificial synapses&lt;/strong&gt;. Each "synapse" was a vacuum tube paired with a &lt;strong&gt;potentiometer&lt;/strong&gt; — picture a volume knob, a simple dial that changes how much resistance flows through a circuit. That dial's position &lt;em&gt;was&lt;/em&gt; the connection's strength, standing in for what we'd now call a "weight."&lt;/p&gt;

&lt;p&gt;Here's the learning loop, in plain terms:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A signal representing the "rat" travels through the network, picking a path.&lt;/li&gt;
&lt;li&gt;If that path leads to reward, the potentiometers ("volume knobs") along that path get turned to &lt;em&gt;lower&lt;/em&gt; resistance — meaning that path becomes electrically easier to travel next time.&lt;/li&gt;
&lt;li&gt;If the path leads nowhere, those knobs stay put or drift the other way.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fuydwodumc7cadtgqsmlh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fuydwodumc7cadtgqsmlh.png" alt="mouse" width="800" height="437"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Notice what's happening here: this is &lt;strong&gt;credit assignment&lt;/strong&gt;, done with actual electricity. The machine had no rule anywhere that said "this specific connection caused the reward." It used the reward signal traveling backward through whichever path was active to figure out which knobs to turn. That's structurally the same job that backpropagation does in a modern neural network — just with copper and vacuum tubes instead of calculus.&lt;/p&gt;

&lt;p&gt;The SNARC couldn't scale — 40 synapses is barely a network by today's standards, and analog parts drift and degrade over time. But it proved something that had never been physically shown before: &lt;strong&gt;a machine can change its own internal wiring in response to reward, with no one programming the change directly.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;That single idea — connections that adjust themselves because of reward — is the founding premise of every neural network trained with RL today.&lt;/p&gt;

&lt;p&gt;So now we've got a drive (Wiener), a mechanism (Turing), and proof that self-adjusting hardware works (Minsky). One year later, Claude Shannon showed what happens when you point that same idea at something a person can actually watch move.&lt;/p&gt;




&lt;h2&gt;
  
  
  Claude Shannon's Theseus: Learning You Can See (1952)
&lt;/h2&gt;

&lt;p&gt;Shannon's contribution was the most tangible of the whole decade. In 1952, he built &lt;strong&gt;Theseus&lt;/strong&gt; — a copper mouse that could navigate a 5×5 maze, controlled by a cabinet of 75 telephone relays sitting underneath.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzpu0uxf58s9y1oodpsvk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzpu0uxf58s9y1oodpsvk.png" alt="Claude Shannon" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here's the trick: the mouse itself had no brain. The relays — think of a relay as a mechanical switch that can remember whether it's "on" or "off" — &lt;em&gt;were&lt;/em&gt; the brain. Each of the 25 cells in the maze corresponded to a relay setup that remembered which directions had already failed from that spot. Hit a wall, and the relay for that direction-at-that-position flipped off, so the mouse tried something else next time. Find a working path, and those relay settings locked in for good.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6m57s6tvpgxnkl40yipq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6m57s6tvpgxnkl40yipq.png" alt="Shannon Maze Environment" width="729" height="487"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The payoff: drop Theseus anywhere in a maze it had already solved, and it walked straight to the goal, no hesitation. Drop it somewhere new, and it explored from scratch — then remembered &lt;em&gt;that&lt;/em&gt; too.&lt;/p&gt;

&lt;p&gt;What Shannon had actually built was a physical &lt;strong&gt;lookup table&lt;/strong&gt;: a direct map from state (position in the maze) to action (which way to go), stored as the mechanical position of 75 relays. This is the hardware great-grandparent of what's now called a Q-table.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fvty8q58nbk0v391cspa7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fvty8q58nbk0v391cspa7.png" alt="relay vs plain qtable" width="800" height="437"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But the genuinely clever part was the &lt;strong&gt;"anti-neurotic" circuit&lt;/strong&gt;. Shannon noticed that a strategy based purely on "eliminate what failed" could trap the mouse in an infinite loop — try North, fail, try East, fail, loop back to North forever, repeat. His fix: a circuit that detected this looping behavior and injected a random direction change to break it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F9nvbe3da87tqi3yegh7f.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F9nvbe3da87tqi3yegh7f.png" alt="break loop" width="800" height="437"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is, as far as anyone can tell, the first deliberate hardware solution to &lt;strong&gt;exploration vs. exploitation&lt;/strong&gt; — the tension that sits at the center of nearly every RL algorithm ever written. In plain terms: should the mouse keep using the move it already knows works (&lt;em&gt;exploit&lt;/em&gt;), or try something new in case there's a better option (&lt;em&gt;explore&lt;/em&gt;)? Shannon's answer was a random kick when stuck. Modern RL answers with names like epsilon-greedy (occasionally pick a random action on purpose) or entropy bonuses (reward the agent slightly for staying unpredictable). Same problem, seventy years of better tools.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Theseus proved something important: "learning" could be reduced entirely to hardware state changes. No probability distributions, no gradients — just relays flipping. Intelligence as a lookup table.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Frg4gtpm2i20cio1ns4rh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Frg4gtpm2i20cio1ns4rh.png" alt="hitting walls, then the " width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  The Bridge (1954–1957): From Wires to Equations
&lt;/h2&gt;

&lt;p&gt;By the mid-1950s, the hardware approach was hitting a wall. Shannon's mouse could solve one specific maze. Minsky's SNARC topped out at 40 synapses. Turing's ideas mostly lived on paper. Every one of these machines was an impressive, custom-built solution to one specific problem — and none of them generalized.&lt;/p&gt;

&lt;p&gt;Richard Bellman, among others, got impatient with that. Building a maze-solving mouse was a great parlor trick, but it wasn't a &lt;em&gt;theory&lt;/em&gt;. What he wanted was a general rule — something that could handle any problem made of a long chain of decisions, no matter what the environment looked like underneath.&lt;/p&gt;

&lt;p&gt;The question shifted from &lt;em&gt;"can we make this specific thing work?"&lt;/em&gt; to &lt;em&gt;"can we prove the mathematically best way to act, in general?"&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Bellman's answer became the &lt;strong&gt;Principle of Optimality&lt;/strong&gt; and the &lt;strong&gt;Bellman Equation&lt;/strong&gt;: the idea that the value of being in a state is just the immediate reward, plus the (slightly discounted) value of wherever you end up next. He took the mechanical "vibes" of the SNARC and Theseus and translated them into a single recursive formula — one equation that compresses an agent's entire future into a present-tense number.&lt;/p&gt;

&lt;p&gt;That equation, and the computational nightmare it revealed (Bellman's own term for it: the &lt;strong&gt;Curse of Dimensionality&lt;/strong&gt;), is where Blog 3 picks up. For now, the point is simpler: after a decade of wiring things together by hand, the field realized it needed math to go any further.&lt;/p&gt;

&lt;p&gt;The wires were beautiful. But equations scale.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Decade in One Frame
&lt;/h2&gt;

&lt;p&gt;Zooming out, here's what this era actually built — not a summary, a thesis:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Wiener (1948)&lt;/strong&gt; gave learning a &lt;em&gt;drive&lt;/em&gt;: minimize the gap on a feedback loop.&lt;br&gt;
&lt;strong&gt;Turing (1948)&lt;/strong&gt; gave learning a &lt;em&gt;mechanism&lt;/em&gt;: reward freezes, punishment randomizes.&lt;br&gt;
&lt;strong&gt;Minsky (1951/54)&lt;/strong&gt; gave learning &lt;em&gt;physical weight&lt;/em&gt;: the first adjustable synapses that existed as hardware, not theory.&lt;br&gt;
&lt;strong&gt;Shannon (1952)&lt;/strong&gt; gave learning &lt;em&gt;memory&lt;/em&gt;: state-action mappings stored in the physical position of relays.&lt;br&gt;
&lt;strong&gt;Bellman (1957)&lt;/strong&gt; gave learning &lt;em&gt;math&lt;/em&gt;: a recursive formula that would eventually unify everything above it — that's Blog 3.&lt;/p&gt;

&lt;p&gt;In under a decade, "learning" went from a biological observation about cats and pigeons to a wired, probabilistic, physically real process you could point to on a workbench. The machines were small, fragile, and each one could only do exactly one thing. But the ideas inside them were load-bearing — every one of them is still holding up the RL systems built today.&lt;/p&gt;

</description>
      <category>rl</category>
      <category>ai</category>
      <category>machinelearning</category>
      <category>deeplearning</category>
    </item>
    <item>
      <title>RL 1: Biological foundations and the "Law of Effect" (1898– 1949)</title>
      <dc:creator>Mitansh Gor</dc:creator>
      <pubDate>Wed, 02 Sep 2026 22:58:37 +0000</pubDate>
      <link>https://dev.to/mitanshgor/rl-1-biological-foundations-and-the-law-of-effect-1898-1949-1a9f</link>
      <guid>https://dev.to/mitanshgor/rl-1-biological-foundations-and-the-law-of-effect-1898-1949-1a9f</guid>
      <description>&lt;p&gt;Before GPUs. Before neural networks. Before transistors were even a rumor.&lt;/p&gt;

&lt;p&gt;There was a hungry cat in a wooden crate, trying to get to a piece of fish.&lt;/p&gt;

&lt;p&gt;The main character of this era isn't an engineer. It's a loose group of psychologists — some of whom actively disliked each other's ideas — poking at animals to answer one question: &lt;em&gt;why do living things do the things they do?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;They never wrote a line of code. They were not trying to build AI. And yet, in the fifty years between 1898 and 1949, they collectively reverse-engineered the core loop that every modern reinforcement learning system still runs on.&lt;/p&gt;

&lt;p&gt;This post is that story. No math yet — I promise. Just the loop, and the four people who found its pieces.&lt;/p&gt;




&lt;h2&gt;
  
  
  First, the thing we're building
&lt;/h2&gt;

&lt;p&gt;Let me give you the shape of the answer before the story, so you know what you're collecting.&lt;/p&gt;

&lt;p&gt;Reinforcement learning describes any system that learns by &lt;strong&gt;doing stuff and seeing what happens.&lt;/strong&gt; That's it. Not by being shown correct answers — by trying, failing, and adjusting.&lt;/p&gt;

&lt;p&gt;We'll call the learner the &lt;strong&gt;agent&lt;/strong&gt; (the cat, the rat, the robot, the model). Everything outside it is the &lt;strong&gt;environment&lt;/strong&gt; (the box, the room, the game). The loop runs like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fbm95lgy9r5kbc7tyi1fg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fbm95lgy9r5kbc7tyi1fg.png" alt="RL" width="800" height="462"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The agent observes its &lt;strong&gt;state&lt;/strong&gt; — the situation it's currently in.&lt;/li&gt;
&lt;li&gt;It picks an &lt;strong&gt;action.&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;The environment responds with a &lt;strong&gt;reward&lt;/strong&gt; — a number saying "that was good" or "that was bad."&lt;/li&gt;
&lt;li&gt;The agent lands in a new state, and the loop repeats.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Two more, and they're the ones that do the heavy lifting later.&lt;/p&gt;

&lt;p&gt;The agent needs a &lt;strong&gt;policy&lt;/strong&gt;: a strategy for choosing actions. Not a fixed script — a rule of thumb that says &lt;em&gt;in this kind of situation, do this kind of thing.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;And it needs a sense of &lt;strong&gt;value&lt;/strong&gt;: how good a state is, based not on the reward sitting in it right now, but on everything it tends to lead to. An empty hallway is worth nothing on its own. An empty hallway &lt;em&gt;with the kitchen at the end of it&lt;/em&gt; is worth quite a lot.&lt;/p&gt;

&lt;p&gt;Six words: &lt;strong&gt;agent, state, action, reward, policy, value.&lt;/strong&gt; Every single one of them was discovered by someone studying animals, decades before anyone could program a computer.&lt;/p&gt;

&lt;p&gt;Let's go get them.&lt;/p&gt;




&lt;h2&gt;
  
  
  1898 — Thorndike's Cats and the Law of Effect
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flm8xra1vrxrrankczn0l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flm8xra1vrxrrankczn0l.png" alt="Edward Thorndike" width="800" height="520"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In 1898, a graduate student named Edward Thorndike was annoyed.&lt;/p&gt;

&lt;p&gt;The animal literature of his day was full of charming anecdotes — dogs who &lt;em&gt;understood&lt;/em&gt; latches, cats who &lt;em&gt;figured out&lt;/em&gt; doorknobs. Thorndike's suspicion was that people were flattering their pets. Animals weren't reasoning. They were doing something else, and nobody had bothered to measure it.&lt;/p&gt;

&lt;p&gt;So he built the &lt;a href="https://www.appstate.edu/~steelekm/classes/psy5300/Documents/chance-72-433.pdf" rel="noopener noreferrer"&gt;puzzle box&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The setup is almost comically simple. A hungry cat goes in a small wooden crate. The door opens only if the cat pulls a loop of string, or presses a lever, or steps on a pedal. A piece of fish sits outside, in plain view. Then Thorndike started a stopwatch.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxa8weof0r3zhvb75exe7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxa8weof0r3zhvb75exe7.png" alt="Thorndike's puzzle box environment" width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Trial one is chaos.&lt;/strong&gt; The cat claws the bars. It shoves its paws through every gap. It bites things, yowls, thrashes at anything loose. After a few minutes of pure flailing, it hits the lever &lt;em&gt;by accident.&lt;/em&gt; The door swings open. Fish.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Trial two:&lt;/strong&gt; slightly less flailing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Trial twenty:&lt;/strong&gt; the cat walks in, hits the lever, and strolls out.&lt;/p&gt;

&lt;p&gt;Here's what Thorndike noticed, and it's the part that matters: &lt;strong&gt;there was never a lightbulb moment.&lt;/strong&gt; No trial where the cat suddenly &lt;em&gt;got it.&lt;/em&gt; If cats were reasoning about levers, you'd expect the escape time to fall off a cliff — one long trial, then instantly fast ones. Instead, when he plotted escape time against trial number, he got a slow, noisy, gradual curve. The useless behaviors quietly faded. The useful one got faster.&lt;/p&gt;

&lt;p&gt;That curve is the first real evidence in this story. Learning wasn't insight. It was &lt;strong&gt;selection&lt;/strong&gt; — good behaviors surviving, bad ones dying off.&lt;/p&gt;

&lt;p&gt;Thorndike wrote it up as the &lt;strong&gt;Law of Effect&lt;/strong&gt;:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;If an action is followed by a satisfying state of affairs, the bond between that situation and that action is strengthened. If followed by discomfort, it is weakened.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Read that again with our vocabulary. &lt;em&gt;Situation&lt;/em&gt; is the &lt;strong&gt;state&lt;/strong&gt;. &lt;em&gt;Action&lt;/em&gt; is the &lt;strong&gt;action&lt;/strong&gt;. &lt;em&gt;Satisfying&lt;/em&gt; is the &lt;strong&gt;reward&lt;/strong&gt;. &lt;em&gt;Bond strengthened&lt;/em&gt; is the &lt;strong&gt;policy update&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Thorndike, in 1898, wrote pseudocode for a policy gradient. He just used the word "bond."&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;🎒 &lt;strong&gt;In the backpack:&lt;/strong&gt; trial-and-error learning. Rewards make actions more likely. Learning is gradual, not sudden.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h3&gt;
  
  
  But something's missing
&lt;/h3&gt;

&lt;p&gt;Thorndike's cat only learns &lt;em&gt;after&lt;/em&gt; it gets the fish. The reward does all the teaching.&lt;/p&gt;

&lt;p&gt;But watch a real animal for five minutes and you'll notice it reacting to things that aren't rewards at all. Your dog loses its mind at the sound of a cupboard opening. Nothing has been eaten yet. The cupboard &lt;em&gt;predicts&lt;/em&gt; food.&lt;/p&gt;

&lt;p&gt;Thorndike had no account of that. Rewards were where his story started and ended.&lt;/p&gt;

&lt;p&gt;The person who noticed the signal was, characteristically, not looking for it.&lt;/p&gt;




&lt;h2&gt;
  
  
  The 1900s–1920s — Pavlov and the Problem of Prediction
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxrb3lotitr11lo46umfx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxrb3lotitr11lo46umfx.png" alt="Ivan Pavlov" width="800" height="1019"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Ivan Pavlov was a Russian physiologist studying digestion. He won a Nobel Prize for it in 1904. He was, by most accounts, mildly irritated that history remembers him for the dogs.&lt;/p&gt;

&lt;p&gt;His actual research required measuring saliva. And his dogs kept ruining the measurements by salivating &lt;strong&gt;early&lt;/strong&gt; — at the sight of the lab assistant who usually brought food, at the sound of footsteps in the corridor. Before any food existed.&lt;/p&gt;

&lt;p&gt;Most researchers would call that noise and try to control for it. Pavlov called it the experiment.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9me8tgsxmv8vn7qrwgf1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9me8tgsxmv8vn7qrwgf1.png" alt="Pavlov's dog experiment" width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;He ran it systematically. Present a neutral signal — a metronome, a buzzer, a light, a tone — then deliver food, a second or two later. Repeat.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;(Quick myth-correction, since it costs one sentence: the famous bell is mostly folklore. Pavlov's lab notes lean heavily on metronomes, buzzers, and tuning forks. The bell survived because it's easier to draw.)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;After enough pairings, the signal alone made the dogs salivate. Nothing about the food had changed. What changed was that the dog had learned &lt;strong&gt;the signal carries information about the future.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This is the second piece, and it's a big one. Thorndike's cat learned &lt;em&gt;what to do.&lt;/em&gt; Pavlov's dog learned &lt;em&gt;what's coming.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;In RL terms, that's &lt;strong&gt;value&lt;/strong&gt;. The value of a state is roughly: &lt;em&gt;how much good stuff do I expect from here on out?&lt;/em&gt; A metronome that reliably precedes food is a high-value state — not because a metronome is nutritious, but because of what tends to follow it.&lt;/p&gt;

&lt;p&gt;You do this constantly. The smell of coffee is not caffeine. Your inbox badge is not the email. A green light is not arriving anywhere. Every one of these is a state you've assigned value to, purely because of what historically came next.&lt;/p&gt;

&lt;p&gt;And this is why RL agents can learn anything at all in sparse environments. A chess engine that only felt reward at checkmate would learn approximately nothing — the signal is 60 moves away from most of the decisions that caused it. What it actually learns is to value &lt;em&gt;positions&lt;/em&gt;: this pawn structure tends to precede winning. That's a metronome.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;🎒 &lt;strong&gt;In the backpack:&lt;/strong&gt; states have value. Value comes from &lt;em&gt;prediction&lt;/em&gt;, not from the reward itself.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h3&gt;
  
  
  But something's still missing
&lt;/h3&gt;

&lt;p&gt;Pavlov's dogs were passive. They sat in a harness and predicted. The dog's salivation doesn't make the food arrive any sooner.&lt;/p&gt;

&lt;p&gt;So now we have two halves of an agent and no glue:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;Thorndike's cat&lt;/th&gt;
&lt;th&gt;Pavlov's dog&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Learns&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;which actions pay off&lt;/td&gt;
&lt;td&gt;which signals predict payoff&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Can it act?&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;❌&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Can it anticipate?&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;❌&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;A real agent needs both — and it needs someone to make this a controllable science rather than a collection of observations. That took a genuine control freak.&lt;/p&gt;




&lt;h2&gt;
  
  
  The 1930s–50s — Skinner Turns Behavior Into Engineering
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvwal2v9jj5pw68zrj5oa.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvwal2v9jj5pw68zrj5oa.png" alt="B.F. Skinner" width="800" height="800"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;B.F. Skinner's question was different from everyone before him. Not "how do animals learn?" but: &lt;strong&gt;"how precisely can I control what an animal learns?"&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;His tool was the operant conditioning chamber — the Skinner Box. A rat inside can press a bar. A pigeon can peck a disc. Food is dispensed on rules Skinner sets. Simple inputs, measurable outputs, and — critically — the animal &lt;em&gt;stays in the box.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8oszf4z6acztkuf32c73.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8oszf4z6acztkuf32c73.png" alt="Rat in a Skinner box" width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That last detail seems minor and isn't. Thorndike's cats escaped, which meant one trial, then a reset by hand. Skinner's animals could run thousands of trials in an afternoon, uninterrupted. He'd built the first high-throughput training environment. Every RL researcher who has ever run a simulator overnight is doing the same thing.&lt;/p&gt;

&lt;p&gt;Two of his findings matter for us.&lt;/p&gt;

&lt;h3&gt;
  
  
  Finding 1: Unpredictable rewards are the stickiest
&lt;/h3&gt;

&lt;p&gt;Skinner varied &lt;em&gt;when&lt;/em&gt; reward arrived — every press, every fifth press, every fifth press &lt;em&gt;on average.&lt;/em&gt; These are &lt;strong&gt;schedules of reinforcement.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The counterintuitive result: &lt;strong&gt;variable&lt;/strong&gt; reward — where the animal can't predict which press pays — produced behavior that was hardest to extinguish. Reward a pigeon every single time, then stop, and it gives up quickly. Reward it unpredictably, then stop, and it keeps going for a remarkably long time.&lt;/p&gt;

&lt;p&gt;Slot machines run on this. So do infinite-scroll feeds. Skinner found the exploit in the 1950s; the attention economy just productized it.&lt;/p&gt;

&lt;p&gt;For us, the useful version is that reward &lt;em&gt;structure&lt;/em&gt; is a design decision with enormous consequences. Which sets up an entire genre of modern RL failure — agents that learn the reward signal instead of the task, in ways nobody intended. We'll spend real time there in a later post.&lt;/p&gt;

&lt;h3&gt;
  
  
  Finding 2: You can build complex behavior out of crumbs
&lt;/h3&gt;

&lt;p&gt;The bigger idea is &lt;strong&gt;shaping.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Skinner taught pigeons to play a passable game of table tennis. Not by waiting for a pigeon to spontaneously play table tennis — you'd wait forever. He rewarded &lt;em&gt;incremental steps.&lt;/em&gt; First, reward the bird for merely facing the table. Once that's reliable, stop rewarding it and only pay for approaching the ball. Then only for contact. Then only for direction.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/shorts/RPJyKSmH9WM?feature=share" rel="noopener noreferrer"&gt;https://www.youtube.com/shorts/RPJyKSmH9WM?feature=share&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You are moving the goalposts on purpose, in small enough increments that the animal never falls off the curve.&lt;/p&gt;

&lt;p&gt;This is &lt;strong&gt;reward shaping&lt;/strong&gt;, and it's how we train robots today. A robot arm rewarded only for "successfully assembled the part" will flail randomly forever, because the odds of stumbling into success by accident are effectively zero. So we hand it crumbs: reward for moving toward the part, then for gripping it, then for lifting. Same ladder. Different species.&lt;/p&gt;

&lt;p&gt;And the strategy the animal ends up with — &lt;em&gt;in this situation, do this&lt;/em&gt; — is exactly what we called a &lt;strong&gt;policy&lt;/strong&gt; at the top of this post. Skinner spent thirty years training policies. He just did it with pigeons and a food dispenser instead of gradients and a GPU.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;🎒 &lt;strong&gt;In the backpack:&lt;/strong&gt; policies can be &lt;em&gt;trained&lt;/em&gt;, not just observed. Reward timing and reward structure change everything.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h3&gt;
  
  
  But something's still missing
&lt;/h3&gt;

&lt;p&gt;We now have a full behavioral picture: act, predict, get shaped, improve.&lt;/p&gt;

&lt;p&gt;Every bit of it is described from the outside. Skinner was deliberate about this — he treated the mind as a black box and argued you should only ever talk about observable behavior. Which is scientifically disciplined and completely useless if you want to &lt;em&gt;build&lt;/em&gt; one.&lt;/p&gt;

&lt;p&gt;Because if you're going to build this thing, you need to answer a question Skinner refused to ask: &lt;strong&gt;where does the learning physically live?&lt;/strong&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  1949 — Hebb Finds the Storage
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgpq0oxiztlxp2o9uy8z1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgpq0oxiztlxp2o9uy8z1.png" alt="Donald Hebb" width="491" height="480"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Donald Hebb, a Canadian psychologist, published &lt;em&gt;The Organization of Behavior&lt;/em&gt; in 1949 and proposed a mechanism so simple it fits in a sentence.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;If neuron A repeatedly takes part in firing neuron B, some growth process or metabolic change takes place in both cells such that A's efficiency in firing B is increased.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That's &lt;strong&gt;Hebb's Rule&lt;/strong&gt;, and the pop version is stickier: &lt;strong&gt;neurons that fire together, wire together.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb2ei581ewgfx0kd2zqhk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb2ei581ewgfx0kd2zqhk.png" alt="Hebb's rule: neuron A firing neuron B" width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Two neurons active at the same time? The connection between them — the &lt;strong&gt;synapse&lt;/strong&gt; — physically strengthens. Next time, A triggers B more easily. Do it enough and the path becomes a highway.&lt;/p&gt;

&lt;p&gt;Run Thorndike's cat through this. The cat sees the lever (a pattern of neurons firing) and presses it (another pattern firing). They're active together. Their connection thickens. A hundred trials later, seeing the lever &lt;em&gt;is&lt;/em&gt; pressing the lever — there's a paved road between them.&lt;/p&gt;

&lt;p&gt;That's a habit, described in hardware.&lt;/p&gt;

&lt;p&gt;And this is where artificial neural networks come from. In a network, the connection strength between two artificial neurons is a number called a &lt;strong&gt;weight.&lt;/strong&gt; Learning means adjusting weights so that useful inputs reliably produce useful outputs. Hebb is the reason "learning = changing connection strengths" is the default assumption in the entire field.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;One important correction, because this gets flattened a lot:&lt;/strong&gt; Hebb's rule is &lt;em&gt;not&lt;/em&gt; backpropagation, and the difference is worth thirty seconds.&lt;/p&gt;

&lt;p&gt;Hebb's rule is &lt;strong&gt;local&lt;/strong&gt;. A synapse strengthens based only on what its own two neurons are doing right now. No supervisor, no error signal, nobody keeping score.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Backpropagation&lt;/strong&gt; — the algorithm that actually trains modern networks — is &lt;strong&gt;global and error-driven&lt;/strong&gt;. It compares the network's output to a desired output, computes how wrong it was, and pushes that error signal backward through every layer, adjusting each weight by how much it contributed to the mistake. Every weight update depends on information from far away in the network.&lt;/p&gt;

&lt;p&gt;These are genuinely different mechanisms. In fact, the gap between them is one of the liveliest open arguments in neuroscience: brains clearly don't run backprop — there's no known biological machinery for shipping a precise error signal backward across a network — yet backprop works spectacularly well. Whether the brain approximates something like it, or does something else entirely, is unresolved.&lt;/p&gt;

&lt;p&gt;So the honest lineage is: &lt;strong&gt;Hebb gave us the idea that memory lives in connection strengths.&lt;/strong&gt; Backprop is a much later, mathematically-driven answer to &lt;em&gt;how to update&lt;/em&gt; those strengths. Same neighborhood, different building.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;🎒 &lt;strong&gt;In the backpack:&lt;/strong&gt; learning is stored in connection weights. Local, physical, incremental.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Where that leaves us in 1949
&lt;/h2&gt;

&lt;p&gt;Fifty-one years, four researchers, and the loop is complete:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Idea&lt;/th&gt;
&lt;th&gt;From&lt;/th&gt;
&lt;th&gt;What it becomes&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Rewards strengthen the actions that earned them&lt;/td&gt;
&lt;td&gt;Thorndike, 1898&lt;/td&gt;
&lt;td&gt;the reward signal&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Signals predict future reward&lt;/td&gt;
&lt;td&gt;Pavlov, 1900s&lt;/td&gt;
&lt;td&gt;value&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Behavior can be sculpted step by step&lt;/td&gt;
&lt;td&gt;Skinner, 1930s–50s&lt;/td&gt;
&lt;td&gt;policies, reward shaping&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Learning is stored in connection strengths&lt;/td&gt;
&lt;td&gt;Hebb, 1949&lt;/td&gt;
&lt;td&gt;weights&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Read that table top to bottom and you have a specification. Something that acts, predicts, gets shaped by consequences, and stores what it learned in the strength of its connections.&lt;/p&gt;

&lt;p&gt;Nobody had built it. Nobody could — the ideas were all written in the language of biology, describing wet tissue that nobody could manufacture.&lt;/p&gt;

&lt;p&gt;But 1949 is the year that stops being true. The war had just produced digital computers. A new field called &lt;strong&gt;cybernetics&lt;/strong&gt; was arguing that control and feedback worked the same way in animals and machines, and that the distinction was less fundamental than everyone assumed.&lt;/p&gt;

&lt;p&gt;For the first time, people had a spec for learning &lt;em&gt;and&lt;/em&gt; a machine to run it on.&lt;/p&gt;




&lt;h2&gt;
  
  
  One thing they all got wrong
&lt;/h2&gt;

&lt;p&gt;Before we leave the psychologists, here's the crack in the foundation — worth holding onto, because it takes another twenty years to fix.&lt;/p&gt;

&lt;p&gt;Every idea above says learning happens when things &lt;strong&gt;co-occur.&lt;/strong&gt; Metronome and food together → learn. Lever and fish together → learn. Neurons active together → wire together.&lt;/p&gt;

&lt;p&gt;But co-occurrence can't be the whole story:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Your alarm has gone off at 7am every day for a year.&lt;/strong&gt; By the co-occurrence rule, this morning should have strengthened that association a little further, same as every other morning. It didn't. You learned it in the first week and then stopped — even though the pairing kept happening, perfectly, hundreds more times.&lt;/p&gt;

&lt;p&gt;So what switches learning &lt;em&gt;off&lt;/em&gt;?&lt;/p&gt;

&lt;p&gt;Nobody in this post can answer that. The answer arrives in 1972, from a pair of psychologists still studying rats, and when it does it turns out to be the single most important equation in this entire series. We'll get there.&lt;/p&gt;




&lt;h2&gt;
  
  
  Next up
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;RL #2 — Cybernetics and Early Machines (1948–1954).&lt;/strong&gt; The first people to actually build this thing. Alan Turing sketching a "pleasure-pain system" in 1948. Claude Shannon's Theseus, a mechanical mouse that learned a maze by trial and error and could remember it. And Marvin Minsky wiring together the SNARC — 40 vacuum tubes, motors, and a clutch, arguably the first machine that learned by reinforcement.&lt;/p&gt;

&lt;p&gt;The cats gave us the algorithm. Now watch people try to solder it.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;If you spot an error or think I've oversimplified something, drop it in the comments — I'd rather fix it than have it sit there.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>rl</category>
      <category>machinelearning</category>
      <category>deeplearning</category>
      <category>ai</category>
    </item>
    <item>
      <title>Reinforcement Learning Series</title>
      <dc:creator>Mitansh Gor</dc:creator>
      <pubDate>Wed, 19 Aug 2026 18:40:39 +0000</pubDate>
      <link>https://dev.to/mitanshgor/reinforcement-learning-series-4m6j</link>
      <guid>https://dev.to/mitanshgor/reinforcement-learning-series-4m6j</guid>
      <description>&lt;p&gt;I created this series to make that steep learning curve far less daunting for you. My goal is to trace the evolution of RL chronologically—from its roots in early psychology and physical mechanical machines to digital binary systems and modern mathematical breakthroughs. By breaking down complex concepts with clear visual guides, graphics, and real-world analogies, I hope to demystify RL and give back to the community that inspired me. Let’s dive in!&lt;/p&gt;

&lt;h3&gt;
  
  
  Blog 1: The Psychological Seeds (1898–1949)
&lt;/h3&gt;

&lt;p&gt;This entry explores the &lt;strong&gt;Law of Effect&lt;/strong&gt; (1911), where Edward Thorndike established that actions followed by satisfaction are strengthened. It also covers Ivan Pavlov’s formal definition of &lt;strong&gt;reinforcement&lt;/strong&gt; (1927) and Donald Hebb’s 1949 hypothesis that "neurons that fire together, wire together," laying the groundwork for neural learning.&lt;/p&gt;

&lt;h3&gt;
  
  
  Blog 2: Cybernetics and Early Machines (1948–1954)
&lt;/h3&gt;

&lt;p&gt;This blog details the first computational investigations, including &lt;strong&gt;Alan Turing’s&lt;/strong&gt; "pleasure-pain system" (1948) and Marvin Minsky’s construction of &lt;strong&gt;SNARCs&lt;/strong&gt; (1954), the first analog neural-network reinforcement calculators. It also highlights &lt;strong&gt;Claude Shannon’s&lt;/strong&gt; 1952 demonstration of "Theseus," a maze-running mouse that used trial and error to "remember" paths.&lt;/p&gt;

&lt;h3&gt;
  
  
  Blog 3: The Mathematical Framework (1950s–1960s)
&lt;/h3&gt;

&lt;p&gt;This post focuses on &lt;strong&gt;Richard Bellman’s&lt;/strong&gt; development of &lt;strong&gt;Dynamic Programming&lt;/strong&gt; and the Bellman Equation (1957), which provided the formal tools for solving optimal control problems. It also introduces &lt;strong&gt;Markov Decision Processes (MDPs)&lt;/strong&gt; and Ron Howard’s &lt;strong&gt;policy iteration&lt;/strong&gt; method (1960), which are the bedrock of modern RL theory.&lt;/p&gt;

&lt;h3&gt;
  
  
  Blog 4: Early Heuristics and Checkers (1959–1968)
&lt;/h3&gt;

&lt;p&gt;This entry discusses &lt;strong&gt;Arthur Samuel’s&lt;/strong&gt; celebrated checkers program (1959), which was the first to implement &lt;strong&gt;temporal-difference (TD)&lt;/strong&gt; ideas by using board evaluation differences to modify earlier positions. It also details Donald Michie’s &lt;strong&gt;MENACE&lt;/strong&gt; (1961), a physical "matchbox" engine that learned to play Noughts and Crosses through reinforcement.&lt;/p&gt;

&lt;h3&gt;
  
  
  Blog 5: The Birth of Learning Automata (1961–1974)
&lt;/h3&gt;

&lt;p&gt;This blog examines the Soviet lineage of RL, specifically &lt;strong&gt;Mikhail Tsetlin’s&lt;/strong&gt; work on "learning automata" (1961), which were finite-state machines that updated action probabilities based on stochastic environmental feedback. It traces how this research was later systematised by Narendra and Thathachar in 1974.&lt;/p&gt;

&lt;h3&gt;
  
  
  Blog 6: The "Hedonistic" Revival (1972–1980)
&lt;/h3&gt;

&lt;p&gt;This post covers &lt;strong&gt;Harry Klopf’s&lt;/strong&gt; pivotal role in reviving the trial-and-error thread by proposing the &lt;strong&gt;"hedonistic neuron"&lt;/strong&gt; (1972), which argued that neurons act as pleasure-seeking units. It also explores Paul Werbos’s 1974 thesis, which was the first to describe &lt;strong&gt;backpropagation&lt;/strong&gt; in the context of "Adaptive Dynamic Programming".&lt;/p&gt;

&lt;h3&gt;
  
  
  Blog 7: The Sutton and Barto Foundation (1981–1984)
&lt;/h3&gt;

&lt;p&gt;This blog highlights the formalisation of modern RL, beginning with &lt;strong&gt;Sutton and Barto’s&lt;/strong&gt; 1981 model of classical conditioning. It details the invention of the &lt;strong&gt;Actor-Critic architecture&lt;/strong&gt; (1983) and Sutton’s 1984 dissertation, which provided the first rigorous computational analysis of &lt;strong&gt;temporal credit assignment&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Blog 8: The Q-Learning Breakthrough (1988–1994)
&lt;/h3&gt;

&lt;p&gt;This entry documents two watershed moments: &lt;strong&gt;Sutton’s&lt;/strong&gt; 1988 formalisation of TD learning and &lt;strong&gt;Chris Watkins’s&lt;/strong&gt; 1989 introduction of &lt;strong&gt;Q-Learning&lt;/strong&gt;, the first model-free, off-policy algorithm. It also covers the introduction of &lt;strong&gt;SARSA&lt;/strong&gt; (1994) as an on-policy alternative that prioritises training stability.&lt;/p&gt;

&lt;h3&gt;
  
  
  Blog 9: Superhuman Achievement in Games (1992–1999)
&lt;/h3&gt;

&lt;p&gt;This post details &lt;strong&gt;Gerald Tesauro’s TD-Gammon&lt;/strong&gt; (1992), which achieved grandmaster-level backgammon play using neural networks and self-play. It also covers the &lt;strong&gt;options framework&lt;/strong&gt; (1999) by Sutton, Precup, and Singh, which introduced temporal abstraction to help RL agents solve problems across different timescales.&lt;/p&gt;

&lt;h3&gt;
  
  
  Blog 10: Theoretical Refinement (2000–2010)
&lt;/h3&gt;

&lt;p&gt;This entry explains the &lt;strong&gt;Policy Gradient Theorem&lt;/strong&gt; (2000), which proved that policy parameters could be optimised using only local information. It also introduces Sham Kakade’s &lt;strong&gt;Natural Policy Gradient&lt;/strong&gt; (2002), a precursor to modern trust-region methods that account for the geometry of parameter space.&lt;/p&gt;

&lt;h3&gt;
  
  
  Blog 11: The Deep RL Revolution (2013–2015)
&lt;/h3&gt;

&lt;p&gt;This post chronicles the birth of &lt;strong&gt;Deep RL&lt;/strong&gt; with DeepMind’s &lt;strong&gt;DQN&lt;/strong&gt; (2013/2015), which used &lt;strong&gt;Experience Replay&lt;/strong&gt; and &lt;strong&gt;Target Networks&lt;/strong&gt; to master Atari games directly from pixels. It also details &lt;strong&gt;DDPG&lt;/strong&gt; (2015), which extended these successes to continuous action spaces like robotics.&lt;/p&gt;

&lt;h3&gt;
  
  
  Blog 12: Mastering Strategy and Control (2015–2017)
&lt;/h3&gt;

&lt;p&gt;This entry explores &lt;strong&gt;Trust Region Policy Optimization (TRPO)&lt;/strong&gt; (2015) and its simpler successor, &lt;strong&gt;Proximal Policy Optimization (PPO)&lt;/strong&gt; (2017), which became the industry standard for stable training. It also covers the historic victory of &lt;strong&gt;AlphaGo&lt;/strong&gt; over Lee Sedol in 2016.&lt;/p&gt;

&lt;h3&gt;
  
  
  Blog 13: Integrated Mastery: Rainbow and MuZero (2017–2019)
&lt;/h3&gt;

&lt;p&gt;This post details the &lt;strong&gt;Rainbow&lt;/strong&gt; agent (2017), which combined seven independent DQN improvements into one "super-agent". It also highlights &lt;strong&gt;MuZero&lt;/strong&gt; (2019), which learned to master games like Go and Chess without even being told the rules of the environment.&lt;/p&gt;

&lt;h3&gt;
  
  
  Blog 14: Hard Exploration and Generalisation (2020–2022)
&lt;/h3&gt;

&lt;p&gt;This blog focuses on &lt;strong&gt;Agent57&lt;/strong&gt; (2020), the first agent to surpass the human benchmark on all 57 Atari games by solving "hard exploration" problems. It also covers &lt;strong&gt;Gato&lt;/strong&gt; (2022), a single transformer-based generalist agent capable of playing Atari, captioning images, and controlling robot arms.&lt;/p&gt;

&lt;h3&gt;
  
  
  Blog 15: The Transformer Pivot and LLM Alignment (2021–2023)
&lt;/h3&gt;

&lt;p&gt;This entry describes the &lt;strong&gt;Decision Transformer&lt;/strong&gt; (2021), which reframed RL as a sequence modeling problem, bypassing traditional bootstrapping. It also covers the rise of &lt;strong&gt;Reinforcement Learning from Human Feedback (RLHF)&lt;/strong&gt; with &lt;strong&gt;InstructGPT&lt;/strong&gt; and the subsequent development of &lt;strong&gt;Direct Preference Optimization (DPO)&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Blog 16: Reasoning Models and Incentivized Thought (2024–2025)
&lt;/h3&gt;

&lt;p&gt;This blog explores &lt;strong&gt;DeepSeek Math&lt;/strong&gt; and &lt;strong&gt;GRPO&lt;/strong&gt; (2024), which removed the need for a separate critic model to improve mathematical reasoning. It details the breakthrough of &lt;strong&gt;DeepSeek-R1&lt;/strong&gt; (2024/2025), which proved that pure RL can spontaneously elicit self-correction and reflection in language models.&lt;/p&gt;

&lt;h3&gt;
  
  
  Blog 17: Massive Depth and the Future of Scaling (2025–2026)
&lt;/h3&gt;

&lt;p&gt;This final entry discusses the 2025 NeurIPS Best Paper on &lt;strong&gt;1,000-layer RL networks&lt;/strong&gt;, which broke the "shallow network" assumption to unlock 50x performance gains. It reflects on &lt;strong&gt;Kimi k1.5&lt;/strong&gt; and the role of the &lt;strong&gt;2024 Turing Award&lt;/strong&gt; in cementing RL as a foundational pillar of the AI revolution.&lt;/p&gt;

</description>
      <category>rl</category>
    </item>
    <item>
      <title>Personal Health Agent (PHA): Multi-Agent Health System</title>
      <dc:creator>Mitansh Gor</dc:creator>
      <pubDate>Thu, 27 Nov 2025 05:33:43 +0000</pubDate>
      <link>https://dev.to/mitanshgor/personal-health-agent-pha-multi-agent-health-system-1i6l</link>
      <guid>https://dev.to/mitanshgor/personal-health-agent-pha-multi-agent-health-system-1i6l</guid>
      <description>&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=cHYuEzxDJb4" rel="noopener noreferrer"&gt;VIDEO LINK&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the last few years, we saw different types of AI systems try to answer this question:&lt;br&gt;
PH-LLM (2024) → focused on personalized coaching from wearable data.&lt;br&gt;
PHIA (2024) → acted like an agent that analyzes your data, writes code, and explains results.&lt;br&gt;
IR Prediction + IR Explainer Agent (2025) → estimated your metabolic risk and explained it like a doctor.&lt;/p&gt;

&lt;p&gt;All of these systems were important steps. But each one had a weakness:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A single LLM tries to do everything.&lt;/li&gt;
&lt;li&gt;It must read data, interpret medical meaning, check safety, and give advice.&lt;/li&gt;
&lt;li&gt;This often leads to confident hallucinations — answers that sound correct but are actually wrong.&lt;/li&gt;
&lt;li&gt;It also mixes medical reasoning with casual coaching, which creates risk. And one model cannot be an expert in every health domain.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9314ab1b0c2ovlg8crme.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9314ab1b0c2ovlg8crme.png" alt="banner" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So the big idea behind the Personal Health Agent (PHA) is simple:&lt;/p&gt;

&lt;p&gt;Instead of one giant model doing everything, why not create multiple smaller agents — each with a role — working together like a mini health team?&lt;br&gt;
This solves the main problem with earlier systems: no single AI can fully handle the complexity of real human health. But a team of specialized agents can.&lt;/p&gt;

&lt;p&gt;Because health is multi-dimensional—where your sleep affects your stress, stress affects metabolic health, exercise influences sleep, and food and biomarkers impact everything—one AI model can’t realistically handle all of it at once. Just like a hospital relies on different specialists, a digital health system also needs different “roles”: one agent to interpret raw data, one agent to check medical safety, and one agent to translate insights into simple coaching. This is why multi-agent systems are becoming so important: they add structure, accountability, and more reliable reasoning, solving many of the issues earlier single-LLM systems struggled with.&lt;/p&gt;

&lt;h2&gt;
  
  
  A System of Specialized Agents
&lt;/h2&gt;

&lt;p&gt;When I look at the PHA system, what stands out first is the Analyst Agent. I think of this agent like a friend who loves numbers and graphs. Its whole job is to read my raw data — sleep hours, steps, heart rate, and other signals — and turn them into clear observations. It doesn’t try to coach me or act like a doctor. It just says, “Here’s what I see happening in your data,” which makes everything feel clean and easy to understand.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy58om1b0a4jbjs6ocgvd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy58om1b0a4jbjs6ocgvd.png" alt="dsAgent" width="800" height="340"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then there is the Domain Expert Agent, which to me is the “doctor brain” of the whole system. This agent takes what the Analyst found and checks if it makes medical sense. It worries about safety, accuracy, and whether the explanation aligns with real health science. I really like this part because it stops the system from giving random or misleading advice. It acts like the strict friend who always says, “Wait, is this actually correct?”&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx4rkm5lh1in07tfqpz67.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx4rkm5lh1in07tfqpz67.png" alt="domainExp" width="800" height="311"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next comes the Coach Agent, the most human-feeling part of PHA. This agent talks to me like a supportive friend who wants me to succeed. It takes all the technical pieces and translates them into simple, everyday advice I can act on. No medical jargon. No complicated charts. Just small, doable suggestions like, “Try walking after dinner” or “Aim for an earlier bedtime tonight.” It’s friendly and practical, which is exactly what people need.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg315ncyax16diti30hvt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg315ncyax16diti30hvt.png" alt="healthcoach" width="799" height="274"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What ties everything together is how these agents work as a team. Instead of one giant AI trying to do everything — and often making confident mistakes — each agent stays in its own lane. One analyzes, one verifies, one coaches. Because of this teamwork, the final answer feels clearer, safer, and much more trustworthy. It’s almost like having a mini health team inside your phone, and that makes the whole system feel both smart and human at the same time.&lt;/p&gt;

&lt;h2&gt;
  
  
  Technical Deep Dive
&lt;/h2&gt;

&lt;p&gt;Even though all agents may start from the same base LLM (like Gemini or GPT-class models), they are trained separately, so each one becomes good at one thing instead of being average at everything.&lt;/p&gt;

&lt;h3&gt;
  
  
  Finetuning
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Analyst Agent is finetuned from wearable logs (heart rate, steps, sleep), time-series patterns, data summaries, and statistical examples. It becomes good at reading numbers and spotting patterns.&lt;/li&gt;
&lt;li&gt;Domain Expert needs more serious data for finetuning, like medical guidelines, curated clinical examples, safe/unsafe reasoning samples, and explanations validated by experts. It learns how to avoid hallucinations and unsafe claims&lt;/li&gt;
&lt;li&gt;Coach Agent is the “human” one. It is finetuned on a friendly conversational dataset, lifestyle advice examples, behavior-change coaching patterns. It learns to talk in a simple, supportive way.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxutm9nruja3q39zgfr6h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxutm9nruja3q39zgfr6h.png" alt="data set" width="800" height="197"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This division is what makes the final system feel more stable than earlier systems like PHIA or the IR Agent, where a single LLM had to juggle all roles and often made confident mistakes.&lt;/p&gt;

&lt;p&gt;The process itself was simple but very intentional. Here’s how I imagine it:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;We first collected examples for each agent’s role.&lt;/li&gt;
&lt;li&gt;Then we cleaned and organized everything.&lt;/li&gt;
&lt;li&gt;Then we cleaned and organized everything.&lt;/li&gt;
&lt;li&gt;After that, we fine-tuned each agent separately.&lt;/li&gt;
&lt;li&gt;Then we tested the agents together.&lt;/li&gt;
&lt;li&gt;Finally, we fixed mistakes and improved the dataset.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  System architecture and Data Flow
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbpizblec7crocjocrwah.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbpizblec7crocjocrwah.png" alt="system arch" width="800" height="438"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Underneath all of this, there’s a system architecture that makes their collaboration possible. I picture it like a small command center. The user’s data flows into a main controller, which decides which agent speaks first and who validates whom. The Analyst generates its interpretation, the Domain Expert checks it, and the Coach turns everything into a simple message. Each agent is isolated enough to stay focused, but interconnected enough to build on each other’s work. There’s also a safety layer running quietly in the background — something like a “medical guardrail” — to make sure the final output stays safe, consistent, and responsible before it reaches the user.&lt;/p&gt;

&lt;h3&gt;
  
  
  Data Pipeline Flow
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;My raw data comes in (wearable data, blood test results, communication history)&lt;/li&gt;
&lt;li&gt;The system cleans and prepares the data.&lt;/li&gt;
&lt;li&gt;The Analyst Agent gets the cleaned data first, and it gives a report.&lt;/li&gt;
&lt;li&gt;The Expert Agent double-checks everything and makes sure the explanation is medically correct and safe.&lt;/li&gt;
&lt;li&gt;The Coach Agent gets the approved explanation and rewrites the message in simple, friendly language&lt;/li&gt;
&lt;li&gt;A final safety filter reviews the message and checks for risky things like any medical diagnosis, unsafe suggestions, and harmful claims.&lt;/li&gt;
&lt;li&gt;I receive the final output.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fspd5g9lkz788hjcvok15.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fspd5g9lkz788hjcvok15.png" alt="pipeline inference" width="800" height="437"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Inference time
&lt;/h3&gt;

&lt;p&gt;During inference — which is just a fancy word for “when the system actually responds to me” — the agents talk to each other almost like coworkers passing notes in a group chat. I don’t see any of this, but it’s happening behind the scenes. The Analyst looks at my raw data and says, “Here’s what I think is happening.” The Domain Expert looks at what the Analyst wrote and either approves it or corrects it. And finally, the Coach turns their combined reasoning into something that sounds human and helpful. What I receive as a single answer is actually the teamwork of multiple roles stitched together.&lt;/p&gt;

&lt;h3&gt;
  
  
  Tools used
&lt;/h3&gt;

&lt;p&gt;To make all of this work, the system relies on a set of tools that help each agent extend its abilities. The Analyst might use data-processing tools to clean and summarize wearable data. The Domain Expert might have access to reference tools that help it compare findings against medical knowledge or validated guidelines. The Coach might use prompt templates designed for empathy, clarity, and motivation. And the main controller uses orchestration tools — something like LangGraph or a custom workflow engine — to decide who talks when and how information flows between them. These tools don’t replace the agents, but they give them structure, context, and external capabilities they wouldn’t have on their own.&lt;/p&gt;

&lt;h3&gt;
  
  
  Collection of data
&lt;/h3&gt;

&lt;p&gt;Everything starts with a real study they ran called &lt;strong&gt;WEAR-ME&lt;/strong&gt;, which included more than a thousand Fitbit users. People had to explicitly opt-in, sign digital consent, link their wearable device, and even go for a blood draw at a Quest Diagnostics center. So the data wasn’t scraped or assumed—it came from real people who agreed to share it for research. That part mattered to me because it made the whole system feel responsible, not rushed.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fozrz0zw4prfut4yef2yk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fozrz0zw4prfut4yef2yk.png" alt="data1" width="799" height="531"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once someone joined the study, their data flowed through a very controlled pipeline.So each person had a mix of: (1) wearable time-series, (2) lab biomarkers, (3) self-reported history, (4) lifestyle questionnaires.&lt;/p&gt;

&lt;p&gt;What I liked is that the system doesn’t directly reach into a live Fitbit account or do anything “real-time.” Instead, the PHA gets access to summaries of the participant’s data, organized into tables—like a daily summary table, an activities table, and even a population-level reference table so the system could compare one user’s values against others in their age group. This gave context, not just raw numbers.&lt;/p&gt;

&lt;p&gt;Inside the actual agent pipeline, each sub-agent only receives the part of the data that’s relevant to its job. The system never dumps the full raw dataset into every agent. Instead, the orchestrator acts like a coordinator who hands the right information to the right specialist. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F34ozz316vec63s0dh1mi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F34ozz316vec63s0dh1mi.png" alt="data2" width="800" height="555"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Nothing is fetched unless the user asks something that genuinely needs it. And the system also avoids asking the user for things it already knows—like their sleep hours or steps—because the orchestrator checks the available data first.&lt;/p&gt;

&lt;h2&gt;
  
  
  PHA vs Gemini Results
&lt;/h2&gt;

&lt;p&gt;PHA wasn’t just a small improvement. It was in a completely different league.&lt;/p&gt;

&lt;p&gt;From the end-user side, I noticed that people consistently picked PHA as the best experience. Not just once or twice — almost half the time. And this is after comparing it side-by-side against a single Gemini agent and a parallel multi-agent system.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftsqsilw9r4hl35m3n5xs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftsqsilw9r4hl35m3n5xs.png" alt="enduser" width="800" height="354"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But the biggest eye-opener for me was the expert evaluation. Experts didn’t just prefer PHA — they almost abandoned the Gemini single-agent baseline. Only around 4–5% of expert rankings put Gemini in first place, while PHA was chosen as #1 about 80% of the time. That’s not a small margin.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5yxu0ccew7z9qmoo2mba.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5yxu0ccew7z9qmoo2mba.png" alt="expUser" width="800" height="336"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Strengths of the system
&lt;/h2&gt;

&lt;p&gt;What struck me most was how real the system felt. Not just in terms of architecture, but in how thoroughly it was tested. It wasn’t a small demo — it involved thousands of human annotations and hundreds of hours of expert evaluation. Because of that, the strengths and limitations felt very honest.&lt;/p&gt;

&lt;p&gt;One of the biggest strengths I noticed is how well the whole system comes together. The three-agent setup — the data scientist, the domain expert, and the coach — isn’t just theoretical. In the evaluations, PHA actually outperformed both a single-agent system and a parallel multi-agent system. End-users preferred talking to PHA almost half the time, and experts loved it even more, choosing it as the best system in about 80% of cases. To me, that says the collaboration between these agents isn’t just helpful — it genuinely changes the quality of the conversation.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcbzp9nzsn8e7xq9ytewz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcbzp9nzsn8e7xq9ytewz.png" alt="daAdv" width="800" height="286"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The data agent in particular felt like a major upgrade. It was much better at breaking down messy, vague health questions into proper statistical analyses, catching missing data, choosing the right timeframes, and generating correct code. I could see why the system became more trustworthy — it wasn’t guessing. It was reasoning over the user’s actual data. And the domain expert agent made a big difference too. It produced safer, more accurate, and more personalized medical explanations. Users rated its responses as far more trustworthy than the base model, and clinicians preferred its summaries because they were more complete and clinically meaningful.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnr1mvix1o1lhgkrxff2f.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnr1mvix1o1lhgkrxff2f.png" alt="domainAdv" width="" height=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The health coach agent also impressed me. It wasn’t just delivering motivational lines. It followed real coaching principles — active listening, SMART goals, motivational interviewing — and this made conversations feel more natural and supportive. Users were more engaged, and the conversations ended more naturally. It reminded me of talking to a real human coach who’s actually paying attention.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpetug6re3d588sbi666a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpetug6re3d588sbi666a.png" alt="coachAdv" width="800" height="723"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As a whole system, PHA feels more thoughtful. The orchestrator doesn’t just mix answers together — it understands the user’s goal, assigns the right agent, reflects on the output, and remembers important details for later turns. This gives the conversation a sense of direction and personalization that the baselines just didn’t have.&lt;/p&gt;

&lt;h2&gt;
  
  
  Limitations of the System
&lt;/h2&gt;

&lt;p&gt;But the system isn’t perfect. One thing that stood out immediately was the cost. PHA is slower and more computationally expensive because each request triggers multiple agents and reflection steps. Where the single-agent system might respond in around 35 seconds, PHA could take over 200. It’s powerful, but not cheap.&lt;/p&gt;

&lt;p&gt;Another limitation is that the diagnostic reasoning, while improved, is still not bulletproof. Sometimes the domain expert agent didn’t complete its reasoning chain, and its reliance on web search occasionally pulled in conflicting information. This reminded me that, even though it acts like a doctor in some ways, it’s not actually one — and the authors make that very clear.&lt;/p&gt;

&lt;p&gt;Bias is also a real concern. The system personalizes advice based on user traits, conditions, and context… which is great, but it also means it can unintentionally repeat patterns or assumptions from datasets that might not represent everyone equally. The paper calls out this risk directly.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjq9spxcb92u8fqw3qlnw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjq9spxcb92u8fqw3qlnw.png" alt="Limitations" width="800" height="437"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The coach agent, despite being strong overall, also had a weakness: it wasn’t great at tracking user progress over time. It did a good job helping set goals, but didn’t always follow up on them in later turns. For long-term coaching, that’s something they’ll need to improve.&lt;/p&gt;

&lt;p&gt;And finally — maybe the biggest limitation — everything was tested in short-term interactions. We don’t yet know whether PHA can support behavior change over weeks or months, which is where health coaching really matters. The team also notes that this is a research framework, not a clinical tool, and major regulatory work would be needed before deploying anything like this in the real world.&lt;/p&gt;

&lt;p&gt;So when I put it all together, here’s how I personally see it:&lt;br&gt;
PHA is a huge improvement over past systems — smarter, safer, more human, and more useful — but it’s still early. It has real strengths, but also real gaps. It’s powerful as an idea, promising as a system, and clearly built with care. But it also reminds me that great AI doesn’t replace medical care — it supports it, and it still has a lot of growing up to do.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;After reading the PHA paper, the biggest thing I realized is that this system isn’t just an AI answering health questions — it feels more like a small team working behind the scenes to help you make sense of your own data. The evaluations show that this multi-agent design really does lead to better, clearer, and more personalized guidance compared to older single-agent approaches.&lt;/p&gt;

&lt;p&gt;At the same time, the authors are very honest about their limits. The system can still make mistakes, it can be biased depending on the data, and it should never replace real medical care. It’s powerful, but it’s also early — more like a research blueprint than a ready product.&lt;/p&gt;

&lt;p&gt;To me, PHA represents a hopeful direction: AI that supports people in understanding their health, not by taking over, but by helping them make smarter choices with empathy, safety, and transparency in mind&lt;/p&gt;

</description>
      <category>ai</category>
      <category>llm</category>
      <category>health</category>
      <category>google</category>
    </item>
    <item>
      <title>PHIA: The Agentic LLM That Writes Code, Analyzes Your Data &amp; Explains Health Insights</title>
      <dc:creator>Mitansh Gor</dc:creator>
      <pubDate>Thu, 27 Nov 2025 05:33:34 +0000</pubDate>
      <link>https://dev.to/mitanshgor/phia-the-agentic-llm-that-writes-code-analyzes-your-data-explains-health-insights-4g1a</link>
      <guid>https://dev.to/mitanshgor/phia-the-agentic-llm-that-writes-code-analyzes-your-data-explains-health-insights-4g1a</guid>
      <description>&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=UR2MTLJ1d4E" rel="noopener noreferrer"&gt;VIDEO LINK&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I honestly felt like I was looking at the “next version” of what health AI should be. Whenever I asked myself questions like, “Is my sleep improving?” or “Does exercising at night change my deep sleep?”, I realized how hard it is to answer these without real analysis.&lt;/p&gt;

&lt;p&gt;That is exactly the problem the PHIA team talks about on page 1 of the paper. They explain that even a simple question like “Do I sleep better after exercising?” requires many steps: checking recent data, comparing different days, calculating metrics, and then interpreting everything in the context of what “healthy” even means. And honestly, I could relate — that’s the kind of analysis I never do on my own.&lt;br&gt;
What really caught my attention is that the paper says today’s LLMs struggle with numerical reasoning, meaning they often miscalculate or oversimplify things. I’ve definitely seen models do that — giving a confident answer but completely messing up basic math. (Limitation of PH-LLM)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fijr3r0wiwgfamfnpd0dv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fijr3r0wiwgfamfnpd0dv.png" alt="int" width="800" height="453"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So PHIA tries to fix this problem by giving an LLM the ability to plan, use tools, write code, and search the web. It doesn’t just “chat.” It becomes more like a small data analyst that works with your wearable data step-by-step.&lt;/p&gt;

&lt;h2&gt;
  
  
  PH-LLM vs PHIA
&lt;/h2&gt;

&lt;p&gt;PH-LLM was an earlier coaching system that worked only with simple, pre-aggregated 30-day summaries and relied purely on the LLM’s internal reasoning. That meant it couldn’t actually analyze detailed daily wearable data, couldn’t run calculations, and completely failed on questions that required numbers or step-by-step reasoning. PHIA addresses these limitations by granting the LLM three new capabilities: (1) it can generate authentic Python code to analyze raw wearable data, (2) it can plan and break down tasks using an agent loop, and it can search the web to incorporate fresh, verified health knowledge.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj8xekitn7246fd5p1e9k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj8xekitn7246fd5p1e9k.png" alt="difference" width="800" height="552"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Because of this, PHIA shifts from being “just a health coach” to becoming a true data analyst + coach, delivering insights that are more accurate, personalized, and grounded in both the user’s data and real health science. PHIA feels like the bridge between “AI as a friendly coach” and “AI as a personal data scientist.” By mixing reasoning, code execution, and web search, it finally unlocks the kind of deeper, more accurate insights that wearables have always had the potential to provide.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnqkihmir6plcn25xlyp4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnqkihmir6plcn25xlyp4.png" alt="diff" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How PHIA Works
&lt;/h2&gt;

&lt;p&gt;PHIA more like a mini health data analyst that can think step-by-step, write code, check your wearable data, search the web, and then explain everything in normal language. The PHIA paper shows this clearly — PHIA literally cycles through think → act → observe just like a human analyst would.&lt;/p&gt;

&lt;p&gt;I’ll explain this in the simple way I understood it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft9fqs7m9hl4jtzdwrc61.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft9fqs7m9hl4jtzdwrc61.png" alt="ReAct" width="799" height="571"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Instead of guessing answers, PHIA acts more like a small data analyst that plans its steps, checks your wearable data, and only then explains what it found. The paper describes this using the ReAct loop— &lt;strong&gt;Thought → Action → Observation&lt;/strong&gt; — and seeing it in action helped me understand why PHIA is so different.&lt;/p&gt;

&lt;p&gt;PHIA starts by thinking through the question. If I ask something like “Is my resting heart rate improving?”, it doesn’t jump to a quick reply. It pauses and decides what it needs—maybe comparing two weeks of data or calculating averages. Then, PHIA takes action by writing and running Python code in a safe &lt;strong&gt;virtual environment tool&lt;/strong&gt;. This lets it analyze real daily time-series data using Pandas, just like a real data scientist. The nice part is that this removes mathematical mistakes that normal LLMs often make. And if its code crashes, PHIA actually fixes the error and tries again (&lt;u&gt;recurrent trials system&lt;/u&gt;), which the paper highlights as one of its strengths.&lt;/p&gt;

&lt;p&gt;In their evaluation, PHIA scored &lt;strong&gt;84% accuracy&lt;/strong&gt; on objective questions, way higher than simple LLM reasoning. This happens because PHIA can recover when the code fails.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5p6ma2p9tzg1o75gjizq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5p6ma2p9tzg1o75gjizq.png" alt="ReAct Arch" width="799" height="375"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When a question requires more than numbers—like understanding recommended sleep hours—PHIA uses a built-in web &lt;strong&gt;search tool&lt;/strong&gt; to fetch verified information from trusted sources.  Sometimes the user needs context, like: “Is this amount of sleep normal for my age?” “What workouts improve resting heart rate?” “Is my stress score healthy?”&lt;br&gt;
PHIA has a built-in search tool that pulls information from verified online sources. This mixing of data + domain knowledge is what makes PHIA feel smart and practical.&lt;/p&gt;

&lt;p&gt;What impressed me most is how PHIA blends everything together. It doesn’t just give numbers or copy facts. It calculates, it checks, it researches, and then it explains the result in clear language. The examples in the paper, like &lt;u&gt;comparing a user’s sleep with national guidelines&lt;/u&gt;, really show how these steps come together. In the end, PHIA feels less like a chatbot and more like someone doing careful, step-by-step reasoning to help you understand your own health patterns.&lt;/p&gt;

&lt;h2&gt;
  
  
  A Deep Dive Into PHIA’s Technical Architecture
&lt;/h2&gt;

&lt;p&gt;PHIA is not a fine-tuned model. It’s an agent framework built around &lt;strong&gt;&lt;u&gt;Gemini 1.0 Ultra&lt;/u&gt;&lt;/strong&gt;, with two major tools: (1) Python data analysis runtime, (2) Web search tool.&lt;/p&gt;

&lt;p&gt;These tools are orchestrated using the ReAct (Reason + Act) agent pattern, which is why PHIA can do multi-step reasoning without fine-tuning. This design gives PHIA abilities that raw LLMs don’t have: planning, correction, stepwise attention, and grounded analysis.&lt;/p&gt;

&lt;h3&gt;
  
  
  No Fintuning
&lt;/h3&gt;

&lt;p&gt;One of the most interesting things I learned from the paper is that PHIA is not fine-tuned like PH-LLM. Instead of modifying the model’s weights, the authors built a smart scaffolding around the model and taught it how to act like an agent.&lt;/p&gt;

&lt;p&gt;Fine-tuning a huge LLM like Gemini Ultra is expensive, slow, requires tons of supervised data, and risky (can break general reasoning ability).&lt;/p&gt;

&lt;p&gt;So instead, PHIA keeps the base model untouched and teaches the model how it should “think” and use tools using few-shot ReAct examples.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;This is a totally different philosophy: PH-LLM → change the model. PHIA → change the system around the model&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Process
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;The authors started with thousands of wearable-related questions (objective + open-ended). They needed a tiny set of example tasks that could teach the model how to behave like an agent.&lt;/li&gt;
&lt;li&gt;Instead of randomly picking examples, they converted every question into numerical embeddings using Sentence-T5. This turns each question into a vector representing its meaning, so similar questions sit close together in vector space.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flpyn3yfndl2r7mcb4vox.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flpyn3yfndl2r7mcb4vox.png" alt="Process" width="800" height="427"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;They ran k-means clustering (k=20) on these embeddings to automatically group similar questions into 20 clusters. Each cluster represents a whole “type” of question, like sleep trends, workout comparisons, anomaly detection, correlations, and so on.&lt;/li&gt;
&lt;li&gt;From each cluster, they selected the most central question — the one closest to the cluster centroid.This gives 20 representative queries, each standing in for a larger family of similar queries.&lt;/li&gt;
&lt;li&gt;For each of these 20 representative queries, the team manually wrote a complete ReAct agent trajectory that included every step of reasoning:

&lt;ul&gt;
&lt;li&gt;Thought: what the model should plan to do&lt;/li&gt;
&lt;li&gt;Action (Python): the exact Pandas code needed&lt;/li&gt;
&lt;li&gt;Observation: the real output that the code would return&lt;/li&gt;
&lt;li&gt;Thought again: interpreting the output&lt;/li&gt;
&lt;li&gt;Action (Search): when domain knowledge is needed&lt;/li&gt;
&lt;li&gt;Observation: the retrieved information&lt;/li&gt;
&lt;li&gt;Final Answer: a clear, natural-language explanation. These aren’t partial examples — they are full step-by-step walkthroughs that demonstrate how an agent should behave.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;These 20 full trajectories were inserted into PHIA’s few-shot prompt, acting as demonstrations inside its system instructions. So the model is not fine-tuned — instead, it is taught by example how to: plan before acting, decide when to run code, decide when to search the web, fix code errors, combine numerical results with domain knowledge, and produce a final personalized insight.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;This is called “behavior cloning via prompting.” : It will learn the “pattern of behavior” from the examples, even without changing its internal parameters.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;PHIA is a perfect example of how powerful LLMs become when they are paired with the right scaffolding instead of relying only on internal reasoning. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpezd2e5c7ozuk7p1ljgh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpezd2e5c7ozuk7p1ljgh.png" alt="graph" width="800" height="697"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Limitations in the PHIA
&lt;/h2&gt;

&lt;p&gt;PHIA is a huge step forward, especially compared to simple chat-based coaching. But it’s still early-stage. It shows what’s possible when LLMs use tools, but it also exposes how much work is left to make an AI truly trustworthy in personal health.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;PHIA hasn’t been tested on real people yet, so we still don’t know if it truly helps users change habits or understand their health better in everyday life.&lt;/li&gt;
&lt;li&gt;It only uses wearable data, and I feel it needs more context—like nutrition, medical records, or mood logs—to give deeper and more holistic insights.&lt;/li&gt;
&lt;li&gt;PHIA isn’t medically validated, so even though it sounds smart, its recommendations haven’t been checked by doctors or health experts for real accuracy. Personalization still feels limited, because sometimes PHIA gives generic advice even when the user’s data is available right there.&lt;/li&gt;
&lt;li&gt;Its reasoning depends heavily on prompting and Gemini Ultra, which means its behavior might change across models or updates, making it less consistent.&lt;/li&gt;
&lt;li&gt;Error handling is better than basic LLMs but still imperfect, since PHIA can misread data columns or fail on messy real-world data.&lt;/li&gt;
&lt;li&gt;Its toolset is still narrow, and I’d love to see it generate visualizations, analyze other health signals, or track long-term goals instead of just answering one question at a time.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Learnings from the paper
&lt;/h2&gt;

&lt;p&gt;Reading the PHIA paper honestly changed the way I think about building AI systems. Before this, I used to focus mainly on making the model smarter, but PHIA showed me that the real progress comes from giving the model the right tools and the right structure. Seeing how PHIA uses the ReAct loop—think, act, observe—made me realize how important disciplined reasoning is for avoiding hallucinations and building trust.&lt;/p&gt;

&lt;p&gt;The use of synthetic data was another eye-opener, because it proved that we can train and evaluate personal-health agents responsibly without touching real user data. On top of that, the way the authors handled safety—650 hours of human review, strict guardrails, and cautious refusal behavior—reminded me that responsible AI isn’t optional; it’s part of the engineering.&lt;/p&gt;

&lt;p&gt;More than anything, PHIA taught me that the future of AI isn’t “a bigger model,” but a system where models, tools, data, and reasoning frameworks all work together. As an AI engineer, this shifted how I think about agents: not as chatbots, but as full pipelines designed to solve real problems with accuracy, humility, and safety.&lt;/p&gt;

&lt;h2&gt;
  
  
  Key Insights I’m Taking With Me
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;PHIA wins because it’s structured, not because the LLM is smarter.&lt;/li&gt;
&lt;li&gt;Reasoning and architecture beat raw model size.&lt;/li&gt;
&lt;li&gt;PHIA shines when a question needs data + external knowledge + multi-step logic, not just basic statistics.&lt;/li&gt;
&lt;li&gt;Its real strength is disciplined reasoning, not raw computation.&lt;/li&gt;
&lt;li&gt;PHIA’s strict safety guardrails make it trustworthy in a way normal LLMs aren’t.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>ai</category>
      <category>llm</category>
      <category>google</category>
      <category>health</category>
    </item>
    <item>
      <title>PH-LLM - A LLM that gives personalized sleep and fitness coaching using wearable data.</title>
      <dc:creator>Mitansh Gor</dc:creator>
      <pubDate>Thu, 27 Nov 2025 05:32:57 +0000</pubDate>
      <link>https://dev.to/mitanshgor/ph-llm-a-llm-that-gives-personalized-sleep-and-fitness-coaching-using-wearable-data-2m7f</link>
      <guid>https://dev.to/mitanshgor/ph-llm-a-llm-that-gives-personalized-sleep-and-fitness-coaching-using-wearable-data-2m7f</guid>
      <description>&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=G-n7BMqxJqk" rel="noopener noreferrer"&gt;VIDEO LINK&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;PH-LLM (Personal Health Large Language Model) is a version of Gemini Ultra that has been fine-tuned specifically for sleep and fitness coaching. It isn’t just chatting—it actually learns from up to 30 days of wearable data, understands your patterns, and gives expert-level insights. The research paper shows PH-LLM scoring 79% on sleep medicine exams and 88% on fitness exams, which is on par or better than the expert groups they tested with.&lt;/p&gt;

&lt;p&gt;What really caught my interest is that the system can:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;analyze daily-resolution sensor data&lt;/li&gt;
&lt;li&gt;generate personalized insights&lt;/li&gt;
&lt;li&gt;Predict how rested or tired you will feel based only on wearable data and speak to you like a sleep coach or fitness expert.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj5efo1s358xmkr5lfp16.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj5efo1s358xmkr5lfp16.png" alt="system can solve 3 tasks" width="799" height="389"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What Problem PH-LLM Tries to Solve
&lt;/h2&gt;

&lt;p&gt;Wearables track you, but they don’t talk to you. They tell you what happened, but not why it happened or how to fix it. PH-LLM aims to act like a personal health coach — one that understands your data, your patterns, your goals, and the science behind all of it.&lt;/p&gt;

&lt;p&gt;Instead of treating sensor data like random numbers on a dashboard, it tries to interpret them the way a human expert would. If your bedtime has been drifting later over the past two weeks, or your deep sleep dropped right after you increased workout intensity, PH-LLM doesn’t just point it out — it explains why it happened and how it connects to your goals. It transforms passive metrics into an actual conversation about your habits.&lt;/p&gt;

&lt;p&gt;The system was trained specifically for this kind of reasoning. The researchers fine-tuned Gemini Ultra so it could combine textbook knowledge with real-world wearable data. Interestingly, PH-LLM doesn’t just “sound smart.” In testing, it actually outperformed sleep experts on sleep medicine exam questions and matched them in fitness knowledge. That means the model isn’t just giving generic advice — it has a near-expert understanding of the underlying science.&lt;/p&gt;

&lt;p&gt;But what really makes PH-LLM different is that it doesn’t stop at general knowledge. It looks at a person’s actual patterns over weeks. If you always sleep well on weekdays but crash on weekends, it's noticeable. If your HRV is dropping while your workouts are getting harder, it connects the dots. In one of the paper’s examples, the model realized a user had a very regular sleep schedule but consistently slept too little, and it suggested shifting bedtime by small increments rather than giving a one-size-fits-all rule. That’s the kind of nuance real coaches provide, but most apps don’t.&lt;/p&gt;

&lt;h2&gt;
  
  
  High-level Working of the PH-LLM
&lt;/h2&gt;

&lt;p&gt;Researchers took Gemini Ultra — a very capable general-purpose model — and taught it how to understand sleep and fitness the same way a human expert would. They basically turned a large language model into a personal health specialist.&lt;/p&gt;

&lt;p&gt;The process happened in two major steps. First, they fine-tuned the entire Gemini Ultra model on hundreds of detailed sleep and fitness case studies. These weren’t made-up examples — each case study was based on real wearable data from real people. The case studies included up to thirty days of information such as bedtimes, wake times, restlessness, workout intensity, heart rate metrics, and more. Alongside the data, sleep physicians and athletic trainers wrote expert-level insights, possible causes, and recommendations. These human-written explanations became the “teacher examples” that the model learned from. By imitating these expert responses over and over, PH-LLM learned how to talk like a coach and reason like one too.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy98wa021cc4x12jo4c5a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy98wa021cc4x12jo4c5a.png" alt="case study" width="800" height="277"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After this, the researchers added a second layer of training using something called a multimodal adapter. This part fascinated me because it let the model go beyond simple text input. Instead of only reading written summaries of the user’s data, PH-LLM also receives a compressed representation of the actual sensor values — the statistical patterns hidden in daily heart rate, HRV, sleep duration, respiratory rate, and other signals across fifteen days. These adapter-generated “soft tokens” get injected directly into the LLM’s internal understanding. In simple terms, the model doesn’t just read your data — it absorbs it. This is how PH-LLM can predict things like “Will this person feel tired tomorrow?” with accuracy on par with traditional machine learning approaches.&lt;/p&gt;

&lt;p&gt;The result of these two training phases is a model that can look at your daily metrics and instantly form a holistic picture. If your bedtime keeps drifting later, PH-LLM notices. If your deep sleep drops right after your workout intensity spikes, it picks up the relationship. If your HRV has been declining all week, it connects that to stress, recovery, or the need for rest. What impressed me is that PH-LLM isn’t just matching patterns — it can articulate the reasoning behind them, almost like an expert thinking out loud.&lt;/p&gt;

&lt;p&gt;The paper shows a great example of this. For one user, the model pointed out that the midsleep point was extremely consistent — meaning their circadian rhythm was stable — but their total sleep time was consistently too low. From there, PH-LLM suggested a gradual shift in bedtime over several days. This wasn’t a generic “try to sleep more” tip; it was a specific plan tailored to what the data actually showed. That kind of reasoning is the whole point of the system.&lt;/p&gt;

&lt;p&gt;Another thing I appreciated is that PH-LLM adapts its responses based on how much data it has. When the researchers removed parts of the input — like today’s sleep metrics or the last week of workout logs — PH-LLM still adjusted its explanations in a sensible way. To me, this shows that the model doesn’t rely on memorized patterns but actually understands the structure of sleep and fitness behavior.&lt;/p&gt;

&lt;h2&gt;
  
  
  Technical Working
&lt;/h2&gt;

&lt;p&gt;The foundation of PH-LLM is Gemini Ultra 1.0, Google’s flagship multimodal model. In this work, it functions mainly as a text LLM (the vision-side is not used). Structurally, it’s a Transformer decoder with extremely large context and token embedding dimensions. This gives it the capacity needed to reason across long-form case studies, sleep explanations, and multi-step fitness logic.&lt;/p&gt;

&lt;p&gt;The base model (Gemini Ultra 1.0) already has strong performance in medical question answering and general health reasoning. But by itself, it doesn’t know how to interpret raw wearable data — it needs domain-specific training.&lt;/p&gt;

&lt;h3&gt;
  
  
  Finetuning
&lt;/h3&gt;

&lt;p&gt;The first major training step is a full-parameter finetuning of Gemini Ultra on 857 expert-annotated sleep and fitness case studies. Each case study includes: (1) Up to 30 days of daily metrics, (2) Aggregated (mean, variance, percentiles) statistics, (3) Expert-written insights, etiologies, and recommendations. This dataset is unique because each example combines real sensor patterns with expert-level reasoning. When the researchers fine-tuned the model, they essentially taught it:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“When you see patterns like this in the data, here’s how a real sleep doctor or athletic trainer explains it.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2r28f6w5d75qwklf8o5e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2r28f6w5d75qwklf8o5e.png" alt="Fine Tuned" width="800" height="237"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To teach Gemini Ultra how to behave like a real sleep and fitness coach, the researchers fine-tuned the entire model—not just a small part of it—using a large collection of expert-written examples. Each example paired a user’s real wearable data with the exact explanation a sleep doctor or athletic trainer would give. There were about thirteen hundred of these pairs for sleep and fifteen hundred for fitness, and the model was trained on them over roughly fifteen hundred optimization steps. Instead of using shortcuts like LoRA, they updated all of the model’s weights directly, following a smooth cosine schedule for the learning rate so the model gradually stabilized as it learned. After this full training process, the base Gemini model effectively “became” PH-LLM: an LLM that now understands how to read multi-day sensor patterns and talk like a personal health expert.&lt;/p&gt;

&lt;h3&gt;
  
  
  Multimodal Adapter for Sensor Data
&lt;/h3&gt;

&lt;p&gt;Once PH-LLM can generate coaching advice, the second challenge is enabling it to interpret raw numerical sensor data for prediction tasks (like estimating how tired someone will feel).&lt;/p&gt;

&lt;p&gt;To do this, the researchers added a custom MLP-based multimodal adapter. This is the most “technical” part of the architecture.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvb7hndcteg79bo0a1qgn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvb7hndcteg79bo0a1qgn.png" alt="Multimodal Adapter" width="800" height="437"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;How the adapter works:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;For each of the 20 wearable sensor signals (HRV, resting HR, sleep duration, etc.), the system collects 15 days of values.&lt;/li&gt;
&lt;li&gt;It computes standardized mean and variance for each signal.&lt;/li&gt;
&lt;li&gt;These 40 numbers (20 means + 20 variances) feed into a multi-layer perceptron (MLP):

&lt;ul&gt;
&lt;li&gt;Input: 40&lt;/li&gt;
&lt;li&gt;Hidden layers: 1024 → 4096 → 1024 (ReLU activations)&lt;/li&gt;
&lt;li&gt;Output: 4 “soft tokens,” each of size 14,336 (the embedding size of PH-LLM).&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;These 4 soft tokens are prepended to the text input as if they were real tokens.&lt;/li&gt;
&lt;li&gt;The LLM then processes the numerical data inside its own embedding space, letting its reasoning layers combine subjective sleep patterns with wearable readings&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;The LLM never sees raw numbers — it sees learned embeddings representing the person’s physiological state. This allows PH-LLM to achieve machine-learning level accuracy in predicting subjective sleep outcomes, without needing a separate ML pipeline.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Input Format and Context Handling
&lt;/h3&gt;

&lt;p&gt;The system uses two kinds of input representations:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Textual Representations

&lt;ul&gt;
&lt;li&gt;Daily tables written out in text&lt;/li&gt;
&lt;li&gt;Time ranges (bedtime, sleep duration)&lt;/li&gt;
&lt;li&gt;Percentile comparisons&lt;/li&gt;
&lt;li&gt;Metric summaries&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Soft Token Representation via Adapter

&lt;ul&gt;
&lt;li&gt;Encodes underlying numerical structure&lt;/li&gt;
&lt;li&gt;Injected directly into the model’s attention layers&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwyollwpfqcdqvz3ggyqf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwyollwpfqcdqvz3ggyqf.png" alt="input format" width="800" height="437"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Because PH-LLM was trained on long, structured case studies, it naturally handles: multi-day patterns, variations in missing data, differences in available context.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Output Structure
&lt;/h3&gt;

&lt;p&gt;PH-LLM produces multi-part responses in the same structure experts use:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Insights: Patterns detected in the data&lt;/li&gt;
&lt;li&gt;Etiology: Possible causes based on sleep medicine frameworks (like RU-SATED)&lt;/li&gt;
&lt;li&gt;Recommendations: Personalized, SMART-style advice&lt;/li&gt;
&lt;li&gt;Readiness Scoring (Fitness): Evaluation of fatigue, HRV trends, and recovery loads&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Full7svmjpuvkmtlv0ek4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Full7svmjpuvkmtlv0ek4.png" alt="output structure" width="800" height="437"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Because the model was trained on structured expert templates, it learns to produce cohesive, medically-grounded narratives instead of generic advice.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Evaluation Architecture
&lt;/h3&gt;

&lt;p&gt;The team built a secondary system called &lt;strong&gt;AutoEval&lt;/strong&gt;, which is an LLM finetuned to grade PH-LLM’s responses against expert criteria. This created an automated loop for model validation, enabling: fast benchmarking, ablation studies, large-scale quality scoring.&lt;br&gt;
AutoEval itself is built using Gemini Pro with LoRA finetuning&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fflzsbauapv7l5oq46m0x.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fflzsbauapv7l5oq46m0x.png" alt="Evaluation Arch" width="800" height="271"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Strengths of the system
&lt;/h2&gt;

&lt;p&gt;What I like most about PH-LLM is how personal it feels. Instead of giving generic sleep or fitness advice, it actually looks at your patterns over weeks and speaks to you the way a real coach would. When it notices your bedtime shifting or your deep sleep dropping after intense workouts, it doesn’t just state the numbers—it explains what those changes mean and why they matter.&lt;/p&gt;

&lt;p&gt;The system’s expert-level reasoning also stands out. In the paper, PH-LLM &lt;strong&gt;performs as well as or better than trained professionals&lt;/strong&gt; on board-style sleep and fitness exams, scoring &lt;u&gt;79% in sleep medicine&lt;/u&gt; and &lt;u&gt;88% in fitness&lt;/u&gt;. This gives its recommendations a level of credibility that most consumer health apps don’t have.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu1yk9ktks5jjb3gl55nj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu1yk9ktks5jjb3gl55nj.png" alt="trained professionals vs PHLLM" width="800" height="198"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Another strength is how smoothly it blends wearable data with human-like reasoning. Using the multimodal adapter, PH-LLM can predict subjective feelings like tiredness or restfulness based purely on sensor trends, something even many traditional ML models struggle with.&lt;/p&gt;

&lt;p&gt;Finally, PH-LLM adapts well when information is missing or incomplete. The paper shows that when certain sleep or workout metrics are removed, the model still adjusts its reasoning instead of failing outright. That flexibility makes it feel more intelligent and reliable, almost like it truly understands how sleep and fitness behaviors change from day to day.&lt;/p&gt;

&lt;h2&gt;
  
  
  Limitations
&lt;/h2&gt;

&lt;p&gt;The biggest one, in my opinion, is its dependence on the quality of the wearable data itself. If your device misreads your sleep stages or your heart rate jumps around because the watch wasn’t snug, PH-LLM will still try to interpret that noise as if it’s meaningful. The paper even points out that the model sometimes references data incorrectly or forms conclusions that don’t perfectly match the input — small confabulations that become more noticeable when the data is messy&lt;/p&gt;

&lt;p&gt;Another issue is that the model sometimes struggles with consistency when giving recommendations. For sleep insights, the fine-tuning helped a lot, but for fitness coaching the improvements were smaller, and in certain sections like “training load,” PH-LLM actually performed worse than the base Gemini model and human experts.&lt;strong&gt;&lt;u&gt; That tells me the model doesn’t fully grasp every fitness scenario as deeply as it understands sleep patterns.&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The paper itself admits there were demographic skews — more middle-aged users, fewer younger or older participants, and no information about race or ethnicity. That means the &lt;strong&gt;eva&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;And finally, there’s the broader limitation that PH-LLM, no matter how smart it sounds, is not a medical device. It can give coaching-style suggestions, but it isn’t validated for clinical decision-making. Sometimes its tone feels authoritative, which can make the advice sound more medically precise than it actually is.&lt;/p&gt;

&lt;h2&gt;
  
  
  Final Takeaways
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fprfuqfo9k4xwc0ftalxb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fprfuqfo9k4xwc0ftalxb.png" alt="summarize" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What impressed me most is the model’s ability to turn a messy week of habits into a simple, actionable story. It doesn’t lecture or overwhelm. It just explains what’s going on and nudges you in the right direction. At the same time, it’s important to remember that PH-LLM isn’t a medical system. It still makes small mistakes, relies heavily on the data it sees, and carries the biases of the Fitbit-dominated population it was trained on.&lt;/p&gt;

&lt;p&gt;But the core idea feels powerful. PH-LLM represents a shift from “apps that measure you” to “systems that understand you.” This paper is a glimpse of where personal health AI is heading, and it sets a strong foundation for the next models I’ll be reviewing in this series. As I move into PHIA, the IR Explainer Agent, and later multi-agent systems, I can already see how all these ideas start to connect. PH-LLM feels like the first major building block in creating an AI that doesn’t just track your health—but helps you improve it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Links
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Data + code: &lt;a href="https://github.com/google-health/consumer-health-research" rel="noopener noreferrer"&gt;https://github.com/google-health/consumer-health-research&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;NSCA: &lt;a href="https://www.nsca.com/certification/cscs/certified-strength-and-conditioning-specialist-exam-description" rel="noopener noreferrer"&gt;https://www.nsca.com/certification/cscs/certified-strength-and-conditioning-specialist-exam-description&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Healthcare Board Exam: &lt;a href="https://www.boardvitals.com/" rel="noopener noreferrer"&gt;https://www.boardvitals.com/&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>google</category>
      <category>ai</category>
      <category>health</category>
      <category>llm</category>
    </item>
    <item>
      <title>AI for Personal Health — My Review, Reflections &amp; Real-Life Understanding</title>
      <dc:creator>Mitansh Gor</dc:creator>
      <pubDate>Thu, 27 Nov 2025 05:32:31 +0000</pubDate>
      <link>https://dev.to/mitanshgor/ai-for-personal-health-my-review-reflections-real-life-understanding-12kh</link>
      <guid>https://dev.to/mitanshgor/ai-for-personal-health-my-review-reflections-real-life-understanding-12kh</guid>
      <description>&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=0JXDsAcQ6JU" rel="noopener noreferrer"&gt;VIDEO LINK&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;1. Introduction&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;I’ve been using wearables like Fitbit and Pixel Watch for a while, and I’ve always had the same question in the back of my mind:&lt;br&gt;
&lt;strong&gt;“These devices collect so much data… but what does it actually mean for my health?”&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I could see my steps, sleep score, heart rate, all the usual numbers — but I didn’t really know how to connect them to real insights about my body. That curiosity is what pulled me into this world of AI for personal health.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft2fxpfyi8zq3goovtaoh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft2fxpfyi8zq3goovtaoh.png" alt="i am personal coach" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As I started reading research papers and experimenting with data, I realized something important:&lt;br&gt;
&lt;strong&gt;AI is slowly becoming the “missing link” between raw wearable data and actual, useful guidance.&lt;/strong&gt;&lt;br&gt;
It can interpret patterns, explain them in simple language, and sometimes even coach you like a personal guide.&lt;/p&gt;

&lt;p&gt;This blog series is my attempt to share what I learned — not as a researcher writing a formal report, but as a student trying to make sense of a fast-moving field in a friendly, simple way.&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;What This Series Will Cover (Based on the Timeline of Publications)&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;I studied four papers and mapped out how AI in personal health evolved over the past few years.&lt;br&gt;
Here’s the order I’ll follow in this series — from earlier work to the most recent:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7pkx6pw5z4uwcispwd3v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7pkx6pw5z4uwcispwd3v.png" alt="timeline" width="800" height="437"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Intro Blog (this one)&lt;/strong&gt; - Why I’m exploring this topic and how the whole series is structured.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Blog 1 (2024)&lt;/strong&gt; — &lt;strong&gt;PH-LLM&lt;/strong&gt; - A large language model that gives personalized sleep and fitness coaching using wearable data.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Blog 2 (2024)&lt;/strong&gt; — &lt;strong&gt;PHIA&lt;/strong&gt; - An agentic LLM that writes code, analyzes your data, and turns it into meaningful health insights.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Blog 3 (2025)&lt;/strong&gt; — &lt;strong&gt;IR Prediction + IR Explainer Agent&lt;/strong&gt; - A combination of machine learning and an LLM-based explainer to estimate metabolic risk.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Blog 4 (2025)&lt;/strong&gt; — &lt;strong&gt;Personal Health Agent (PHA)&lt;/strong&gt; - A multi-agent system where different AI “roles” collaborate — data analyst, coach, and domain expert.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Blog 5 (My Project, 2025)&lt;/strong&gt; - My own proof-of-concept that mixes ideas from all four systems to create a unified health agent architecture. My goal is to keep everything straightforward, even if someone is reading about AI for the first time.&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;Why This Topic Matters (and What I Hope You’ll Learn)&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Most of us don’t think much about our health until something feels wrong. But our wearables are quietly tracking us every day — our sleep, heart rate, movement, and even stress signals. That means they’re collecting clues long before we ever feel anything.&lt;/p&gt;

&lt;p&gt;AI can turn those clues into something meaningful by noticing patterns we might miss, predicting early risks, explaining things in plain English, and even giving small suggestions that feel personal. To me, this makes health feel more understandable and less like a set of random numbers.&lt;/p&gt;

&lt;p&gt;Through this series, I want to share what I learned about these systems in a simple, relatable way. I’ll talk about how wearables work with AI, how different models make sense of health data, why LLMs and multi-agent systems matter, where the ethical issues show up, and how these ideas connect to real projects.&lt;/p&gt;

&lt;p&gt;I’m writing as a student — sharing what made sense to me, what confused me at first, and what finally “clicked.”  And at the end of the series, I’ll also walk through my own proof-of-concept project where I combine everything I learned into one architecture.&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;10. References&lt;/strong&gt;
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;PH-LLM: A Personal Health LLM for Sleep &amp;amp; Fitness Coaching&lt;br&gt;
Nature Medicine (2025)&lt;br&gt;
&lt;a href="https://www.nature.com/articles/s41591-025-03888-0" rel="noopener noreferrer"&gt;https://www.nature.com/articles/s41591-025-03888-0&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;PHIA: Transforming Wearable Data into Health Insights Using LLM Agents&lt;br&gt;
Google Research Blog (2024)&lt;br&gt;
&lt;a href="https://research.google/blog/advancing-personal-health-and-wellness-insights-with-ai/" rel="noopener noreferrer"&gt;https://research.google/blog/advancing-personal-health-and-wellness-insights-with-ai/&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;SHARP Framework: Principles for Building Health &amp;amp; Wellness LLMs&lt;br&gt;
Google (2025)&lt;br&gt;
&lt;a href="https://services.google.com/fh/files/blogs/winslow_2025_sharp_framework.pdf" rel="noopener noreferrer"&gt;https://services.google.com/fh/files/blogs/winslow_2025_sharp_framework.pdf&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Insulin Resistance Prediction From Wearables + Routine Blood Biomarkers&lt;br&gt;
arXiv (2025)&lt;br&gt;
&lt;a href="https://arxiv.org/pdf/2505.03784" rel="noopener noreferrer"&gt;https://arxiv.org/pdf/2505.03784&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Personal Health Agent (PHA): Multi-Agent System for Data + Coaching + Expertise&lt;br&gt;
arXiv (2025)&lt;br&gt;
&lt;a href="https://arxiv.org/pdf/2508.20148" rel="noopener noreferrer"&gt;https://arxiv.org/pdf/2508.20148&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>google</category>
      <category>llm</category>
      <category>health</category>
      <category>ai</category>
    </item>
    <item>
      <title>Nested Learning — My Reflections on a Model That Learns How to Learn</title>
      <dc:creator>Mitansh Gor</dc:creator>
      <pubDate>Mon, 17 Nov 2025 02:57:13 +0000</pubDate>
      <link>https://dev.to/mitanshgor/nested-learning-my-reflections-on-a-model-that-learns-how-to-learn-14b5</link>
      <guid>https://dev.to/mitanshgor/nested-learning-my-reflections-on-a-model-that-learns-how-to-learn-14b5</guid>
      <description>&lt;p&gt;I recently came across a paper called &lt;a href="https://research.google/blog/introducing-nested-learning-a-new-ml-paradigm-for-continual-learning/" rel="noopener noreferrer"&gt;&lt;strong&gt;Nested Learning: The Illusion of Deep Learning&lt;/strong&gt;&lt;/a&gt; by Behrouz and the team — the same researchers behind Titans and Atlas. It really caught my attention because it challenges what we usually think “deep learning” means. The paper says that depth in neural networks isn’t just about stacking layers — it’s about how many layers of learning the system can apply to itself. Instead of just updating weights, this model learns how to improve its own learning process.&lt;/p&gt;

&lt;p&gt;While reading it, I realized this isn’t just another optimization trick. It actually feels like a glimpse into what real intelligence could be — an AI that doesn’t just react but reflects, improves, and evolves how it learns over time. The authors even built a prototype called Hope, a model that modifies itself using feedback, learning not just what to learn but how to learn better.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F65zccs9kcg5k6ilukwrf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F65zccs9kcg5k6ilukwrf.png" alt="LearningToLearn" width="389" height="220"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Take on the Problems in Deep Learning and Transformers
&lt;/h2&gt;

&lt;p&gt;Today’s deep learning systems — even transformers — are strong but still limited in how they actually learn.&lt;/p&gt;

&lt;p&gt;Neural networks are called “deep” because of their layers, but their learning is flat — one optimizer like Adam or SGD updates everything the same way. Once training ends, the model stops learning, like a student who graduates and never studies again. :)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm5sr0zxhnevjaum8ho0v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm5sr0zxhnevjaum8ho0v.png" alt="contextWindow" width="800" height="600"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Transformers improved context handling, but they only have short-term memory. They remember what’s inside their context window and forget the rest. Even if I teach GPT something new, it won’t remember it next time — its knowledge is frozen.&lt;/p&gt;

&lt;p&gt;To me, that’s what makes this paper exciting. It explores real, continuous learning, where models don’t just perform tasks but actually grow and evolve from their experiences — more like how the human brain learns over time.&lt;/p&gt;

&lt;h2&gt;
  
  
  How the Human Brain Actually Learns
&lt;/h2&gt;

&lt;p&gt;When I compared this idea to how our brain works, the difference was clear. The brain doesn’t just store facts — it keeps updating how it learns from every experience. Each new moment changes not only what we know but how we learn next time.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frc2xjpat5qyf0uesc61o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frc2xjpat5qyf0uesc61o.png" alt="brain" width="706" height="726"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Like when I study late and remember less, my brain quietly adjusts — it learns how to learn better. We also have different kinds of memory: fast, short-term memory for quick thoughts and slow, long-term memory for what truly matters.&lt;/p&gt;

&lt;p&gt;What’s amazing is that all this happens at different speeds — reflexes form instantly, habits take time. That’s what makes our learning flexible and self-improving. This paper helped me realize that real intelligence isn’t just about storing knowledge — it’s about systems that can adapt the way they adapt.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Real Intelligence Learns at Many Speeds
&lt;/h2&gt;

&lt;p&gt;“Nested Learning” mirrors the way our brain learns at multiple speeds. In real life, not all learning happens instantly — some lessons come from quick feedback, and others sink in over time through reflection and repetition.&lt;/p&gt;

&lt;p&gt;For example, when I make a mistake in code, I fix it fast — that’s short-term learning. But when I notice a pattern of mistakes across projects and change how I approach debugging, that’s slow, higher-order learning. My brain is basically nesting layers of learning, one inside another.&lt;/p&gt;

&lt;p&gt;This is exactly what the paper argues AI should do. Instead of having one rigid update rule for all situations, it should have systems that operate on different timescales — fast ones for reacting to the present and slow ones for improving how it learns in the future. Real intelligence, human or artificial, grows when it can &lt;em&gt;learn fast, remember slow, and keep adjusting both.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff7cf72h9sp4dz83sq58w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff7cf72h9sp4dz83sq58w.png" alt="levelBRain" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Optimizers Are Still “Shallow”
&lt;/h2&gt;

&lt;p&gt;One part that stood out to me was how the paper calls our current optimizers “shallow.” At first, that sounded odd — optimizers like Adam or SGD are what make models learn, right? But the point is deeper: they only operate at one level. They adjust the weights, but they never learn &lt;em&gt;how to optimize better&lt;/em&gt; on their own.&lt;/p&gt;

&lt;p&gt;Think about it like this — an optimizer is a rulebook. It says, “If error is high, change parameters this way.” That rule never changes, no matter how the model behaves or what patterns it encounters. It doesn’t evolve. It’s like a student who keeps using the same study method forever, even when it stops working.&lt;/p&gt;

&lt;p&gt;Nested Learning challenges that. It treats the optimizer as something that can &lt;em&gt;learn from its own history&lt;/em&gt; — almost like giving the optimizer memory and awareness. So instead of being a fixed rule, it becomes a learner itself. That’s why normal optimizers are called “shallow” — they only see one layer of the learning process, while true intelligence needs many.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Nested Learning Really Means
&lt;/h2&gt;

&lt;p&gt;When I finally got to the main idea — Nested Learning — it clicked for me that this isn’t just about deeper networks, but deeper &lt;em&gt;learning loops.&lt;/em&gt; Normally, a model learns by updating its parameters once per round. But in Nested Learning, there are multiple layers of learning stacked inside each other, each operating at its own level. &lt;/p&gt;

&lt;p&gt;The paper calls these “levels.”&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Level 1&lt;/strong&gt; is the fast learner — it adjusts to new data right away.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Level 2&lt;/strong&gt; is slower — it learns how well Level 1 is learning and changes its strategy.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Level 3 and beyond&lt;/strong&gt; keep zooming out, letting the model reflect on its own updates and tweak the process itself.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxenaeptaijj1ljete540.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxenaeptaijj1ljete540.png" alt="levelsLearning" width="800" height="564"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc5wn947001ly0ew6abyi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc5wn947001ly0ew6abyi.png" alt="nestedLearning" width="800" height="281"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It’s like having a mind inside a mind inside a mind — each layer watching and improving the one below. What makes it powerful is that it never stops at one rule; it can always find a better way to learn. I realized that’s what makes it feel almost human — because that’s how we grow too, by not just learning facts, but by constantly refining &lt;em&gt;how&lt;/em&gt; we learn them.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Power of Associative Memory
&lt;/h2&gt;

&lt;p&gt;In this paper, associative memory is what allows the model to connect surprise signals over time. Each time it encounters something unexpected, it doesn’t just correct the output; it stores that “surprise” pattern and learns from how surprises evolve. So instead of forgetting past mistakes, it builds a history of how it has been wrong before — and uses that as context for new learning.&lt;/p&gt;

&lt;p&gt;I liked how this turns memory from a passive storage system into an active, learning part of the network. It’s not just remembering data; it’s remembering &lt;em&gt;how learning felt last time.&lt;/em&gt; That’s what makes the system more adaptive and self-improving, just like how human intuition forms through repeated experiences.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmsc3ap0y9ran5cvszl20.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmsc3ap0y9ran5cvszl20.png" alt="associativeMemory" width="800" height="548"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  HOPE — The Model That Learns to Learn
&lt;/h2&gt;

&lt;p&gt;The paper introduces a model called &lt;strong&gt;HOPE (Hierarchical Optimizing Processing Ensemble)&lt;/strong&gt;, and it really ties everything together. HOPE is basically the first real example of Nested Learning in action. It builds on the older &lt;strong&gt;Titans architecture&lt;/strong&gt;, which was already designed for smart memory management — storing “surprising” experiences and forgetting the rest. But Titans could only update its parameters in two layers, which meant it was still limited to first-order learning.&lt;/p&gt;

&lt;p&gt;HOPE takes that concept and adds &lt;em&gt;self-modification&lt;/em&gt;. It doesn’t just store knowledge — it rewrites how it learns based on what it experiences. The more it learns, the better it gets at learning itself. That’s what makes it “hierarchical” — every layer is optimizing the one below it, creating an infinite loop of improvement.&lt;/p&gt;

&lt;p&gt;When I read that, it felt like looking at a prototype for true adaptive intelligence. HOPE doesn’t just grow its memory; it evolves its own way of thinking. It’s almost like the model is building its own brain architecture in real time — guided only by feedback and surprise.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp2h73hnhrw783xirbqwv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp2h73hnhrw783xirbqwv.png" alt="hope" width="548" height="1064"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  CMS — Learning Across Multiple Memory Speeds
&lt;/h2&gt;

&lt;p&gt;One of the coolest parts of the paper was the &lt;strong&gt;Continuum Memory System (CMS)&lt;/strong&gt;. This idea clicked with me right away because it’s inspired by how our brain manages memory at different speeds. We have fast, short-term memory for reacting to the moment, and slower, long-term memory for storing what truly matters. CMS brings that same principle to AI.&lt;/p&gt;

&lt;p&gt;In HOPE, CMS creates layers of memory that operate on different time scales. Fast memory reacts instantly to new data, slow memory holds onto stable knowledge, and middle layers balance both. The system learns what to keep, what to adapt, and what to forget — automatically.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzbwdvohd05ptemienwye.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzbwdvohd05ptemienwye.png" alt="cms" width="800" height="536"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This makes the model more flexible and less likely to “forget” old knowledge when it learns something new, solving a big problem in continual learning. For me, CMS felt like giving the model an actual sense of &lt;em&gt;time&lt;/em&gt; — letting it learn short-term lessons without losing its long-term wisdom. It’s memory that grows, refines, and stays balanced, just like ours.&lt;/p&gt;

&lt;h2&gt;
  
  
  From Titans to HOPE — How the Architecture Evolved
&lt;/h2&gt;

&lt;p&gt;Before HOPE came along, there was the &lt;strong&gt;Titans architecture&lt;/strong&gt;, which was already an interesting idea. Titans worked like a long-term memory system for AI — it didn’t try to remember everything, only what was &lt;em&gt;surprising&lt;/em&gt;. Whenever the model saw something that didn’t match its expectations, it marked that as “important” and stored it. This made Titans good at keeping rare or unexpected experiences while forgetting routine ones, kind of like how our brain remembers unusual events more vividly than daily habits.  &lt;/p&gt;

&lt;p&gt;But Titans had a big limitation — it could only learn at &lt;strong&gt;two levels&lt;/strong&gt;. It could store knowledge (Level 1) and slightly adjust how it stored it (Level 2), but it couldn’t modify its own learning process. It was stuck with fixed update rules, so even though its memory was smart, its way of learning stayed static.  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F11ji4gmdtjpf0zooj1ta.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F11ji4gmdtjpf0zooj1ta.png" alt="Titan" width="800" height="1218"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That’s where &lt;strong&gt;HOPE (Hierarchical Optimizing Processing Ensemble)&lt;/strong&gt; came in as the next step. HOPE keeps Titans’ “surprise-based memory,” but adds &lt;strong&gt;self-modification&lt;/strong&gt; — meaning it can change how it learns over time. Instead of just remembering, it &lt;em&gt;reflects&lt;/em&gt; on how it learned and improves that process.  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg95ycli6qj5dfgutnrh8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg95ycli6qj5dfgutnrh8.png" alt="Hope" width="756" height="1266"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In simple terms:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Titans learns &lt;em&gt;what&lt;/em&gt; to remember.
&lt;/li&gt;
&lt;li&gt;HOPE learns &lt;em&gt;how&lt;/em&gt; to learn better next time.
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This shift from reactive memory (Titans) to reflective learning (HOPE) is what made the architecture truly recursive — an AI that can not only adapt but evolve its own learning rules.&lt;/p&gt;

&lt;h2&gt;
  
  
  My Takes on the Paper
&lt;/h2&gt;

&lt;p&gt;This paper made me rethink what “deep learning” really means. It’s not just about adding layers — it’s about adding &lt;em&gt;levels of learning.&lt;/em&gt; I liked how it pushed the idea that intelligence should evolve, not just perform.&lt;/p&gt;

&lt;p&gt;What stood out to me was the mindset shift. Instead of models that just learn tasks, it showed a system that learns &lt;em&gt;how to learn better.&lt;/em&gt; That’s the kind of loop real intelligence needs — self-awareness in its own process.&lt;/p&gt;

&lt;p&gt;I also liked the balance between fast and slow learning. It reminded me of how humans think — reacting quickly to new events while slowly refining long-term habits. The whole idea felt less like training a model and more like nurturing an evolving mind.&lt;/p&gt;

</description>
      <category>deeplearning</category>
      <category>google</category>
      <category>nestedlearning</category>
      <category>hope</category>
    </item>
    <item>
      <title>GEN-AI 5 : WGAN and WGAN-GP</title>
      <dc:creator>Mitansh Gor</dc:creator>
      <pubDate>Sun, 20 Apr 2025 01:19:50 +0000</pubDate>
      <link>https://dev.to/mitanshgor/gen-ai-2-generative-ai-and-auto-encoders-do8</link>
      <guid>https://dev.to/mitanshgor/gen-ai-2-generative-ai-and-auto-encoders-do8</guid>
      <description>&lt;h2&gt;
  
  
  Why ❌  GAN
&lt;/h2&gt;

&lt;p&gt;In the ever-evolving landscape of generative models, GANs have taken center stage with their remarkable ability to generate data that mimics real-world distributions. But as with all great things, classic GANs came with caveats—training instability, vanishing gradients, and mode collapse, to name a few. &lt;/p&gt;

&lt;p&gt;Let’s dive deeper into these powerful models: WGAN and its enhanced cousin WGAN-GP, two sophisticated upgrades that fix many of GANs' shortcomings.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyi492wjs6nr3z58wf2hg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyi492wjs6nr3z58wf2hg.png" alt="I0" width="800" height="800"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Wasserstein distance
&lt;/h2&gt;

&lt;p&gt;Wasserstein Distance, also known as the Earth Mover's Distance (EMD), is a mathematical measure of the distance between two probability distributions.&lt;/p&gt;

&lt;p&gt;Imagine you have two piles of sand—one symbolizing real data and the other representing data generated by a model. The goal is to reshape one pile into the other by moving portions of sand. The effort required depends not only on how much sand you move but also on how far you move it. This effort is what the Wasserstein Distance measures—a cost-efficient way to transform one distribution into another.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkddlg8za5taek2wm2503.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkddlg8za5taek2wm2503.gif" alt="I1" width="400" height="232"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What makes this distance especially powerful is its ability to compare distributions even when they don't overlap at all—a situation where traditional measures like JS divergence fail. It offers a continuous and interpretable signal for how "far off" the generated data is from the real data, making it incredibly useful for training generative models like WGANs.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5lout24z5bpr2hnaw7vf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5lout24z5bpr2hnaw7vf.png" alt="I2" width="800" height="285"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Traditional GANs use Jensen-Shannon (JS) divergence to measure similarity between distributions.&lt;br&gt;
BUT :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;JS divergence becomes undefined or uninformative when distributions don't overlap.&lt;/li&gt;
&lt;li&gt;This leads to vanishing gradients—a huge problem for training&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By contrast, Wasserstein Distance:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Remains well-defined and continuous even when distributions are far apart.&lt;/li&gt;
&lt;li&gt;Provides meaningful gradients, allowing the generator to learn effectively from the start.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Improvement in WGAN wrt GAN
&lt;/h2&gt;

&lt;p&gt;WGAN is a variant of GAN that uses the Wasserstein Distance as its loss function instead of JS divergence.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdia5wcuesljnfdvcm59n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdia5wcuesljnfdvcm59n.png" alt="I3" width="685" height="328"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key differences from traditional GAN:&lt;/strong&gt;&lt;br&gt;
The discriminator is now called a critic. It doesn't classify data as real/fake, but scores it to reflect how “real” it looks.&lt;/p&gt;

&lt;p&gt;The loss function is based on the difference in critic scores for real vs. fake data.&lt;/p&gt;

&lt;p&gt;In simple terms:&lt;br&gt;
&lt;code&gt;Real Data → High Critic Score&lt;/code&gt;&lt;br&gt;
&lt;code&gt;Fake Data → Low Critic Score&lt;/code&gt;&lt;br&gt;
&lt;code&gt;The generator improves by producing data that the critic scores higher.&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Working
&lt;/h2&gt;

&lt;p&gt;Just like in standard GANs, WGAN consists of two neural networks:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;A Generator (G) that tries to generate realistic data from random noise.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A Critic (C) (not called a discriminator here) that scores the realness of data, assigning higher values to real data and lower values to fake ones.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Unlike GANs, which use a &lt;strong&gt;sigmoid function&lt;/strong&gt; to classify samples as real or fake, WGAN's critic outputs real-valued scores—this small shift changes everything.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  The Loss Function
&lt;/h3&gt;

&lt;p&gt;The heart of WGAN lies in replacing Jensen-Shannon divergence with the Wasserstein distance (also called Earth Mover’s Distance)—a metric that measures how much "effort" it takes to morph the generated distribution into the real one.&lt;/p&gt;

&lt;p&gt;This results in the following loss functions:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu2hxwngfpuhab0mlsvf7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu2hxwngfpuhab0mlsvf7.png" alt="I4" width="800" height="318"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Critic's Loss:&lt;/p&gt;

&lt;p&gt;𝐿c = E[C(fake)]−E[C(real)]&lt;/p&gt;

&lt;p&gt;The critic aims to maximize the difference, rewarding real data with higher scores and penalizing fakes.&lt;/p&gt;

&lt;p&gt;Generator's Loss:&lt;/p&gt;

&lt;p&gt;𝐿G = −E[C(fake)]&lt;/p&gt;

&lt;p&gt;The generator tries to minimize the critic’s ability to detect its fakes by generating better, more realistic data.&lt;/p&gt;

&lt;h2&gt;
  
  
  Missing Something? 🤔
&lt;/h2&gt;

&lt;p&gt;The model that we learned until now has some issues.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;The critic assigns real-valued scores to data samples, so nothing stops the critic from amplifying its outputs to maximize the loss. For example, it might assign real samples a score of +10,000. And fake samples a score of -10,000. This leads to :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The generator receiving extreme gradients, which are not helpful and can distort learning. &lt;/li&gt;
&lt;li&gt;Loss curves spike or crash. Generated samples look worse over time instead of better, making training unstable.&lt;/li&gt;
&lt;li&gt;Mode collapse and exploding gradients can occur.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;How can we solve this problem?&lt;/strong&gt;&lt;br&gt;
Let's introduce a 1-Lipschitz Function. This will solve our problem. &lt;br&gt;
We will add a 1-Lipschitz Function to the critic (discriminator).&lt;br&gt;
In the Lipshitz function, we will give any 2 images (x1 and x2) as input. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpqyaa5r2vhscshwtdqeh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpqyaa5r2vhscshwtdqeh.png" alt="I5" width="360" height="152"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Numerator: Absolute difference between the critic predictions&lt;/code&gt;&lt;br&gt;
&lt;code&gt;Denominator: Average pixelwise absolute difference between two images&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;What we are trying to do with this function is to limit the rate at which the predictions of the critic can change between 2 images, when comparing it with the real/pixel-wise difference of the image.&lt;/p&gt;

&lt;p&gt;You can get this using a graph by visualizing 2 (white) cones whose origin can be moved along the graph so that the whole graph always stays outside the cones.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fip68lijcqaz11cb3ytl7.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fip68lijcqaz11cb3ytl7.gif" alt="I6" width="737" height="677"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;By doing so, we are clipping the weights of the critic to lie within a small range, eliminating problems of exploding gradients.&lt;br&gt;
But again NEW PROBLEM !! &lt;br&gt;
Learning significantly decreases 😢 😢 &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Futcfv5rhwinwjilaquer.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Futcfv5rhwinwjilaquer.png" alt="I7" width="800" height="408"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A much better Solution is the WGAN-GP&lt;/p&gt;




&lt;h2&gt;
  
  
  Adding Gradient Penalty
&lt;/h2&gt;

&lt;p&gt;As the Lipshitz function did a partial job. We need to modify/tweak the function so that it can eliminate the problem of &lt;code&gt;Learning significantly decreases&lt;/code&gt;.&lt;br&gt;
The solution should be to penalize the Gradient if it's too far away from 1. &lt;/p&gt;

&lt;p&gt;The Lipschitz constraint is enforced by including a gradient penalty (GP) term in the loss function for the critic. The GP penalizes the model if the gradient norm deviates from 1&lt;br&gt;
The GP term, which we will be using with Lipschitz constraint, will measure the square difference between the gradient of the prediction wrt input image and 1.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fevcfujtd57fj59oku5c2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fevcfujtd57fj59oku5c2.png" alt="I8" width="456" height="118"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft56qfswe9xzp17xwgvij.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft56qfswe9xzp17xwgvij.png" alt="III" width="800" height="800"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;From the above image, it's clear that the gradient penalty increases as we move away from 1.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;There are a few important things to take care of while using training WGAN-GP&lt;/strong&gt; :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;With Wasserstein loss, the Critic must be trained to converge before updating the Generator. To do so, we train the Critic several times between Generator updates. A typical ratio used is &lt;code&gt;3 to 5 Critic updates per Generator update&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Batch Normalization shouldn't be used in the critic. Batch Norm creates a correlation between images in the same batch. This makes the gradient penalty loss less effective. Experiments have shown that WGAN-GPs works great without it anyway&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Results after WGAN-GP model:
&lt;/h2&gt;

&lt;p&gt;Using Wasserstein distance + Lipschitz function + Gradient penalty has improved the results of the images generated significantly. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Traditional GANs suffer from vanishing gradients or mode collapse due to the Jensen-Shannon divergence. WGAN-GP, by using Wasserstein distance + gradient penalty, leads to more consistent and stable convergence. You get smoother generator updates, making training less sensitive to hyperparameters and architectural choices.&lt;/li&gt;
&lt;li&gt;In classic GANs, generators can produce a limited variety (mode collapse). WGAN-GP encourages the generator to explore the data distribution more fully, thanks to the meaningful gradient feedback from the critic. Hence, more diverse outputs, especially noticeable in image generation tasks.&lt;/li&gt;
&lt;li&gt;The loss correlates with sample quality, unlike traditional GAN loss, which becomes meaningless when the discriminator is too good. Hence, you can track training progress numerically, not just visually&lt;/li&gt;
&lt;li&gt;There are no sudden spikes or flat zones in gradients. Hence, more efficient and productive generator learning.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Disadvantages of WGAN
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Slower training, higher memory usage, and increased training time, especially on large datasets.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Hyperparameters are sensitive. Even a small change in hyperparameters can cause a lot of change. It needs to be tuned carefully.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Summarize
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;A WGAN-GP uses the Wasserstein loss&lt;/li&gt;
&lt;li&gt;The WGAN-GP is trained using labels of 1 for real and -1 for fake&lt;/li&gt;
&lt;li&gt;No Sigmoid activation in the final layer of the Critic&lt;/li&gt;
&lt;li&gt;Include a GP term in the loss function for the Critic&lt;/li&gt;
&lt;li&gt;Train the &lt;strong&gt;&lt;u&gt;Critic multiple times&lt;/u&gt;&lt;/strong&gt; for each update of the Generator&lt;/li&gt;
&lt;li&gt;There are &lt;strong&gt;&lt;u&gt;no Batch Norm layers&lt;/u&gt;&lt;/strong&gt; in the Critic&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffarqvyv498oeh1bkku1r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffarqvyv498oeh1bkku1r.png" alt="II" width="800" height="1200"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>generative</category>
      <category>deeplearning</category>
      <category>wgan</category>
      <category>wgangp</category>
    </item>
    <item>
      <title>GEN-AI 4 : GAN</title>
      <dc:creator>Mitansh Gor</dc:creator>
      <pubDate>Sun, 20 Apr 2025 01:19:40 +0000</pubDate>
      <link>https://dev.to/mitanshgor/gen-ai-4-gan-how-ai-learns-to-generate-realistic-images-17bn</link>
      <guid>https://dev.to/mitanshgor/gen-ai-4-gan-how-ai-learns-to-generate-realistic-images-17bn</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpyxk9w3e576t3sa0kefw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpyxk9w3e576t3sa0kefw.png" alt=" " width="800" height="533"&gt;&lt;/a&gt;&lt;br&gt;
In the world of generative models, Variational Autoencoders (VAEs) were among the first to show us how machines can learn to create new data. But they came with limitations which sparked the need for a new direction in generative modeling. &lt;/p&gt;

&lt;p&gt;Enter Generative Adversarial Networks (GANs): a powerful, game-theoretic approach that changed the landscape by producing stunningly realistic outputs and pushing the boundaries of what machines can generate.&lt;/p&gt;

&lt;p&gt;Lets start by understanding the limitations of VAE.&lt;/p&gt;

&lt;h2&gt;
  
  
  Disadvantages of VAE
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Blurry Outputs:&lt;/strong&gt; In a VAE, two things are being balanced: how well the model can recreate the input data (reconstruction loss) and how closely the latent variables follow the assumed normal distribution (KL divergence). If this balance isn't right, it can cause problems. For example, if the model focuses too much on making the latent space look normal, it might not focus enough on accurately recreating the input data, leading to blurry or low-quality reconstructions. Finding the right balance is tricky, and if it's off, the output can look fuzzy or unclear.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Latent Space Constraints: When we assume a simple normal distribution for the latent variables in a VAE, it means we expect the data to follow a very basic pattern (like a bell curve). However, real-world data is often more complex and doesn't always fit this simple pattern. Because of this, the VAE might not capture all the details or variations in the data, leading to less accurate results and poor generation of new data. Essentially, the model's assumption limits its ability to understand and recreate the data’s true complexity fully.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Mode Averaging: When the data has many different patterns or "modes" (called multimodal data), VAEs can struggle to capture all of them. The model tends to average over these modes, meaning it might create a mix of features from different data patterns instead of focusing on the specific details of each mode. This can result in the model generating outputs that don’t accurately reflect the diversity of the data, often leading to a loss of important variations or details in the generated samples. Essentially, the model might not fully capture all the unique aspects of the data.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fexqc8hqb3nxa8wc90ais.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fexqc8hqb3nxa8wc90ais.png" alt="some10.png" width="800" height="789"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How is GAN better than VAE?
&lt;/h2&gt;

&lt;p&gt;While Variational Autoencoders (VAEs) offer a powerful framework for generative modeling, they come with certain limitations. To address these challenges, Generative Adversarial Networks (GANs) provide an alternative approach. Unlike VAEs, which rely on a probabilistic framework, GANs use two neural networks—a generator and a discriminator—that compete against each other to improve the quality of generated data. The adversarial setup in GANs enables them to produce sharper, more realistic outputs, particularly in applications like image generation, where detail and realism are crucial.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0hsyg8ggkyw0cjw04r11.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0hsyg8ggkyw0cjw04r11.png" alt="s11.png" width="182" height="276"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here’s how GANs are better than VAEs:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Sharper Outputs&lt;/strong&gt;: GANs produce clearer and more detailed images because they focus on distinguishing real data from generated data, leading to more realistic results.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;No Blurry Reconstructions&lt;/strong&gt;: Unlike VAEs, which can sometimes produce blurry outputs due to their reliance on a probabilistic framework, GANs avoid this issue by directly optimizing for realism.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Better for High-Quality Generation&lt;/strong&gt;: GANs excel in tasks where the goal is to generate high-quality data, like realistic images, videos, or audio, because the adversarial training encourages the generator to produce more lifelike results.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Flexibility in Learning Complex Patterns&lt;/strong&gt;: GANs can learn complex data distributions better, especially when data has many modes (variety of patterns), without averaging out the details like VAEs might.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Working of GAN
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnszgqd2lzvg2svs0lo0a.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnszgqd2lzvg2svs0lo0a.jpg" alt="GAN.jpg" width="800" height="274"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A Generative Adversarial Network (GAN) is a machine learning model that consists of two neural networks, a generator and a discriminator, that work against each other in a process called adversarial training. Here's how it works in detail:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3qmo8icxg9z835a2knp4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3qmo8icxg9z835a2knp4.png" alt="image.png" width="790" height="218"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  The Generator:
&lt;/h3&gt;

&lt;p&gt;The generator is like an artist trying to create new data (e.g., images) that looks as real as possible. It starts with random noise and uses this as input to produce a generated output. The goal of the generator is to produce data that can fool the discriminator into thinking it’s real.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Discriminator:
&lt;/h3&gt;

&lt;p&gt;The discriminator is like a critic trying to tell whether a piece of data is real (from the training data) or fake (produced by the generator). It takes an input—either real data or a generated one—and outputs a probability that the input is real or fake. It can be considered as a supervised image classification problem.&lt;/p&gt;

&lt;h3&gt;
  
  
  Adversarial Training:
&lt;/h3&gt;

&lt;p&gt;The key idea behind GANs is the competition between the generator and the discriminator:&lt;/p&gt;

&lt;p&gt;The generator tries to improve by creating more convincing, realistic data to fool the discriminator.&lt;/p&gt;

&lt;p&gt;The discriminator tries to improve by getting better at distinguishing real data from the fake data created by the generator.&lt;/p&gt;

&lt;p&gt;This process is a game where the generator tries to "cheat" by generating better data, and the discriminator tries to become more skilled at detecting fake data. Over time, both networks improve.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3vrlbludcpvjllfo9g1t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3vrlbludcpvjllfo9g1t.png" alt="some1.png" width="265" height="190"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  The Objective:
&lt;/h3&gt;

&lt;p&gt;Generator's Goal: Minimize how often the discriminator correctly identifies fake data. It wants to produce data that the discriminator can't distinguish from real data.&lt;/p&gt;

&lt;p&gt;Discriminator's Goal: Maximize its ability to correctly classify real vs. fake data, helping it get better at spotting fakes.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frhg52w0ldba0ahgpg9gs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frhg52w0ldba0ahgpg9gs.png" alt="some2.png" width="182" height="276"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The interaction between the discriminator and generator in a GAN requires a delicate balance. If the discriminator is too good, it can easily distinguish real from fake data, leaving the generator with little feedback and hindering its ability to improve. On the other hand, if the generator is too strong, it may exploit weaknesses in the discriminator, producing fake data that the discriminator wrongly classifies as real (false negatives). The ideal situation occurs when the discriminator outputs a value close to 0.5, meaning it cannot distinguish between real and fake data, indicating that the generator is producing high-quality samples. For example, if the discriminator outputs ~1, the fake images are too realistic, and the generator won't be forced to improve. If it outputs ~0, the fake images are too obvious, and the generator needs more training. However, when the discriminator outputs ~0.5, it suggests the generator is performing well, producing convincing, realistic samples.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd47g58th8vmdc4u1489q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd47g58th8vmdc4u1489q.png" alt="some3.png" width="600" height="800"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  The Loss Functions:
&lt;/h3&gt;

&lt;p&gt;The generator's job in a GAN is to create fake data that looks so real that the discriminator can’t tell it apart from the real data. Instead of directly focusing on the quality of the data, the generator’s main goal is to trick the discriminator into thinking the fake data is real. The generator gets feedback from the discriminator, which helps it improve. The loss function for the generator encourages it to produce data that has a high probability of being classified as real by the discriminator&lt;/p&gt;

&lt;p&gt;The discriminator in a GAN's job is to tell whether the data it sees is real (from the true data source) or fake (generated by the generator). It outputs a probability (between 0 and 1) that the input is real.&lt;br&gt;
The goal of the discriminator is to correctly classify Real data as real and Fake data as fake.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fscfwv8mldnqp6ejri6s5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fscfwv8mldnqp6ejri6s5.png" alt="some4.png" width="299" height="168"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Together, the overall training objective for the GAN can be summarized as : &lt;br&gt;
&lt;code&gt;GAN Loss = Discriminator Loss + Generator Loss&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Training Process:
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl8eefxz86uoy2mr8mx80.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl8eefxz86uoy2mr8mx80.png" alt="some5.png" width="799" height="216"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The training process of a Generative Adversarial Network (GAN) involves a series of steps that &lt;strong&gt;&lt;u&gt;&lt;em&gt;alternate&lt;/em&gt;&lt;/u&gt;&lt;/strong&gt; between training the discriminator and the generator.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Initialize the generator and discriminator.&lt;/li&gt;
&lt;li&gt;Train the discriminator on real and fake data.&lt;/li&gt;
&lt;li&gt;Train the generator to fool the discriminator.&lt;/li&gt;
&lt;li&gt;Alternate between training the discriminator and the generator.&lt;/li&gt;
&lt;li&gt;Repeat until the generator produces convincing fake data.&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;p&gt;We must alternate the training of these two networks, making sure that we only update the weights of one network at a time!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Initially, the generator creates very poor, random data, and the discriminator easily detects it as fake. This adversarial training process continues until the generator has learned to produce realistic data, and the discriminator has become more adept at distinguishing real from fake data.&lt;/p&gt;

&lt;p&gt;Training can be stopped when the generator produces high-quality data that the discriminator cannot reliably distinguish from real data (i.e., the discriminator’s output approaches 0.5, meaning it cannot differentiate between real and fake data).&lt;/p&gt;

&lt;h2&gt;
  
  
  Situations in GAN
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1z6msqpfu3z786tw6egc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1z6msqpfu3z786tw6egc.png" alt="Imagesome6.png" width="418" height="121"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;1) - We normalize the input range from &lt;a href="https://dev.tothe%20typical%20image%20range"&gt;0, 255&lt;/a&gt; to [-1, 1] instead of [0, 1] because the tanh activation function works better with inputs in the range of [-1, 1]. The tanh function outputs values between -1 and 1, and normalizing the data to this range helps ensure the gradients are stronger and more stable during training. In contrast, the sigmoid activation function has a range of [0, 1] and produces weaker gradients, which can slow down learning. Therefore, using [-1, 1] helps improve the training process.&lt;br&gt;
2) - The training process of GANs can be unstable because the generator and discriminator are constantly competing. Over time, the discriminator may become too good at distinguishing real from fake data, which could cause issues. However, this isn't always a problem because the generator might have already learned enough by that point. To improve stability, we can add a small amount of random noise to the training labels, which helps prevent the discriminator from becoming too dominant too quickly&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb4pbeagq47hzvvleztjf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb4pbeagq47hzvvleztjf.png" alt="Imagesome.png" width="259" height="194"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;3) - When the Discriminator Overpowers the Generator,&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The discriminator becomes too good at distinguishing real from fake images.&lt;/li&gt;
&lt;li&gt;This causes the generator to receive weak feedback, and the loss signal becomes too weak to improve the generator.&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The discriminator perfectly classifies real and fake images, causing the gradients to vanish, and the generator stops training.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Solutions to Weaken the Discriminator:&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Increase the Dropout rate in the discriminator to reduce its ability to overfit.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Reduce the learning rate of the discriminator to slow down its training.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Reduce the number of convolutional filters in the discriminator to limit its capacity.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Add noise to the labels when training the discriminator to make it harder for the discriminator to distinguish real from fake.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Randomly flip labels of some images during training to confuse the discriminator and prevent it from becoming too powerful.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft7q9cy3u8sc04fajzjvn.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft7q9cy3u8sc04fajzjvn.jpg" alt=" " width="800" height="449"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;4) - When the Generator Overpowers the Discriminator:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The discriminator becomes too weak, and the generator tricks it with a small set of nearly identical images.&lt;/li&gt;
&lt;li&gt;&lt;p&gt;This results in &lt;strong&gt;&lt;u&gt;mode collapse&lt;/u&gt;&lt;/strong&gt;, where the generator produces limited variety in its outputs, focusing on a single observation that fools the discriminator.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Solutions to Weaken the Generator:&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If you find that your generator is suffering from mode collapse, you can try strengthening the discriminator using the opposite suggestions to those listed in the previous section. Also, you can try reducing the learning rate of both networks and increasing the batch size.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;5) - The generator's loss is evaluated based on the current discriminator, which constantly improves during training. This makes it hard to compare the generator's loss at different stages, as it may not reflect the actual quality of generated images. The loss can even increase over time, despite the images improving, because the discriminator is getting better, making it harder for the generator to fool it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffca9ule00a1mnua6d48q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffca9ule00a1mnua6d48q.png" alt="sonme8.pnh" width="304" height="166"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Disadvantages of GAN.
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Mode Collapse: The generator may start producing limited, identical outputs, tricking the discriminator, and failing to capture the full diversity of the data.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fygkvklwy4ememu7pqrty.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fygkvklwy4ememu7pqrty.png" alt="some9.png" width="268" height="188"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Uninformative Loss: The generator's loss may increase even as image quality improves, making it hard to track progress.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Vanishing Gradients: If the discriminator becomes too powerful, the generator may receive weak gradients, preventing meaningful learning.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Hyperparameter Sensitivity: GANs are sensitive to choices like learning rates, dropout rates, and the number of layers, requiring careful tuning for optimal performance.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>gan</category>
      <category>van</category>
      <category>deeplearning</category>
      <category>machinelearning</category>
    </item>
    <item>
      <title>GEN-AI-3 : VAE</title>
      <dc:creator>Mitansh Gor</dc:creator>
      <pubDate>Sun, 20 Apr 2025 01:19:30 +0000</pubDate>
      <link>https://dev.to/mitanshgor/gen-ai-5-wgan-and-wgan-gp-2245</link>
      <guid>https://dev.to/mitanshgor/gen-ai-5-wgan-and-wgan-gp-2245</guid>
      <description>&lt;p&gt;So far, we’ve seen how Autoencoders (AEs) can take data—like images, audio, or text—and compress it into a lower-dimensional space, only to reconstruct it again like a digital magician pulling a rabbit out of a hat. Pretty neat, right?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw5kvoc1suag2yjgn3667.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw5kvoc1suag2yjgn3667.png" alt=" " width="800" height="800"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But there’s a catch: while AEs are great at learning compact representations, they’re not exactly dreamers. Their latent space—the core of their compressed understanding—isn’t built for imagination. Try sampling from it randomly, and you’re more likely to get noise than meaningful data.&lt;/p&gt;

&lt;p&gt;Now, what if we wanted a model that not only compresses data but can also generate new, meaningful samples that look like they came from the original dataset? A model that understands probability, uncertainty, and can dream up new content with finesse?&lt;/p&gt;

&lt;p&gt;🎉 Enter the Variational Autoencoder (VAE).&lt;/p&gt;

&lt;p&gt;In this post, we’re going to unpack how VAEs work, why they’re a major leap forward from traditional autoencoders, and how they lay the groundwork for some of the most exciting generative models in AI today.&lt;/p&gt;

&lt;p&gt;Let’s dive in.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Problem with Regular Autoencoders 🧩
&lt;/h2&gt;

&lt;p&gt;Traditional autoencoders compress data by learning a direct mapping from input to a latent vector, and then decompress it using a decoder. While effective for feature learning, they suffer from:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi4jb8wgld9qpoxj38sh7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi4jb8wgld9qpoxj38sh7.png" alt=" " width="800" height="426"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Disorganized Latent Space: Nearby latent points don’t necessarily produce similar outputs.&lt;/li&gt;
&lt;li&gt;Poor Generative Ability: Sampling randomly from the latent space usually results in noisy, incoherent outputs.&lt;/li&gt;
&lt;li&gt;No Uncertainty Modeling: The model doesn't capture how confident it is in the latent representation.&lt;/li&gt;
&lt;li&gt;We needed structure, smoothness, and the ability to reason probabilistically.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwds1p7qngk33z7lfa6s6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwds1p7qngk33z7lfa6s6.png" alt=" " width="641" height="295"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Variational Autoencoders
&lt;/h2&gt;

&lt;p&gt;VAEs solve these issues by introducing two key ideas:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Injecting randomness into the encoding process.&lt;/li&gt;
&lt;li&gt;Imposing constraints on the distribution of the latent space.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Instead of encoding an input to a fixed point, the VAE encodes it to a &lt;strong&gt;probability distribution—specifically&lt;/strong&gt;, a multivariate normal distribution centered at a point in the latent space. &lt;br&gt;
Or in other words,&lt;br&gt;
Instead of encoding input into a fixed latent vector, it encodes it into a &lt;strong&gt;distribution&lt;/strong&gt; (usually Gaussian), from which it &lt;strong&gt;samples&lt;/strong&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;By doing so, it not only compresses data, but VAEs &lt;strong&gt;learn to imagine variations&lt;/strong&gt;.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Faeyel02ruwfwdwbpnjdq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Faeyel02ruwfwdwbpnjdq.png" alt=" " width="800" height="800"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  🎯 Constraints on the latent space
&lt;/h2&gt;

&lt;p&gt;To bring structure to the latent space, we constrain how encodings are distributed:&lt;/p&gt;

&lt;p&gt;🌀 Centering: Each encoded distribution should be centered as close to the origin (0, 0, ..., 0) as possible.&lt;br&gt;
📏 Unit Variance: The spread (standard deviation) of each distribution should be close to 1.&lt;/p&gt;

&lt;p&gt;The further the encoder deviates from these goals, the higher the loss during training.&lt;/p&gt;

&lt;p&gt;Why? This forces all encoded samples to live near the same area in latent space, enabling smooth interpolation and consistent generation.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fynnt1sj7uwv3fux9gwrj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fynnt1sj7uwv3fux9gwrj.png" alt=" " width="800" height="1200"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Changes in VAE Encoder
&lt;/h2&gt;

&lt;p&gt;The encoder no longer outputs just a point, but rather, it parameterizes a distribution from which we can sample.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;x → (μ, σ) → z ~ N(μ, σ²)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft3wkg1a19i7zfwfu56aj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft3wkg1a19i7zfwfu56aj.png" alt=" " width="799" height="336"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We do this because we want to generate new data by sampling from a continuous, meaningful latent space.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;z_mean (μ): The center of the distribution where we want our encoding to be.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;z_log_var (log(σ²)): The (log of) the variance, controlling the spread of that distribution.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Together, they define a normal distribution, from which we will later sample to get a latent variable z for decoding.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Now the question is why log(σ²) and not just σ² ?&lt;/strong&gt;&lt;br&gt;
There are two  major reasons: positivity constraint, numerical stability&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Variance Must Be Positive: If we try to output σ directly from a neural network, we need to ensure that the network only produces positive values. But neural nets naturally output values from (−∞,∞). Hence, log(σ²) guarantees that σ&amp;gt;0, always.&lt;/li&gt;
&lt;li&gt;We work in the log domain, where multiplications become additions, and exponentials become linear. It avoids premature underflow for tiny variances or instability from tiny gradients when optimizing 
σ directly.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Imagine we want to allow the encoder to learn variances from 0.0001 to 1000:&lt;br&gt;
If we output σ directly, the network must learn to span that huge dynamic range. But if we output log(σ²), the values range from about:&lt;br&gt;
&lt;code&gt;log(0.0001)=−9.2&lt;/code&gt; to &lt;code&gt;log(1000)=6.9&lt;/code&gt;.&lt;br&gt;
A much more manageable range!&lt;/p&gt;

&lt;p&gt;But wait on!!&lt;br&gt;
There is one problem.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpl0h0wu3ww3pry99yl3r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpl0h0wu3ww3pry99yl3r.png" alt=" " width="404" height="220"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's go through it using the example&lt;/p&gt;

&lt;p&gt;Let’s imagine the encoder outputs:&lt;br&gt;
&lt;code&gt;μ=0.5&lt;/code&gt;&lt;br&gt;
&lt;code&gt;σ=1.0&lt;/code&gt;&lt;br&gt;
If we directly sample&lt;br&gt;
&lt;code&gt;z = np.random.normal(mu, sigma)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This operation:&lt;br&gt;
Picks a random number (say 0.23 or 1.42) with no guarantee&lt;/p&gt;

&lt;p&gt;There's no way to know how the output Z would change if μ or &lt;br&gt;
σ changed — because the randomness hides the function's slope&lt;/p&gt;

&lt;p&gt;And without a gradient, the network can’t learn.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How can we deal with it?&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Reparameterization Trick
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftp15wzbenoh861qgt3px.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftp15wzbenoh861qgt3px.png" alt=" " width="400" height="284"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here’s the twist:&lt;/p&gt;

&lt;p&gt;Instead of sampling like this:&lt;br&gt;
&lt;code&gt;z∼N(μ,σ2)&lt;/code&gt;&lt;br&gt;
We reparameterize it as:&lt;br&gt;
&lt;code&gt;z = μ+ σ⋅ε where ε∼N(0,1)&lt;/code&gt;&lt;br&gt;
Here :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;ε = Random noise from a fixed distribution&lt;/li&gt;
&lt;li&gt;μ, σ = Output from the encoder (learnable)&lt;/li&gt;
&lt;li&gt;z = Latent vector to feed into the decoder&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Why this works:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;ε is independent of the network, so its randomness doesn’t interfere with gradient flow.&lt;br&gt;
μ and σ are now involved in a deterministic operation (addition and multiplication), so gradients can be calculated&lt;br&gt;
Now, you can compute:&lt;br&gt;
&lt;code&gt;&lt;br&gt;
∂z/∂μ = 1&lt;br&gt;
∂z/∂σ = ε&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8duwhgbungvqbjoygara.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8duwhgbungvqbjoygara.png" alt=" " width="800" height="360"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Backpropagation is happy again. 🎉&lt;/p&gt;

&lt;p&gt;This tiny trick makes backpropagation work through the stochastic layer. Without it, training would collapse.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0r6j5cn84w8jssmdq7ju.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0r6j5cn84w8jssmdq7ju.png" alt=" " width="330" height="220"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Changes in VAE Decoder wrt AE
&lt;/h2&gt;

&lt;p&gt;The decoder no longer sees a fixed vector in the latent space.&lt;br&gt;
Instead, it gets:&lt;br&gt;
&lt;code&gt;z=μ+σ⋅ε&lt;/code&gt;&lt;br&gt;
The decoder must be able to take any nearby sample around μ and still reconstruct a very similar output.&lt;/p&gt;




&lt;h2&gt;
  
  
  VAE Loss Function: More Than Just Reconstruction
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq0x5ro5zk3uubjp1zz7w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq0x5ro5zk3uubjp1zz7w.png" alt=" " width="220" height="220"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We used reconstruction loss for AutoEncoders. We cannot use just the reconstruction loss anymore.  We’re now dealing with probability distributions, and we need to keep the latent distributions close to a standard normal (N(0,1)).&lt;/p&gt;

&lt;p&gt;So we add a Kullback–Leibler (KL) divergence term:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Loss = ReconstructionLoss + β∗KLDivergence&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;KL measures how much our learned distribution (μ, σ²) deviates from the standard normal. A higher KL means our encoding is straying too far.&lt;/p&gt;

&lt;p&gt;Think of it like this:&lt;br&gt;
Reconstruction loss: "How well did we recreate the input?"&lt;br&gt;
KL divergence: "How wild is our latent distribution? Should we calm it down?"&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5hxif5cocmb8k1c9w07i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5hxif5cocmb8k1c9w07i.png" alt=" " width="800" height="324"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What's the use case of the β Parameter?&lt;/p&gt;

&lt;p&gt;The β coefficient balances reconstruction and regularization.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;If &lt;strong&gt;β is too small&lt;/strong&gt;, the KL divergence is ignored. The latent space becomes disorganized, similar to a vanilla AE. Good reconstructions, bad generation.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If &lt;strong&gt;β is too large&lt;/strong&gt;, the model prioritizes matching N(0,1) over reconstruction. All samples start looking the same—blurry outputs, poor expressiveness.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;p&gt;✅ Sweet spot: When β is balanced, we get coherent generation and meaningful reconstructions.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4ju6apoe8ksc86mhxear.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4ju6apoe8ksc86mhxear.jpg" alt=" " width="800" height="280"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  🧱 Disadvantages of VAEs
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Tends to generate &lt;strong&gt;blurry images&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;KL term is &lt;strong&gt;tricky to balance&lt;/strong&gt; with reconstruction loss&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Not ideal for high-resolution data&lt;/strong&gt; (GANs often outperform here)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx032anta80601q6lu48r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx032anta80601q6lu48r.png" alt=" " width="289" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;TL;DR: VAEs are smarter but also harder to tame.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  🧭 Wrap-up: When to Use What and Why It All Matters
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Use &lt;strong&gt;Autoencoders&lt;/strong&gt; when you need compression, denoising, or anomaly detection.&lt;/li&gt;
&lt;li&gt;Use &lt;strong&gt;VAEs&lt;/strong&gt; when you need controlled generation, diversity, and smooth interpolation.&lt;/li&gt;
&lt;li&gt;Use &lt;strong&gt;GANs&lt;/strong&gt; when you need photo-realism.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The future of generative models lies in &lt;strong&gt;hybrids&lt;/strong&gt; — combining VAEs, GANs, and Diffusion models.&lt;/p&gt;

</description>
      <category>deeplearning</category>
      <category>vae</category>
      <category>autoencoder</category>
      <category>generativeai</category>
    </item>
  </channel>
</rss>
