<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Reinforcement-Learning on</title><link>https://tdhopper.com/tags/reinforcement-learning/</link><description>Recent content in Reinforcement-Learning on</description><generator>Hugo -- gohugo.io</generator><language>en-us</language><lastBuildDate>Thu, 08 Dec 2011 00:00:00 +0000</lastBuildDate><atom:link href="https://tdhopper.com/tags/reinforcement-learning/index.xml" rel="self" type="application/rss+xml"/><item><title>When to Transplant: Value Iteration and Optimal Stopping</title><link>https://tdhopper.com/blog/transplant-value-iteration/</link><pubDate>Thu, 08 Dec 2011 00:00:00 +0000</pubDate><guid>https://tdhopper.com/blog/transplant-value-iteration/</guid><description>&lt;link rel="stylesheet" href="https://tdhopper.com/css/mdp-viz.css"&gt;
&lt;p&gt;Notes from ISE 789, the healthcare-optimization seminar I am taking this term at NC State. We keep circling a small, stylized model of a hard question: if you are on a transplant waiting list, when should you accept an organ rather than hold out for a better moment? The model is a toy, but the machinery behind it, &lt;a class="link" href="https://en.wikipedia.org/wiki/Markov_decision_process" target="_blank" rel="noopener"
&gt;value iteration&lt;/a&gt; on a Markov decision process, is the same dynamic programming that scales up to real sequential-decision problems. The math below is solved live, not baked in.&lt;/p&gt;
&lt;h2 id="the-model"&gt;The model
&lt;/h2&gt;&lt;p&gt;The patient occupies one of five states. Three describe pre-transplant health, from &lt;strong&gt;Good&lt;/strong&gt; to &lt;strong&gt;Fair&lt;/strong&gt; to &lt;strong&gt;Poor&lt;/strong&gt;. Two are absorbing: &lt;strong&gt;Transplanted&lt;/strong&gt; (the organ has been accepted) and &lt;strong&gt;Death&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Each period the patient chooses one of two actions:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Wait.&lt;/strong&gt; Stay on the list and live another period. Reward $r = 17$. Health may hold, decline, or, at worst, end in death.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Transplant now.&lt;/strong&gt; Accept an organ. The reward is larger the healthier the patient, $100$, $75$, or $60$ from Good, Fair, and Poor. The process then ends.&lt;/li&gt;
&lt;/ul&gt;
&lt;figure class="mdp-fig"&gt;
&lt;svg viewBox="0 0 520 250" role="img" aria-label="State diagram of the transplant Markov decision process"&gt;
&lt;defs&gt;
&lt;marker id="mdp-ah" markerWidth="9" markerHeight="9" refX="6.5" refY="3" orient="auto"&gt;&lt;path d="M0,0 L7,3 L0,6 Z"/&gt;&lt;/marker&gt;
&lt;marker id="mdp-ah-t" markerWidth="9" markerHeight="9" refX="6.5" refY="3" orient="auto"&gt;&lt;path d="M0,0 L7,3 L0,6 Z"/&gt;&lt;/marker&gt;
&lt;/defs&gt;
&lt;path class="edge-t" marker-end="url(#mdp-ah-t)" d="M104,88 C240,150 350,150 448,128"/&gt;
&lt;path class="edge-t" marker-end="url(#mdp-ah-t)" d="M244,94 C320,138 400,138 449,124"/&gt;
&lt;path class="edge-t" marker-end="url(#mdp-ah-t)" d="M408,84 C430,100 440,110 452,116"/&gt;
&lt;path class="edge" marker-end="url(#mdp-ah)" d="M92,96 C130,140 170,164 198,178"/&gt;
&lt;path class="edge" marker-end="url(#mdp-ah)" d="M228,102 C228,130 228,148 228,166"/&gt;
&lt;path class="edge" marker-end="url(#mdp-ah)" d="M368,98 C320,142 285,160 258,176"/&gt;
&lt;path class="edge" marker-end="url(#mdp-ah)" d="M112,64 C150,52 180,52 199,60"/&gt;
&lt;path class="edge" marker-end="url(#mdp-ah)" d="M262,64 C300,52 330,52 349,60"/&gt;
&lt;circle class="node" cx="80" cy="72" r="30"/&gt;&lt;text x="80" y="76" text-anchor="middle"&gt;Good&lt;/text&gt;
&lt;circle class="node" cx="230" cy="72" r="30"/&gt;&lt;text x="230" y="76" text-anchor="middle"&gt;Fair&lt;/text&gt;
&lt;circle class="node" cx="380" cy="72" r="30"/&gt;&lt;text x="380" y="76" text-anchor="middle"&gt;Poor&lt;/text&gt;
&lt;circle class="node node-absorb" cx="480" cy="122" r="32"/&gt;&lt;text x="480" y="119" text-anchor="middle"&gt;Trans-&lt;/text&gt;&lt;text x="480" y="133" text-anchor="middle"&gt;planted&lt;/text&gt;
&lt;circle class="node node-absorb" cx="228" cy="196" r="28"/&gt;&lt;text x="228" y="200" text-anchor="middle"&gt;Death&lt;/text&gt;
&lt;text class="lbl-dim" x="150" y="40" text-anchor="middle"&gt;health declines&lt;/text&gt;
&lt;text class="lbl-dim" x="470" y="180" text-anchor="middle"&gt;transplant: r = 100 / 75 / 60&lt;/text&gt;
&lt;text class="lbl-dim" x="120" y="150" text-anchor="middle"&gt;wait: r = 17&lt;/text&gt;
&lt;/svg&gt;
&lt;figcaption&gt;The decision states are Good, Fair, and Poor. Waiting (gray) keeps the patient alive but risks decline or death; transplanting (green) ends the process with a health-dependent payoff. Exact transition probabilities appear below.&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Waiting moves the patient between health states, or to death, with these probabilities:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;From \ to&lt;/th&gt;
&lt;th&gt;Good&lt;/th&gt;
&lt;th&gt;Fair&lt;/th&gt;
&lt;th&gt;Poor&lt;/th&gt;
&lt;th&gt;Death&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Good&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;0.80&lt;/td&gt;
&lt;td&gt;0.10&lt;/td&gt;
&lt;td&gt;0.05&lt;/td&gt;
&lt;td&gt;0.05&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Fair&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;0.10&lt;/td&gt;
&lt;td&gt;0.20&lt;/td&gt;
&lt;td&gt;0.40&lt;/td&gt;
&lt;td&gt;0.30&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Poor&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;0.05&lt;/td&gt;
&lt;td&gt;0.05&lt;/td&gt;
&lt;td&gt;0.10&lt;/td&gt;
&lt;td&gt;0.80&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Transplanting sends any health state to &lt;strong&gt;Transplanted&lt;/strong&gt; with probability 1. Future rewards are discounted by $\lambda = 0.95$ per period.&lt;/p&gt;
&lt;h2 id="solving-it-by-value-iteration"&gt;Solving it by value iteration
&lt;/h2&gt;&lt;p&gt;The optimal value of a state satisfies the Bellman optimality equation: the best action is the one whose immediate reward plus discounted expected future value is largest.&lt;/p&gt;
$$V(s) = \max_{a \in \{\text{wait},\, \text{transplant}\}} \left[\, r(s, a) + \lambda \sum_{s'} P(s' \mid s, a)\, V(s') \,\right]$$&lt;p&gt;Value iteration turns this equation into an algorithm. Start from $V_0 = 0$ and apply the right-hand side as an update, $V_{k+1} = \mathcal{T} V_k$. Because $\lambda &lt; 1$, the update $\mathcal{T}$ is a contraction, so the $V_k$ converge to the unique fixed point $V^\star$ regardless of where they start. The optimal policy reads off greedily: in each state, pick the action attaining the maximum.&lt;/p&gt;
&lt;h2 id="the-result-the-healthiest-patient-waits"&gt;The result: the healthiest patient waits
&lt;/h2&gt;&lt;p&gt;Value iteration converges to&lt;/p&gt;
$$V^\star = (\,112.40,\ 75,\ 60,\ 0,\ 0\,), \qquad \pi^\star = (\,\text{wait},\ \text{transplant},\ \text{transplant}\,).$$&lt;p&gt;The Fair and Poor states transplant immediately: their values equal the transplant payoffs $75$ and $60$ exactly, because acting now is best and the process ends. The interesting state is &lt;strong&gt;Good&lt;/strong&gt;. Its value, $112.40$, is larger than the $100$ it would earn by transplanting today:&lt;/p&gt;
$$\begin{aligned}
Q(\text{Good}, \text{wait}) &amp;= 17 + 0.95\big(0.8 \cdot 112.40 + 0.1 \cdot 75 + 0.05 \cdot 60 + 0.05 \cdot 0\big) = 112.40, \\
Q(\text{Good}, \text{transplant}) &amp;= 100, \qquad\text{so waiting wins.}
\end{aligned}$$&lt;p&gt;That gap is the &lt;strong&gt;option value of waiting&lt;/strong&gt;. A healthy patient is likely to stay healthy, collecting the $17$ per-period reward and keeping the choice open, so holding the organ in reserve beats spending it now. This is a &lt;a class="link" href="https://en.wikipedia.org/wiki/Optimal_stopping" target="_blank" rel="noopener"
&gt;control-limit policy&lt;/a&gt;: wait while you are above a health threshold, act once you cross it. Such thresholds show up throughout optimal stopping, from equipment replacement to exercising an option.&lt;/p&gt;
&lt;h2 id="play-it-yourself"&gt;Play it yourself
&lt;/h2&gt;&lt;p&gt;The numbers make the case, but the tradeoff is easier to feel than to read. You are the patient, starting in Good health. Each period you choose: wait for a better moment, or accept the organ in front of you. The panel shows the odds you face and what the optimal policy would do; your job is to beat its long-run average of 112.40. Wait too long in a declining state and you will learn firsthand why the threshold exists.&lt;/p&gt;
&lt;div data-mdp="play"&gt;&lt;/div&gt;
&lt;h2 id="what-the-discount-factor-decides"&gt;What the discount factor decides
&lt;/h2&gt;&lt;p&gt;The whole story hinges on how much the future is worth. The discount factor $\lambda$ trades immediate payoff against the option value of waiting. Drag it and watch the policy move: a patient future keeps Good on the list, while a heavily discounted future tips every state toward transplanting now.&lt;/p&gt;
&lt;div data-mdp="discount"&gt;&lt;/div&gt;
&lt;p&gt;I built the model in Mathematica for the seminar and explored the policy with an interactive &lt;code&gt;Manipulate&lt;/code&gt;; the playable version here tells the same story. The interaction is the teaching: the optimal policy is three lines of algebra, but having to choose, and sometimes losing a patient to waiting, makes the control limit feel earned. For the theory behind scaling these ideas well past five states, Warren Powell&amp;rsquo;s &lt;em&gt;Approximate Dynamic Programming&lt;/em&gt; is where I first met the subject.&lt;/p&gt;
&lt;script src="https://tdhopper.com/js/mdp-viz.js" defer&gt;&lt;/script&gt;</description></item></channel></rss>