<?xml version="1.0" encoding="UTF-8"?>
<rss  xmlns:atom="http://www.w3.org/2005/Atom" 
      xmlns:media="http://search.yahoo.com/mrss/" 
      xmlns:content="http://purl.org/rss/1.0/modules/content/" 
      xmlns:dc="http://purl.org/dc/elements/1.1/" 
      version="2.0">
<channel>
<title>Andreas Bogossian</title>
<link>https://andreasbogossian.com/blog.html</link>
<atom:link href="https://andreasbogossian.com/blog.xml" rel="self" type="application/rss+xml"/>
<description>Notes on challenging technical things</description>
<generator>quarto-99.9.9</generator>
<lastBuildDate>Sat, 25 Apr 2026 21:00:00 GMT</lastBuildDate>
<item>
  <title>The Kruskal-Wallis test, derived from first principles</title>
  <dc:creator>Andreas Bogossian</dc:creator>
  <link>https://andreasbogossian.com/posts/Kruskal-Wallis-test/</link>
  <description><![CDATA[ 




<p>Let’s say that we want to test the effects of pain management protocols. We have 45 post-surgical patients randomized to three groups: opioid-only, NSAID + nerve block and multimodal. 48 hours after their operations, each patient marks their pain on a 0–10 visual analog scale (VAS). The question that the clinic is interested in is whether the three different protocols produce different pain levels or not.</p>
<p>ANOVA <span class="citation" data-cites="wiki_anova">[1]</span> is a popular test for testing whether group means are equal. The problem with ANOVA in the pain scale example is that the pain scores are typically right-skewed (clustering around 2-4) and with small sample sizes, the within-group variance can be inflated by some observations being at the right tail (8-10). ANOVA computes an F-statistic as a ratio of between-group variance to within-group variance. If the within group variance is inflated, ANOVA needs a larger between-group variance to detect a difference.</p>
<p>The Kruskal-Wallis test solves this problem. The KW test replaces raw scores with their ranks in the pooled dataset (see Figure&nbsp;2) and tests whether the ranks cluster by treatment. Under the null hypothesis, the ranks should equally be distributed to the groups.</p>
<div class="callout callout-style-default callout-note callout-titled">
<div class="callout-header d-flex align-content-center collapsed" data-bs-toggle="collapse" data-bs-target=".callout-1-contents" aria-controls="callout-1" aria-expanded="false" aria-label="Toggle callout">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
<span class="screen-reader-only">Note</span>Notation used in this post
</div>
<div class="callout-btn-toggle d-inline-block border-0 py-1 ps-1 pe-0 float-end"><i class="callout-toggle"></i></div>
</div>
<div id="callout-1" class="callout-1-contents callout-collapse collapse">
<div class="callout-body-container callout-body">
<table class="caption-top table">
<colgroup>
<col style="width: 47%">
<col style="width: 52%">
</colgroup>
<thead>
<tr class="header">
<th>Symbol</th>
<th>Meaning</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td><img src="https://latex.codecogs.com/png.latex?K"></td>
<td>Number of groups</td>
</tr>
<tr class="even">
<td><img src="https://latex.codecogs.com/png.latex?j"></td>
<td>Group index, <img src="https://latex.codecogs.com/png.latex?j%20%5Cin%20%5C%7B1,%20%5Cldots,%20K%5C%7D"></td>
</tr>
<tr class="odd">
<td><img src="https://latex.codecogs.com/png.latex?n_j"></td>
<td>Number of observations in group <img src="https://latex.codecogs.com/png.latex?j"></td>
</tr>
<tr class="even">
<td><img src="https://latex.codecogs.com/png.latex?N"></td>
<td>Total sample size <img src="https://latex.codecogs.com/png.latex?N%20=%20%5Csum_j%20n_j"></td>
</tr>
<tr class="odd">
<td><img src="https://latex.codecogs.com/png.latex?x_%7Bij%7D"></td>
<td>The <img src="https://latex.codecogs.com/png.latex?i">-th observation in group <img src="https://latex.codecogs.com/png.latex?j"></td>
</tr>
<tr class="even">
<td><img src="https://latex.codecogs.com/png.latex?R_%7Bij%7D"></td>
<td>Rank of <img src="https://latex.codecogs.com/png.latex?x_%7Bij%7D"> among all <img src="https://latex.codecogs.com/png.latex?N"> pooled observations</td>
</tr>
<tr class="odd">
<td><img src="https://latex.codecogs.com/png.latex?R_j"></td>
<td>Rank sum of group <img src="https://latex.codecogs.com/png.latex?j">: <img src="https://latex.codecogs.com/png.latex?R_j%20=%20%5Csum_i%20R_%7Bij%7D"></td>
</tr>
<tr class="even">
<td><img src="https://latex.codecogs.com/png.latex?%5Cbar%7BR%7D_j"></td>
<td>Mean rank of group <img src="https://latex.codecogs.com/png.latex?j">: <img src="https://latex.codecogs.com/png.latex?%5Cbar%7BR%7D_j%20=%20R_j%20/%20n_j"></td>
</tr>
<tr class="odd">
<td><img src="https://latex.codecogs.com/png.latex?%5Cbar%7BR%7D"></td>
<td>Grand mean rank: <img src="https://latex.codecogs.com/png.latex?%5Cbar%7BR%7D%20=%20(N+1)/2"></td>
</tr>
<tr class="even">
<td><img src="https://latex.codecogs.com/png.latex?H"></td>
<td>Kruskal-Wallis test statistic</td>
</tr>
<tr class="odd">
<td><img src="https://latex.codecogs.com/png.latex?F"></td>
<td>ANOVA F-statistic</td>
</tr>
<tr class="even">
<td><img src="https://latex.codecogs.com/png.latex?%5Cchi%5E2(K-1)"></td>
<td>Chi-square distribution with <img src="https://latex.codecogs.com/png.latex?K-1"> degrees of freedom</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<section id="the-pain-trial" class="level1">
<h1>The pain trial</h1>
<p>This post will use a made up example: the data will have three groups of 15 patients with NRS scores at 48 hours post surgery. The Figure&nbsp;1 shows both the theoretical (Gamma) distributions where the samples are drawn from and the actual samples. Then Table&nbsp;1 summarizes the data.</p>
<div id="cell-fig-pain-data" class="cell" data-execution_count="1">
<details class="code-fold">
<summary>Pain trial data</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb1-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> numpy <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> np</span>
<span id="cb1-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> matplotlib.pyplot <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> plt</span>
<span id="cb1-3"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> scipy <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> stats</span>
<span id="cb1-4"></span>
<span id="cb1-5"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># VAS pain scores at 48 h post-op (0 = no pain, 10 = worst imaginable)</span></span>
<span id="cb1-6"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Gamma(shape=0.5) → heavy right skew; offset shifts group medians apart</span></span>
<span id="cb1-7">rng <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.random.default_rng(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">99</span>)</span>
<span id="cb1-8">pain_a <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.clip(np.<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">round</span>(rng.gamma(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">3.0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">15</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>), <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>)  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># multimodal:          mean ≈ 2.6</span></span>
<span id="cb1-9">pain_b <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.clip(np.<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">round</span>(rng.gamma(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">3.0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">15</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.8</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>), <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>)  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># NSAID + nerve block: mean ≈ 3.4</span></span>
<span id="cb1-10">pain_c <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.clip(np.<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">round</span>(rng.gamma(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">3.0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">15</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2.6</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>), <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>)  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># opioid-only:         mean ≈ 3.9</span></span>
<span id="cb1-11"></span>
<span id="cb1-12">labels <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Multimodal"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"NSAID + nerve block"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Opioid-only"</span>]</span>
<span id="cb1-13">colors <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mediumseagreen"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"darkorange"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"steelblue"</span>]</span>
<span id="cb1-14">groups <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [pain_a, pain_b, pain_c]</span>
<span id="cb1-15"></span>
<span id="cb1-16">plt.rcParams.update(</span>
<span id="cb1-17">    {</span>
<span id="cb1-18">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"text.color"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"white"</span>,</span>
<span id="cb1-19">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"axes.labelcolor"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"white"</span>,</span>
<span id="cb1-20">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"xtick.color"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"white"</span>,</span>
<span id="cb1-21">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ytick.color"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"white"</span>,</span>
<span id="cb1-22">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"axes.edgecolor"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"white"</span>,</span>
<span id="cb1-23">    }</span>
<span id="cb1-24">)</span>
<span id="cb1-25"></span>
<span id="cb1-26">fig, axes <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> plt.subplots(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>, figsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">3.2</span>), sharey<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>, sharex<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>)</span>
<span id="cb1-27">fig.patch.set_alpha(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>)</span>
<span id="cb1-28"></span>
<span id="cb1-29"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> ax, g, color, label <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">zip</span>(axes, groups, colors, labels):</span>
<span id="cb1-30">    ax.hist(</span>
<span id="cb1-31">        g,</span>
<span id="cb1-32">        bins<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>np.linspace(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">12</span>),</span>
<span id="cb1-33">        color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>color,</span>
<span id="cb1-34">        alpha<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8</span>,</span>
<span id="cb1-35">        edgecolor<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"white"</span>,</span>
<span id="cb1-36">        linewidth<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8</span>,</span>
<span id="cb1-37">    )</span>
<span id="cb1-38">    ax.axvline(np.median(g), color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"white"</span>, linewidth<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, linestyle<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"--"</span>, alpha<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9</span>)</span>
<span id="cb1-39">    ax.set_title(<span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>label<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">\n</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">median = </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>np<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>median(g)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:.1f}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>, fontsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>, color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"white"</span>)</span>
<span id="cb1-40">    ax.set_xlabel(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Pain score (0–10)"</span>)</span>
<span id="cb1-41">    ax.set_xlim(<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">10.5</span>)</span>
<span id="cb1-42">    ax.patch.set_alpha(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>)</span>
<span id="cb1-43"></span>
<span id="cb1-44">axes[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>].set_ylabel(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Count"</span>)</span>
<span id="cb1-45">plt.tight_layout()</span>
<span id="cb1-46">plt.show()</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div id="fig-pain-data" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-pain-data-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<a href="index_files/figure-html/fig-pain-data-output-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-1" title="Figure&nbsp;1: VAS pain scores at 48 h post-surgery for three protocols. Dashed line shows the group median."><img src="https://andreasbogossian.com/posts/Kruskal-Wallis-test/index_files/figure-html/fig-pain-data-output-1.png" width="945" height="298" class="figure-img"></a>
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-pain-data-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;1: VAS pain scores at 48 h post-surgery for three protocols. Dashed line shows the group median.
</figcaption>
</figure>
</div>
</div>
</div>
<div id="4e761a04" class="cell" data-execution_count="2">
<div class="cell-output cell-output-display">
<script type="ojs-define">{"contents": [{"name": "pain_groups", "value": [[1.77, 1.79, 2.19, 1.25, 7.63, 1.29, 1.22, 8.02, 3.42, 1.27, 1.61, 1.57, 2.06, 2.41, 1.11], [1.99, 1.84, 4.26, 2.13, 3.42, 4.16, 2.03, 2.81, 3.32, 3.97, 1.8, 6.73, 4.31, 3.56, 1.82], [3.83, 2.79, 4.54, 3.5, 10.0, 4.49, 3.08, 6.08, 2.6, 2.82, 2.81, 3.35, 3.22, 2.8, 3.03]]}, {"name": "pain_labels", "value": ["Multimodal", "NSAID + nerve block", "Opioid-only"]}]}</script>
</div>
</div>
<div class="cell" data-execution_count="3">
<details class="code-fold">
<summary>Summary statistics</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb2-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> IPython.display <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> HTML</span>
<span id="cb2-2"></span>
<span id="cb2-3">rows <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>.join(</span>
<span id="cb2-4">    <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"&lt;tr&gt;&lt;td style='padding:5px 14px;'&gt;</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>lbl<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">&lt;/td&gt;"</span></span>
<span id="cb2-5">    <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"&lt;td style='padding:5px 14px; text-align:right;'&gt;</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">len</span>(g)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">&lt;/td&gt;"</span></span>
<span id="cb2-6">    <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"&lt;td style='padding:5px 14px; text-align:right;'&gt;</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>g<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>mean()<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:.2f}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">&lt;/td&gt;"</span></span>
<span id="cb2-7">    <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"&lt;td style='padding:5px 14px; text-align:right;'&gt;</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>np<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>median(g)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:.1f}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">&lt;/td&gt;"</span></span>
<span id="cb2-8">    <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"&lt;td style='padding:5px 14px; text-align:right;'&gt;</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>g<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>std(ddof<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:.2f}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">&lt;/td&gt;&lt;/tr&gt;"</span></span>
<span id="cb2-9">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> lbl, g <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">zip</span>(labels, groups)</span>
<span id="cb2-10">)</span>
<span id="cb2-11">th <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"padding:6px 14px; text-align:right; border-bottom:1px solid #555;"</span></span>
<span id="cb2-12">th_l <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"padding:6px 14px; text-align:left; border-bottom:1px solid #555;"</span></span>
<span id="cb2-13">display(HTML(<span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"""</span></span>
<span id="cb2-14"><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">&lt;table style="border-collapse:collapse; font-size:0.9em;"&gt;</span></span>
<span id="cb2-15"><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">  &lt;thead&gt;&lt;tr&gt;</span></span>
<span id="cb2-16"><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">    &lt;th style="</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>th_l<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"&gt;Protocol&lt;/th&gt;</span></span>
<span id="cb2-17"><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">    &lt;th style="</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>th<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"&gt;n&lt;/th&gt;</span></span>
<span id="cb2-18"><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">    &lt;th style="</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>th<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"&gt;Mean&lt;/th&gt;</span></span>
<span id="cb2-19"><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">    &lt;th style="</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>th<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"&gt;Median&lt;/th&gt;</span></span>
<span id="cb2-20"><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">    &lt;th style="</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>th<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"&gt;SD&lt;/th&gt;</span></span>
<span id="cb2-21"><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">  &lt;/tr&gt;&lt;/thead&gt;</span></span>
<span id="cb2-22"><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">  &lt;tbody&gt;</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>rows<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">&lt;/tbody&gt;</span></span>
<span id="cb2-23"><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">&lt;/table&gt;</span></span>
<span id="cb2-24"><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"""</span>))</span></code></pre></div></div>
</details>
<div id="tbl-pain-summary" class="cell quarto-float quarto-figure quarto-figure-center anchored" data-execution_count="3">
<figure class="quarto-float quarto-float-tbl figure">
<figcaption class="quarto-float-caption-top quarto-float-caption quarto-float-tbl" id="tbl-pain-summary-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Table&nbsp;1: Summary statistics for the three pain management protocols.
</figcaption>
<div aria-describedby="tbl-pain-summary-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<div class="cell-output cell-output-display">
<table class="cell caption-top table table-sm table-striped small">
<thead>
<tr class="header">
<th data-quarto-table-cell-role="th" style="text-align: left; padding: 6px 14px; border-bottom: 1px solid #555;">Protocol</th>
<th data-quarto-table-cell-role="th" style="text-align: right; padding: 6px 14px; border-bottom: 1px solid #555;">n</th>
<th data-quarto-table-cell-role="th" style="text-align: right; padding: 6px 14px; border-bottom: 1px solid #555;">Mean</th>
<th data-quarto-table-cell-role="th" style="text-align: right; padding: 6px 14px; border-bottom: 1px solid #555;">Median</th>
<th data-quarto-table-cell-role="th" style="text-align: right; padding: 6px 14px; border-bottom: 1px solid #555;">SD</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="padding: 5px 14px">Multimodal</td>
<td style="text-align: right; padding: 5px 14px;">15</td>
<td style="text-align: right; padding: 5px 14px;">2.57</td>
<td style="text-align: right; padding: 5px 14px;">1.8</td>
<td style="text-align: right; padding: 5px 14px;">2.21</td>
</tr>
<tr class="even">
<td style="padding: 5px 14px">NSAID + nerve block</td>
<td style="text-align: right; padding: 5px 14px;">15</td>
<td style="text-align: right; padding: 5px 14px;">3.21</td>
<td style="text-align: right; padding: 5px 14px;">3.3</td>
<td style="text-align: right; padding: 5px 14px;">1.37</td>
</tr>
<tr class="odd">
<td style="padding: 5px 14px">Opioid-only</td>
<td style="text-align: right; padding: 5px 14px;">15</td>
<td style="text-align: right; padding: 5px 14px;">3.93</td>
<td style="text-align: right; padding: 5px 14px;">3.2</td>
<td style="text-align: right; padding: 5px 14px;">1.92</td>
</tr>
</tbody>
</table>
</div>
</div>
</figure>
</div>
</div>
</section>
<section id="the-key-insight-order-is-enough" class="level1">
<h1>The key insight: order is enough</h1>
<p>For deducing whether one protocol produces less pain than another, we don’t need to know how much less. We only need to know who ranks lower. Thus we use a ranking transformation. The animation in Figure&nbsp;2 shows how the data points are transformed into ranks.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb3" data-startfrom="144" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 143;"><span id="cb3-144">viewof transform_t <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> Inputs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">range</span>(</span>
<span id="cb3-145">  [<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb3-146">  { <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">step</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.005</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">value</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"← original values  ·  ranks →"</span> }</span>
<span id="cb3-147">)</span></code></pre></div></div>
<div id="ojs-rank-transform-control" class="cell-output cell-output-display">
<div id="ojs-cell-1" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb4" data-startfrom="155" data-source-offset="-1" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 154;"><span id="cb4-155">rt_colors <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"steelblue"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"darkorange"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mediumseagreen"</span>]</span>
<span id="cb4-156">N_rt <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pain_groups<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">flat</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length</span></span>
<span id="cb4-157"></span>
<span id="cb4-158">rt_flat_pain <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pain_groups<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">flatMap</span>((g<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> j) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> g<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(v <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> ({ v<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">group</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> j })))</span>
<span id="cb4-159"></span>
<span id="cb4-160">rt_ranks_pain <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (() <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb4-161">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> indexed <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> rt_flat_pain<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>((d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> i) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> ({ <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">v</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">v</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> i }))<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sort</span>((a<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> b) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> a<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">v</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> b<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">v</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-162">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> ranks <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">new</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Array</span>(rt_flat_pain<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-163">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> i <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-164">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">while</span> (i <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> indexed<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length</span>) {</span>
<span id="cb4-165">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> j <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> i<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-166">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">while</span> (j <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> indexed<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;&amp;</span> indexed[j <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">v</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> indexed[j]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">v</span>) j<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">++;</span></span>
<span id="cb4-167">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> avg <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (i <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> j) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-168">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> (<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> k <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> i<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> k <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;=</span> j<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> k<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">++</span>) ranks[indexed[k]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">i</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> avg<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-169">    i <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> j <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-170">  }</span>
<span id="cb4-171">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> ranks<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-172">})()</span>
<span id="cb4-173"></span>
<span id="cb4-174">rt_x_lo <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> transform_t) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> transform_t <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span></span>
<span id="cb4-175">rt_x_hi <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> transform_t) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> transform_t <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> N_rt</span>
<span id="cb4-176"></span>
<span id="cb4-177">rt_pts_groups <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> rt_flat_pain<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>((d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> i) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> ({</span>
<span id="cb4-178">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> (<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> transform_t) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">v</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> transform_t <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> rt_ranks_pain[i]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb4-179">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> pain_labels[d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">group</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb4-180">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">group</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> pain_labels[d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">group</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb4-181">}))</span>
<span id="cb4-182"></span>
<span id="cb4-183">rt_pts_pooled <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> rt_flat_pain<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>((d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> i) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> ({</span>
<span id="cb4-184">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> rt_ranks_pain[i]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb4-185">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Pooled"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb4-186">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">group</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> pain_labels[d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">group</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb4-187">}))</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-2-1" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-2-2" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-2-3" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-2-4" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-2-5" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-2-6" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-2-7" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-2-8" data-nodetype="declaration">

</div>
</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb5" data-startfrom="193" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 192;"><span id="cb5-193">Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>({</span>
<span id="cb5-194">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">width</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">680</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb5-195">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">height</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">270</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb5-196">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">marginLeft</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">145</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb5-197">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">marginRight</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb5-198">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> {</span>
<span id="cb5-199">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> transform_t <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.05</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Pain score (0–10) →"</span></span>
<span id="cb5-200">         <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> transform_t <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.95</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> <span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`Rank (1–</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>N_rt<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">) →`</span></span>
<span id="cb5-201">         <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Transforming… →"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb5-202">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">domain</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> [rt_x_lo<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> rt_x_hi]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb5-203">  }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb5-204">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> {</span>
<span id="cb5-205">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">domain</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> [<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">...</span>pain_labels<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Pooled"</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb5-206">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">null</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb5-207">  }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb5-208">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">color</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> {</span>
<span id="cb5-209">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">domain</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> pain_labels<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb5-210">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">range</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> rt_colors<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb5-211">  }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb5-212">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">marks</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> [</span>
<span id="cb5-213">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dot</span>(rt_pts_groups<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {</span>
<span id="cb5-214">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"x"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"y"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb5-215">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">fill</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"group"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">r</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">7</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb5-216">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">fillOpacity</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.85</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb5-217">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">stroke</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"white"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">strokeWidth</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb5-218">    })<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb5-219">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dot</span>(rt_pts_pooled<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {</span>
<span id="cb5-220">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"x"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"y"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb5-221">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">fill</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"group"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">r</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">7</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb5-222">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">fillOpacity</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> transform_t <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.85</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb5-223">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">stroke</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"white"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">strokeWidth</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb5-224">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">strokeOpacity</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> transform_t<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb5-225">    })<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb5-226">  ]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb5-227">})</span></code></pre></div></div>
<div id="fig-rank-transform" class="cell-output cell-output-display quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-rank-transform-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<div id="ojs-cell-3" data-nodetype="expression">

</div>
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-rank-transform-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;2: Each dot is one of the 45 patients, coloured by protocol. Drag to 1: each pain score is replaced by its rank in the pooled dataset, spreading the dots uniformly. The pooled row fades in to show all 45 ranks in sequence.
</figcaption>
</figure>
</div>
</div>
</section>
<section id="deriving-the-h-statistic" class="level1">
<h1>Deriving the <img src="https://latex.codecogs.com/png.latex?H"> statistic</h1>
<section id="setting-up-the-problem" class="level2">
<h2 class="anchored" data-anchor-id="setting-up-the-problem">Setting up the problem</h2>
<p>Abstracting from the medical example, let’s say that we have <img src="https://latex.codecogs.com/png.latex?K"> groups with the number of observations in each group being <img src="https://latex.codecogs.com/png.latex?n_1,%20...,%20n_K">. Then the total number of observations is <img src="https://latex.codecogs.com/png.latex?N%20=%20%5Csum_j%20n_j">. After combining the observations into one pool and ranking them (as shown in Figure&nbsp;2), let <img src="https://latex.codecogs.com/png.latex?R_%7Bij%7D"> be the rank of the <img src="https://latex.codecogs.com/png.latex?i">-th observation in group <img src="https://latex.codecogs.com/png.latex?j">.</p>
<p>The goal is to test whether the groups share the same distribution with each other. Transforming this into a null hypothesis becomes</p>
<p><img src="https://latex.codecogs.com/png.latex?H_0:%20%5Ctext%7Bthe%20ranks%20%7D%201,%202,%20%5Cldots,%20N%20%5Ctext%7B%20are%20randomly%20distributed%20across%20groups%7D"></p>
<p>So the next question to answer is: what does a large deviation from the random distribution look like and how can we measure the deviation?</p>
</section>
<section id="expected-rank-mean-under-h_0" class="level2">
<h2 class="anchored" data-anchor-id="expected-rank-mean-under-h_0">Expected rank mean under <img src="https://latex.codecogs.com/png.latex?H_0"></h2>
<p>Under <img src="https://latex.codecogs.com/png.latex?H_0">, every rank is equally likely to fall into any group. Then the expected value of a single rank <img src="https://latex.codecogs.com/png.latex?R"> drawn from the uniform set <img src="https://latex.codecogs.com/png.latex?%5C%7B1,%20%5Cldots,%20N%5C%7D"> is</p>
<p><span id="eq-expected-rank"><img src="https://latex.codecogs.com/png.latex?%5Cmathbb%7BE%7D%5BR%5D%20=%20%5Cfrac%7B1%7D%7BN%7D%20%5Csum_%7Br=1%7D%5E%7BN%7D%20r%20=%20%5Cfrac%7B1%7D%7BN%7D%5Cfrac%7BN(N+1)%7D%7B2%7D%20=%20%5Cfrac%7BN+1%7D%7B2%7D%20%5Ctag%7B1%7D"></span></p>
<p>The expected mean rank in all groups is <img src="https://latex.codecogs.com/png.latex?%5Cbar%7BR%7D%20=%20%5Cfrac%7BN+1%7D%7B2%7D">, regardless of the individual group sizes. The only thing that matters is the total sample size. If <img src="https://latex.codecogs.com/png.latex?H_0"> is true, all groups’ mean ranks should hover around <img src="https://latex.codecogs.com/png.latex?%5Cbar%7BR%7D">.</p>
</section>
<section id="building-the-test-statistic" class="level2">
<h2 class="anchored" data-anchor-id="building-the-test-statistic">Building the test statistic</h2>
<p>A natural way to measure deviation from the null is the squared distance of each group’s mean rank <img src="https://latex.codecogs.com/png.latex?%5Cbar%7BR%7D_j"> from the expected grand mean:</p>
<p><span id="eq-rank-ss"><img src="https://latex.codecogs.com/png.latex?T%20=%20%5Csum_%7Bj=1%7D%5E%7BK%7D%20n_j%20%5Cleft(%5Cbar%7BR%7D_j%20-%20%5Cfrac%7BN+1%7D%7B2%7D%5Cright)%5E2%20%5Ctag%7B2%7D"></span></p>
<p>Here <img src="https://latex.codecogs.com/png.latex?n_j"> is the size of group <img src="https://latex.codecogs.com/png.latex?j"> to weight the penalty of bigger groups more because we have more information of them. This structure is extremely similar to ANOVA that is defined as the between group sum of squared deviations from each group mean from the global mean:</p>
<p><img src="https://latex.codecogs.com/png.latex?SS_%7B%5Ctext%7Bbetween%7D%7D%20=%20%5Csum_%7Bj=1%7D%5E%7BK%7D%20n_j%20%5Cleft(%5Cbar%7Bx%7D_j%20-%20%5Cbar%7Bx%7D%5Cright)%5E2"></p>
</section>
<section id="the-12nn1-scaling-factor" class="level2">
<h2 class="anchored" data-anchor-id="the-12nn1-scaling-factor">The <img src="https://latex.codecogs.com/png.latex?12/N(N+1)"> scaling factor</h2>
<p>To turn <img src="https://latex.codecogs.com/png.latex?T"> from Equation&nbsp;2 into a statistic with a known null distribution, we need to normalize it by the variance of the ranks. With Equation&nbsp;1, the variance for a discrete uniform distribution on <img src="https://latex.codecogs.com/png.latex?%5C%7B1,%20%5Cdots,%20N%5C%7D"> is:</p>
<p><img src="https://latex.codecogs.com/png.latex?%5Cbegin%7Balign*%7D%0A%5Ctext%7BVar%7D(R)%20=%20%5Csigma%5E2_R%20&amp;=%20%5Cmathbb%7BE%7D%5BR%5E2%5D%20-%20%5Cleft(%5Cmathbb%7BE%7D%5BR%5D%5Cright)%5E2%20%5C%5C%0A&amp;=%20%5Cfrac%7B1%7D%7BN%7D%5Csum_%7Br=1%7D%5E%7BN%7D%20r%5E2%20-%20%5Cleft(%5Cfrac%7BN+1%7D%7B2%7D%5Cright)%5E2%20%5C%5C%0A&amp;=%20%5Cfrac%7B(N+1)(2N+1)%7D%7B6%7D%20-%20%5Cfrac%7B(N+1)%5E2%7D%7B4%7D%20%5C%5C%0A&amp;=%20(N+1)%5Cleft%5B%5Cfrac%7B2(2N+1)%7D%7B12%7D%20-%20%5Cfrac%7B3(N+1)%7D%7B12%7D%5Cright%5D%20%5C%5C%0A&amp;=%20(N+1)%20%5Ccdot%20%5Cfrac%7B4N+2%20-%203N-3%7D%7B12%7D%20%5C%5C%0A&amp;=%20%5Cfrac%7B(N+1)(N-1)%7D%7B12%7D%20%5C%5C%0A&amp;=%20%5Cfrac%7BN%5E2-1%7D%7B12%7D%0A%5Cend%7Balign*%7D"></p>
<p>By analogy with the ANOVA F-statistic, we normalise <img src="https://latex.codecogs.com/png.latex?T"> by <img src="https://latex.codecogs.com/png.latex?SS_%7B%5Ctext%7Btotal%7D%7D/(N-1)">, where the total rank sum-of-squares for the complete set of ranks <img src="https://latex.codecogs.com/png.latex?%5C%7B1,%5Cdots,N%5C%7D"> is <img src="https://latex.codecogs.com/png.latex?SS_%7B%5Ctext%7Btotal%7D%7D%20=%20N%5Csigma%5E2_R%20=%20%5Cfrac%7BN(N%5E2-1)%7D%7B12%7D">:</p>
<p><img src="https://latex.codecogs.com/png.latex?H%20=%20(N-1)%5Ccdot%5Cfrac%7BT%7D%7BSS_%7B%5Ctext%7Btotal%7D%7D%7D%20=%20%5Cfrac%7B12%7D%7BN(N+1)%7D%20%5Csum_%7Bj=1%7D%5E%7BK%7D%20n_j%20%5Cleft(%5Cbar%7BR%7D_j%20-%20%5Cfrac%7BN+1%7D%7B2%7D%5Cright)%5E2"></p>
<p>The factor <img src="https://latex.codecogs.com/png.latex?12/%5BN(N+1)%5D"> scales <img src="https://latex.codecogs.com/png.latex?H"> so that its expected value under <img src="https://latex.codecogs.com/png.latex?H_0"> equals <img src="https://latex.codecogs.com/png.latex?K-1">, which is exactly the degrees-of-freedom parameter of a chi-square distribution. For large <img src="https://latex.codecogs.com/png.latex?N">, <img src="https://latex.codecogs.com/png.latex?H%20%5Cxrightarrow%7Bd%7D%20%5Cchi%5E2(K-1)"> under <img src="https://latex.codecogs.com/png.latex?H_0">.</p>
</section>
</section>
<section id="back-to-the-pain-trial" class="level1">
<h1>Back to the pain trial</h1>
<p>Now that we’ve shown the mathematical difference between ANOVA and the Kruskal-Wallis test, we can compute the p-values using both of the tests and compare them.</p>
<div id="pain-kw" class="cell" data-execution_count="4">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb6-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> numpy <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> np</span>
<span id="cb6-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> scipy <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> stats</span>
<span id="cb6-3"></span>
<span id="cb6-4">N <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">sum</span>(<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">len</span>(g) <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> g <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> groups)</span>
<span id="cb6-5">K <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">len</span>(groups)</span>
<span id="cb6-6"></span>
<span id="cb6-7">all_scores <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.concatenate(groups)</span>
<span id="cb6-8">ranks <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> stats.rankdata(all_scores)</span>
<span id="cb6-9"></span>
<span id="cb6-10">idx <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span></span>
<span id="cb6-11">rank_groups <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> []</span>
<span id="cb6-12"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> g <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> groups:</span>
<span id="cb6-13">    rank_groups.append(ranks[idx : idx <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">len</span>(g)])</span>
<span id="cb6-14">    idx <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">len</span>(g)</span>
<span id="cb6-15"></span>
<span id="cb6-16">grand_mean_rank <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (N <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span></span>
<span id="cb6-17">H, p_kw <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> stats.kruskal(<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>groups)</span>
<span id="cb6-18">F, p_anova <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> stats.f_oneway(<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>groups)</span></code></pre></div></div>
</div>
<div id="83fbbdaa" class="cell" data-execution_count="5">
<details class="code-fold">
<summary>Table rendering</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb7-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> IPython.display <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> HTML</span>
<span id="cb7-2"></span>
<span id="cb7-3">th <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"padding:6px 14px; text-align:right; border-bottom:1px solid #555;"</span></span>
<span id="cb7-4">th_l <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"padding:6px 14px; text-align:left; border-bottom:1px solid #555;"</span></span>
<span id="cb7-5">td <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"padding:5px 14px; text-align:right;"</span></span>
<span id="cb7-6">td_l <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"padding:5px 14px;"</span></span>
<span id="cb7-7"></span>
<span id="cb7-8">rank_rows <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>.join(</span>
<span id="cb7-9">    <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"&lt;tr&gt;&lt;td style='</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>td_l<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">'&gt;</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>lbl<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">&lt;/td&gt;"</span></span>
<span id="cb7-10">    <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"&lt;td style='</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>td<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">'&gt;</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>rg<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">sum</span>()<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:.0f}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">&lt;/td&gt;"</span></span>
<span id="cb7-11">    <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"&lt;td style='</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>td<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">'&gt;</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>rg<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>mean()<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:.2f}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">&lt;/td&gt;"</span></span>
<span id="cb7-12">    <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"&lt;td style='</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>td<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">'&gt;</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>rg<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>mean() <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> grand_mean_rank<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:+.2f}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">&lt;/td&gt;&lt;/tr&gt;"</span></span>
<span id="cb7-13">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> lbl, rg <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">zip</span>(labels, rank_groups)</span>
<span id="cb7-14">)</span>
<span id="cb7-15"></span>
<span id="cb7-16">test_rows <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (</span>
<span id="cb7-17">    <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"&lt;tr&gt;&lt;td style='</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>td_l<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">'&gt;Kruskal-Wallis&lt;/td&gt;"</span></span>
<span id="cb7-18">    <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"&lt;td style='</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>td<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">'&gt;H = </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>H<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:.3f}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">&lt;/td&gt;"</span></span>
<span id="cb7-19">    <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"&lt;td style='</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>td<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">'&gt;</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>K <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">&lt;/td&gt;"</span></span>
<span id="cb7-20">    <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"&lt;td style='</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>td<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">'&gt;</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>p_kw<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:.4f}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">&lt;/td&gt;&lt;/tr&gt;"</span></span>
<span id="cb7-21">    <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"&lt;tr&gt;&lt;td style='</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>td_l<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">'&gt;ANOVA&lt;/td&gt;"</span></span>
<span id="cb7-22">    <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"&lt;td style='</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>td<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">'&gt;F = </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>F<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:.3f}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">&lt;/td&gt;"</span></span>
<span id="cb7-23">    <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"&lt;td style='</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>td<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">'&gt;</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>K <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">&lt;/td&gt;"</span></span>
<span id="cb7-24">    <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"&lt;td style='</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>td<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">'&gt;</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>p_anova<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:.4f}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">&lt;/td&gt;&lt;/tr&gt;"</span></span>
<span id="cb7-25">)</span>
<span id="cb7-26"></span>
<span id="cb7-27">display(HTML(<span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"""</span></span>
<span id="cb7-28"><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">&lt;p style="font-size:0.85em;color:#aaa;margin-bottom:4px;"&gt;</span></span>
<span id="cb7-29"><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">  Grand mean rank (null expectation): </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>grand_mean_rank<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:.1f}</span></span>
<span id="cb7-30"><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">&lt;/p&gt;</span></span>
<span id="cb7-31"><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">&lt;table style="border-collapse:collapse;font-size:0.9em;margin-bottom:1.2em;"&gt;</span></span>
<span id="cb7-32"><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">  &lt;thead&gt;&lt;tr&gt;</span></span>
<span id="cb7-33"><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">    &lt;th style="</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>th_l<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"&gt;Protocol&lt;/th&gt;</span></span>
<span id="cb7-34"><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">    &lt;th style="</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>th<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"&gt;Rank sum&lt;/th&gt;</span></span>
<span id="cb7-35"><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">    &lt;th style="</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>th<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"&gt;Mean rank&lt;/th&gt;</span></span>
<span id="cb7-36"><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">    &lt;th style="</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>th<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"&gt;Deviation&lt;/th&gt;</span></span>
<span id="cb7-37"><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">  &lt;/tr&gt;&lt;/thead&gt;</span></span>
<span id="cb7-38"><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">  &lt;tbody&gt;</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>rank_rows<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">&lt;/tbody&gt;</span></span>
<span id="cb7-39"><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">&lt;/table&gt;</span></span>
<span id="cb7-40"><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">&lt;table style="border-collapse:collapse;font-size:0.9em;"&gt;</span></span>
<span id="cb7-41"><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">  &lt;thead&gt;&lt;tr&gt;</span></span>
<span id="cb7-42"><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">    &lt;th style="</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>th_l<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"&gt;Test&lt;/th&gt;</span></span>
<span id="cb7-43"><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">    &lt;th style="</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>th<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"&gt;Statistic&lt;/th&gt;</span></span>
<span id="cb7-44"><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">    &lt;th style="</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>th<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"&gt;df&lt;/th&gt;</span></span>
<span id="cb7-45"><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">    &lt;th style="</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>th<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"&gt;p-value&lt;/th&gt;</span></span>
<span id="cb7-46"><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">  &lt;/tr&gt;&lt;/thead&gt;</span></span>
<span id="cb7-47"><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">  &lt;tbody&gt;</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>test_rows<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">&lt;/tbody&gt;</span></span>
<span id="cb7-48"><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">&lt;/table&gt;</span></span>
<span id="cb7-49"><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"""</span>))</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<p style="font-size:0.85em;color:#aaa;margin-bottom:4px;">
  Grand mean rank (null expectation): 23.0
</p>

<table class="caption-top table table-sm table-striped small">
<thead>
<tr class="header">
<th data-quarto-table-cell-role="th" style="text-align: left; padding: 6px 14px; border-bottom: 1px solid #555;">Protocol</th>
<th data-quarto-table-cell-role="th" style="text-align: right; padding: 6px 14px; border-bottom: 1px solid #555;">Rank sum</th>
<th data-quarto-table-cell-role="th" style="text-align: right; padding: 6px 14px; border-bottom: 1px solid #555;">Mean rank</th>
<th data-quarto-table-cell-role="th" style="text-align: right; padding: 6px 14px; border-bottom: 1px solid #555;">Deviation</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="padding: 5px 14px">Multimodal</td>
<td style="text-align: right; padding: 5px 14px;">212</td>
<td style="text-align: right; padding: 5px 14px;">14.17</td>
<td style="text-align: right; padding: 5px 14px;">-8.83</td>
</tr>
<tr class="even">
<td style="padding: 5px 14px">NSAID + nerve block</td>
<td style="text-align: right; padding: 5px 14px;">378</td>
<td style="text-align: right; padding: 5px 14px;">25.20</td>
<td style="text-align: right; padding: 5px 14px;">+2.20</td>
</tr>
<tr class="odd">
<td style="padding: 5px 14px">Opioid-only</td>
<td style="text-align: right; padding: 5px 14px;">444</td>
<td style="text-align: right; padding: 5px 14px;">29.63</td>
<td style="text-align: right; padding: 5px 14px;">+6.63</td>
</tr>
</tbody>
</table>


<table class="caption-top table table-sm table-striped small">
<thead>
<tr class="header">
<th data-quarto-table-cell-role="th" style="text-align: left; padding: 6px 14px; border-bottom: 1px solid #555;">Test</th>
<th data-quarto-table-cell-role="th" style="text-align: right; padding: 6px 14px; border-bottom: 1px solid #555;">Statistic</th>
<th data-quarto-table-cell-role="th" style="text-align: right; padding: 6px 14px; border-bottom: 1px solid #555;">df</th>
<th data-quarto-table-cell-role="th" style="text-align: right; padding: 6px 14px; border-bottom: 1px solid #555;">p-value</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="padding: 5px 14px">Kruskal-Wallis</td>
<td style="text-align: right; padding: 5px 14px;">H = 11.034</td>
<td style="text-align: right; padding: 5px 14px;">2</td>
<td style="text-align: right; padding: 5px 14px;">0.0040</td>
</tr>
<tr class="even">
<td style="padding: 5px 14px">ANOVA</td>
<td style="text-align: right; padding: 5px 14px;">F = 1.976</td>
<td style="text-align: right; padding: 5px 14px;">2</td>
<td style="text-align: right; padding: 5px 14px;">0.1513</td>
</tr>
</tbody>
</table>
</div>
</div>
<p>The multimodal group’s mean rank is well below 23.0 (the grand mean rank), the opioid-only group’s mean rank is well above it. The NSAID + nerve block is quite close to the mean rank. The <img src="https://latex.codecogs.com/png.latex?H">-statistic is able to quantify the spread. The chi-square p-value tells us whether a deviation this large would occur by chance under the null. With <img src="https://latex.codecogs.com/png.latex?p%20%3C%200.05">, we reject. The KW-test rejects the null, ANOVA doesn’t. This shows that the KW-test is able to quantify the differences between distributions when they are heavily skewed better than ANOVA.</p>
<div class="callout callout-style-default callout-note callout-titled">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
<span class="screen-reader-only">Note</span>What KW doesn’t tell
</div>
</div>
<div class="callout-body-container callout-body">
<p>A statistically significant KW result only says that something differs, not which pairs differ. To investigate which pairs differ, the Dunn test <span class="citation" data-cites="bobbitt2020dunns">[2]</span> fits this problem well.</p>
</div>
</div>



</section>

<div id="quarto-appendix" class="default"><section class="quarto-appendix-contents" id="quarto-bibliography"><h2 class="anchored quarto-appendix-heading">References</h2><div id="refs" class="references csl-bib-body" data-entry-spacing="0">
<div id="ref-wiki_anova" class="csl-entry">
<div class="csl-left-margin">[1] </div><div class="csl-right-inline">Wikipedia contributors, <span>“Analysis of variance.”</span> <a href="https://en.wikipedia.org/wiki/Analysis_of_variance" class="uri">https://en.wikipedia.org/wiki/Analysis_of_variance</a>, 2025.</div>
</div>
<div id="ref-bobbitt2020dunns" class="csl-entry">
<div class="csl-left-margin">[2] </div><div class="csl-right-inline">Z. Bobbitt, <span>“Dunn’s test for multiple comparisons.”</span> <a href="https://www.statology.org/dunns-test/" class="uri">https://www.statology.org/dunns-test/</a>, 2020.</div>
</div>
</div></section><section class="quarto-appendix-contents" id="quarto-reuse"><h2 class="anchored quarto-appendix-heading">Reuse</h2><div class="quarto-appendix-contents"><div><a rel="license" href="https://creativecommons.org/licenses/by/4.0/">CC BY 4.0</a></div></div></section><section class="quarto-appendix-contents" id="quarto-citation"><h2 class="anchored quarto-appendix-heading">Citation</h2><div><div class="quarto-appendix-secondary-label">BibTeX citation:</div><div class="code-copy-outer-scaffold"><pre class="sourceCode code-with-copy quarto-appendix-bibtex"><code class="sourceCode bibtex">@online{bogossian2026,
  author = {Bogossian, Andreas},
  title = {The {Kruskal-Wallis} Test, Derived from First Principles},
  date = {2026-04-26},
  url = {https://andreasbogossian.com/posts/Kruskal-Wallis-test/},
  langid = {en}
}
</code></pre></div><div class="quarto-appendix-secondary-label">For attribution, please cite this work as:</div><div id="ref-bogossian2026" class="csl-entry quarto-appendix-citeas">
<div class="">A.
Bogossian, <span>“The Kruskal-Wallis test, derived from first
principles.”</span> [Online]. Available: <a href="https://andreasbogossian.com/posts/Kruskal-Wallis-test/">https://andreasbogossian.com/posts/Kruskal-Wallis-test/</a></div>
</div></div></section></div> ]]></description>
  <category>statistics</category>
  <category>hypothesis testing</category>
  <guid>https://andreasbogossian.com/posts/Kruskal-Wallis-test/</guid>
  <pubDate>Sat, 25 Apr 2026 21:00:00 GMT</pubDate>
  <media:content url="https://andreasbogossian.com/posts/Kruskal-Wallis-test/thumbnail.webp" medium="image" type="image/webp"/>
</item>
<item>
  <title>The EM-algorithm</title>
  <dc:creator>Andreas Bogossian</dc:creator>
  <link>https://andreasbogossian.com/posts/em-algorithm/</link>
  <description><![CDATA[ 




<p>Let’s start from a practical example. Let’s say that a teacher has their 220 students choose between a difficult exam or an easier exam. When the exam papers are collected, the teacher accidentally messes up the papers and doesn’t know which scores are from the difficult exam and which are from the easer one. Thus the teacher is left with a pile of 220 unlabelled exam scores.</p>
<p>Now what would be the best way to distinguish which exam result comes from which exam? One solution would be to just draw a line where e.g.&nbsp;everyone under 67 points on the exam took the more difficult exam and everyone over took the easier one. The problem with this approach is that the point distributions overlap. This means that some students achieving great points on the more difficult exam would be incorrectly labelled as the worst performing people on the easier exam.</p>
<p>A better approach is to fit who Gaussian models to soft label the exam scores. This way, every exam result would have a probability that would tell the teacher the chances of the point coming from each category. Now in order to soft label the exam scores, we need to know the parameters <img src="https://latex.codecogs.com/png.latex?%5Ctheta"> for the Gaussian distributions. But to know what parameters fit the models to the data the best, we need the information about which group each data point belongs to.</p>
<p>The problem is that this is a “chicken-and-egg” problem, where in order to acquire one, you need the other. When you don’t know either, you can’t determine either. This deadlock can be broken by alternating between guessing the labels and updating the distributions until distributions converge. This method is called the EM-algorithm.</p>
<div class="callout callout-style-default callout-note callout-titled">
<div class="callout-header d-flex align-content-center collapsed" data-bs-toggle="collapse" data-bs-target=".callout-1-contents" aria-controls="callout-1" aria-expanded="false" aria-label="Toggle callout">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
<span class="screen-reader-only">Note</span>Notation used in this post
</div>
<div class="callout-btn-toggle d-inline-block border-0 py-1 ps-1 pe-0 float-end"><i class="callout-toggle"></i></div>
</div>
<div id="callout-1" class="callout-1-contents callout-collapse collapse">
<div class="callout-body-container callout-body">
<table class="caption-top table">
<colgroup>
<col style="width: 29%">
<col style="width: 22%">
<col style="width: 48%">
</colgroup>
<thead>
<tr class="header">
<th>Symbol</th>
<th>Name</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td><img src="https://latex.codecogs.com/png.latex?X"></td>
<td>Observed data</td>
<td>The full set of exam scores</td>
</tr>
<tr class="even">
<td><img src="https://latex.codecogs.com/png.latex?x_i"></td>
<td>Single observation</td>
<td>The score of student <img src="https://latex.codecogs.com/png.latex?i"></td>
</tr>
<tr class="odd">
<td><img src="https://latex.codecogs.com/png.latex?Z"></td>
<td>Latent variables</td>
<td>The hidden group labels for all scores</td>
</tr>
<tr class="even">
<td><img src="https://latex.codecogs.com/png.latex?z_i"></td>
<td>Single latent variable</td>
<td>The hidden group label for student <img src="https://latex.codecogs.com/png.latex?i"></td>
</tr>
<tr class="odd">
<td><img src="https://latex.codecogs.com/png.latex?%5Ctheta"></td>
<td>Parameters</td>
<td>All model parameters <img src="https://latex.codecogs.com/png.latex?%5C%7B%5Cpi_k,%20%5Cmu_k,%20%5Csigma_k%5E2%5C%7D_%7Bk=1%7D%5EK"></td>
</tr>
<tr class="even">
<td><img src="https://latex.codecogs.com/png.latex?%5Ctheta%5E%7B(t)%7D"></td>
<td>Parameters at iteration <img src="https://latex.codecogs.com/png.latex?t"></td>
<td>The current parameter estimate during EM</td>
</tr>
<tr class="odd">
<td><img src="https://latex.codecogs.com/png.latex?n"></td>
<td>Sample size</td>
<td>The total number of exam scores</td>
</tr>
<tr class="even">
<td><img src="https://latex.codecogs.com/png.latex?K"></td>
<td>Number of components</td>
<td>The number of Gaussian distributions in the mixture</td>
</tr>
<tr class="odd">
<td><img src="https://latex.codecogs.com/png.latex?k"></td>
<td>Component index</td>
<td>Indexes a single Gaussian component, <img src="https://latex.codecogs.com/png.latex?k%20%5Cin%20%5C%7B1,%20%5Cldots,%20K%5C%7D"></td>
</tr>
<tr class="even">
<td><img src="https://latex.codecogs.com/png.latex?%5Cpi_k"></td>
<td>Mixing weight</td>
<td>How common group <img src="https://latex.codecogs.com/png.latex?k"> is; all <img src="https://latex.codecogs.com/png.latex?%5Cpi_k"> sum to 1</td>
</tr>
<tr class="odd">
<td><img src="https://latex.codecogs.com/png.latex?%5Cmu_k"></td>
<td>Mean</td>
<td>Centre of the <img src="https://latex.codecogs.com/png.latex?k">-th Gaussian</td>
</tr>
<tr class="even">
<td><img src="https://latex.codecogs.com/png.latex?%5Csigma_k%5E2"></td>
<td>Variance</td>
<td>Spread of the <img src="https://latex.codecogs.com/png.latex?k">-th Gaussian</td>
</tr>
<tr class="odd">
<td><img src="https://latex.codecogs.com/png.latex?%5Cmathcal%7BN%7D(x%20%5Cmid%20%5Cmu,%20%5Csigma%5E2)"></td>
<td>Gaussian density</td>
<td>PDF of a Normal distribution evaluated at <img src="https://latex.codecogs.com/png.latex?x"></td>
</tr>
<tr class="even">
<td><img src="https://latex.codecogs.com/png.latex?%5Cell(%5Ctheta)"></td>
<td>Log-likelihood</td>
<td>Log probability of the observed data under <img src="https://latex.codecogs.com/png.latex?%5Ctheta"></td>
</tr>
<tr class="odd">
<td><img src="https://latex.codecogs.com/png.latex?%5Cell_c(%5Ctheta)"></td>
<td>Complete-data log-likelihood</td>
<td>Log probability if the hidden labels <img src="https://latex.codecogs.com/png.latex?Z"> were known</td>
</tr>
<tr class="even">
<td><img src="https://latex.codecogs.com/png.latex?Q(%5Ctheta%20%5Cmid%20%5Ctheta%5E%7B(t)%7D)"></td>
<td>Q-function</td>
<td>Expected complete-data log-likelihood under the current posterior of <img src="https://latex.codecogs.com/png.latex?Z"></td>
</tr>
<tr class="odd">
<td><img src="https://latex.codecogs.com/png.latex?r_%7Bik%7D"></td>
<td>Responsibility</td>
<td>Posterior probability that score <img src="https://latex.codecogs.com/png.latex?i"> came from component <img src="https://latex.codecogs.com/png.latex?k"></td>
</tr>
<tr class="even">
<td><img src="https://latex.codecogs.com/png.latex?%5Cmathbf%7B1%7D%5B%5Ccdot%5D"></td>
<td>Indicator function</td>
<td>1 if the condition inside is true, 0 otherwise</td>
</tr>
<tr class="odd">
<td><img src="https://latex.codecogs.com/png.latex?%5Cepsilon"></td>
<td>Convergence threshold</td>
<td>Minimum log-likelihood change required to keep iterating</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<section id="theory" class="level1">
<h1>Theory</h1>
<section id="the-model-gaussian-mixture-model" class="level2">
<h2 class="anchored" data-anchor-id="the-model-gaussian-mixture-model">The model: Gaussian Mixture Model</h2>
<p>We model the data as coming from a Gaussian Mixture Model (GMM). A GMM is a weighted sum of <img src="https://latex.codecogs.com/png.latex?K"> Normal distributions. The marginal likelihood (the probability of the data given the parameters) is:</p>
<p><img src="https://latex.codecogs.com/png.latex?p(x_i%20%5Cmid%20%5Ctheta)%20=%20%5Csum_%7Bk=1%7D%5E%7BK%7D%20%5Cpi_k%20%5C,%20%5Cmathcal%7BN%7D(x_i%20%5Cmid%20%5Cmu_k,%20%5Csigma_k%5E2)"></p>
<p>where</p>
<ul>
<li><img src="https://latex.codecogs.com/png.latex?%5Cpi_k"> is mixing weight. It asks how common is group <img src="https://latex.codecogs.com/png.latex?k">? Must sum to 1.</li>
<li><img src="https://latex.codecogs.com/png.latex?%5Cmu_k,%20%5Csigma_k%5E2"> are the mean and variance of the <img src="https://latex.codecogs.com/png.latex?k">-th Gaussian.</li>
<li><img src="https://latex.codecogs.com/png.latex?Z_i%20%5Cin%20%5C%7B1,%20%5Cldots,%20K%5C%7D"> is the latent group assignment for point <img src="https://latex.codecogs.com/png.latex?i">, which we don’t know.</li>
</ul>
<p>Now in order to soft label the exam scores, we want to find <img src="https://latex.codecogs.com/png.latex?%5Ctheta%20=%20%5C%7B%5Cpi_k,%20%5Cmu_k,%20%5Csigma_k%5E2%5C%7D_%7Bk=1%7D%5EK"> that maximises the log-likelihood of the data. The log likelihood can be written as:</p>
<p><img src="https://latex.codecogs.com/png.latex?%5Cbegin%7Balign*%7D%0A%5Clog%20P(x_1,%20x_2,%20%5Cdots,%20x_n%20%5Cmid%20%5Ctheta)%20=%20%5Cell(%5Ctheta)%0A%20%20&amp;=%20%5Clog%20%5Cprod_%7Bi=1%7D%5E%7Bn%7D%20P(x_i%20%5Cmid%20%5Ctheta)%20%5C%5C%0A%20%20&amp;=%20%5Clog%20%5Cprod_%7Bi=1%7D%5E%7Bn%7D%20%5Csum_%7Bk=1%7D%5E%7BK%7D%20%5Cpi_k%20%5C,%20%5Cmathcal%7BN%7D(x_i%20%5Cmid%20%5Cmu_k,%20%5Csigma_k%5E2)%20%5C%5C%0A%20%20&amp;=%20%5Csum_%7Bi=1%7D%5E%7Bn%7D%20%5Clog%20%5Csum_%7Bk=1%7D%5E%7BK%7D%20%5Cpi_k%20%5C,%20%5Cmathcal%7BN%7D(x_i%20%5Cmid%20%5Cmu_k,%20%5Csigma_k%5E2)%0A%5Cend%7Balign*%7D"></p>
<p>But there is a problem: The log of a sum has no tidy closed form derivative and this is why plain maximum likelihood fails <span class="citation" data-cites="bishop2006pattern">[1]</span>.</p>
</section>
<section id="the-em-fix-complete-data-log-likelihood" class="level2">
<h2 class="anchored" data-anchor-id="the-em-fix-complete-data-log-likelihood">The EM fix: complete-data log-likelihood</h2>
<p>The trick the EM algorithm uses is that it imagines we did observe the hidden labels <img src="https://latex.codecogs.com/png.latex?Z">. So If we know which group each score came from, the joint probability of a single observation would be:</p>
<p><img src="https://latex.codecogs.com/png.latex?p(x_i,%20z_i%20=%20k%20%5Cmid%20%5Ctheta)%20=%20%5Cpi_k%20%5C,%20%5Cmathcal%7BN%7D(x_i%20%5Cmid%20%5Cmu_k,%20%5Csigma_k%5E2)"></p>
<p>Over all <img src="https://latex.codecogs.com/png.latex?n"> points, the complete-data log-likelihood is:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cell_c(%5Ctheta)%20=%20%5Csum_%7Bi=1%7D%5E%7Bn%7D%20%5Clog%20%5C,%20p(x_i,%20z_i%20%5Cmid%20%5Ctheta)%0A%20%20%20%20=%20%5Csum_%7Bi=1%7D%5E%7Bn%7D%20%5Clog%20%5Cleft%5B%20%5Cpi_%7Bz_i%7D%20%5C,%20%5Cmathcal%7BN%7D(x_i%20%5Cmid%20%5Cmu_%7Bz_i%7D,%20%5Csigma_%7Bz_i%7D%5E2)%20%5Cright%5D%0A"></p>
<p>Since each <img src="https://latex.codecogs.com/png.latex?z_i"> takes exactly one value in <img src="https://latex.codecogs.com/png.latex?%7B1,%20%5Cdots,%20K%7D">, we can rewrite this using an indicator that makes the sum over k explicit</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%20%20%5Cell_c(%5Ctheta)%20=%20%5Csum_%7Bi=1%7D%5E%7Bn%7D%20%5Csum_%7Bk=1%7D%5E%7BK%7D%0A%20%20%20%20%5Cmathbf%7B1%7D%5Bz_i%20=%20k%5D%20%5Cleft%5B%20%5Clog%20%5Cpi_k%20+%20%5Clog%20%5Cmathcal%7BN%7D(x_i%20%5Cmid%20%5Cmu_k,%20%5Csigma_k%5E2)%20%5Cright%5D%20%20%20%20%0A"></p>
<p>In this notation <img src="https://latex.codecogs.com/png.latex?%5Cmathbf%7B1%7D%5Bz_i%20=%20k%5D"> is 1 when point <img src="https://latex.codecogs.com/png.latex?i"> is truly from group <img src="https://latex.codecogs.com/png.latex?k"> and 0 otherwise. Now the reason we write the likelihood in this for is because the sum of logs is tractable and can be used for optimization. But there is a catch: we still don’t know <img src="https://latex.codecogs.com/png.latex?Z">, so we can’t evaluate <img src="https://latex.codecogs.com/png.latex?%5Cell_c"> directly. Instead, we take the expectation of <img src="https://latex.codecogs.com/png.latex?%5Cell_c"> over the posterior of <img src="https://latex.codecogs.com/png.latex?Z"> given the data and current parameters <img src="https://latex.codecogs.com/png.latex?%5Ctheta%5E%7B(t)%7D">:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0AQ(%5Ctheta%20%5Cmid%20%5Ctheta%5E%7B(t)%7D)%20=%20%5Cmathbb%7BE%7D_%7BZ%20%5Cmid%20X,%5C,%5Ctheta%5E%7B(t)%7D%7D%5C!%5Cbigl%5B%5Cell_c(%5Ctheta)%5Cbigr%5D%0A"></p>
<p>Expanding the expectation, the hard indicators <img src="https://latex.codecogs.com/png.latex?%5Cmathbf%7B1%7D%5Bz_i%20=%20k%5D"> get replaced by soft posterior probabilities <img src="https://latex.codecogs.com/png.latex?r_%7Bik%7D%20=%20p(z_i%20=%20k%20%5Cmid%20x_i,%20%5Ctheta%5E%7B(t)%7D)">:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0AQ(%5Ctheta%20%5Cmid%20%5Ctheta%5E%7B(t)%7D)%20=%20%5Csum_%7Bi=1%7D%5E%7Bn%7D%20%5Csum_%7Bk=1%7D%5E%7BK%7D%0A%20%20r_%7Bik%7D%20%5Cleft%5B%20%5Clog%20%5Cpi_k%20+%20%5Clog%20%5Cmathcal%7BN%7D(x_i%20%5Cmid%20%5Cmu_k,%20%5Csigma_k%5E2)%20%5Cright%5D%0A"></p>
<p>This form is a weighted sum of logs that is differentiable and maximisable in closed form. We can derive the meaning of the two steps from this form:</p>
<ul>
<li><strong>E-step</strong>: compute (estimate) the weights <img src="https://latex.codecogs.com/png.latex?r_%7Bik%7D"></li>
<li><strong>M-step</strong>: maximise <img src="https://latex.codecogs.com/png.latex?Q"> over <img src="https://latex.codecogs.com/png.latex?%5Ctheta"> treating <img src="https://latex.codecogs.com/png.latex?r_%7Bik%7D"> as fixed</li>
</ul>
<p>So in summary this means that we solve the chicken-and-egg problem by estimating the responsibilities and then estimating the parameters based on the estimate of the responsibility. This way we always have one of the two unknowns locked and can create an estimate from the other unknown.</p>
</section>
<section id="e-step-compute-responsibilities" class="level2">
<h2 class="anchored" data-anchor-id="e-step-compute-responsibilities">E-step: compute responsibilities</h2>
<p>The weights <img src="https://latex.codecogs.com/png.latex?r_%7Bik%7D"> are the posterior probability that the point <img src="https://latex.codecogs.com/png.latex?i"> came from the component <img src="https://latex.codecogs.com/png.latex?k">, given the current parameters. By Bayes’ theorem, prior belief about group membership gets updated by how well each Gaussian explains the observed score:</p>
<p><img src="https://latex.codecogs.com/png.latex?r_%7Bik%7D%20=%20p(z_i%20=%20k%20%5Cmid%20x_i,%20%5Ctheta%5E%7B(t)%7D)%20=%0A%20%20%5Cfrac%7B%0A%20%20%20%20%5Cpi_k%5E%7B(t)%7D%5C,%5Cmathcal%7BN%7D(x_i%20%5Cmid%20%5Cmu_k%5E%7B(t)%7D,%5C,%20%5Csigma_k%5E%7B2(t)%7D)%0A%20%20%7D%7B%0A%20%20%20%20%5Cdisplaystyle%5Csum_%7Bj=1%7D%5E%7BK%7D%0A%20%20%20%20%5Cpi_j%5E%7B(t)%7D%5C,%5Cmathcal%7BN%7D(x_i%20%5Cmid%20%5Cmu_j%5E%7B(t)%7D,%5C,%20%5Csigma_j%5E%7B2(t)%7D)%0A%20%20%7D%0A"></p>
<p>In the fraction, the numerator is the prior belief that point <img src="https://latex.codecogs.com/png.latex?i"> is from group <img src="https://latex.codecogs.com/png.latex?k"> (<img src="https://latex.codecogs.com/png.latex?%5Cpi_k%5E%7B(t)%7D">), multiplied by how well group <img src="https://latex.codecogs.com/png.latex?k">’s Gaussian explains the score (<img src="https://latex.codecogs.com/png.latex?%5Cmathcal%7BN%7D(x_i%20%5Cmid%20%5Cmu_k%5E%7B(t)%7D,%5C,%20%5Csigma_k%5E%7B2(t)%7D)">). The denominator then normalizes across all <img src="https://latex.codecogs.com/png.latex?K"> groups so the responsibilities for each point sum up to 1. The result <img src="https://latex.codecogs.com/png.latex?r_%7Bik%7D"> is then a soft assignment so every point gets a fractional membership in every group rather than a binary 0/1 label. After this step we have an <img src="https://latex.codecogs.com/png.latex?n%20%5Ctimes%20K"> matrix of responsibilities.</p>
</section>
<section id="m-step-update-parameters" class="level2">
<h2 class="anchored" data-anchor-id="m-step-update-parameters">M-step: update parameters</h2>
<p>With responsibilities fixed, we maximize <img src="https://latex.codecogs.com/png.latex?Q"> over <img src="https://latex.codecogs.com/png.latex?%5Ctheta"> by differentiating with respect to each parameter, setting to zero and solving. The resulting updates are weighted statistics where each data point contributes to component <img src="https://latex.codecogs.com/png.latex?k"> in proportion to <img src="https://latex.codecogs.com/png.latex?r_%7Bik%7D"> <span class="citation" data-cites="bishop2006pattern">[1, Ch. 9]</span>.</p>
<p><img src="https://latex.codecogs.com/png.latex?%5Chat%7B%5Cmu%7D_k%20=%20%5Cfrac%7B%5Csum_i%20r_%7Bik%7D%5C,x_i%7D%7B%5Csum_i%20r_%7Bik%7D%7D,%0A%20%20%5Cqquad%0A%20%20%5Chat%7B%5Csigma%7D_k%5E2%20=%20%5Cfrac%7B%5Csum_i%20r_%7Bik%7D(x_i%20-%20%5Chat%7B%5Cmu%7D_k)%5E2%7D%7B%5Csum_i%20r_%7Bik%7D%7D,%0A%20%20%5Cqquad%0A%20%20%5Chat%7B%5Cpi%7D_k%20=%20%5Cfrac%7B1%7D%7Bn%7D%5Csum_i%20r_%7Bik%7D%0A"></p>
<p>Here</p>
<ul>
<li><img src="https://latex.codecogs.com/png.latex?%5Chat%7B%5Cmu%7D_k"> is the responsibility-weighted mean of the data</li>
<li><img src="https://latex.codecogs.com/png.latex?%5Chat%7B%5Csigma%7D_k%5E2"> is the responsibility-weighted variance around that mean</li>
<li><img src="https://latex.codecogs.com/png.latex?%5Chat%7B%5Cpi%7D_k"> is the average responsibility — the fraction of the data “owned” by component <img src="https://latex.codecogs.com/png.latex?k"></li>
</ul>
</section>
<section id="convergence" class="level2">
<h2 class="anchored" data-anchor-id="convergence">Convergence</h2>
<p>Now to solve the optimal parameters, we iterate alternating the E and M steps until the change in the log-likelihood falls below a threshold <img src="https://latex.codecogs.com/png.latex?%5Cepsilon">. A thing to keep in mind with the EM algorithm is that it is guaranteed to reach a <em>local</em> maximum (or a saddle point) and not necessary the global one <span class="citation" data-cites="bishop2006pattern">[1, Ch. 9]</span>. Also initialization matters because different starting points can lead to different local optima.</p>
</section>
</section>
<section id="code-demo" class="level1">
<h1>Code demo</h1>
<p>In this code demo, we’ll use the example from the introduction. We’ll create a data set from two exams that are sampled from two distinct Gaussian distribution. The goal is to soft label the exam scores so that students can get their correct grades based on exam difficulty they chose.</p>
<section id="setup-and-data-generation" class="level2">
<h2 class="anchored" data-anchor-id="setup-and-data-generation">Setup and data generation</h2>
<div id="setup" class="cell" data-message="false" data-execution_count="1">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb1-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> numpy <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> np</span>
<span id="cb1-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> json</span>
<span id="cb1-3"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> scipy.stats <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> norm</span>
<span id="cb1-4"></span>
<span id="cb1-5">rng <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.random.default_rng(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">42</span>)</span>
<span id="cb1-6"></span>
<span id="cb1-7"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Generate synthetic "exam score" data from two groups:</span></span>
<span id="cb1-8"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#   Group 1 (hard paper): mean=45, sd=8</span></span>
<span id="cb1-9"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#   Group 2 (easy paper): mean=70, sd=6</span></span>
<span id="cb1-10">n1, n2 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">120</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span></span>
<span id="cb1-11">group1 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> rng.normal(loc<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">45</span>, scale<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>, size<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>n1)</span>
<span id="cb1-12">group2 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> rng.normal(loc<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">70</span>, scale<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>, size<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>n2)</span>
<span id="cb1-13">true_labels <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.array([<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> n1 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> [<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> n2)</span>
<span id="cb1-14">idx <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> rng.permutation(n1 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> n2)</span>
<span id="cb1-15">X <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.concatenate([group1, group2])[idx]</span>
<span id="cb1-16">true_labels <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> true_labels[idx]</span>
<span id="cb1-17">n <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">len</span>(X)</span></code></pre></div></div>
</div>
<div id="07c54b3e" class="cell" data-execution_count="2">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb2-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> matplotlib.pyplot <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> plt</span>
<span id="cb2-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> scipy.stats <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> norm <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> sp_norm</span>
<span id="cb2-3"></span>
<span id="cb2-4">fig, ax <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> plt.subplots(figsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">3.5</span>))</span>
<span id="cb2-5">ax.hist(X, bins<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">30</span>, density<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>, color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#cbd5e1"</span>, edgecolor<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"white"</span>, label<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Observed scores"</span>)</span>
<span id="cb2-6"></span>
<span id="cb2-7">xs_plot <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.linspace(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">300</span>)</span>
<span id="cb2-8">ax.plot(xs_plot, sp_norm.pdf(xs_plot, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">45</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>),  color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"steelblue"</span>,  lw<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, label<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"True group 1 (μ=45, σ=8)"</span>)</span>
<span id="cb2-9">ax.plot(xs_plot, sp_norm.pdf(xs_plot, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">70</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>),  color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"darkorange"</span>, lw<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, label<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"True group 2 (μ=70, σ=6)"</span>)</span>
<span id="cb2-10"></span>
<span id="cb2-11">ax.set_xlabel(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Score"</span>)</span>
<span id="cb2-12">ax.set_ylabel(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Density"</span>)</span>
<span id="cb2-13">ax.legend()</span>
<span id="cb2-14">plt.tight_layout()</span>
<span id="cb2-15">plt.show()</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div>
<figure class="figure">
<p><a href="index_files/figure-html/cell-3-output-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-1"><img src="https://andreasbogossian.com/posts/em-algorithm/index_files/figure-html/cell-3-output-1.png" width="758" height="326" class="figure-img"></a></p>
</figure>
</div>
</div>
</div>
<p>There are 220 exam scores in the dataset sampled from two overlapping Gaussian distributions. After sampling the exam scores, we shuffle the scores so that the algorithm can’t distinguish what scores come from what distribution. We include the original labels only for testing purposes to visualize how well the EM algorithm is able to find the correct labels. The EM algorithm follows roughly the following steps:</p>
<ol type="1">
<li>Start with a rough guess at where the two groups are</li>
<li>For each data point, calculate the probability it belongs to group 1 vs group 2</li>
<li>Use those probabilities as soft weights to refit the distributions. Points clearly in one group pull hard on that group’s mean, uncertain points contribute a little to both</li>
<li>After this we have slightly better distributions, which give slightly better probabilities next time</li>
<li>Repeat until both stabilize</li>
</ol>
</section>
<section id="em-implementation" class="level2">
<h2 class="anchored" data-anchor-id="em-implementation">EM implementation</h2>
<div id="cell-em-algorithm" class="cell" data-execution_count="3">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb3-1"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">def</span> em_gmm(X, K<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, n_iter<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">30</span>, seed<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>):</span>
<span id="cb3-2">    rng_init <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.random.default_rng(seed)</span>
<span id="cb3-3">    n <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">len</span>(X)</span>
<span id="cb3-4"></span>
<span id="cb3-5">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># --- Initialise parameters randomly ---</span></span>
<span id="cb3-6">    mu    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> rng_init.choice(X, K, replace<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">False</span>)   <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># pick K random data points as starting means</span></span>
<span id="cb3-7">    sigma <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.full(K, np.std(X))                  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># same initial spread for all components</span></span>
<span id="cb3-8">    pi    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.ones(K) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> K                          <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># equal mixing weights</span></span>
<span id="cb3-9"></span>
<span id="cb3-10">    history <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> []   <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># store every snapshot for the OJS step-through</span></span>
<span id="cb3-11"></span>
<span id="cb3-12">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> t <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">range</span>(n_iter):</span>
<span id="cb3-13"></span>
<span id="cb3-14">        <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># --- E-step: responsibilities ---</span></span>
<span id="cb3-15">        <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># r[i, k] = p(z_i = k | x_i, theta^(t))</span></span>
<span id="cb3-16">        r <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.array([</span>
<span id="cb3-17">            pi[k] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> norm.pdf(X, mu[k], sigma[k])</span>
<span id="cb3-18">            <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> k <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">range</span>(K)</span>
<span id="cb3-19">        ]).T                              <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># shape: (n, K)</span></span>
<span id="cb3-20">        r <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/=</span> r.<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">sum</span>(axis<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, keepdims<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># normalise rows</span></span>
<span id="cb3-21"></span>
<span id="cb3-22">        <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># --- M-step: update parameters ---</span></span>
<span id="cb3-23">        Nk    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> r.<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">sum</span>(axis<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>)</span>
<span id="cb3-24">        mu    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (r <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> X[:, <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">None</span>]).<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">sum</span>(axis<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> Nk</span>
<span id="cb3-25">        sigma <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.sqrt((r <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> (X[:, <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">None</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> mu) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">**</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>).<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">sum</span>(axis<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> Nk)</span>
<span id="cb3-26">        pi    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> Nk <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> n</span>
<span id="cb3-27"></span>
<span id="cb3-28">        <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># --- Log-likelihood ---</span></span>
<span id="cb3-29">        ll <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.log(</span>
<span id="cb3-30">            <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">sum</span>(pi[k] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> norm.pdf(X, mu[k], sigma[k]) <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> k <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">range</span>(K))</span>
<span id="cb3-31">        ).<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">sum</span>()</span>
<span id="cb3-32"></span>
<span id="cb3-33">        history.append({</span>
<span id="cb3-34">            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"iter"</span>:  t <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,</span>
<span id="cb3-35">            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mu"</span>:    mu.tolist(),</span>
<span id="cb3-36">            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sigma"</span>: sigma.tolist(),</span>
<span id="cb3-37">            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pi"</span>:    pi.tolist(),</span>
<span id="cb3-38">            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ll"</span>:    <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">round</span>(ll, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>),</span>
<span id="cb3-39">            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"r"</span>:     r.tolist(),   <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># full responsibility matrix. Used for rug colouring</span></span>
<span id="cb3-40">        })</span>
<span id="cb3-41"></span>
<span id="cb3-42">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> history</span>
<span id="cb3-43"></span>
<span id="cb3-44"></span>
<span id="cb3-45">history <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> em_gmm(X, K<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, n_iter<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">30</span>)</span>
<span id="cb3-46"></span>
<span id="cb3-47"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Bridge to OJS</span></span>
<span id="cb3-48">ojs_define(</span>
<span id="cb3-49">    history     <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> history,</span>
<span id="cb3-50">    X_data      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> X.tolist(),</span>
<span id="cb3-51">    true_labels <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> true_labels.tolist(),</span>
<span id="cb3-52">    true_mu     <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">45.0</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">70.0</span>],</span>
<span id="cb3-53">    true_sigma  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">8.0</span>,  <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">6.0</span>],</span>
<span id="cb3-54">)</span></code></pre></div></div>
<div id="em-algorithm" class="cell-output cell-output-display">
<script type="ojs-define">{"contents": [{"name": "history", "value": [{"iter": 1, "mu": [48.86820924573083, 60.00615270256476], "sigma": [11.995807954598373, 13.532553858696676], "pi": [0.3529033910432074, 0.6470966089567927], "ll": -892.299, "r": [[0.46502227995582174, 0.5349777200441782], [0.23337937532311762, 0.7666206246768824], [0.18818175134461199, 0.811818248655388], [0.43736487501755383, 0.5626351249824462], [0.5705690498024438, 0.4294309501975562], [0.12247561468639503, 0.877524385313605], [0.5098088164620027, 0.4901911835379972], [0.25919218459325877, 0.7408078154067412], [0.5438445901270759, 0.45615540987292413], [0.201223076927326, 0.798776923072674], [0.6724389339960535, 0.32756106600394647], [0.143875650349712, 0.8561243496502879], [0.40970916703424487, 0.5902908329657551], [0.530327625700821, 0.4696723742991789], [0.507837792654723, 0.49216220734527694], [0.19173578391606388, 0.8082642160839361], [0.25172399139193136, 0.7482760086080686], [0.4406251606471967, 0.5593748393528033], [0.6106624191841454, 0.38933758081585457], [0.5490983547648702, 0.4509016452351298], [0.4674399839339095, 0.5325600160660905], [0.5761497066442224, 0.42385029335577756], [0.09583539199075032, 0.9041646080092496], [0.602579609994878, 0.3974203900051219], [0.24159184666936603, 0.758408153330634], [0.12636973828025902, 0.873630261719741], [0.2029288751224911, 0.7970711248775089], [0.14469350087190763, 0.8553064991280924], [0.6033426077259167, 0.3966573922740833], [0.5359807292174512, 0.4640192707825488], [0.16906776311286698, 0.830932236887133], [0.10674400692238455, 0.8932559930776154], [0.13482837008270623, 0.8651716299172937], [0.47508440968842736, 0.5249155903115726], [0.16646874670006942, 0.8335312532999306], [0.15724835935379636, 0.8427516406462037], [0.38618846239532617, 0.6138115376046738], [0.14906403906214016, 0.8509359609378598], [0.39567091853598274, 0.6043290814640173], [0.18430134533018974, 0.8156986546698104], [0.19347201380786808, 0.806527986192132], [0.09345124525413466, 0.9065487547458653], [0.56247037437298, 0.43752962562702], [0.1594053800725031, 0.8405946199274968], [0.18751538805483506, 0.8124846119451649], [0.18790166660554228, 0.8120983333944577], [0.6735662922998126, 0.32643370770018737], [0.15023532816408497, 0.849764671835915], [0.415596718973155, 0.5844032810268449], [0.614363128163381, 0.3856368718366191], [0.15670938141849, 0.84329061858151], [0.3555513310415673, 0.6444486689584328], [0.13519362522530026, 0.8648063747746997], [0.5495976816635261, 0.45040231833647393], [0.4565338750547596, 0.5434661249452403], [0.2476374571920916, 0.7523625428079084], [0.6583114641320247, 0.3416885358679754], [0.5016463333020337, 0.4983536666979663], [0.22770990816391187, 0.7722900918360881], [0.3745463396259466, 0.6254536603740534], [0.13959269242544659, 0.8604073075745533], [0.34469257643690177, 0.6553074235630981], [0.40179644660096087, 0.5982035533990391], [0.4323026233211402, 0.5676973766788597], [0.11547163710126954, 0.8845283628987304], [0.19359969732872714, 0.8064003026712729], [0.21385629496304223, 0.7861437050369579], [0.5188438912556874, 0.4811561087443125], [0.2158107824817186, 0.7841892175182814], [0.24111605133007216, 0.7588839486699279], [0.6528972406917657, 0.34710275930823425], [0.43435845659567296, 0.5656415434043272], [0.5433921487008555, 0.4566078512991445], [0.5406194572473233, 0.4593805427526766], [0.17258188770845967, 0.8274181122915404], [0.6988367819718524, 0.3011632180281476], [0.6983572853176696, 0.3016427146823304], [0.44885971265018487, 0.5511402873498151], [0.16879578219173036, 0.8312042178082696], [0.14537405507822804, 0.8546259449217719], [0.09824322662451619, 0.9017567733754838], [0.597772984946047, 0.402227015053953], [0.5396643277472705, 0.4603356722527296], [0.252338907079104, 0.7476610929208959], [0.44453186868649514, 0.5554681313135049], [0.1747777191757847, 0.8252222808242153], [0.5379101308189765, 0.4620898691810235], [0.38995794551727114, 0.6100420544827289], [0.6723204380840185, 0.32767956191598135], [0.41630274936446804, 0.5836972506355319], [0.18939753776797838, 0.8106024622320215], [0.4656643308155679, 0.5343356691844321], [0.2271776453887251, 0.7728223546112749], [0.17466756574611286, 0.8253324342538871], [0.10595182247505888, 0.894048177524941], [0.46572967799357834, 0.5342703220064218], [0.15248594423996495, 0.847514055760035], [0.23875322762410184, 0.7612467723758981], [0.5603038955066048, 0.4396961044933953], [0.47454850245990876, 0.5254514975400911], [0.48666580220105143, 0.5133341977989485], [0.4211901690789886, 0.5788098309210115], [0.4082824678030903, 0.5917175321969097], [0.12635442377377235, 0.8736455762262276], [0.41749444223252447, 0.5825055577674755], [0.1348010626495218, 0.8651989373504781], [0.15159254613362383, 0.8484074538663762], [0.11705595247905384, 0.8829440475209461], [0.5384359876290541, 0.4615640123709459], [0.16457957216715677, 0.8354204278328432], [0.5400961963019216, 0.4599038036980783], [0.5794634312379656, 0.4205365687620343], [0.1467797517555319, 0.8532202482444682], [0.3106212524038102, 0.6893787475961898], [0.10421447502490361, 0.8957855249750963], [0.12649714010524096, 0.873502859894759], [0.08496949989137498, 0.915030500108625], [0.4936871570515277, 0.5063128429484722], [0.27444636298104086, 0.725553637018959], [0.726367181113171, 0.273632818886829], [0.2285287422242253, 0.7714712577757746], [0.21808024929457828, 0.7819197507054217], [0.4401722959986234, 0.5598277040013767], [0.15788799099336662, 0.8421120090066334], [0.21970068420137717, 0.7802993157986228], [0.6200540246185745, 0.37994597538142555], [0.20642798587581132, 0.7935720141241887], [0.5540252756804588, 0.4459747243195412], [0.4804108041658268, 0.5195891958341731], [0.6436111070067032, 0.3563888929932968], [0.5346707460421782, 0.4653292539578218], [0.4924940925647801, 0.50750590743522], [0.4484425020051784, 0.5515574979948217], [0.46681697627796553, 0.5331830237220344], [0.20826912788843055, 0.7917308721115695], [0.2191633841336886, 0.7808366158663114], [0.43865107014954496, 0.561348929850455], [0.17504316188641106, 0.824956838113589], [0.4279082675563159, 0.572091732443684], [0.3852253650011654, 0.6147746349988346], [0.40091443597496584, 0.5990855640250342], [0.4771344937499667, 0.5228655062500333], [0.6041404931609221, 0.395859506839078], [0.6559532652706187, 0.3440467347293813], [0.6251758974599464, 0.37482410254005355], [0.22125552102325638, 0.7787444789767437], [0.4265546445490894, 0.5734453554509106], [0.6010043735911633, 0.3989956264088366], [0.4132072401245017, 0.5867927598754983], [0.1846725928395932, 0.8153274071604069], [0.1891374953235838, 0.8108625046764162], [0.09202654651678595, 0.907973453483214], [0.4585084617702929, 0.5414915382297072], [0.31401988059017066, 0.6859801194098293], [0.14813012480906665, 0.8518698751909333], [0.1023030447936399, 0.8976969552063602], [0.5550358936944161, 0.444964106305584], [0.505445102268685, 0.494554897731315], [0.21439996950901036, 0.7856000304909897], [0.17455001059923111, 0.825449989400769], [0.7031117774208512, 0.2968882225791488], [0.1569096191287663, 0.8430903808712337], [0.44290041435238764, 0.5570995856476124], [0.35575367365722527, 0.6442463263427747], [0.17593300681669466, 0.8240669931833053], [0.33591173822547804, 0.664088261774522], [0.5257786754716611, 0.4742213245283389], [0.11957886048409389, 0.8804211395159062], [0.06136941844515009, 0.9386305815548498], [0.10223776703452235, 0.8977622329654776], [0.2254334143959823, 0.7745665856040177], [0.4057291368136319, 0.5942708631863681], [0.5149804250197498, 0.48501957498025017], [0.15489061183407768, 0.8451093881659223], [0.5790179235418484, 0.42098207645815144], [0.16145038236915826, 0.8385496176308418], [0.09972168695698254, 0.9002783130430175], [0.519664122516254, 0.4803358774837459], [0.15803774116395786, 0.8419622588360421], [0.4860859819415638, 0.5139140180584362], [0.4974224445075294, 0.5025775554924705], [0.10789463174702399, 0.8921053682529759], [0.24527884541021355, 0.7547211545897864], [0.08113228175344916, 0.9188677182465509], [0.4789907665596959, 0.521009233440304], [0.1783139702730487, 0.8216860297269514], [0.5990855640250342, 0.40091443597496584], [0.4335784142861934, 0.5664215857138066], [0.2238063109598757, 0.7761936890401243], [0.4868631051781994, 0.5131368948218005], [0.37786360804991725, 0.6221363919500827], [0.5414794352195512, 0.45852056478044884], [0.5549136594255832, 0.44508634057441676], [0.12312135451191739, 0.8768786454880826], [0.30395446865968206, 0.696045531340318], [0.4025001806378353, 0.5974998193621648], [0.19437653813458503, 0.8056234618654149], [0.5355457634845681, 0.46445423651543194], [0.6362596713578316, 0.3637403286421685], [0.6123788644387425, 0.3876211355612575], [0.5214632776440665, 0.4785367223559336], [0.1737953667823842, 0.8262046332176158], [0.5813788281283466, 0.4186211718716535], [0.24872641833007053, 0.7512735816699294], [0.38533984679764083, 0.6146601532023592], [0.5469653445345171, 0.4530346554654829], [0.20386084852063757, 0.7961391514793624], [0.16836919926709198, 0.8316308007329081], [0.23901887582006945, 0.7609811241799306], [0.30240192272115274, 0.6975980772788473], [0.615433320404696, 0.3845666795953041], [0.24151217964431368, 0.7584878203556863], [0.5497334304478413, 0.4502665695521587], [0.12038743738825057, 0.8796125626117495], [0.41137903297216727, 0.5886209670278328], [0.6089665671815342, 0.3910334328184658], [0.1548598590559142, 0.8451401409440858], [0.39756966135136756, 0.6024303386486324], [0.4360180556606596, 0.5639819443393405], [0.3878162978813316, 0.6121837021186685]]}, {"iter": 2, "mu": [48.342858164654366, 60.308627994922034], "sigma": [11.3131417735525, 13.604357210826972], "pi": [0.3537669007148855, 0.6462330992851145], "ll": -891.517, "r": [[0.4924149362638394, 0.5075850637361605], [0.2342297308720525, 0.7657702691279475], [0.17503276691647635, 0.8249672330835236], [0.46653152189637515, 0.5334684781036247], [0.5798043507604473, 0.42019564923955266], [0.09081527592035002, 0.9091847240796499], [0.531618814645571, 0.4683811853544289], [0.26731201922541264, 0.7326879807745873], [0.5592896940650534, 0.44071030593494653], [0.19219372153054176, 0.8078062784694582], [0.6490230926147681, 0.3509769073852319], [0.11743062964642706, 0.8825693703535729], [0.43931505117404723, 0.5606849488259527], [0.5485121934180858, 0.4514878065819143], [0.5299615314409922, 0.47003846855900777], [0.1797097449871714, 0.8202902550128286], [0.2578205279716334, 0.7421794720283665], [0.46965126010384556, 0.5303487398961545], [0.6086894464081999, 0.3913105535918002], [0.5634050421001505, 0.4365949578998495], [0.49461560342618205, 0.505384396573818], [0.583958571008503, 0.41604142899149704], [0.05998571863876595, 0.9400142813612341], [0.6030433263502484, 0.39695667364975157], [0.24483583609550508, 0.7551641639044949], [0.09556094843736854, 0.9044390515626315], [0.1944368023832773, 0.8055631976167227], [0.11847029577139584, 0.8815297042286042], [0.6035800661451254, 0.3964199338548747], [0.5530530319801295, 0.44694696801987066], [0.1499517652243548, 0.8500482347756453], [0.07221921718016691, 0.9277807828198331], [0.10602884741854411, 0.8939711525814559], [0.5015093684195231, 0.4984906315804768], [0.14655945693078, 0.85344054306922], [0.13458244366413388, 0.8654175563358661], [0.41509020990768175, 0.5849097900923184], [0.12404838872896956, 0.8759516112710304], [0.4249769530232304, 0.5750230469767695], [0.16992859035357144, 0.8300714096464286], [0.18199484621041256, 0.8180051537895875], [0.057397768808233114, 0.9426022311917669], [0.5736968491571579, 0.42630315084284204], [0.1373751979381404, 0.8626248020618595], [0.17415603215072847, 0.8258439678492715], [0.17466425022840756, 0.8253357497715924], [0.6497140043934481, 0.350285995606552], [0.12554927875509497, 0.8744507212449051], [0.4452229191101968, 0.5547770808898033], [0.6112453195147283, 0.3887546804852718], [0.1338855956960683, 0.8661144043039317], [0.382027831621726, 0.6179721683782741], [0.10648533520165597, 0.8935146647983441], [0.5637940497171773, 0.4362059502828226], [0.4846103197931562, 0.5153896802068438], [0.252597744915106, 0.747402255084894], [0.6402297351963071, 0.35977026480369295], [0.5247156363432897, 0.47528436365671023], [0.22687031043543554, 0.7731296895645645], [0.4027280537888731, 0.5972719462111269], [0.11200935145858831, 0.8879906485414116], [0.36989949314147436, 0.6301005068585257], [0.43127702723122346, 0.5687229727687766], [0.46165069288937527, 0.5383493071106248], [0.08241355715116414, 0.917586442848836], [0.18216289488001058, 0.8178371051199894], [0.20878148751406528, 0.7912185124859348], [0.5391378009036827, 0.46086219909631726], [0.21134119290229386, 0.7886588070977062], [0.24422325635215733, 0.7557767436478426], [0.6367930502276552, 0.3632069497723447], [0.4636382608457562, 0.5363617391542437], [0.5589333764287069, 0.4410666235712931], [0.5567430987023205, 0.4432569012976795], [0.15454753529810855, 0.8454524647018915], [0.6647854083067994, 0.3352145916932006], [0.6645068306181386, 0.33549316938186124], [0.47744867445429207, 0.5225513255457078], [0.14959648554827396, 0.8504035144517261], [0.1193364604219138, 0.8806635395780862], [0.06263216119622157, 0.9373678388037785], [0.5996439126234521, 0.400356087376548], [0.555985939322333, 0.4440140606776669], [0.258604679423215, 0.741395320576785], [0.47336520992502545, 0.5266347900749745], [0.15742381778228454, 0.8425761822177154], [0.5545917764254367, 0.4454082235745632], [0.4190399546428092, 0.5809600453571908], [0.6489503789693939, 0.3510496210306061], [0.4459272241542004, 0.5540727758457997], [0.1766325491076745, 0.8233674508923254], [0.4930003094613631, 0.5069996905386368], [0.22617795758586487, 0.7738220424141352], [0.15727945424537096, 0.8427205457546291], [0.07131068899098361, 0.9286893110090163], [0.4930598491328161, 0.5069401508671838], [0.1284397889717241, 0.8715602110282759], [0.24117760946130765, 0.7588223905386924], [0.5720470574374135, 0.4279529425625865], [0.5010292617401033, 0.4989707382598968], [0.5117689695701162, 0.48823103042988375], [0.45077834367068675, 0.5492216563293133], [0.43787407945712536, 0.5621259205428747], [0.09554218860590388, 0.9044578113940961], [0.4471139876873522, 0.5528860123126478], [0.10599473309906139, 0.8940052669009386], [0.1272913721144683, 0.8727086278855316], [0.08429800172211584, 0.9157019982778841], [0.555010189897754, 0.44498981010224614], [0.14409769093072483, 0.8559023090692751], [0.55632846331099, 0.4436715366890101], [0.5864045036227188, 0.4135954963772813], [0.12112842860385405, 0.878871571396146], [0.3304762427448675, 0.6695237572551325], [0.06932867181737656, 0.9306713281826234], [0.09571704068551892, 0.9042829593144811], [0.048473490980186024, 0.951526509019814], [0.5178821400482885, 0.48211785995171164], [0.28646667903925455, 0.7135333209607454], [0.6802987000272547, 0.3197012999727452], [0.22793496352761905, 0.772065036472381], [0.21431056475353796, 0.785689435246462], [0.46921902528511755, 0.5307809747148824], [0.1354099457324644, 0.8645900542675357], [0.2164287350852397, 0.7835712649147604], [0.6151402105685654, 0.38485978943143456], [0.1990353735984944, 0.8009646264015056], [0.5672274047508256, 0.43277259524917433], [0.5062552923629625, 0.49374470763703754], [0.6308118782206585, 0.3691881217793414], [0.5520050936998923, 0.44799490630010774], [0.5168490304386572, 0.4831509695613428], [0.47705642981044977, 0.5229435701895503], [0.4940494631881198, 0.5059505368118802], [0.20145328240071364, 0.7985467175992864], [0.2157265894491193, 0.7842734105508806], [0.4677644832676124, 0.5322355167323877], [0.1577717296043212, 0.8422282703956787], [0.45737734743600517, 0.5426226525639948], [0.4140769123405438, 0.5859230876594562], [0.4303740624083072, 0.5696259375916928], [0.5033415914885161, 0.4966584085114838], [0.6041405070611546, 0.3958594929388454], [0.638737429759325, 0.36126257024067504], [0.618609121917373, 0.3813908780826269], [0.21845948947070526, 0.7815405105292949], [0.45605414389721954, 0.5439458561027805], [0.601932716383456, 0.3980672836165441], [0.44283267373527363, 0.5571673262647264], [0.17041676501775238, 0.8295832349822476], [0.17629035806879131, 0.8237096419312087], [0.05586725815883595, 0.9441327418411641], [0.4864367539982873, 0.5135632460017128], [0.3345000735382967, 0.6654999264617034], [0.1228534223797112, 0.8771465776202888], [0.06716515278934135, 0.9328348472106588], [0.568007059492372, 0.4319929405076281], [0.5279414601668779, 0.4720585398331221], [0.20949373121827894, 0.790506268781721], [0.15712539870541448, 0.8428746012945855], [0.6672564482900111, 0.33274355170998887], [0.1341444371344965, 0.8658555628655034], [0.4718174723532214, 0.5281825276467786], [0.3822518015849536, 0.6177481984150464], [0.158938349138988, 0.8410616508610119], [0.3599363321674495, 0.6400636678325504], [0.5448229983443188, 0.45517700165568115], [0.08731858173960941, 0.9126814182603906], [0.026454368483871723, 0.9735456315161283], [0.06709158936334136, 0.9329084106366586], [0.22390748384593076, 0.7760925161540693], [0.43528607674121017, 0.5647139232587899], [0.5359382202322246, 0.46406177976777546], [0.13153714776712613, 0.8684628522328739], [0.5860765619565919, 0.41392343804340814], [0.14002840684978018, 0.8599715931502199], [0.06427287161745777, 0.9357271283825422], [0.5398141039923368, 0.4601858960076632], [0.1356037600422577, 0.8643962399577424], [0.5112605621913555, 0.4887394378086445], [0.521101796151386, 0.4788982038486141], [0.07354404173366777, 0.9264559582663322], [0.2495744255830101, 0.7504255744169899], [0.04459331295033741, 0.9554066870496627], [0.5049945957987797, 0.49500540420122024], [0.1620620781543449, 0.8379379218456552], [0.6005753281562569, 0.3994246718437431], [0.4628849930488409, 0.5371150069511591], [0.2217872986337411, 0.7782127013662589], [0.5119418468133696, 0.4880581531866303], [0.40627564597601795, 0.593724354023982], [0.557423662032365, 0.44257633796763507], [0.5679128395044623, 0.43208716049553775], [0.0915987388789164, 0.9084012611210835], [0.3225259222467429, 0.677474077753257], [0.43199647327289264, 0.5680035267271074], [0.18318531472589336, 0.8168146852741066], [0.5527053623568052, 0.4472946376431948], [0.625998501038695, 0.37400149896130486], [0.6098771692330597, 0.3901228307669404], [0.541293911202623, 0.4587060887973769], [0.15613665295939197, 0.8438633470406081], [0.5878112755034278, 0.41218872449657207], [0.2539914262381238, 0.7460085737618761], [0.4141974497179859, 0.5858025502820141], [0.5617391498750716, 0.4382608501249283], [0.19566199085155175, 0.8043380091484482], [0.14903938354334256, 0.8509606164566574], [0.2415203169734167, 0.7584796830265833], [0.32066372045959624, 0.6793362795404039], [0.6119810435906095, 0.38801895640939066], [0.2447332828380895, 0.7552667171619105], [0.5638997432305488, 0.4361002567694512], [0.08829162322243844, 0.9117083767775617], [0.44099698410870514, 0.5590030158912949], [0.6075121068868882, 0.39248789311311183], [0.1314974804483946, 0.8685025195516054], [0.4269370563681479, 0.5730629436318522], [0.46523734951030277, 0.5347626504896973], [0.4167990589089772, 0.5832009410910227]]}, {"iter": 3, "mu": [47.57079270483803, 60.732436343548876], "sigma": [10.631404131938876, 13.514420342062943], "pi": [0.35382371563772574, 0.6461762843622743], "ll": -890.279, "r": [[0.5148383863072213, 0.4851616136927786], [0.21862141090418055, 0.7813785890958194], [0.15099777617840635, 0.8490022238215937], [0.4871190805499886, 0.5128809194500114], [0.6018433388574064, 0.39815666114259357], [0.06371664097948529, 0.9362833590205147], [0.5552628299923488, 0.44473717000765134], [0.25743037440714045, 0.7425696255928596], [0.5824809738017251, 0.4175190261982749], [0.1702562549551173, 0.8297437450448827], [0.660395643284407, 0.3396043567155931], [0.08963729214825467, 0.9103627078517453], [0.45721275791777255, 0.5427872420822275], [0.5720216131716529, 0.42797838682834705], [0.5535959959595894, 0.44640400404041053], [0.15621151334586345, 0.8437884866541365], [0.24625421224055685, 0.7537457877594431], [0.49049934346249335, 0.5095006565375065], [0.6277232794394182, 0.37227672056058186], [0.5864243053404637, 0.4135756946595362], [0.5171595767283858, 0.48284042327161425], [0.6056705090088541, 0.3943294909911459], [0.036530068959564364, 0.9634699310404357], [0.6228054243524739, 0.3771945756475261], [0.23101409313909235, 0.7689859068609077], [0.06819305984455414, 0.9318069401554459], [0.17279803018467357, 0.8272019698153263], [0.09068707708629208, 0.909312922913708], [0.6232760627116899, 0.37672393728831], [0.5764513160074325, 0.4235486839925674], [0.1235626210148454, 0.8764373789851546], [0.04688922302813101, 0.9531107769718691], [0.07829877434788678, 0.9217012256521132], [0.5243927491429713, 0.47560725085702876], [0.11992835710178394, 0.880071642898216], [0.1072645575870299, 0.8927354424129701], [0.43002434906724946, 0.5699756509327505], [0.09636212358422148, 0.9036378764157785], [0.44118014582478216, 0.5588198541752178], [0.14534031448772683, 0.8546596855122732], [0.15876875596460796, 0.8412312440353921], [0.03442134289179516, 0.9655786571082049], [0.5961576172991971, 0.4038423827008029], [0.11019310280786157, 0.8898068971921385], [0.1500235409297759, 0.849976459070224], [0.15058815496246997, 0.84941184503753], [0.660910749801857, 0.33908925019814296], [0.09790105073167221, 0.9020989492683278], [0.4637653826796026, 0.5362346173203975], [0.6299250299530254, 0.3700749700469746], [0.10653623616524412, 0.8934637638347559], [0.39219555752637475, 0.6078044424736252], [0.07874633926766239, 0.9212536607323376], [0.5867955660695531, 0.41320443393044676], [0.506560089008592, 0.49343991099140805], [0.2401164456347188, 0.7598835543652812], [0.6536915140252674, 0.3463084859747326], [0.5482941153497758, 0.4517058846502243], [0.21005872302375309, 0.7899412769762468], [0.41596891981348605, 0.5840310801865138], [0.08420540058597123, 0.9157945994140289], [0.37814548743674775, 0.6218545125632522], [0.44824678358042497, 0.551753216419575], [0.4818101641391544, 0.5181898358608457], [0.055966320132675225, 0.9440336798673248], [0.15895706741350005, 0.8410429325865], [0.18916924926454953, 0.8108307507354504], [0.5627748926859423, 0.4372251073140578], [0.1921099988811809, 0.8078900011188191], [0.2302968238819588, 0.7697031761180412], [0.6510007910899934, 0.34899920891000663], [0.48397504519779727, 0.5160249548022028], [0.5821382103271945, 0.4178617896728055], [0.5800266195815474, 0.4199733804184525], [0.12851735480853532, 0.8714826451914647], [0.6716702586562403, 0.32832974134375964], [0.671480366745062, 0.328519633254938], [0.49890202407986145, 0.5010979759201386], [0.12318106917986864, 0.8768189308201314], [0.09156360993614153, 0.9084363900638585], [0.038717575854187294, 0.9612824241458127], [0.6198097651469843, 0.3801902348530158], [0.5792948204564828, 0.4207051795435172], [0.24717654093294833, 0.7528234590670517], [0.4945098525692324, 0.5054901474307676], [0.1316358669315335, 0.8683641330684665], [0.5779448990787451, 0.422055100921255], [0.43449050474942286, 0.565509495250577], [0.6603413291715877, 0.33965867082841233], [0.4645443849943501, 0.53545561500565], [0.15277803564872786, 0.8472219643512722], [0.5154563859669521, 0.48454361403304785], [0.20925489000762007, 0.7907451099923799], [0.13147903142691542, 0.8685209685730846], [0.046098987816855015, 0.9539010121831449], [0.5155192211627659, 0.4844807788372341], [0.10087862185251657, 0.8991213781474834], [0.2267332788944918, 0.7732667211055083], [0.5946100079338579, 0.4053899920661421], [0.523890903894753, 0.4761090961052469], [0.535047067894168, 0.4649529321058321], [0.4698971910208993, 0.5301028089791008], [0.45560967243931344, 0.5443903275606865], [0.06817523060076004, 0.93182476939924], [0.4658559545931052, 0.5341440454068948], [0.0782653490965532, 0.9217346509034469], [0.09969346264970244, 0.9003065373502976], [0.057684432902398594, 0.9423155670976013], [0.5783503679106906, 0.4216496320893093], [0.11730369164855849, 0.8826963083514415], [0.5796259885650241, 0.4203740114349759], [0.607908236503344, 0.392091763496656], [0.09338255173557355, 0.9066174482644265], [0.33200593534698086, 0.6679940646530191], [0.04438622823376444, 0.9556137717662356], [0.06834144955307855, 0.9316585504469215], [0.027396272351825866, 0.972603727648174], [0.5413302849369215, 0.4586697150630785], [0.28004248595188835, 0.7199575140481117], [0.6816025059316888, 0.3183974940683112], [0.21129540112004885, 0.7887045988799511], [0.1955281062121933, 0.8044718937878067], [0.49003163092270163, 0.5099683690772984], [0.10813069210707388, 0.8918693078929261], [0.19797061741207664, 0.8020293825879234], [0.6332499106759513, 0.36675008932404873], [0.17802499789679485, 0.8219750021032052], [0.5900609792813937, 0.4099390207186065], [0.5293379823099933, 0.47066201769000665], [0.6462302676191723, 0.35376973238082765], [0.5754319469248601, 0.42456805307513984], [0.5402719377620051, 0.45972806223799484], [0.49848092501687286, 0.5015190749831272], [0.5165629871867728, 0.4834370128132272], [0.1807816251530935, 0.8192183748469065], [0.1971605743432812, 0.8028394256567187], [0.4884562384307185, 0.5115437615692815], [0.13201397072913418, 0.8679860292708659], [0.47714190582763183, 0.5228580941723682], [0.4288765956765772, 0.5711234043234227], [0.4472360291296084, 0.5527639708703916], [0.5263052837101033, 0.4736947162898966], [0.6237667903842471, 0.37623320961575296], [0.6525277852491698, 0.3474722147508302], [0.6361793317905658, 0.36382066820943404], [0.20031552575957434, 0.7996844742404257], [0.47569268346250854, 0.5243073165374915], [0.6218295406947493, 0.3781704593052508], [0.46111816715972204, 0.5388818328402779], [0.1458798874951401, 0.85412011250486], [0.1523969641453583, 0.8476030358546417], [0.03318884677434506, 0.9668111532256549], [0.5085037566240612, 0.49149624337593867], [0.3367409599975957, 0.6632590400024043], [0.0951404432270774, 0.9048595567729225], [0.04253451146047231, 0.9574654885395277], [0.5907996410342341, 0.4092003589657658], [0.5515589722723222, 0.4484410277276778], [0.18998696919876915, 0.8100130308012308], [0.1313117028951855, 0.8686882971048144], [0.6733382919533055, 0.3266617080466945], [0.10680665474811386, 0.8931933452518861], [0.49284033875328354, 0.5071596612467165], [0.3924542287330923, 0.6075457712669076], [0.13328321373197122, 0.8667167862680288], [0.36654600939011284, 0.6334539906098872], [0.5683987876661183, 0.4316012123338816], [0.0604631121968902, 0.9395368878031097], [0.012033524499082618, 0.9879664755009173], [0.04247188380202091, 0.9575281161979791], [0.20662103439218804, 0.793378965607812], [0.45272582445552784, 0.5472741755444721], [0.5595884254246296, 0.44041157457537045], [0.10408894537106855, 0.8959110546289315], [0.6076088929565536, 0.39239110704344643], [0.11298933906790971, 0.8870106609320904], [0.04008908702032054, 0.9599109129796795], [0.5634464687629556, 0.43655353123704455], [0.10833375102219632, 0.8916662489778037], [0.5345222933683375, 0.46547770663166266], [0.544619325063168, 0.45538067493683204], [0.04804723532439519, 0.9519527646756047], [0.23656806844316136, 0.7634319315568386], [0.024470592435035438, 0.9755294075649645], [0.5280271190213054, 0.47197288097869455], [0.1366920497513989, 0.8633079502486012], [0.6206330930924537, 0.3793669069075463], [0.48315505759445043, 0.5168449424055495], [0.20416465470242087, 0.7958353452975792], [0.5352254334585328, 0.4647745665414672], [0.4200140058519231, 0.5799859941480768], [0.5806835832102458, 0.4193164167897542], [0.5907104316019568, 0.40928956839804337], [0.06445090384492606, 0.935549096155074], [0.32263835031448895, 0.6773616496855112], [0.4490516068489074, 0.5509483931510927], [0.16010349327301257, 0.8398965067269873], [0.576113320429874, 0.42388667957012605], [0.6423146873101722, 0.3576853126898279], [0.6287483733860502, 0.37125162661394995], [0.5649135312137863, 0.4350864687862138], [0.1302386657357818, 0.8697613342642182], [0.6091899106983882, 0.3908100893016117], [0.24175334034425797, 0.758246659655742], [0.4290131690418806, 0.5709868309581193], [0.5848314941907206, 0.41516850580927944], [0.17418856527615068, 0.8258114347238493], [0.1225832059424585, 0.8774167940575415], [0.22713404077936278, 0.7728659592206373], [0.32044216184162727, 0.6795578381583727], [0.6305559187573058, 0.36944408124269434], [0.23089400169274812, 0.7691059983072519], [0.5868963929829574, 0.41310360701704263], [0.06136457194987525, 0.9386354280501247], [0.4590815259689224, 0.5409184740310775], [0.6267038705710399, 0.37329612942896007], [0.104047705220594, 0.895952294779406], [0.44338234817199906, 0.5566176518280008], [0.48571381714917466, 0.5142861828508254], [0.4319581331029762, 0.5680418668970237]]}, {"iter": 4, "mu": [46.59450359611299, 61.27288947235747], "sigma": [9.777659862894998, 13.313424541396772], "pi": [0.3540821742101984, 0.6459178257898017], "ll": -888.021, "r": [[0.5397553688427331, 0.46024463115726677], [0.19062181785279222, 0.8093781821472078], [0.11790738262200667, 0.8820926173779933], [0.507963102159361, 0.4920368978406389], [0.6339632131792372, 0.36603678682076285], [0.038020213865486145, 0.9619797861345138], [0.5847765913779628, 0.41522340862203727], [0.2349567083689939, 0.765043291631006], [0.6139390039786442, 0.38606099602135574], [0.13788749618652185, 0.8621125038134783], [0.6886800642476806, 0.3113199357523195], [0.05952278782891411, 0.9404772121710859], [0.47301951125999453, 0.5269804887400055], [0.6028599017305266, 0.3971400982694734], [0.5829574664625686, 0.4170425335374315], [0.12325029861292211, 0.876749701387078], [0.22204165869328538, 0.7779583413067147], [0.5118737214455494, 0.48812627855445057], [0.6595080753193928, 0.3404919246806073], [0.618070694621864, 0.381929305378136], [0.5423869575359269, 0.457613042464073], [0.6378373036688086, 0.36216269633119136], [0.01832258921280369, 0.9816774107871963], [0.6547818301816797, 0.3452181698183204], [0.204615266702283, 0.795384733297717], [0.041565701718615386, 0.9584342982813847], [0.14057268533193773, 0.8594273146680623], [0.06043982940193631, 0.9395601705980637], [0.6552370223728242, 0.3447629776271759], [0.6075727170939401, 0.3924272829060599], [0.0906967736423455, 0.9093032263576546], [0.02542153880795139, 0.9745784611920486], [0.049836901920292796, 0.9501630980797072], [0.5505539148166431, 0.4494460851833569], [0.087216457837034, 0.912783542162966], [0.07534119638268522, 0.9246588036173147], [0.440811525658263, 0.559188474341737], [0.06545375941874518, 0.9345462405812548], [0.45406917483238235, 0.5459308251676176], [0.11216867108905047, 0.8878313289109495], [0.12588934823793432, 0.8741106517620657], [0.016948414680620593, 0.9830515853193794], [0.6281540451413418, 0.37184595485865835], [0.07805139763941883, 0.9219486023605813], [0.11691472120479357, 0.8830852787952064], [0.11748979201108027, 0.8825102079889197], [0.6890971190770901, 0.31090288092290974], [0.0668294705710075, 0.9331705294289925], [0.48072455115036994, 0.5192754488496301], [0.6616015372210756, 0.33839846277892427], [0.07467065347378977, 0.9253293465262102], [0.39554138375746073, 0.6044586162425392], [0.05021136514523228, 0.9497886348547677], [0.6184583504158206, 0.3815416495841793], [0.5303294893074246, 0.4696705106925753], [0.21499632512867406, 0.7850036748713258], [0.683097863791749, 0.31690213620825114], [0.5771480034007299, 0.42285199659927014], [0.1810558818587768, 0.8189441181412233], [0.42403918864264184, 0.5759608113573581], [0.05483166907072368, 0.9451683309292763], [0.37865167680641665, 0.6213483231935834], [0.4624379956115416, 0.5375620043884585], [0.5018040321157072, 0.49819596788429277], [0.032067491885240086, 0.96793250811476], [0.12608415486083502, 0.8739158451391651], [0.15811334096942206, 0.8418866590305779], [0.592930034541572, 0.40706996545842805], [0.16130689995829392, 0.838693100041706], [0.20380081552115084, 0.7961991844788492], [0.680785573129567, 0.31921442687043305], [0.5043180798359251, 0.4956819201640749], [0.613578658631612, 0.386421341368388], [0.6113545761512628, 0.38864542384873724], [0.09549095895174953, 0.9045090410482505], [0.6973125086230368, 0.30268749137696316], [0.6971772890486315, 0.3028227109513685], [0.5215560125691701, 0.47844398743083005], [0.09032992705519213, 0.9096700729448078], [0.06120805860224178, 0.9387919413977582], [0.01977463608885635, 0.9802253639111437], [0.6518707605783963, 0.34812923942160373], [0.6105821306344302, 0.3894178693655698], [0.22310336918682425, 0.7768966308131758], [0.5165020129895406, 0.48349798701045943], [0.09853679759893494, 0.901463202401065], [0.6091550166506201, 0.39084498334937995], [0.44612550777511095, 0.553874492224889], [0.688635982138115, 0.31136401786188495], [0.48163887315433207, 0.5183611268456679], [0.11972599667441305, 0.8802740033255869], [0.5404565077612751, 0.45954349223872487], [0.18016244289639075, 0.8198375571036092], [0.09838310329995473, 0.9016168967000452], [0.024860884279852506, 0.9751391157201474], [0.5405277759957816, 0.45947222400421833], [0.06951017281223497, 0.930489827187765], [0.19976251477751023, 0.8002374852224897], [0.6265621789359688, 0.3734378210640313], [0.5499889565044668, 0.4500110434955331], [0.5624864901681597, 0.4375135098318404], [0.4879114001084331, 0.512088599891567], [0.47113075545792643, 0.5288692445420735], [0.04155143124259611, 0.9584485687574039], [0.48317744113929884, 0.5168225588607012], [0.049808962931390935, 0.950191037068609], [0.06844021269998452, 0.9315597873000154], [0.03336596922765714, 0.9666340307723428], [0.6095839715291451, 0.3904160284708549], [0.08472254272155598, 0.915277457278444], [0.6109317979148415, 0.38906820208515835], [0.6400883278016023, 0.35991167219839776], [0.06280953027474226, 0.9371904697252577], [0.32318982222203646, 0.6768101777779635], [0.023656120457375304, 0.9763438795426247], [0.04168451792631462, 0.9583154820736853], [0.0125656676906256, 0.9874343323093744], [0.5694658247183519, 0.4305341752816481], [0.2613849305054666, 0.7386150694945335], [0.7036492189854179, 0.29635078101458223], [0.1824319801198961, 0.8175680198801039], [0.16503431583376396, 0.834965684166236], [0.5113331456876896, 0.48866685431231044], [0.07614043186551357, 0.9238595681344864], [0.16770781373707605, 0.832292186262924], [0.6647347902146937, 0.3352652097853062], [0.14612766321453, 0.8538723367854699], [0.6218577870464514, 0.3781422129535486], [0.5561073019571514, 0.44389269804284864], [0.6765988631170596, 0.3234011368829403], [0.6064908268473016, 0.3935091731526984], [0.5682933451327853, 0.4317066548672146], [0.5210721437866151, 0.47892785621338485], [0.5417110780184894, 0.45828892198151067], [0.14907476523596822, 0.8509252347640317], [0.16682025689616867, 0.8331797431038312], [0.5095110954147755, 0.4904889045852246], [0.09890755030017927, 0.9010924496998206], [0.4963715203304047, 0.5036284796695953], [0.439444599070358, 0.560555400929642], [0.4612424849290996, 0.5387575150709004], [0.552704631587101, 0.447295368412899], [0.6557110074004259, 0.3442889925995742], [0.6821024319771535, 0.31789756802284647], [0.6674657817598766, 0.33253421824012347], [0.17028213004026369, 0.8297178699597364], [0.4946819722750993, 0.5053180277249008], [0.6538360882610693, 0.3461639117389307], [0.47761477957543924, 0.5223852204245608], [0.11271328291948612, 0.8872867170805139], [0.11933620878330592, 0.8806637912166941], [0.016157280524424698, 0.9838427194755753], [0.5325481652260419, 0.4674518347739582], [0.32886926396442373, 0.6711307360355763], [0.0643664686025704, 0.9356335313974296], [0.022369980513842928, 0.9776300194861571], [0.622624192686117, 0.37737580731388304], [0.5807295562231629, 0.4192704437768371], [0.15900010629435463, 0.8409998937056454], [0.09821918572073404, 0.9017808142792659], [0.6984816314404209, 0.30151836855957903], [0.07491945641348811, 0.9250805435865119], [0.5145768611260279, 0.4854231388739722], [0.3958520955722133, 0.6041479044277868], [0.10015439989548383, 0.8998456001045162], [0.3646968899100138, 0.6353031100899861], [0.5989839254288486, 0.40101607457115146], [0.035491783124028384, 0.9645082168759715], [0.0042767775182953795, 0.9957232224817045], [0.02232678430814025, 0.9776732156918596], [0.177240662456273, 0.8227593375437271], [0.4677294560107252, 0.5322705439892749], [0.5894806409080028, 0.4105193590919971], [0.07242781411343333, 0.9275721858865666], [0.6397878247112215, 0.3602121752887784], [0.08065971371001693, 0.9193402862899832], [0.02069835463782575, 0.9793016453621742], [0.5936552687060609, 0.40634473129393905], [0.0763280904028331, 0.9236719095971668], [0.5619015883019296, 0.43809841169807034], [0.573101282764518, 0.42689871723548206], [0.026248500512517738, 0.9737514994874822], [0.21093963585152023, 0.7890603641484797], [0.010837190599643385, 0.9891628094003567], [0.554637692421611, 0.445362307578389], [0.10352029980997153, 0.8964797001900284], [0.6526731709132707, 0.3473268290867293], [0.5033662376981398, 0.4966337623018602], [0.17452372490283452, 0.8254762750971655], [0.5626852237193761, 0.4373147762806239], [0.42887316346239585, 0.5711268365376042], [0.612047304653435, 0.38795269534656507], [0.6225316836671143, 0.3774683163328858], [0.03859655637467776, 0.9614034436253223], [0.3119705094876878, 0.6880294905123122], [0.4633895636138142, 0.5366104363861859], [0.12727150421305153, 0.8727284957869484], [0.6072141674911717, 0.39278583250882826], [0.6730875735292843, 0.32691242647071583], [0.6604845452817328, 0.33951545471826705], [0.5952373895808527, 0.4047626104191474], [0.09716948912407247, 0.9028305108759275], [0.6413727714842294, 0.3586272285157706], [0.21687180756695804, 0.783128192433042], [0.43960727916830294, 0.5603927208316971], [0.616404909299598, 0.383595090700402], [0.14204617491865112, 0.8579538250813489], [0.08975578901728905, 0.910244210982711], [0.20021599082735678, 0.7997840091726433], [0.309343883790606, 0.6906561162093939], [0.6621987105103431, 0.3378012894896569], [0.20447886675727203, 0.795521133242728], [0.6185635895323093, 0.3814364104676908], [0.036188148512534615, 0.9638118514874653], [0.47521947247574386, 0.5247805275242562], [0.6585339820233485, 0.3414660179766515], [0.0723901564616725, 0.9276098435383275], [0.45667975972410013, 0.5433202402758998], [0.5063348206350602, 0.49366517936493987], [0.44311340354457884, 0.5568865964554212]]}, {"iter": 5, "mu": [45.4571384689928, 61.94310473248842], "sigma": [8.6583480671749, 12.986738458579898], "pi": [0.3559130202807854, 0.6440869797192146], "ll": -883.905, "r": [[0.5719049465023014, 0.4280950534976986], [0.14806441165562914, 0.8519355883443709], [0.07634111936746835, 0.9236588806325315], [0.5335794635141615, 0.4664205364858386], [0.6778510889108142, 0.32214891108918575], [0.01612444148371995, 0.98387555851628], [0.6242710629063686, 0.37572893709363137], [0.1971323246078791, 0.8028676753921209], [0.6566057923998037, 0.34339420760019634], [0.09475656116717344, 0.9052434388328265], [0.7287195545360331, 0.2712804454639669], [0.02978767491138478, 0.9702123250886152], [0.49052834481102586, 0.5094716551889742], [0.6444959352209623, 0.3555040647790378], [0.6222077959764126, 0.3777922040235874], [0.08115729540113234, 0.9188427045988676], [0.18250036835695688, 0.8174996316430431], [0.5383425273201554, 0.46165747267984464], [0.7033955322383717, 0.29660446776162835], [0.661060982460965, 0.338939017539035], [0.5750330215673908, 0.4249669784326092], [0.6818515851935188, 0.31814841480648104], [0.005961568586743786, 0.9940384314132562], [0.6988344651062555, 0.3011655348937445], [0.16318507019103462, 0.8368149298089654], [0.01821438190438848, 0.9817856180956115], [0.0973130824817017, 0.9026869175182982], [0.030419301592169472, 0.9695806984078305], [0.699277514500619, 0.30072248549938096], [0.649675246904936, 0.35032475309506395], [0.053159511624188145, 0.9468404883758119], [0.009310504463472319, 0.9906894955365277], [0.023349906833145577, 0.9766500931668545], [0.5846924067600064, 0.41530759323999356], [0.05036943784692586, 0.9496305621530741], [0.04117756788064979, 0.9588224321193503], [0.45026041296370395, 0.549739587036296], [0.03393696713387808, 0.9660630328661219], [0.46688690837700164, 0.5331130916229985], [0.07126068331273709, 0.928739316687263], [0.08356601233809574, 0.9164339876619042], [0.005361753298802944, 0.994638246701197], [0.6717814374254003, 0.3282185625745997], [0.0432292697370152, 0.9567707302629848], [0.075455385697129, 0.9245446143028709], [0.07596816088787764, 0.9240318391121223], [0.7290237440406964, 0.27097625595930364], [0.03492070740597755, 0.9650792925940224], [0.5000886073438754, 0.4999113926561246], [0.7053866676264671, 0.29461333237353293], [0.04067428761073111, 0.9593257123892689], [0.3932083921742768, 0.6067916078257233], [0.02359057887053157, 0.9764094211294684], [0.6614771972690509, 0.33852280273094915], [0.5606416817299255, 0.4393583182700745], [0.1746297012775549, 0.8253702987224452], [0.7244190655194073, 0.2755809344805928], [0.6155859827814022, 0.3844140172185978], [0.13794429184187004, 0.8620557081581299], [0.42915477891561565, 0.5708452210843844], [0.02661539403222043, 0.9733846059677796], [0.37191530113596183, 0.6280846988640382], [0.47734785152813386, 0.5226521484718663], [0.5260531458129946, 0.47394685418700544], [0.01277924832132802, 0.987220751678672], [0.08374458644611112, 0.9162554135538888], [0.1144547934047718, 0.8855452065952282], [0.6334561460348215, 0.3665438539651785], [0.1176546691684126, 0.8823453308315874], [0.16229515420329035, 0.8377048457967097], [0.722533996202608, 0.27746600379739184], [0.5291288428443042, 0.4708711571556959], [0.6562156055309448, 0.3437843944690552], [0.6538016968954088, 0.3461983031045912], [0.057070992922593114, 0.942929007077407], [0.734276221705372, 0.26572377829462795], [0.7342052839060632, 0.26579471609393673], [0.5500796323584263, 0.44992036764157367], [0.0528634367775748, 0.9471365632224252], [0.030951265466636402, 0.9690487345333636], [0.006613424409287439, 0.9933865755907126], [0.6959831686556037, 0.3040168313443962], [0.6529610775731394, 0.3470389224268607], [0.18369343688841758, 0.8163065631115823], [0.5439632231207059, 0.45603677687929406], [0.059596016965901256, 0.9404039830340988], [0.6514050117945632, 0.34859498820543683], [0.45693187284827025, 0.5430681271517297], [0.7286872434275917, 0.2713127565724084], [0.5012208065658301, 0.4987791934341699], [0.07797125462404868, 0.9220287453759514], [0.5727390879317219, 0.4272609120682781], [0.13700849182963928, 0.8629915081703607], [0.05946787127602374, 0.9405321287239762], [0.009031863511550109, 0.9909681364884498], [0.5728238461420919, 0.4271761538579081], [0.0368599834969589, 0.963140016503041], [0.1579003517477344, 0.8420996482522656], [0.6701040977109354, 0.3298959022890646], [0.5840266288995524, 0.41597337110044763], [0.5986657928434567, 0.40133420715654333], [0.5089741876014773, 0.4910258123985227], [0.4881798252355151, 0.5118201747644848], [0.018205830911343417, 0.9817941690886566], [0.5031248687083554, 0.4968751312916447], [0.023331977552006194, 0.9766680224479938], [0.03608243746501741, 0.9639175625349826], [0.01349066098558231, 0.9865093390144176], [0.6518731329467381, 0.34812686705326196], [0.048396351982721235, 0.9516036480172788], [0.6533417475662077, 0.3466582524337923], [0.6841576129159067, 0.3158423870840931], [0.03206843367429597, 0.9679315663257041], [0.30259721779489884, 0.6974027822051012], [0.008440938687479001, 0.991559061312521], [0.018285620487960046, 0.9817143795120399], [0.003569916303652981, 0.996430083696347], [0.6067562593978115, 0.3932437406021886], [0.22781647640307132, 0.7721835235969287], [0.7363333041046871, 0.2636666958953129], [0.13938882545841808, 0.860611174541582], [0.1214188603547562, 0.8785811396452438], [0.5376848632068859, 0.462315136793114], [0.041779699437085586, 0.9582203005629144], [0.12413789914141955, 0.8758621008585805], [0.7083302428725733, 0.2916697571274267], [0.10266010340002071, 0.8973398965999794], [0.6651134970675294, 0.3348865029324706], [0.5912169695891366, 0.4087830304108634], [0.7189988618600008, 0.28100113813999905], [0.6484898462929429, 0.3515101537070571], [0.6054015743316884, 0.39459842566831155], [0.54949503696454, 0.45050496303546006], [0.5742303360413469, 0.4257696639586531], [0.10552810007119343, 0.8944718999288066], [0.12323346633749768, 0.8767665336625023], [0.5354663832547204, 0.4645336167452795], [0.059905457251187996, 0.940094542748812], [0.5193908682144825, 0.4806091317855174], [0.4485429189395189, 0.5514570810604811], [0.47585532797565655, 0.5241446720243436], [0.5872235470427082, 0.41277645295729176], [0.6997380280386207, 0.3002619719613793], [0.7236140209451023, 0.27638597905489765], [0.7108573128892182, 0.2891426871107819], [0.12677094744208808, 0.8732290525579118], [0.5173145095717399, 0.48268549042826014], [0.6979114985204767, 0.30208850147952326], [0.4962341141048318, 0.5037658858951681], [0.07173862332745275, 0.9282613766725473], [0.07762105943577212, 0.922378940564228], [0.005024280984099097, 0.9949757190159009], [0.5633009326787761, 0.4366990673212239], [0.30962695474580965, 0.6903730452541904], [0.03316506083101419, 0.9668349391689859], [0.007822199933273445, 0.9921778000667265], [0.6659298765216702, 0.33407012347832976], [0.6196741696717183, 0.38032583032828166], [0.11534095538345322, 0.8846590446165469], [0.05933128694490139, 0.9406687130550987], [0.7348576182203868, 0.26514238177961325], [0.040860825707709714, 0.9591391742922902], [0.5416274925775243, 0.45837250742247565], [0.39360038743816234, 0.6063996125618377], [0.0609493961274519, 0.9390506038725482], [0.35436256132326144, 0.6456374386767385], [0.6402066731008971, 0.35979332689910287], [0.01467768484250438, 0.9853223151574957], [0.0008256789608260665, 0.9991743210391739], [0.007801640634253456, 0.9921983593657465], [0.13395967620578614, 0.8660403237942139], [0.4839459167322732, 0.5160540832677267], [0.6295830340365292, 0.37041696596347073], [0.03900360617790876, 0.9609963938220912], [0.6838505753026789, 0.31614942469732105], [0.04522999927096337, 0.9547700007290366], [0.00703737548611026, 0.9929626245138896], [0.63426803134273, 0.3657319686572701], [0.04192143326587662, 0.9580785667341234], [0.5979849243594519, 0.40201507564054817], [0.6109449097307549, 0.3890550902692451], [0.009725638514805039, 0.990274361485195], [0.1701352645759077, 0.8298647354240923], [0.0029196605892618977, 0.997080339410738], [0.5894939044319419, 0.41050609556805795], [0.06379255174529576, 0.9362074482547041], [0.6967721323426749, 0.303227867657325], [0.5279649234961463, 0.4720350765038536], [0.1311406042465757, 0.8688593957534243], [0.5988970347125914, 0.4011029652874086], [0.4352439808136899, 0.56475601918631], [0.6545545842904413, 0.3454454157095586], [0.6658314034120414, 0.33416859658795856], [0.016459385514527986, 0.983540614485472], [0.28877446452631633, 0.7112255354736837], [0.4785353618323771, 0.5214646381676229], [0.08483526979872102, 0.915164730201279], [0.6492826326369192, 0.3507173673630808], [0.7159311101502465, 0.2840688898497535], [0.7043266116753538, 0.29567338832464607], [0.6360361982234147, 0.36396380177658527], [0.05845871866668636, 0.9415412813333136], [0.6854671255676281, 0.31453287443237177], [0.17671691987378607, 0.8232830801262139], [0.4487473486191573, 0.5512526513808427], [0.659268943710816, 0.34073105628918404], [0.09872381903325436, 0.9012761809667457], [0.05240099399600406, 0.947599006003996], [0.15839238161521932, 0.8416076183847806], [0.2855516312918182, 0.7144483687081817], [0.7059511527389224, 0.29404884726107766], [0.16303594915964006, 0.8369640508403599], [0.6615901354470681, 0.338409864552932], [0.015072414202578691, 0.9849275857974213], [0.4932614098430155, 0.5067385901569845], [0.7024627541199765, 0.29753724588002345], [0.03897572332754768, 0.9610242766724524], [0.47015327536707197, 0.529846724632928], [0.5315926041346877, 0.4684073958653123], [0.45315139515866265, 0.5468486048413373]]}, {"iter": 6, "mu": [44.31107017669336, 62.74621484465729], "sigma": [7.335806343644979, 12.49709646258985], "pi": [0.3618458264040023, 0.6381541735959978], "ll": -877.644, "r": [[0.615158345404676, 0.3848416545953241], [0.08956503734836262, 0.9104349626516373], [0.03319812139760584, 0.9668018786023941], [0.5665094488229023, 0.4334905511770978], [0.7362815422293225, 0.26371845777067754], [0.003363631797942658, 0.9966363682020574], [0.6780565511717205, 0.3219434488282795], [0.13779080402753952, 0.8622091959724606], [0.7141312062073296, 0.2858687937926704], [0.045833394598284234, 0.9541666054017158], [0.7786431886341698, 0.2213568113658301], [0.00826319492504583, 0.9917368050749542], [0.5100266743822531, 0.4899733256177468], [0.7009169825855278, 0.2990830174144722], [0.67567398215291, 0.3243260178470901], [0.03636704213285925, 0.9636329578671408], [0.12270065755908674, 0.8772993424409133], [0.5726518671093621, 0.4273481328906379], [0.760522828524401, 0.239477171475599], [0.7188923938335556, 0.2811076061664443], [0.6190428641733396, 0.3809571358266604], [0.7402788059642518, 0.2597211940357481], [0.0007874014629791307, 0.9992125985370209], [0.756452451213156, 0.24354754878684404], [0.10368443413570029, 0.8963155658642996], [0.004019638218295989, 0.9959803617817039], [0.047695514381892325, 0.9523044856181077], [0.008521744690804897, 0.9914782553091952], [0.756853838908979, 0.24314616109102105], [0.7066154929947417, 0.29338450700525837], [0.019399774325371304, 0.9806002256746288], [0.0015086660227014315, 0.9984913339772986], [0.005781836205773245, 0.9942181637942268], [0.6309452382800826, 0.3690547617199174], [0.017912924930157424, 0.9820870750698426], [0.01330443097005185, 0.9866955690299481], [0.45611609925970686, 0.5438839007402931], [0.010008285350267545, 0.9899917146497325], [0.47845776385657285, 0.5215422361434272], [0.029963845922882176, 0.9700361540771179], [0.03798863547429821, 0.9620113645257017], [0.0006745745303328932, 0.9993254254696671], [0.7301035516460683, 0.2698964483539317], [0.014293307388464394, 0.9857066926115355], [0.03262614558945463, 0.9673738544105454], [0.03295686439611933, 0.9670431356038807], [0.7787578333060404, 0.22124216669395952], [0.01043780802168398, 0.9895621919783161], [0.5226994313149881, 0.47730056868501197], [0.7622534393310957, 0.23774656066890434], [0.013065467987802133, 0.9869345320121978], [0.37928873731111695, 0.6207112626888831], [0.0058693493812392705, 0.9941306506187607], [0.71933426509656, 0.2806657349034401], [0.6010562599085855, 0.3989437400914145], [0.11482381913404438, 0.8851761808659555], [0.7765319344150838, 0.22346806558491614], [0.6679688749401321, 0.3320311250598678], [0.08051417018694307, 0.9194858298130569], [0.427673793304155, 0.572326206695845], [0.007004685111572778, 0.9929953148884273], [0.3508338091887867, 0.6491661908112133], [0.4924616944997149, 0.507538305500285], [0.55675480969234, 0.44324519030765985], [0.0023950139480757543, 0.9976049860519243], [0.03810981699910744, 0.9618901830008926], [0.060822176735483596, 0.9391778232645165], [0.6885531122139887, 0.31144688778601126], [0.06339206297107507, 0.936607937028925], [0.10283428561438422, 0.8971657143856159], [0.7753977678076076, 0.2246022321923925], [0.560748136896904, 0.43925186310309605], [0.7137115421296629, 0.28628845787033697], [0.711105939917321, 0.288894060082679], [0.021550110043721895, 0.9784498899562782], [0.7791256270559955, 0.2208743729440045], [0.7791596166711495, 0.22084038332885048], [0.587678240268841, 0.4123217597311591], [0.019240116945293567, 0.9807598830547064], [0.008741504988852938, 0.991258495011147], [0.0009160544935738272, 0.9990839455064261], [0.753840864490925, 0.24615913550907506], [0.710194842655462, 0.289805157344538], [0.1239096077430116, 0.8760903922569884], [0.5798678034476051, 0.42013219655239487], [0.02297810937848589, 0.977021890621514], [0.7085033261241465, 0.29149667387585365], [0.4650908442151703, 0.5349091557848297], [0.7786306693598936, 0.22136933064010636], [0.5241959800111564, 0.47580401998884364], [0.034259639235237, 0.965740360764763], [0.6161956008703641, 0.383804399129636], [0.07969397171435393, 0.9203060282856461], [0.02290489642800797, 0.977095103571992], [0.0014432520364438945, 0.9985567479635561], [0.6163009411379596, 0.3836990588620403], [0.011301698726838495, 0.9886983012731616], [0.09867055663160898, 0.9013294433683909], [0.7283737099523404, 0.2716262900476596], [0.630129493096068, 0.36987050690393203], [0.6478990360948201, 0.35210096390517986], [0.5344181150563417, 0.46558188494365815], [0.5069043353904477, 0.4930956646095523], [0.004016878857175827, 0.9959831211428243], [0.5267106285262151, 0.47328937147378486], [0.0057753337652150715, 0.994224666234785], [0.010952615388773413, 0.9890473846112265], [0.002592167350077873, 0.997407832649922], [0.7090128726220886, 0.2909871273779115], [0.016885650191063747, 0.9831143498089363], [0.7106076640315722, 0.28939233596842784], [0.7425539537745927, 0.2574460462254073], [0.009208923605663874, 0.9907910763943362], [0.2607300087627016, 0.7392699912372984], [0.001307597848900678, 0.9986924021510992], [0.004042650106632132, 0.9959573498933678], [0.0003726989193752988, 0.9996273010806248], [0.6575615036875342, 0.34243849631246576], [0.17118395637361802, 0.828816043626382], [0.7741935664860463, 0.22580643351395363], [0.08178588039858604, 0.918214119601414], [0.06646167757331774, 0.9335383224266822], [0.5718052220326211, 0.4281947779673789], [0.013592206559889883, 0.9864077934401102], [0.06870986098890206, 0.9312901390110979], [0.7647532761498688, 0.23524672385013126], [0.05167180848943994, 0.9483281915105601], [0.7231726759959598, 0.27682732400404014], [0.6389017970149752, 0.36109820298502493], [0.7730410356300785, 0.22695896436992147], [0.705317278289395, 0.2946827217106049], [0.6559518297759548, 0.3440481702240452], [0.5869336800722438, 0.4130663199277562], [0.6180474391685221, 0.381952560831478], [0.05384936064827188, 0.946150639351728], [0.0679591966149758, 0.9320408033850243], [0.568945753273193, 0.43105424672680714], [0.02315522529744367, 0.9768447747025564], [0.5480731566654279, 0.45192684333457206], [0.4538039295377132, 0.5461960704622868], [0.4904667568185258, 0.5095332431814743], [0.6340400833097818, 0.36595991669021827], [0.757269737702092, 0.24273026229790795], [0.7760598055929118, 0.2239401944070881], [0.7668368676828743, 0.2331631323171257], [0.07091131738375259, 0.9290886826162474], [0.5453589304597006, 0.4546410695402994], [0.7556123827509771, 0.24438761724902294], [0.5175975953043878, 0.4824024046956123], [0.030263275384452202, 0.9697367246155478], [0.034030636229103205, 0.9659693637708967], [0.0006135542087389615, 0.999386445791261], [0.6044015403805081, 0.3955984596194918], [0.26962322428257074, 0.7303767757174293], [0.009675423761969051, 0.9903245762380309], [0.001170170490815422, 0.9988298295091845], [0.7240288821826879, 0.27597111781731215], [0.6727362913491378, 0.32726370865086224], [0.06153020292919817, 0.9384697970708018], [0.02282694908132285, 0.977173050918677], [0.7787484374454222, 0.22125156255457776], [0.013153871149679433, 0.9868461288503205], [0.5768735279880648, 0.4231264720119352], [0.379814568705418, 0.6201854312945819], [0.02375612560541627, 0.9762438743945837], [0.3275862582198413, 0.6724137417801588], [0.6961474485378513, 0.30385255146214873], [0.002931940247807594, 0.9970680597521924], [4.389346761176862e-05, 0.9999561065323882], [0.0011656872161540093, 0.9988343127838459], [0.07704179326942817, 0.9229582067305718], [0.5012669524635477, 0.49873304753645226], [0.6841492981144398, 0.31585070188556014], [0.012282557276926672, 0.9877174427230734], [0.7422523007092724, 0.25774769929072766], [0.015280002956048384, 0.9847199970439517], [0.0010029438806747808, 0.9989970561193252], [0.6894720087944246, 0.31052799120557534], [0.013660241109353335, 0.9863397588906467], [0.647080576803384, 0.35291942319661596], [0.6625170299022564, 0.3374829700977437], [0.0016078030644034057, 0.9983921969355967], [0.11040410954924046, 0.8895958904507595], [0.0002779294291116901, 0.9997220705708884], [0.636807284416643, 0.36319271558335703], [0.025418817447991057, 0.9745811825520089], [0.7545682909018936, 0.24543170909810635], [0.5592380821548736, 0.4407619178451264], [0.07461696311296973, 0.9253830368870303], [0.6481768239315482, 0.35182317606845187], [0.4358840245754639, 0.5641159754245361], [0.7119203269645611, 0.28807967303543897], [0.7239257150498125, 0.27607428495018743], [0.0034662369939559116, 0.9965337630060441], [0.24344869423465576, 0.7565513057653442], [0.49404814861967644, 0.5059518513803235], [0.03885282600899998, 0.961147173991], [0.7061859154347773, 0.29381408456522273], [0.7708096720630108, 0.22919032793698924], [0.7613358410587407, 0.2386641589412592], [0.6914680620749367, 0.3085319379250633], [0.02233110299091035, 0.9776688970090898], [0.743836000604177, 0.256163999395823], [0.11689582945371402, 0.883104170546286], [0.4540791747206654, 0.5459208252793346], [0.7169841104544598, 0.28301588954554024], [0.04873394255584217, 0.9512660574441578], [0.01899163284578636, 0.9810083671542137], [0.09913383022134041, 0.9008661697786596], [0.23946114129867288, 0.7605388587013272], [0.7627384477745881, 0.2372615522254119], [0.10354181299198306, 0.8964581870080168], [0.7194540769612525, 0.2805459230387474], [0.003047841140991393, 0.9969521588590087], [0.5136558432420091, 0.4863441567579909], [0.7597019684852176, 0.24029803151478235], [0.012269626926957919, 0.9877303730730421], [0.4828355937953636, 0.5171644062046364], [0.563940016948391, 0.4360599830516089], [0.4600065699914262, 0.5399934300085739]]}, {"iter": 7, "mu": [43.45734171897661, 63.63460031847058], "sigma": [6.228037202176262, 11.842296243508809], "pi": [0.3746329360748538, 0.6253670639251461], "ll": -871.95, "r": [[0.6696741645054719, 0.33032583549452815], [0.03216848715058983, 0.9678315128494103], [0.006616480306357005, 0.993383519693643], [0.6048882534566485, 0.3951117465433514], [0.8072999146516925, 0.19270008534830754], [0.00018471297881638275, 0.9998152870211836], [0.7463779538196945, 0.2536220461803055], [0.06481903010234259, 0.9351809698976575], [0.7855836955345104, 0.21441630446548968], [0.011017124085821211, 0.9889828759141789], [0.8343383750955519, 0.16566162490444825], [0.000750049320432212, 0.9992499506795678], [0.5256947398001571, 0.474305260199843], [0.7717082391472085, 0.2282917608527915], [0.7436502672308855, 0.2563497327691146], [0.007639986822466367, 0.9923600131775335], [0.05362367394132858, 0.9463763260586715], [0.6132762548370976, 0.38672374516290253], [0.8277384936142405, 0.17226150638575952], [0.7904274092464688, 0.2095725907535313], [0.6746659049070493, 0.32533409509295075], [0.8109669283176784, 0.18903307168232159], [1.9140238871691436e-05, 0.9999808597611283], [0.8246812938022836, 0.17531870619771636], [0.0407708524437078, 0.9592291475562922], [0.00024386281128169644, 0.9997561371887183], [0.011735705378193984, 0.9882642946218061], [0.0007869723713919986, 0.999213027628608], [0.8249919188639138, 0.17500808113608618], [0.7777665005514323, 0.22223349944856777], [0.002845260122619566, 0.9971547398773805], [5.2868049920225366e-05, 0.9999471319500798], [0.0004298105628981257, 0.999570189437102], [0.6897702746546406, 0.3102297253453594], [0.002511310883961479, 0.9974886891160385], [0.0015773485793412886, 0.9984226514206588], [0.44814364180899574, 0.5518563581910042], [0.0010113481041899618, 0.9989886518958101], [0.48037595390423926, 0.5196240460957607], [0.005629952110070156, 0.9943700478899299], [0.008184957997082581, 0.9918150420029175], [1.5028069708699097e-05, 0.9999849719302912], [0.8014654305626426, 0.19853456943735728], [0.0017643270915830103, 0.9982356729084171], [0.006437688618382512, 0.9935623113816174], [0.006540842451121135, 0.9934591575488788], [0.8341710616842779, 0.1658289383157221], [0.0010798900739044505, 0.9989201099260956], [0.5437279010863334, 0.45627209891366666], [0.8289678053986715, 0.1710321946013284], [0.0015333152145916408, 0.9984666847854083], [0.33861823858648726, 0.6613817614135127], [0.0004399955808732022, 0.9995600044191267], [0.790872455884461, 0.20912754411553908], [0.6513100246676774, 0.34868997533232254], [0.04812700383737379, 0.9518729961626263], [0.8355056971416995, 0.1644943028583005], [0.7347235237904549, 0.26527647620954514], [0.02709171701611614, 0.9729082829838838], [0.4071946565923748, 0.5928053434076253], [0.0005796768107200786, 0.99942032318928], [0.2994636994818883, 0.7005363005181118], [0.5005324281335677, 0.4994675718664324], [0.591461974221046, 0.40853802577895404], [0.00010875446571577453, 0.9998912455342843], [0.008226252135688521, 0.9917737478643115], [0.01728148489961228, 0.9827185151003877], [0.7582033887031521, 0.24179661129684785], [0.018462627890976704, 0.9815373721090233], [0.040229832550915605, 0.9597701674490844], [0.8355138587823709, 0.16448614121762908], [0.5969734775245332, 0.4030265224754667], [0.7851526142540601, 0.21484738574593978], [0.7824615542134654, 0.21753844578653453], [0.00335475029500242, 0.9966452497049976], [0.8272411306930437, 0.17275886930695622], [0.8274337877444156, 0.1725662122555844], [0.6335598257457321, 0.36644017425426795], [0.0028086714035633815, 0.9971913285964366], [0.000818855497155022, 0.999181144502845], [2.424939302102121e-05, 0.999975750606979], [0.8226174751433613, 0.17738252485663875], [0.7815147376750653, 0.21848526232493484], [0.05448860930902526, 0.9455113906909747], [0.623060156989411, 0.3769398430105891], [0.0037098861539548488, 0.996290113846045], [0.7797490328045087, 0.22025096719549128], [0.46109497240927744, 0.5389050275907226], [0.8343553058161951, 0.16564469418380487], [0.5458492865907205, 0.4541507134092795], [0.006953148442499392, 0.9930468515575006], [0.6710099838382938, 0.32899001616170626], [0.02664894707405822, 0.9733510529259417], [0.0036913590492055302, 0.9963086409507945], [4.9332561232766384e-05, 0.9999506674387671], [0.6711455273093483, 0.3288544726906517], [0.001222594618914538, 0.9987774053810855], [0.03762244184224131, 0.9623775581577587], [0.799798407588212, 0.20020159241178803], [0.6887445159216439, 0.3112554840783561], [0.710756997007902, 0.2892430029920981], [0.5602867442975611, 0.43971325570243885], [0.5212345437744593, 0.4787654562255406], [0.0002436018637111662, 0.9997563981362888], [0.5494095863676086, 0.45059041363239133], [0.0004290572121491907, 0.9995709427878509], [0.0011641600412959808, 0.998835839958704], [0.00012303792790970667, 0.9998769620720902], [0.7802819968182643, 0.21971800318173573], [0.002289621144181395, 0.9977103788558186], [0.7819441141535406, 0.21805588584645938], [0.8130122212793038, 0.18698777872069608], [0.0008881724858511361, 0.9991118275141488], [0.18515835246557127, 0.8148416475344288], [4.2285040918398924e-05, 0.9999577149590817], [0.00024604289562614776, 0.9997539571043738], [5.936949785219637e-06, 0.9999940630502148], [0.7224200796118427, 0.2775799203881572], [0.09257377001492448, 0.9074262299850755], [0.8113767565108918, 0.18862324348910814], [0.027783955914636407, 0.9722160440853637], [0.019913188162581513, 0.9800868118374184], [0.6121232749702202, 0.3878767250297797], [0.0016309749165093399, 0.9983690250834908], [0.021002716027296496, 0.9789972839727035], [0.8306518455431915, 0.1693481544568084], [0.013327801523698665, 0.9866721984763014], [0.7947051125576112, 0.20529488744238883], [0.699699643033737, 0.300300356966263], [0.8349844809682635, 0.1650155190317365], [0.7763959957116212, 0.22360400428837873], [0.7204928277493173, 0.2795071722506826], [0.6325631013835472, 0.36743689861645285], [0.6733895938864297, 0.3266104061135703], [0.014232441507532608, 0.9857675584924674], [0.02063638877333292, 0.9793636112266672], [0.6082216027538957, 0.39177839724610436], [0.0037548482487202253, 0.9962451517512798], [0.5794117536845799, 0.42058824631542024], [0.4448077279284769, 0.5551922720715231], [0.4976651344711643, 0.5023348655288358], [0.6936488954734259, 0.30635110452657405], [0.825311803617003, 0.17468819638299696], [0.8355383771695233, 0.16446162283047674], [0.8319550682112506, 0.16804493178874932], [0.022091610549058262, 0.9779083894509418], [0.5756262592317571, 0.4243737407682429], [0.8240253293122691, 0.17597467068773082], [0.5364824030048988, 0.4635175969951012], [0.005718766936025572, 0.9942812330639743], [0.00687998746580374, 0.9931200125341964], [1.2956445057929769e-05, 0.9999870435549421], [0.6556997181133665, 0.3443002818866335], [0.19562339396857106, 0.804376606031429], [0.0009593561174659486, 0.9990406438825341], [3.5551393754239337e-05, 0.9999644486062458], [0.7955516789066716, 0.20444832109332847], [0.7402656246809121, 0.2597343753190879], [0.017603852153784096, 0.9823961478462159], [0.0036716715487174045, 0.9963283284512826], [0.8254082758119684, 0.17459172418803157], [0.0015495523653106167, 0.9984504476346893], [0.619009749670593, 0.3809902503294071], [0.3393516609568331, 0.6606483390431668], [0.003908876643473514, 0.9960911233565265], [0.2683933919622888, 0.7316066080377113], [0.7665553552846006, 0.23344464471539936], [0.00014909779075412193, 0.9998509022092459], [2.065114878198235e-07, 0.9999997934885121], [3.533883189658849e-05, 0.9999646611681033], [0.02523714721481527, 0.9747628527851848], [0.5131668419141495, 0.4868331580858505], [0.7532807657494154, 0.24671923425058465], [0.0013922505085932541, 0.9986077494914068], [0.8127428874796747, 0.18725711252032523], [0.001958374382257029, 0.9980416256177431], [2.7939020026998012e-05, 0.9999720609799729], [0.7592232996294613, 0.24077670037053855], [0.001643747987281953, 0.998356252012718], [0.7097588484366714, 0.29024115156332864], [0.7283128120406626, 0.27168718795933744], [5.839113636382027e-05, 0.9999416088636361], [0.045149284182863146, 0.9548507158171368], [3.7488305546734963e-06, 0.9999962511694453], [0.6970992657189818, 0.30290073428101816], [0.004346885211031916, 0.9956531147889681], [0.8231994713363621, 0.17680052866363782], [0.5948917364198965, 0.4051082635801036], [0.02397319158179702, 0.9760268084182031], [0.7110954150909237, 0.28890458490907633], [0.4189887538898632, 0.5810112461101368], [0.7833053256204623, 0.21669467437953777], [0.7954498384689477, 0.2045501615310523], [0.0001935735290158273, 0.9998064264709842], [0.1654255329949683, 0.8345744670050317], [0.5028114380493585, 0.4971885619506416], [0.008481157954740994, 0.9915188420452591], [0.7773136441076945, 0.22268635589230557], [0.8340889470265198, 0.1659110529734802], [0.8283218783127347, 0.1716781216872653], [0.761430018173263, 0.2385699818267371], [0.003547346605938159, 0.9964526533940619], [0.8141503981041396, 0.1858496018958605], [0.04954946310812834, 0.9504505368918716], [0.4452048111199145, 0.5547951888800855], [0.7884965617045967, 0.21150343829540327], [0.012143956401822767, 0.9878560435981772], [0.0027520727783764388, 0.9972479272216237], [0.03790906087264457, 0.9620909391273554], [0.16098975951863484, 0.8390102404813652], [0.8293035384673643, 0.17069646153263565], [0.040679887014744426, 0.9593201129852557], [0.7909929944936674, 0.2090070055063326], [0.00015839063821570872, 0.9998416093617842], [0.5308709019090017, 0.46912909809099845], [0.8271395764507969, 0.172860423549203], [0.0013899623510002942, 0.9986100376489997], [0.4866836470505025, 0.5133163529494974], [0.6013639189493067, 0.3986360810506932], [0.4537576477844226, 0.5462423522155773]]}, {"iter": 8, "mu": [43.03900489843431, 64.48838427094583], "sigma": [5.719854241984883, 11.11654760096291], "pi": [0.3922187881261858, 0.6077812118738143], "ll": -868.953, "r": [[0.7262167379381319, 0.2737832620618681], [0.006864928106079302, 0.9931350718939206], [0.0006445090051283633, 0.9993554909948718], [0.6415708941557244, 0.3584291058442755], [0.8751787031188021, 0.12482129688119797], [3.1464374502103303e-06, 0.9999968535625499], [0.8156623180992233, 0.18433768190077676], [0.0199418686940161, 0.980058131305984], [0.8554346460130348, 0.1445653539869653], [0.0013774511935304569, 0.9986225488064695], [0.889586717031206, 0.11041328296879413], [2.5328060230732574e-05, 0.9999746719397692], [0.5311628036620534, 0.4688371963379465], [0.8419007282554634, 0.1580992717445366], [0.8127281931873062, 0.18727180681269387], [0.0007983682515411956, 0.9992016317484589], [0.01491365797667039, 0.9850863420233296], [0.6528940676087813, 0.3471059323912187], [0.8911935665565026, 0.1088064334434974], [0.8600027358897615, 0.13999726411023855], [0.7324340924702817, 0.26756590752971826], [0.8782977246379332, 0.12170227536206674], [1.069957612879944e-07, 0.9999998930042386], [0.8890938655080125, 0.1109061344919875], [0.009826546993155938, 0.9901734530068441], [4.758844817081483e-06, 0.9999952411551829], [0.0015135968012684846, 0.9984864031987315], [2.7204298024323623e-05, 0.9999727957019757], [0.8893150187148195, 0.1106849812851804], [0.8478883555975623, 0.15211164440243777], [0.00018377933467647752, 0.9998162206653236], [4.87461796564428e-07, 0.9999995125382034], [1.106324171065121e-05, 0.9999889367582894], [0.7509387870707984, 0.24906121292920164], [0.00015265679570448663, 0.9998473432042955], [7.64809185473792e-05, 0.9999235190814525], [0.42086799777471195, 0.5791320022252882], [3.950229526058969e-05, 0.9999604977047395], [0.46660268201109867, 0.5333973179889013], [0.0005068813623499612, 0.99949311863765], [0.0008846251562463736, 0.9991153748437537], [7.455615009485685e-08, 0.9999999254438499], [0.8700725878311535, 0.12992741216884654], [9.03358680877974e-05, 0.9999096641319123], [0.0006187656414995063, 0.9993812343585005], [0.0006335760326784443, 0.9993664239673216], [0.8892388901745264, 0.11076110982547364], [4.3547337298555014e-05, 0.9999564526627015], [0.5567129609623932, 0.44328703903760686], [0.8919779815530273, 0.10802201844697268], [7.332928843482323e-05, 0.9999266707115652], [0.2724168523069196, 0.7275831476930803], [1.1455593520676989e-05, 0.9999885444064793], [0.8604181182437163, 0.13958188175628364], [0.7029350351344165, 0.2970649648655836], [0.012645163634960606, 0.9873548363650395], [0.8928654091180029, 0.10713459088199696], [0.8029867416833933, 0.19701325831660663], [0.005298809865323906, 0.9947011901346761], [0.363706183977723, 0.636293816022277], [1.7264799761678764e-05, 0.9999827352002383], [0.2239236904104232, 0.7760763095895767], [0.4953344392790096, 0.5046655607209904], [0.6232620006252061, 0.37673799937479385], [1.4290178426797168e-06, 0.9999985709821573], [0.0008912797217803922, 0.9991087202782195], [0.00269864437177726, 0.9973013556282226], [0.8281441298673593, 0.17185587013264061], [0.002979450336451819, 0.9970205496635483], [0.00962940550229388, 0.990370594497706], [0.8936255404568433, 0.10637445954315664], [0.6308039800881582, 0.36919601991184187], [0.8550239957510991, 0.1449760042489008], [0.8524457654575684, 0.1475542345424315], [0.000234756845598177, 0.9997652431544017], [0.8774974773860005, 0.12250252261399946], [0.8777996010501069, 0.12220039894989304], [0.6798647858719574, 0.3201352141280426], [0.00018027807378973753, 0.9998197219262103], [2.8859303482502406e-05, 0.9999711406965176], [1.5233227694925583e-07, 0.9999998476677231], [0.8875886755656976, 0.11241132443430234], [0.851532696756311, 0.1484673032436889], [0.015282872179438165, 0.9847171278205618], [0.6659794168692595, 0.3340205831307404], [0.00027262928032782235, 0.9997273707196721], [0.8498217955224739, 0.15017820447752608], [0.4391935050869883, 0.5608064949130116], [0.8896224997023884, 0.11037750029761154], [0.5597077437408332, 0.44029225625916685], [0.000693914234523267, 0.9993060857654767], [0.7278853495294056, 0.2721146504705943], [0.0051689961229658896, 0.9948310038770342], [0.00027060797577500075, 0.9997293920242251], [4.396411068757002e-07, 0.9999995603588931], [0.7280544655943346, 0.27194553440566543], [5.2371184472846447e-05, 0.9999476288155271], [0.008699414182250283, 0.9913005858177497], [0.8685844020906242, 0.13141559790937588], [0.7496972162173702, 0.2503027837826298], [0.7758308431606903, 0.22416915683930969], [0.5800118845669534, 0.41998811543304654], [0.5248228281682386, 0.4751771718317614], [4.751264135428542e-06, 0.9999952487358647], [0.5647277468111219, 0.435272253188878], [1.1034398903557026e-05, 0.9999889656010965], [4.8693855681252934e-05, 0.9999513061443188], [1.7175537361709035e-06, 0.9999982824462638], [0.8503393256252818, 0.14966067437471814], [0.00013306636140812136, 0.9998669336385919], [0.8519471485715749, 0.14805285142842498], [0.8800030749465625, 0.1199969250534375], [3.256573192886969e-05, 0.9999674342680711], [0.10342417263178294, 0.8965758273682171], [3.49314120063945e-07, 0.9999996506858799], [4.822332031432289e-06, 0.9999951776679685], [1.8610634755666815e-08, 0.9999999813893652], [0.7892230090092096, 0.21077699099079045], [0.03460531497577247, 0.9653946850242275], [0.8532796926467714, 0.14672030735322852], [0.005503987381111845, 0.9944960126188881], [0.0033369947876194916, 0.9966630052123804], [0.6513431993461025, 0.3486568006538975], [8.037721007006268e-05, 0.99991962278993], [0.0036144915795862024, 0.9963855084204138], [0.8929706182855106, 0.10702938171448928], [0.0018301169107430967, 0.9981698830892568], [0.8639638645068323, 0.13603613549316776], [0.7628390415588786, 0.23716095844112142], [0.8943357372566102, 0.1056642627433898], [0.8465442058744598, 0.15345579412554022], [0.7870327260531492, 0.21296727394685083], [0.6785539768100501, 0.3214460231899498], [0.7308491003429454, 0.26915089965705463], [0.002018744445415568, 0.9979812555545845], [0.003520347318196719, 0.9964796526818034], [0.6460817931935744, 0.35391820680642555], [0.00027755509701137134, 0.9997224449029887], [0.6066555791966303, 0.39334442080336984], [0.41616291745372036, 0.5838370825462795], [0.4912461450603121, 0.5087538549396879], [0.7556129595358716, 0.24438704046412846], [0.8895411235548502, 0.1104588764451498], [0.8932287204064203, 0.10677127959357967], [0.8936441129511095, 0.10635588704889061], [0.0038992981910910642, 0.9961007018089089], [0.6014081159298583, 0.3985918840701417], [0.8886219546991284, 0.11137804530087154], [0.5464656627814095, 0.45353433721859054], [0.0005188209668561968, 0.9994811790331437], [0.0006830758327805349, 0.9993169241672195], [5.97390112232441e-08, 0.9999999402609888], [0.7085567303699368, 0.2914432696300632], [0.11294947928016462, 0.8870505207198354], [3.6521149922950016e-05, 0.999963478850077], [2.696538570813774e-07, 0.999999730346143], [0.8647392690634753, 0.13526073093652474], [0.8090595027926797, 0.19094049720732034], [0.0027743471439081184, 0.9972256528560919], [0.0002684654845179032, 0.999731534515482], [0.8746466260928155, 0.1253533739071844], [7.448639334962873e-05, 0.9999255136066503], [0.6605788034144924, 0.3394211965855077], [0.273353764545241, 0.7266462354547589], [0.00029464720423298625, 0.9997053527957669], [0.18781376311722633, 0.8121862368827737], [0.8367168183844673, 0.16328318161553265], [2.286827619863733e-06, 0.9999977131723802], [1.2197776771797316e-10, 0.9999999998780221], [2.6725131479631364e-07, 0.9999997327486853], [0.004762581363799963, 0.9952374186362001], [0.5133404592670452, 0.48665954073295475], [0.8229961196630232, 0.17700388033697675], [6.35300714929633e-05, 0.9999364699285069], [0.8797800127790129, 0.12021998722098726], [0.00010548926285440467, 0.9998945107371456], [1.8819915458555865e-07, 0.9999998118008453], [0.8292020177483224, 0.17079798225167764], [8.1314545406804e-05, 0.9999186854545933], [0.7746696600154258, 0.22533033998457416], [0.795862888599649, 0.20413711140035098], [5.653406637751404e-07, 0.9999994346593363], [0.011473618888079495, 0.9885263811119206], [9.358495223558712e-09, 0.9999999906415048], [0.7597434750038665, 0.24025652499613345], [0.00034504315091236134, 0.9996549568490876], [0.8880190250840511, 0.111980974915949], [0.6279594597845222, 0.3720405402154778], [0.004408581826578499, 0.9955914181734216], [0.7762240070032389, 0.22377599299676104], [0.38001965007022814, 0.6199803499297719], [0.8532568678777521, 0.14674313212224788], [0.8646461418841263, 0.1353538581158737], [3.3738719893439237e-06, 0.9999966261280107], [0.08638052091191431, 0.9136194790880856], [0.4985836700856389, 0.501416329914361], [0.0009327216993810401, 0.9990672783006189], [0.8474448887144875, 0.15255511128551244], [0.894388098036588, 0.10561190196341189], [0.8915710754771221, 0.10842892452287788], [0.8314805101022597, 0.16851948989774032], [0.0002550655984320666, 0.999744934401568], [0.8809404269003654, 0.11905957309963448], [0.01321917454909397, 0.9867808254509061], [0.4167226150506932, 0.5832773849493068], [0.8581920296713079, 0.14180797032869213], [0.0015928341913152581, 0.9984071658086847], [0.00017490564391716313, 0.9998250943560828], [0.008799999833922153, 0.9912000001660779], [0.08271822280443274, 0.9172817771955672], [0.8921843556319207, 0.10781564436807943], [0.009793300854584389, 0.9902066991454156], [0.8605304938846762, 0.13946950611532374], [2.5023917144555743e-06, 0.9999974976082856], [0.5385115569159779, 0.4614884430840221], [0.8907972240063909, 0.10920277599360903], [6.337493918239792e-05, 0.9999366250608177], [0.4755898980393502, 0.5244101019606497], [0.6367861062090445, 0.3632138937909554], [0.4288008615190814, 0.5711991384809186]]}, {"iter": 9, "mu": [42.91884944487435, 65.25669247555875], "sigma": [5.587692876083031, 10.423113668286057], "pi": [0.41101362273638004, 0.58898637726362], "ll": -866.977, "r": [[0.7772703488308282, 0.2227296511691718], [0.002287968575835455, 0.9977120314241645], [0.00012626519055823008, 0.9998737348094417], [0.6811484319607679, 0.31885156803923215], [0.9230849117315234, 0.07691508826847662], [1.916900225440015e-07, 0.9999998083099775], [0.8691495125865729, 0.13085048741342709], [0.008527649956685604, 0.9914723500433144], [0.9058731625366564, 0.09412683746334362], [0.00031951215420621934, 0.9996804878457937], [0.9380810538272298, 0.061918946172770106], [2.433409479381681e-06, 0.9999975665905205], [0.5475703295289992, 0.45242967047100086], [0.8936914797972205, 0.10630852020277942], [0.8663310360918481, 0.13366896390815183], [0.00016401795790881685, 0.9998359820420911], [0.005951992677738586, 0.9940480073222614], [0.6944084463365924, 0.3055915536634076], [0.9368681949099048, 0.06313180509009507], [0.9099116687491854, 0.09008833125081464], [0.7840192979398608, 0.21598070206013917], [0.9257546711297553, 0.07424532887024474], [3.127025659591275e-09, 0.9999999968729744], [0.9350111410135475, 0.06498885898645254], [0.0035573075880288526, 0.9964426924119711], [3.172879569514884e-07, 0.999999682712043], [0.00035855738103540485, 0.9996414426189646], [2.6548919626287797e-06, 0.9999973451080373], [0.9352044035643792, 0.06479559643562079], [0.8991211859528568, 0.10087881404714323], [2.72848081444048e-05, 0.9999727151918556], [1.9794758643576892e-08, 0.9999999802052414], [8.867786389097317e-07, 0.9999991132213611], [0.8038114346551215, 0.19618856534487844], [2.1756594412259742e-05, 0.9999782434055877], [9.363045469078044e-06, 0.9999906369545309], [0.41120810977183103, 0.588791890228169], [4.1833462619789094e-06, 0.999995816653738], [0.46765937816349024, 0.5323406218365098], [9.415497545775237e-05, 0.9999058450245423], [0.00018592885328867192, 0.9998140711467114], [2.0149729082724524e-09, 0.999999997985027], [0.918690782895031, 0.08130921710496895], [1.1471267321258795e-05, 0.9999885287326787], [0.00012013110739978387, 0.9998798688926002], [0.0001236532980254552, 0.9998763467019746], [0.9378780394666678, 0.062121960533332084], [4.711357232477704e-06, 0.9999952886427675], [0.5789961699602079, 0.42100383003979225], [0.9375816659902929, 0.06241833400970719], [8.894619914197921e-06, 0.9999911053800858], [0.23543268843319518, 0.7645673115668048], [9.252470416833593e-07, 0.9999990747529584], [0.9102771064506948, 0.08972289354930518], [0.7515837697652803, 0.24841623023471965], [0.004854694936682615, 0.9951453050633174], [0.9398687320252929, 0.060131267974707095], [0.8568703063350964, 0.14312969366490366], [0.001664547494941126, 0.998335452505059], [0.34169856179306074, 0.6583014382069391], [1.525280477191231e-06, 0.9999984747195227], [0.18256979008398816, 0.8174302099160118], [0.5032573658474394, 0.4967426341525606], [0.6594924549588509, 0.34050754504114916], [7.331276416336793e-08, 0.9999999266872358], [0.00018763980039398587, 0.999812360199606], [0.0007277265870767163, 0.9992722734129232], [0.8809746646429993, 0.11902533535700066], [0.000821553243718252, 0.9991784467562818], [0.003469603523221953, 0.996530396476778], [0.9402066004600168, 0.05979339953998329], [0.6684439122885418, 0.3315560877114583], [0.9055083340526688, 0.09449166594733117], [0.9032109887364022, 0.09678901126359786], [3.6785989172037765e-05, 0.9999632140108279], [0.9305245624643265, 0.06947543753567359], [0.930721311002213, 0.069278688997787], [0.725533283757238, 0.274466716242762], [2.6651794165672297e-05, 0.9999733482058343], [2.85307064354216e-06, 0.9999971469293564], [4.806230601115077e-09, 0.9999999951937694], [0.9337046535777642, 0.0662953464222358], [0.9023945688000748, 0.09760543119992518], [0.006134653590334576, 0.9938653464096654], [0.7095937775661162, 0.2904062224338838], [4.415388006434186e-05, 0.9999558461199357], [0.9008607718837143, 0.09913922811628573], [0.43377160566863876, 0.5662283943313612], [0.9381018469499115, 0.06189815305008857], [0.5826653770404531, 0.41733462295954693], [0.0001381897180008038, 0.9998618102819993], [0.77908636945265, 0.22091363054735003], [0.001614623268649207, 0.9983853767313507], [4.375458993607669e-05, 0.9999562454100639], [1.7457038571327688e-08, 0.9999999825429614], [0.7792702327085332, 0.2207297672914667], [5.900010555525758e-06, 0.9999940999894444], [0.003061734820341105, 0.9969382651796589], [0.9174034100813788, 0.08259658991862125], [0.8024977255894921, 0.19750227441050794], [0.8296930252658358, 0.17030697473416426], [0.6074431869192234, 0.3925568130807767], [0.5397446750714296, 0.46025532492857024], [3.1667240153933337e-07, 0.9999996833275985], [0.5888080053949282, 0.41119199460507183], [8.83962367510909e-07, 0.9999991160376325], [5.398812549746406e-06, 0.9999946011874502], [9.171363624316123e-08, 0.9999999082863638], [0.9013252801180146, 0.09867471988198542], [1.8399778256193615e-05, 0.9999816002217438], [0.9027653343405642, 0.09723466565943582], [0.927211370631346, 0.07278862936865405], [3.30584954920343e-06, 0.9999966941504508], [0.06741630075892248, 0.9325836992410776], [1.3194877636196695e-08, 0.9999999868051225], [3.2245153865638976e-07, 0.9999996775484613], [3.7253211283385367e-10, 0.9999999996274679], [0.843239895005242, 0.1567601049947581], [0.01692665392153814, 0.983073346078462], [0.9140352587838643, 0.08596474121613576], [0.0017440339504342477, 0.9982559660495658], [0.000943958154495349, 0.9990560418455047], [0.6925986748459059, 0.30740132515409413], [9.948040055095322e-06, 0.999990051959945], [0.0010410682510897061, 0.9989589317489104], [0.9385167927682696, 0.061483207231730445], [0.00045233843383710653, 0.9995476615661628], [0.9133846540956047, 0.08661534590439543], [0.8162950832028417, 0.18370491679715828], [0.9403691913564609, 0.05963080864353914], [0.897907867856092, 0.10209213214390794], [0.8410431580706814, 0.15895684192931855], [0.7240365850834432, 0.2759634149165569], [0.7823033899717119, 0.21769661002828805], [0.0005100415129157885, 0.9994899584870841], [0.0010079239814626908, 0.9989920760185373], [0.68644371353515, 0.31355628646484995], [4.512967142296263e-05, 0.999954870328577], [0.6396427168724277, 0.36035728312757226], [0.40543180977979265, 0.5945681902202073], [0.4981919491129471, 0.5018080508870528], [0.8087382589806039, 0.19126174101939616], [0.9354024332519254, 0.0645975667480745], [0.940038462858114, 0.05996153714188604], [0.9391940502266335, 0.060805949773366556], [0.0011425304436388408, 0.9988574695563611], [0.6333332655307217, 0.36666673446927833], [0.9346000073803746, 0.06539999261962542], [0.5664167381811268, 0.43358326181887313], [9.687096096777442e-05, 0.9999031290390323], [0.0001355570166353282, 0.9998644429833646], [1.5389027231619176e-09, 0.9999999984610973], [0.7578440180229432, 0.24215598197705687], [0.07546256864100499, 0.9245374313589949], [3.8016852725371043e-06, 0.9999961983147275], [9.629484441334624e-09, 0.9999999903705156], [0.9140614482013215, 0.08593855179867857], [0.8627865735697761, 0.13721342643022397], [0.0007528119148737281, 0.9992471880851262], [4.3332081355144156e-05, 0.9999566679186448], [0.9286546403787126, 0.07134535962128745], [9.066094967408865e-06, 0.9999909339050326], [0.7033450887934817, 0.29665491120651827], [0.23648243051637707, 0.7635175694836228], [4.854506323339409e-05, 0.9999514549367666], [0.14534002136082894, 0.854659978639171], [0.8889388357451273, 0.11106116425487264], [1.2996425125213328e-07, 0.9999998700357488], [8.263201793620846e-13, 0.9999999999991737], [9.525175802099407e-09, 0.9999999904748241], [0.001460222744201218, 0.9985397772557988], [0.5255512047526313, 0.47444879524736866], [0.8761300908453644, 0.12386990915463562], [7.46706513629523e-06, 0.9999925329348637], [0.9270209104707897, 0.07297908952921017], [1.3860054281247368e-05, 0.9999861399457187], [6.216383764132072e-09, 0.9999999937836161], [0.8819644666693949, 0.11803553333060512], [1.0089719217247947e-05, 0.9999899102807829], [0.8285056293715952, 0.17149437062840472], [0.8498532751410254, 0.15014672485897462], [2.3708302366205314e-08, 0.9999999762916977], [0.004305966671221538, 0.9956940333287785], [1.614775277486652e-10, 0.9999999998385225], [0.8130668273409186, 0.18693317265908138], [5.8865762958759647e-05, 0.9999411342370412], [0.934076853288772, 0.06592314671122797], [0.6650726959688411, 0.33492730403115883], [0.0013281889636672394, 0.9986718110363328], [0.8300946085669787, 0.16990539143302136], [0.3613665965627942, 0.6386334034372058], [0.9039349940551289, 0.09606500594487116], [0.9139802161015393, 0.0860197838984607], [2.0869607898838596e-07, 0.9999997913039209], [0.05358203256463262, 0.9464179674353673], [0.5072825427878065, 0.49271745721219357], [0.00019835862689242145, 0.9998016413731075], [0.8987212407734266, 0.10127875922657335], [0.9401367795415926, 0.05986322045840743], [0.9372095781536246, 0.06279042184637536], [0.8840896374106324, 0.1159103625893676], [4.070668360770602e-05, 0.9999592933163922], [0.9280115697003966, 0.07198843029960349], [0.005128149320624827, 0.9948718506793751], [0.40611852806705107, 0.5938814719329489], [0.9083152151239822, 0.09168478487601775], [0.00038165359365408187, 0.999618346406346], [2.5685768030921727e-05, 0.999974314231969], [0.0031053697518933685, 0.9968946302481067], [0.05070954369867631, 0.9492904563013237], [0.9377723920362356, 0.062227607963764434], [0.003542487424978535, 0.9964575125750215], [0.9103759196495366, 0.08962408035046346], [1.4503281196898486e-07, 0.9999998549671881], [0.5566289505169222, 0.44337104948307776], [0.9365129377088862, 0.06348706229111381], [7.444834684766047e-06, 0.9999925551653152], [0.47879171326101033, 0.5212082867389896], [0.6755137307067131, 0.32448626929328706], [0.42096360926469223, 0.5790363907353079]]}, {"iter": 10, "mu": [42.98042731981458, 65.98211945576699], "sigma": [5.580955766261183, 9.78166045843759], "pi": [0.430689390581057, 0.5693106094189431], "ll": -865.066, "r": [[0.826372719777178, 0.173627280222822], [0.0016429603160448404, 0.9983570396839552], [7.551243162053377e-05, 0.9999244875683795], [0.7321382484783773, 0.2678617515216227], [0.9538257594872656, 0.046174240512734444], [8.026176480601188e-08, 0.9999999197382352], [0.9092117845584117, 0.09078821544158842], [0.006712394352012184, 0.9932876056479878], [0.9398763801651727, 0.06012361983482722], [0.00020217104707438477, 0.9997978289529257], [0.9702164884704828, 0.029783511529517276], [1.1638986268464547e-06, 0.9999988361013731], [0.5918064683023381, 0.40819353169766187], [0.9298665931663155, 0.0701334068336845], [0.906797008763918, 0.09320299123608192], [9.96438944368657e-05, 0.999900356105563], [0.00456550534342296, 0.9954344946565771], [0.7455234602625688, 0.2544765397374312], [0.9653483962830686, 0.03465160371693149], [0.9431636926917994, 0.05683630730820056], [0.8327233407955429, 0.1672766592044571], [0.9559907273369409, 0.04400927266305921], [1.0691525457705035e-09, 0.9999999989308473], [0.9636889145806296, 0.03631108541937047], [0.002632255804967501, 0.9973677441950325], [1.3632839615646587e-07, 0.9999998636716039], [0.00022850113206553642, 0.9997714988679344], [1.275804536953786e-06, 0.9999987241954631], [0.9638578296126069, 0.03614217038739305], [0.934346920271614, 0.0656530797283859], [1.4920218112255842e-05, 0.9999850797818878], [7.398813915309654e-09, 0.999999992601186], [4.0196750881930935e-07, 0.9999995980324912], [0.8511207981693819, 0.14887920183061812], [1.1744741934810682e-05, 0.9999882552580652], [4.820624513529885e-06, 0.9999951793754865], [0.4411811587594262, 0.5588188412405737], [2.060451064067529e-06, 0.999997939548936], [0.5041685945056051, 0.49583140549439486], [5.533385098770589e-05, 0.9999446661490123], [0.00011381467663738142, 0.9998861853233627], [6.747165423100497e-10, 0.9999999993252836], [0.9502728137925761, 0.049727186207423876], [5.97324125579066e-06, 0.9999940267587443], [7.163044600456774e-05, 0.9999283695539954], [7.385802855355329e-05, 0.9999261419714465], [0.9701885341644239, 0.029811465835576163], [2.3356122455216723e-06, 0.9999976643877544], [0.6256143611245738, 0.37438563887542625], [0.966016495368642, 0.033983504631358095], [4.566421523498089e-06, 0.9999954335784765], [0.24339775826691096, 0.756602241733089], [4.203435711646213e-07, 0.9999995796564288], [0.943460507261717, 0.05653949273828299], [0.8018612453574108, 0.19813875464258915], [0.003670673346031351, 0.9963293266539687], [0.9702095732875614, 0.029790426712438624], [0.898628232459587, 0.10137176754041297], [0.001170214791711366, 0.9988297852082887], [0.3629435412088727, 0.6370564587911273], [7.115289493573155e-07, 0.9999992884710507], [0.1847776357573224, 0.8152223642426776], [0.5434713659988912, 0.45652863400110877], [0.710041385264014, 0.28995861473598605], [2.9239903937098217e-08, 0.9999999707600962], [0.00011492578842416187, 0.9998850742115758], [0.0004848631721709645, 0.999515136827829], [0.9192475184923085, 0.08075248150769154], [0.0005516353368113805, 0.9994483646631886], [0.0025629554095676368, 0.9974370445904324], [0.9700363449283853, 0.029963655071614748], [0.7192097416243504, 0.2807902583756496], [0.9395787202379734, 0.06042127976202651], [0.9377015073418904, 0.06229849265810961], [2.046364248084097e-05, 0.9999795363575191], [0.9683253544203373, 0.03167464557966268], [0.9683850838964303, 0.03161491610356973], [0.7764816385538299, 0.22351836144617016], [1.4554535179387323e-05, 0.9999854454648206], [1.3763744614787719e-06, 0.9999986236255385], [1.6773676861202278e-09, 0.9999999983226324], [0.9625627714908608, 0.03743722850913918], [0.9370331811016321, 0.06296681889836792], [0.004715735654106928, 0.9952842643458931], [0.7607103919988847, 0.2392896080011154], [2.4822768615658303e-05, 0.9999751772313843], [0.935775832619436, 0.06422416738056404], [0.4664386761343241, 0.533561323865676], [0.9702191753925132, 0.029780824607486777], [0.6295334149923184, 0.37046658500768154], [8.309181342379307e-05, 0.9999169081865761], [0.8280853244204766, 0.17191467557952342], [0.0011328351282271863, 0.9988671648717729], [2.458535335484675e-05, 0.9999754146466452], [6.485001506391597e-09, 0.9999999935149986], [0.8282585634308004, 0.17174143656919963], [2.9611456369663967e-06, 0.9999970388543631], [0.002242383807749912, 0.9977576161922501], [0.9492322704573696, 0.05076772954263049], [0.8499104030700081, 0.1500895969299919], [0.8746403149781551, 0.125359685021845], [0.6558319706537014, 0.3441680293462987], [0.5833238272109194, 0.41667617278908076], [1.3605029578441616e-07, 0.9999998639497042], [0.6360803913736396, 0.36391960862636047], [4.0062385620495345e-07, 0.9999995993761438], [2.6964339848484278e-06, 0.9999973035660152], [3.699269944412161e-08, 0.9999999630073005], [0.9361568659265548, 0.06384313407344519], [9.838777986951396e-06, 0.999990161222013], [0.93733677229697, 0.06266322770302997], [0.9571765848034839, 0.042823415196516064], [1.6075596590322401e-06, 0.9999983924403409], [0.06251464817245736, 0.9374853518275427], [4.835178583220771e-09, 0.9999999951648213], [1.3866234946140476e-07, 0.9999998613376506], [1.1528152169030065e-10, 0.9999999998847185], [0.8866919950460806, 0.1133080049539193], [0.01402319950005679, 0.9859768004999432], [0.9627907053290381, 0.03720929467096181], [0.0012298877885523688, 0.9987701122114476], [0.0006395058057423569, 0.9993604941942578], [0.7437032915595456, 0.25629670844045443], [5.139100560228718e-06, 0.9999948608994398], [0.0007097693485568012, 0.9992902306514432], [0.9669385478105461, 0.033061452189454006], [0.00029246708180715055, 0.9997075329181928], [0.9459807538760959, 0.05401924612390406], [0.8625438873861567, 0.13745611261384325], [0.9695220487662244, 0.030477951233775637], [0.9333484476783568, 0.06665155232164315], [0.8847502796674771, 0.11524972033252291], [0.775008356347587, 0.22499164365241298], [0.8311123503060206, 0.16888764969397943], [0.00033226756494275097, 0.9996677324350572], [0.0006857362413177794, 0.9993142637586823], [0.7374970619310878, 0.26250293806891223], [2.5403503370742482e-05, 0.9999745964966292], [0.6895434842124496, 0.31045651578755046], [0.434700850113297, 0.5652991498867029], [0.537902372734143, 0.4620976272658569], [0.8556462061148865, 0.14435379388511344], [0.964031660042331, 0.035968339957668995], [0.9701455853329662, 0.029854414667033834], [0.9676643718373593, 0.03233562816264067], [0.0007836551630668166, 0.9992163448369331], [0.6829814281334804, 0.31701857186651966], [0.9633317672790286, 0.03666823272097136], [0.6121324136475095, 0.38786758635249047], [5.702606881554046e-05, 0.9999429739311845], [8.141483095518924e-05, 0.9999185851690449], [5.087894480095056e-10, 0.9999999994912105], [0.807883589108273, 0.19211641089172704], [0.07066424185052636, 0.9293357581494737], [1.8627466097901826e-06, 0.9999981372533902], [3.4750931560277884e-09, 0.9999999965249069], [0.9465288473824137, 0.0534711526175863], [0.9037479158615433, 0.09625208413845653], [0.0005026621869534165, 0.9994973378130465], [2.4334272898231222e-05, 0.9999756657271017], [0.9677450261848546, 0.032254973815145416], [4.659390581859931e-06, 0.9999953406094182], [0.7544797674978622, 0.2455202325021378], [0.2445704937188381, 0.755429506281162], [2.744194762495389e-05, 0.999972558052375], [0.14420039674125867, 0.8557996032587413], [0.9259188567039289, 0.07408114329607111], [5.335206539327416e-08, 0.9999999466479347], [1.948494842054189e-13, 0.999999999999805], [3.435637262936243e-09, 0.9999999965643628], [0.0010177453025260786, 0.9989822546974739], [0.5678784723554674, 0.4321215276445325], [0.9151548135638894, 0.08484518643611068], [3.7965754128284257e-06, 0.9999962034245872], [0.9570212844752662, 0.04297871552473378], [7.2939471644986374e-06, 0.9999927060528355], [2.1964737852861637e-09, 0.9999999978035263], [0.9200804872328677, 0.07991951276713238], [5.216394942735857e-06, 0.9999947836050572], [0.873575273343467, 0.126424726656533], [0.8925076387723688, 0.10749236122763109], [8.94042996220053e-09, 0.99999999105957], [0.0032286185163887078, 0.9967713814836112], [4.8087840474788307e-11, 0.9999999999519121], [0.8596037138188307, 0.14039628618116934], [3.365188086662669e-05, 0.9999663481191334], [0.9628811205254574, 0.037118879474542656], [0.7157624814536928, 0.2842375185463072], [0.0009199854514308594, 0.9990800145485691], [0.8750002045168198, 0.12499979548318023], [0.3851235301696763, 0.6148764698303236], [0.9382936447541108, 0.06170635524588912], [0.946463075624729, 0.053536924375271064], [8.776249310822588e-08, 0.999999912237507], [0.0487177509479211, 0.9512822490520789], [0.5478907094409858, 0.45210929055901417], [0.00012190095723938808, 0.9998780990427606], [0.9340179631684364, 0.06598203683156363], [0.9689178557561177, 0.03108214424388234], [0.9656651670713451, 0.03433483292865504], [0.9218652368551394, 0.07813476314486048], [2.2777415116047394e-05, 0.999977222584884], [0.9578300549468922, 0.04216994505310772], [0.003892380782697939, 0.9961076192173021], [0.4354715405646113, 0.5645284594353888], [0.9418658119996592, 0.0581341880003408], [0.0002441642005322787, 0.9997558357994677], [1.3997460149582602e-05, 0.9999860025398505], [0.0022765395637032973, 0.9977234604362968], [0.045891332656520574, 0.9541086673434795], [0.9661994750334308, 0.03380052496656921], [0.0026205367035844317, 0.9973794632964156], [0.9435407478710148, 0.05645925212898521], [5.987006919679773e-08, 0.9999999401299308], [0.6015947599197138, 0.3984052400802861], [0.9650234716386442, 0.03497652836135587], [3.7846490737051373e-06, 0.9999962153509262], [0.5164995440050202, 0.48350045599497976], [0.7264165377140477, 0.2735834622859523], [0.45211298429945634, 0.5478870157005438]]}, {"iter": 11, "mu": [43.14323645040599, 66.69137083091387], "sigma": [5.615573449764769, 9.163125541594228], "pi": [0.4508143181100851, 0.5491856818899149], "ll": -863.001, "r": [[0.8740989683219793, 0.12590103167802072], [0.0017478792867297796, 0.9982521207132703], [7.795632010416163e-05, 0.9999220436798958], [0.7915664316865599, 0.20843356831344007], [0.9739963427683959, 0.026003657231604166], [8.292402675535621e-08, 0.9999999170759732], [0.9408808160479548, 0.05911918395204519], [0.007308232303437615, 0.9926917676965623], [0.963875275328725, 0.03612472467127505], [0.00021016638838876285, 0.9997898336116113], [0.9873268546280023, 0.012673145371997721], [1.1918784159678191e-06, 0.999998808121584], [0.6580564057292078, 0.3419435942707922], [0.9564869383704491, 0.043513061629550875], [0.9390257378592051, 0.06097426214079492], [0.00010304646743781394, 0.9998969535325621], [0.0049360649486991405, 0.9950639350513009], [0.8036637391026296, 0.19633626089737038], [0.9823881445893878, 0.017611855410612144], [0.9662769735733103, 0.03372302642668966], [0.8794271449368865, 0.12057285506311366], [0.975556016877915, 0.024443983122084945], [1.1398465650152533e-09, 0.9999999988601534], [0.9811466037741181, 0.018853396225881836], [0.00282004714992394, 0.997179952850076], [1.4050155148154795e-07, 0.9999998594984485], [0.00023778107923096796, 0.999762218920769], [1.3063003646797026e-06, 0.9999986936996352], [0.9812717794496784, 0.018728220550321632], [0.9598081638730023, 0.04019183612699777], [1.529768230452782e-05, 0.9999847023176955], [7.760019705706219e-09, 0.9999999922399803], [4.1262370220991497e-07, 0.9999995873762978], [0.8946798667412434, 0.10532013325875654], [1.2034867213922776e-05, 0.9999879651327861], [4.933398256076164e-06, 0.999995066601744], [0.5025570740085168, 0.4974429259914833], [2.1086611245098654e-06, 0.9999978913388755], [0.5690034535845454, 0.4309965464154547], [5.702570150819873e-05, 0.9999429742984919], [0.0001178058460731323, 0.9998821941539269], [7.22492753471225e-10, 0.9999999992775073], [0.9714336538019073, 0.028566346198092705], [6.114102224605565e-06, 0.9999938858977754], [7.392584009926243e-05, 0.9999260741599008], [7.623842366614291e-05, 0.9999237615763339], [0.9873595594233809, 0.012640440576619132], [2.3900885890042396e-06, 0.999997609911411], [0.6912860763361236, 0.3087139236638764], [0.9828978348592169, 0.017102165140783103], [4.673087930832391e-06, 0.9999953269120692], [0.28248282279609044, 0.7175171772039095], [4.314297867836101e-07, 0.9999995685702131], [0.9664932522067906, 0.03350674779320946], [0.8532431039833185, 0.14675689601668154], [0.00395379307501466, 0.9960462069249854], [0.9867641874321897, 0.01323581256781019], [0.9327051896918621, 0.06729481030813785], [0.0012392229993389782, 0.998760777000661], [0.4174182271193602, 0.5825817728806398], [7.293048949449201e-07, 0.9999992706951051], [0.2146140646776222, 0.7853859353223778], [0.6094470821327828, 0.39055291786721724], [0.771341065072443, 0.22865893492755696], [3.038011188518048e-08, 0.999999969619888], [0.00011896383899482987, 0.9998810361610052], [0.0005081689137867533, 0.9994918310862133], [0.9485230263631832, 0.05147697363681692], [0.0005789469822453151, 0.9994210530177546], [0.002744660152785921, 0.997255339847214], [0.9864708785530208, 0.013529121446979212], [0.7797709376690241, 0.22022906233097586], [0.9636572189690884, 0.03634278103091155], [0.9622797352904519, 0.037720264709548056], [2.1000876186266535e-05, 0.9999789991238138], [0.9876271130658439, 0.012372886934156054], [0.9876305107036732, 0.012369489296326735], [0.831182408217037, 0.16881759178296302], [1.4921775280486443e-05, 0.9999850782247195], [1.4091320623039868e-06, 0.9999985908679377], [1.7809352310711661e-09, 0.9999999982190647], [0.9803170125362219, 0.019682987463778043], [0.9617883584414313, 0.03821164155856864], [0.005101389691741644, 0.9948986103082583], [0.8172449866549037, 0.18275501334509625], [2.549131091917322e-05, 0.9999745086890808], [0.9608625278969918, 0.03913747210300821], [0.5294360701261156, 0.47056392987388423], [0.9873233140580864, 0.01267668594191365], [0.695095937142373, 0.30490406285762695], [8.583041804978535e-05, 0.9999141695819502], [0.8755389654954937, 0.12446103450450627], [0.0011991328746769477, 0.9988008671253231], [2.524662673845182e-05, 0.9999747533732616], [6.8084230785115936e-09, 0.9999999931915768], [0.8756845009861444, 0.12431549901385573], [3.030001338090886e-06, 0.9999969699986619], [0.0023964459287059035, 0.9976035540712941], [0.9706816642049674, 0.029318335795032586], [0.8936849125473779, 0.10631508745262211], [0.9137630609960599, 0.08623693900394011], [0.7204302003548122, 0.27956979964518774], [0.6496180852617889, 0.3503819147382112], [1.4021618777404659e-07, 0.9999998597838121], [0.7014406698849037, 0.2985593301150963], [4.112485518206986e-07, 0.9999995887514481], [2.7591810888913813e-06, 0.9999972408189112], [3.838102687594546e-08, 0.9999999616189731], [0.961143287665476, 0.038856712334523986], [1.0078152886210201e-05, 0.9999899218471137], [0.9620116324255263, 0.037988367574473624], [0.9764106480856324, 0.023589351914367625], [1.6455232477064103e-06, 0.9999983544767522], [0.07143050221729162, 0.9285694977827083], [5.087983317579834e-09, 0.9999999949120166], [1.4289639062026624e-07, 0.9999998571036094], [1.257442691996406e-10, 0.9999999998742557], [0.923348712989635, 0.07665128701036503], [0.015495480597434691, 0.9845045194025653], [0.9868015766375198, 0.01319842336248029], [0.001303265445357754, 0.9986967345546424], [0.000672265657040798, 0.9993277343429592], [0.8020256501743888, 0.19797434982561118], [5.259570872788146e-06, 0.9999947404291272], [0.0007470168878508651, 0.999252983112149], [0.9836158768926442, 0.01638412310735586], [0.0003050086569067618, 0.9996949913430933], [0.9683260227347152, 0.03167397726528478], [0.9040085700875946, 0.09599142991240539], [0.9858604599543098, 0.014139540045690175], [0.9590700147307327, 0.04092998526926731], [0.9218135403622401, 0.07818645963775991], [0.829887731403006, 0.17011226859699405], [0.8780785301593864, 0.1219214698406136], [0.0003469276742641116, 0.9996530723257359], [0.000721436366023463, 0.9992785636339766], [0.7964237779267594, 0.20357622207324055], [2.608988059628321e-05, 0.9999739101194036], [0.7523026536029018, 0.24769734639709814], [0.49561150217250033, 0.5043884978274997], [0.6037656074961644, 0.39623439250383563], [0.8983888701474096, 0.10161112985259038], [0.9814008365646967, 0.01859916343530337], [0.9866419109504826, 0.013358089049517326], [0.9841987048349741, 0.015801295165026007], [0.0008257368512485315, 0.9991742631487516], [0.7461527187232696, 0.25384728127673034], [0.9808826308750868, 0.019117369124913186], [0.6781124110432573, 0.32188758895674274], [5.87790000220848e-05, 0.999941220999978], [8.40876979715246e-05, 0.9999159123020285], [5.463325924983791e-10, 0.9999999994536675], [0.8584092195505457, 0.14159078044945428], [0.08095376493265882, 0.9190462350673412], [1.9064743418939654e-06, 0.999998093525658], [3.6666017501399737e-09, 0.9999999963333982], [0.9687237738730259, 0.03127622612697407], [0.9366745954561733, 0.06332540454382662], [0.0005270236976065427, 0.9994729763023935], [2.4987873200130397e-05, 0.9999750121267998], [0.9875815463878885, 0.012418453612111423], [4.768286881001527e-06, 0.999995231713119], [0.8116919000059801, 0.18830809999401987], [0.28383086037099237, 0.7161691396290076], [2.8191527467437775e-05, 0.9999718084725326], [0.16719297455630325, 0.8328070254436968], [0.95354131319984, 0.04645868680015995], [5.523958268098442e-08, 0.9999999447604173], [2.313826812606545e-13, 0.9999999999997686], [3.625314088080053e-09, 0.999999996374686], [0.0010758327008351539, 0.9989241672991649], [0.6341515638891451, 0.3658484361108548], [0.9454197342640379, 0.05458026573596201], [3.884944347817754e-06, 0.9999961150556522], [0.9762986880097436, 0.02370131199025642], [7.4677509470734165e-06, 0.999992532249053], [2.326556382570064e-09, 0.9999999976734436], [0.9491523432735832, 0.05084765672641676], [5.338740697170806e-06, 0.9999946612593028], [0.9129094840578305, 0.08709051594216954], [0.9279249610206105, 0.07207503897938941], [9.36367953590166e-09, 0.9999999906363205], [0.003470266009466119, 0.9965297339905339], [5.298082843155349e-11, 0.9999999999470192], [0.901618153769275, 0.09838184623072499], [3.459939601782756e-05, 0.9999654006039822], [0.9805507516445455, 0.0194492483554544], [0.776607625933967, 0.22339237406603296], [0.0009712689508546707, 0.9990287310491454], [0.9140512606564575, 0.08594873934354252], [0.4418323248555323, 0.5581676751444677], [0.9627146709528388, 0.03728532904716127], [0.9686760584465095, 0.03132394155349052], [9.063353112679741e-08, 0.9999999093664689], [0.05535864202125248, 0.9446413579787475], [0.6139439630857614, 0.3860560369142385], [0.00012623562497998173, 0.99987376437502], [0.9595651001702992, 0.04043489982970085], [0.9852740742421262, 0.014725925757873766], [0.9826289018876427, 0.01737109811235727], [0.9504981181613819, 0.04950188183861817], [2.338376952292257e-05, 0.9999766162304771], [0.9768819324356165, 0.023118067564383477], [0.0041967498343832435, 0.9958032501656169], [0.49643856554418625, 0.5035614344558138], [0.965330151203487, 0.03466984879651302], [0.0002542251496826782, 0.9997457748503173], [1.434920583554109e-05, 0.9999856507941646], [0.0024335051836080076, 0.9975664948163919], [0.052076366679533685, 0.9479236333204664], [0.9830388022801063, 0.016961197719893666], [0.0028072961077197462, 0.9971927038922803], [0.9665517049011545, 0.03344829509884551], [6.194963160219955e-08, 0.9999999380503684], [0.667743718040602, 0.3322562819593981], [0.9821426658979798, 0.017857334102020266], [3.872736921505499e-06, 0.9999961272630784], [0.5817787639642334, 0.4182212360357666], [0.7863594811170805, 0.21364051888291935], [0.5142284601535727, 0.48577153984642746]]}, {"iter": 12, "mu": [43.352689397063195, 67.3814526140513], "sigma": [5.66938472788498, 8.543515030309662], "pi": [0.4705160155166691, 0.5294839844833309], "ll": -860.782, "r": [[0.916856937841905, 0.08314306215809501], [0.002192432850921122, 0.9978075671490789], [9.989135991650319e-05, 0.9999001086400835], [0.8517152775784398, 0.14828472242156018], [0.9869222209765897, 0.013077779023410336], [1.2090155505417187e-07, 0.999999879098445], [0.9651245636067676, 0.03487543639323239], [0.009175703723026205, 0.9908242962769738], [0.980467774558234, 0.01953222544176602], [0.0002666208425451322, 0.999733379157455], [0.9954364869211945, 0.004563513078805525], [1.635103725556588e-06, 0.9999983648962745], [0.735852509484158, 0.264147490515842], [0.9756319669866266, 0.024368033013373522], [0.9638520058053048, 0.03614799419469515], [0.00013163370671527832, 0.9998683662932847], [0.006191510510926348, 0.9938084894890736], [0.8615926778095828, 0.13840732219041724], [0.992133467477781, 0.007866532522218913], [0.9820179602852664, 0.017982039714733587], [0.9208705734679239, 0.07912942653207616], [0.9878983935328142, 0.012101606467185853], [1.8720905052510638e-09, 0.9999999981279095], [0.9913652949224171, 0.008634705077582936], [0.0035356524934381547, 0.9964643475065619], [2.0221493308769918e-07, 0.9999997977850668], [0.000301337089748036, 0.999698662910252], [1.7887085751189552e-06, 0.9999982112914249], [0.9914426573373997, 0.008557342662600232], [0.9778178632799125, 0.022182136720087606], [2.003793666328021e-05, 0.9999799620633367], [1.2049081746457928e-08, 0.9999999879509183], [5.791425017224252e-07, 0.9999994208574982], [0.9322172161726302, 0.06778278382736981], [1.5823632432767923e-05, 0.9999841763675672], [6.5852692488528865e-06, 0.9999934147307512], [0.5858509505310101, 0.4141490494689899], [2.8598643480087666e-06, 0.999997140135652], [0.6518905912946477, 0.34810940870535245], [7.334292723287263e-05, 0.9999266570727672], [0.00015027593446335656, 0.9998497240655366], [1.2033146769820289e-09, 0.9999999987966853], [0.9853076106336159, 0.014692389366384135], [8.13044971925493e-06, 0.9999918695502807], [9.478476789329752e-05, 0.9999052152321067], [9.771508880832511e-05, 0.9999022849111917], [0.995468201663021, 0.004531798336979019], [3.2336695186689585e-06, 0.9999967663304813], [0.7658319444206683, 0.23416805557933174], [0.992449844488755, 0.00755015551124498], [6.243864939681557e-06, 0.9999937561350603], [0.3467859683582811, 0.6532140316417189], [6.049338955110612e-07, 0.9999993950661045], [0.9821570068773041, 0.017842993122695845], [0.9009103241802202, 0.09908967581977979], [0.004957853348048388, 0.9950421466519516], [0.9949720618887429, 0.005027938111257173], [0.9594820430107859, 0.04051795698921418], [0.001555691577847645, 0.9984443084221523], [0.4970392365148983, 0.5029607634851018], [1.010904459535513e-06, 0.9999989890955405], [0.2669652526383239, 0.7330347473616762], [0.6906711630242771, 0.30932883697572294], [0.8349628785696371, 0.16503712143036284], [4.544919007040205e-08, 0.9999999545508099], [0.00015173778103920793, 0.9998482622189608], [0.0006405070280016287, 0.9993594929719983], [0.9703160521179875, 0.02968394788201242], [0.0007291698239066299, 0.9992708301760934], [0.0034411524220388703, 0.9965588475779611], [0.9947580108125554, 0.005241989187444459], [0.8419811451416914, 0.15801885485830855], [0.9803264806159105, 0.01967351938408941], [0.9794318443406571, 0.020568155659342918], [2.7377183030597662e-05, 0.9999726228169694], [0.9960006641129449, 0.003999335887055208], [0.995993502798208, 0.004006497201792003], [0.8836523071788853, 0.1163476928211147], [1.955307567491534e-05, 0.9999804469243252], [1.9265400708246437e-06, 0.9999980734599291], [2.8859506459591885e-09, 0.9999999971140493], [0.9908527037861528, 0.009147296213847226], [0.9791118541679483, 0.020888145832051765], [0.0063992714926302974, 0.9936007285073697], [0.8725517882246477, 0.1274482117753523], [3.3137815763278676e-05, 0.9999668621842367], [0.97850773897374, 0.021492261026260076], [0.6129124924227879, 0.3870875075772122], [0.9954331101583161, 0.00456688984168377], [0.7692216493783618, 0.23077835062163818], [0.00010986125135374657, 0.9998901387486463], [0.9179441511805847, 0.08205584881941531], [0.0015055146342467492, 0.9984944853657534], [3.2824254027298006e-05, 0.9999671757459727], [1.0610615065395168e-08, 0.999999989389385], [0.9180539301056893, 0.08194606989431075], [4.0809254361214e-06, 0.9999959190745639], [0.0030047642283235255, 0.9969952357716765], [0.9848312609751522, 0.015168739024847876], [0.9314837083939109, 0.06851629160608903], [0.9460955199908964, 0.053904480009103646], [0.7915111377238471, 0.20848886227615293], [0.7281218378242225, 0.2718781621757775], [2.0181413342711426e-07, 0.9999997981858666], [0.7748448543173287, 0.22515514568267117], [5.772556247693941e-07, 0.9999994227443753], [3.7227703400404947e-06, 0.99999627722966], [5.706822147691164e-08, 0.9999999429317785], [0.9786911031666965, 0.0213088968333035], [1.3289011061511432e-05, 0.9999867109889384], [0.9792573079701926, 0.020742692029807497], [0.9884313067034571, 0.011568693296542866], [2.2427092363448527e-06, 0.9999977572907636], [0.09041880869104116, 0.9095811913089589], [7.995422300404058e-09, 0.9999999920045777], [2.055778173268105e-07, 0.9999997944221826], [2.2139691591455367e-10, 0.9999999997786031], [0.9529216448476053, 0.047078355152394766], [0.019513328364740297, 0.9804866716352596], [0.9962375051001655, 0.0037624948998344794], [0.0016358488992421806, 0.9983641511007578], [0.0008460319715899723, 0.9991539680284101], [0.8602615194171084, 0.1397384805828917], [7.012653908227532e-06, 0.9999929873460917], [0.0009396209492192341, 0.9990603790507807], [0.9928975423517351, 0.007102457648264914], [0.0003857704061565399, 0.9996142295938434], [0.9833315725494164, 0.01666842745058358], [0.9390476244090586, 0.060952375590941306], [0.9943374777643618, 0.005662522235638332], [0.9773337072510397, 0.022666292748960336], [0.9518353576787479, 0.04816464232125211], [0.8826274871586256, 0.11737251284137439], [0.9198570718914223, 0.08014292810857773], [0.0004383729772190647, 0.999561627022781], [0.0009075956912661683, 0.9990924043087338], [0.8556942475964925, 0.14430575240350751], [3.390473073366386e-05, 0.9999660952692663], [0.8189262356365866, 0.1810737643634134], [0.5787817461575405, 0.4212182538424593], [0.6852882872594883, 0.3147117127405118], [0.9349431707812108, 0.0650568292187892], [0.9915224306538291, 0.008477569346170945], [0.9948814793382895, 0.005118520661710453], [0.9932636460619774, 0.006736353938022569], [0.0010381648208905782, 0.9989618351791094], [0.8136913614874663, 0.18630863851253354], [0.9912021780695409, 0.008797821930459105], [0.7540355627074206, 0.24596443729257944], [7.556991232805147e-05, 0.999924430087672], [0.00010765538766533114, 0.9998923446123346], [9.178439448292184e-10, 0.999999999082156], [0.9048946477524492, 0.09510535224755076], [0.10243889941183205, 0.897561100588168], [2.5907734473254616e-06, 0.9999974092265527], [5.816528168727891e-09, 0.9999999941834717], [0.9835855884940914, 0.016414411505908662], [0.9622325254198338, 0.037767474580166216], [0.0006641290800565603, 0.9993358709199434], [3.249262318902826e-05, 0.999967507376811], [0.9960598182785234, 0.003940181721476538], [6.36875518010483e-06, 0.9999936312448199], [0.8680876184063818, 0.13191238159361815], [0.3483433636448212, 0.6516566363551787], [3.659585146670603e-05, 0.9999634041485332], [0.2096183480037139, 0.7903816519962861], [0.9736776167406809, 0.02632238325931926], [8.136776127246884e-08, 0.9999999186322387], [5.092113625704015e-13, 0.9999999999994907], [5.7529235197674344e-09, 0.9999999942470764], [0.0013511942557283942, 0.9986488057442716], [0.7138293206834626, 0.28617067931653734], [0.9682180798404778, 0.03178192015952232], [5.208255622226498e-06, 0.9999947917443778], [0.9883615697372713, 0.011638430262728672], [9.896357265632968e-06, 0.9999901036427343], [3.740278127993014e-09, 0.9999999962597218], [0.9707397470537005, 0.029260252946299428], [7.116326547473623e-06, 0.9999928836734525], [0.9454827780702693, 0.0545172219297307], [0.9561434934779298, 0.04385650652207026], [1.4462795682184888e-08, 0.9999999855372044], [0.004351074200204344, 0.9956489257997957], [9.598862585199468e-11, 0.9999999999040113], [0.9373055824891408, 0.06269441751085919], [4.478745688446358e-05, 0.9999552125431156], [0.9909971238303188, 0.009002876169681134], [0.8393535223049443, 0.16064647769505574], [0.0012203233108987223, 0.9987796766891013], [0.9463022279829691, 0.05369777201703083], [0.5229858846008026, 0.4770141153991974], [0.9797147061234273, 0.020285293876572685], [0.9835551328760537, 0.016444867123946345], [1.318500820735809e-07, 0.9999998681499179], [0.07007725389001267, 0.9299227461099873], [0.6949166061232268, 0.3050833938767733], [0.0001609152780891309, 0.999839084721911], [0.9776585431860539, 0.022341456813946142], [0.993950896398253, 0.00604910360174703], [0.9922828004490812, 0.007717199550918802], [0.9716437764861245, 0.02835622351387552], [3.0435794405599556e-05, 0.9999695642055944], [0.9887246119502496, 0.011275388049750442], [0.005262865651463194, 0.9947371343485368], [0.5796251764524277, 0.4203748235475723], [0.9814081638181145, 0.018591836181885518], [0.00032199955395231523, 0.9996780004460477], [1.881423921087714e-05, 0.9999811857607891], [0.0030511990091479507, 0.996948800990852], [0.06591614575305334, 0.9340838542469466], [0.9925375223259735, 0.0074624776740264635], [0.003519668047877346, 0.9964803319521226], [0.9821945705668689, 0.01780542943313109], [9.098594761288951e-08, 0.9999999090140523], [0.7446688041749643, 0.2553311958250357], [0.9919813707917953, 0.008018629208204788], [5.1921900898983004e-06, 0.9999948078099101], [0.6642567251280379, 0.3357432748719621], [0.8474307499605701, 0.15256925003942978], [0.5976594088737903, 0.40234059112620973]]}, {"iter": 13, "mu": [43.57614087132805, 68.02733075879216], "sigma": [5.735604753240732, 7.929705299591642], "pi": [0.4888022270654064, 0.5111977729345936], "ll": -858.56, "r": [[0.9511576305104158, 0.048842369489584196], [0.002951126998594552, 0.9970488730014054], [0.00013942273076578745, 0.9998605772692343], [0.9052696886086735, 0.09473031139132645], [0.9944346360252401, 0.005565363974759859], [2.0252348324858289e-07, 0.9999997974765168], [0.9820177592417371, 0.017982240758262928], [0.012305255609915427, 0.9876947443900846], [0.990923627998722, 0.009076372001277954], [0.0003663973066823858, 0.9996336026933176], [0.9987173884699702, 0.001282611530029928], [2.5174636181072572e-06, 0.999997482536382], [0.8146692947492373, 0.1853307052507626], [0.9881883618139466, 0.011811638186053377], [0.9812528133903841, 0.01874718660961596], [0.0001828624730453928, 0.9998171375269546], [0.008305320216435713, 0.9916946797835643], [0.9124835142873164, 0.08751648571268358], [0.9971071813701847, 0.0028928186298153215], [0.9917830938738368, 0.008216906126163246], [0.9538433336439051, 0.04615666635609491], [0.9949481769296541, 0.0050518230703459135], [3.6882941204434197e-09, 0.9999999963117058], [0.9967247518251684, 0.003275248174831531], [0.004749027134478399, 0.9952509728655217], [3.3275378220145654e-07, 0.9999996672462178], [0.0004134066075746149, 0.9995865933924254], [2.7467162942151717e-06, 0.9999972532837058], [0.9967634621879865, 0.0032365378120134476], [0.9894342854624868, 0.010565714537513217], [2.8890749130628884e-05, 0.9999711092508693], [2.1997247237813368e-08, 0.9999999780027528], [9.204964102020798e-07, 0.9999990795035898], [0.9613320865809392, 0.038667913419060895], [2.2939184294861945e-05, 0.9999770608157053], [9.755201915503435e-06, 0.9999902447980845], [0.6820397377590796, 0.3179602622409204], [4.332932779848063e-06, 0.9999956670672201], [0.7425260949639907, 0.25747390503600937], [0.00010294191273351377, 0.9998970580872665], [0.00020830763179843808, 0.9997916923682015], [2.4158954622537466e-09, 0.9999999975841044], [0.9935741185307095, 0.0064258814692904525], [1.1979381097582675e-05, 0.9999880206189024], [0.00013241790253466405, 0.9998675820974653], [0.00013643812545843312, 0.9998635618745415], [0.998733304345084, 0.0012666956549159706], [4.882513987060543e-06, 0.9999951174860129], [0.8391289785342583, 0.1608710214657417], [0.9972634237892832, 0.0027365762107167697], [9.262244748357673e-06, 0.9999907377552516], [0.43505603610984256, 0.5649439638901574], [9.60158537506738e-07, 0.9999990398414624], [0.9918597283677854, 0.008140271632214703], [0.9403111464289188, 0.05968885357108128], [0.006653014482209254, 0.9933469855177907], [0.9984888572790572, 0.0015111427209428309], [0.9786008644958637, 0.021399135504136267], [0.002098492783474072, 0.9979015072165259], [0.5954641963395867, 0.4045358036604132], [1.5790478550389505e-06, 0.999998420952145], [0.34259753492897, 0.65740246507103], [0.7765106143302828, 0.22348938566971716], [0.8928422323695661, 0.10715776763043387], [7.886864481483164e-08, 0.9999999211313552], [0.00021030117942595213, 0.999789698820574], [0.0008707386714406362, 0.9991292613285593], [0.9851010157248908, 0.014898984275109158], [0.0009899441949256136, 0.9990100558050744], [0.004622538190230435, 0.9953774618097696], [0.998385057248745, 0.001614942751254897], [0.8980776767095483, 0.10192232329045176], [0.9908448402673555, 0.00915515973264444], [0.9903443033076703, 0.009655696692329676], [3.919930524952889e-05, 0.9999608006947505], [0.9990188533228491, 0.0009811466771508673], [0.9990145322133666, 0.0009854677866334403], [0.9282774609713279, 0.07172253902867207], [2.820739614888069e-05, 0.999971792603851], [2.951978199834836e-06, 0.9999970480218002], [5.5831970784332386e-09, 0.9999999944168029], [0.9964671710432217, 0.003532828956778393], [0.9901645861494335, 0.009835413850566476], [0.008583659926684428, 0.9914163400733156], [0.9203857285266429, 0.07961427147335706], [4.7253233693913873e-05, 0.9999527467663061], [0.9898243355804728, 0.010175664419527282], [0.7072246115648343, 0.29277538843516576], [0.9987156972890007, 0.0012843027109992959], [0.8418509315397761, 0.15814906846022395], [0.00015308442981003888, 0.99984691557019], [0.9518869587441551, 0.04811304125584497], [0.0020312735394540323, 0.997968726460546], [4.681554418727357e-05, 0.9999531844558127], [1.9468634085815796e-08, 0.9999999805313659], [0.9519605261551439, 0.048039473844856045], [6.1225513304349615e-06, 0.9999938774486695], [0.00403844842369517, 0.9959615515763048], [0.9933177756268188, 0.0066822243731812225], [0.9608528025992852, 0.03914719740071476], [0.9702635659471546, 0.029736434052845467], [0.8595260224017323, 0.14047397759826777], [0.8082502405851728, 0.19174975941482716], [3.3211671649310487e-07, 0.9999996678832834], [0.846346689781407, 0.15365331021859308], [9.175927427226793e-07, 0.9999990824072572], [5.599223437698859e-06, 0.9999944007765623], [9.820498158514675e-08, 0.9999999017950184], [0.9899277413001111, 0.01007225869988886], [1.934457198846625e-05, 0.9999806554280115], [0.9902463219830305, 0.009753678016969327], [0.9952262334641417, 0.004773766535858298], [3.4214003636392953e-06, 0.9999965785996363], [0.120773640515181, 0.8792263594848191], [1.4836535609927276e-08, 0.9999999851634643], [3.3809746035257253e-07, 0.9999996619025396], [4.790916941211828e-10, 0.9999999995209082], [0.9745525624929158, 0.02544743750708425], [0.026183977316918627, 0.9738160226830813], [0.9992127808844053, 0.000787219115594622], [0.002205863269063363, 0.9977941367309366], [0.0011469336135992525, 0.9988530663864007], [0.9115163282127873, 0.08848367178721268], [1.0371478777628713e-05, 0.9999896285212224], [0.0012725737114247478, 0.9987274262885752], [0.9974832741962633, 0.0025167258037368024], [0.0005275329574509832, 0.9994724670425491], [0.9925039240419785, 0.007496075958021455], [0.9657612258237948, 0.03423877417620529], [0.9981819836858439, 0.0018180163141560746], [0.9891596185353946, 0.010840381464605432], [0.9738750396098023, 0.02612496039019779], [0.9275537349212897, 0.0724462650787103], [0.9531669068041768, 0.046833093195823225], [0.0005985193510260018, 0.999401480648974], [0.0012295883083551444, 0.9987704116916448], [0.9081859666580306, 0.0918140333419693], [4.832343009403954e-05, 0.9999516765699059], [0.880725116780209, 0.11927488321979106], [0.6753692411595872, 0.3246307588404128], [0.7718613083195989, 0.22813869168040113], [0.9631071542160559, 0.036892845783944084], [0.9968033332029839, 0.0031966667970162025], [0.9984448670726115, 0.0015551329273885781], [0.9976620136698153, 0.0023379863301845874], [0.001404800016503085, 0.9985951999834969], [0.8767239597081925, 0.12327604029180758], [0.9966429895075862, 0.003357010492413751], [0.8295870606261527, 0.17041293937384736], [0.00010600873552014007, 0.9998939912644799], [0.0001500632802897915, 0.9998499367197101], [1.864467007826586e-09, 0.999999998135533], [0.9430466557868209, 0.05695334421317917], [0.1365692323585967, 0.8634307676414033], [3.936184677221824e-06, 0.9999960638153227], [1.0932734891909366e-08, 0.9999999890672652], [0.992642475614712, 0.007357524385288002], [0.9802744569269826, 0.019725543073017344], [0.0009025076489870663, 0.9990974923510129], [4.635255058079435e-05, 0.9999536474494193], [0.9990557856877612, 0.0009442143122387779], [9.442645797731203e-06, 0.9999905573542023], [0.9171798775143856, 0.08282012248561443], [0.4368098483579213, 0.5631901516420786], [5.2075413853415336e-05, 0.9999479245861466], [0.27308038821697667, 0.7269196117830233], [0.9870623032663642, 0.012937696733635764], [1.382312011952679e-07, 0.9999998617687988], [1.485426687501822e-12, 0.9999999999985145], [1.0818012974234911e-08, 0.999999989181987], [0.0018244973004328793, 0.9981755026995671], [0.7962628010090633, 0.2037371989909366], [0.9838625340363883, 0.01613746596361161], [7.762898007641102e-06, 0.9999922371019924], [0.995189942456501, 0.0048100575434988704], [1.4509694858841955e-05, 0.9999854903051412], [7.158511410499595e-09, 0.9999999928414885], [0.9853498276742436, 0.014650172325756437], [1.052083982903397e-05, 0.9999894791601709], [0.9698750163290807, 0.030124983670919373], [0.9765502642059427, 0.023449735794057243], [2.621536420651472e-08, 0.9999999737846357], [0.005840585013958087, 0.9941594149860419], [2.1585672761288184e-10, 0.9999999997841433], [0.9646375510025895, 0.035362448997410575], [6.346783276827713e-05, 0.9999365321672317], [0.9965399338115303, 0.003460066188469761], [0.8961224080102664, 0.10387759198973352], [0.0016490812812185868, 0.9983509187187813], [0.9703945150539288, 0.029605484946071226], [0.6213828526703263, 0.3786171473296737], [0.9905028694265411, 0.009497130573458933], [0.9926258784980568, 0.007374121501943179], [2.20193369804646e-07, 0.9999997798066302], [0.09385475758730481, 0.9061452424126952], [0.7801620475281689, 0.21983795247183105], [0.00022281135790147165, 0.9997771886420985], [0.9893439850188639, 0.010656014981136195], [0.9979953427195216, 0.0020046572804783666], [0.9971810210201979, 0.002818978979802081], [0.9858791948993995, 0.014120805100600448], [4.3479038590277344e-05, 0.9999565209614097], [0.9953785480624909, 0.0046214519375091054], [0.00706146552374829, 0.9929385344762518], [0.6761670968045488, 0.32383290319545116], [0.99144610657466, 0.008553893425339859], [0.00044136011954894276, 0.999558639880451], [2.7165448130933676e-05, 0.999972834551869], [0.0041005988636522795, 0.9958994011363477], [0.08832150505240696, 0.9116784949475931], [0.99730659351673, 0.002693406483270006], [0.004727631711612085, 0.9952723682883879], [0.9918804180198136, 0.008119581980186303], [1.5395387214340796e-07, 0.9999998460461279], [0.8219340387572898, 0.17806596124271024], [0.9970318060508995, 0.0029681939491004753], [7.739586267254122e-06, 0.9999922604137327], [0.75348614777981, 0.24651385222018993], [0.9021141097046448, 0.09788589029535526], [0.6930975647419935, 0.3069024352580065]]}, {"iter": 14, "mu": [43.79062542957949, 68.58932594512733], "sigma": [5.811329207836459, 7.361016473548903], "pi": [0.5046147982585258, 0.4953852017414742], "ll": -856.629, "r": [[0.974905764472225, 0.025094235527774993], [0.004090539787471033, 0.9959094602125289], [0.0002003469934070874, 0.9997996530065929], [0.9464237320695675, 0.05357626793043251], [0.9980682231884637, 0.0019317768115362554], [3.579943130603285e-07, 0.9999996420056869], [0.9920923438984871, 0.007907656101512861], [0.01703990034291669, 0.9829600996570833], [0.9964867005471193, 0.00351329945288076], [0.0005179300831162191, 0.9994820699168837], [0.9997346127465662, 0.0002653872534338434], [4.037705181072011e-06, 0.9999959622948189], [0.8835885350771666, 0.11641146492283333], [0.9951838723630893, 0.004816127636910889], [0.9916974542395471, 0.00830254576045292], [0.0002614455613468918, 0.9997385544386531], [0.01149419006400251, 0.9885058099359976], [0.9510744951709705, 0.04892550482902957], [0.9991628525373347, 0.0008371474626652102], [0.9968847036422849, 0.0031152963577151223], [0.9764806539355151, 0.023519346064484924], [0.9982879097456943, 0.0017120902543057395], [7.880642285189655e-09, 0.9999999921193578], [0.9990148387967538, 0.0009851612032461918], [0.006573801820962739, 0.9934261981790373], [5.761827453613732e-07, 0.9999994238172547], [0.0005833661610822801, 0.9994166338389178], [4.392154313662048e-06, 0.9999956078456864], [0.9990299831933006, 0.0009700168066994226], [0.9957835909843721, 0.004216409015627805], [4.3020947732925915e-05, 0.999956979052267], [4.298500272568207e-08, 0.9999999570149972], [1.531279194943507e-06, 0.9999984687208051], [0.9808045413921402, 0.019195458607859706], [3.436676288279568e-05, 0.9999656332371172], [1.4974495744904804e-05, 0.999985025504255], [0.7786400187965716, 0.22135998120342837], [6.823160506657404e-06, 0.9999931768394933], [0.8283303631110253, 0.17166963688897474], [0.0001488210575846162, 0.9998511789424154], [0.00029713984027144853, 0.9997028601597285], [5.277806960121141e-09, 0.9999999947221931], [0.997692467381073, 0.0023075326189270972], [1.8277070574884358e-05, 0.9999817229294251], [0.00019047108819559988, 0.9998095289118044], [0.00019614000113337999, 0.9998038599988667], [0.999739703087318, 0.00026029691268199755], [7.658661719477258e-06, 0.9999923413382805], [0.9013059343460603, 0.09869406565393972], [0.9992222365331691, 0.0007777634668308006], [1.4240008074472624e-05, 0.9999857599919254], [0.5436649065810256, 0.45633509341897444], [1.5947131566767487e-06, 0.9999984052868434], [0.9969198895410891, 0.0030801104589107745], [0.968428601094806, 0.03157139890519395], [0.009206728599686822, 0.9907932714003131], [0.9996600326291444, 0.00033996737085554803], [0.9903118912006738, 0.00968810879932622], [0.002913564060139268, 0.9970864359398608], [0.7022100284487022, 0.29778997155129794], [2.574820258899244e-06, 0.9999974251797412], [0.4418949760395995, 0.5581050239604005], [0.8549102053843034, 0.14508979461569654], [0.9382785344608385, 0.061721465539161406], [1.452554723738073e-07, 0.9999998547445277], [0.00029993391470844587, 0.9997000660852916], [0.0012175579536712765, 0.9987824420463287], [0.9936597001908665, 0.006340299809133522], [0.0013824636532111586, 0.9986175363467887], [0.00639900470597468, 0.9936009952940252], [0.9996252844958431, 0.000374715504157032], [0.9417300184549257, 0.05826998154507439], [0.9964499165753024, 0.003550083424697497], [0.9962151203905533, 0.003784879609446695], [5.792273464532976e-05, 0.9999420772653548], [0.999828672695436, 0.00017132730456411385], [0.999827357786427, 0.0001726422135730335], [0.9610448262980985, 0.038955173701901546], [4.202946268042415e-05, 0.9999579705373196], [4.708730788857946e-06, 0.9999952912692112], [1.1677126893227859e-08, 0.9999999883228732], [0.9989132005449809, 0.0010867994550191338], [0.9961303627612429, 0.0038696372387571013], [0.011879741110342942, 0.988120258889657], [0.9561005576821489, 0.04389944231785113], [6.950744395350045e-05, 0.9999304925560465], [0.9959692609902104, 0.004030739009789581], [0.7996992567360197, 0.2003007432639803], [0.9997340710433966, 0.0002659289566034072], [0.9032446056060573, 0.09675539439394257], [0.00021958776509446956, 0.9997804122349055], [0.9753346394098443, 0.024665360590155606], [0.0028207747135890865, 0.997179225286411], [6.887895330087024e-05, 0.9999311210466992], [3.826791105286917e-08, 0.9999999617320889], [0.9753778509240187, 0.024622149075981238], [9.534316539523612e-06, 0.9999904656834604], [0.0055920292939150695, 0.9944079707060849], [0.9975788567942548, 0.0024211432057451143], [0.9805309627971878, 0.019469037202812223], [0.9858141129301146, 0.014185887069885375], [0.9156687328525579, 0.08433126714744218], [0.878851845621053, 0.12114815437894692], [5.751246715844215e-07, 0.9999994248753283], [0.9064319411823865, 0.09356805881761354], [1.526631515546132e-06, 0.9999984733684845], [8.744202484039862e-06, 0.999991255797516], [1.7911219392258766e-07, 0.9999998208878061], [0.9960183079893195, 0.003981692010680534], [2.911573947055715e-05, 0.9999708842605295], [0.9961689398749505, 0.003831060125049501], [0.99840527574889, 0.0015947242511100055], [5.43026111092532e-06, 0.999994569738889], [0.16599476861624696, 0.834005231383753], [2.9550323507262443e-08, 0.9999999704496765], [5.850548128777421e-07, 0.9999994149451872], [1.143231970045539e-09, 0.999999998856768], [0.9881525054414909, 0.011847494558509118], [0.036328557331782974, 0.9636714426682169], [0.999887294240413, 0.00011270575958707961], [0.0030617750777079218, 0.9969382249222921], [0.0015995055047642944, 0.9984004944952357], [0.9504543533508919, 0.049545646649108106], [1.5891360628196746e-05, 0.9999841086393718], [0.0017731247197785979, 0.9982268752802214], [0.9993046239985556, 0.000695376001444541], [0.0007419653818284312, 0.9992580346181715], [0.9972135728240709, 0.0027864271759292614], [0.983310626517932, 0.016689373482068153], [0.9995558610752265, 0.000444138924773482], [0.9956522321424561, 0.004347767857543928], [0.9877863866226918, 0.01221361337730819], [0.9605946455690386, 0.03940535443096146], [0.9760851484195144, 0.02391485158048556], [0.000840470200323456, 0.9991595297996766], [0.001713730986257521, 0.9982862690137425], [0.9483108788677344, 0.05168912113226572], [7.10436893161089e-05, 0.9999289563106839], [0.9301819748572241, 0.06981802514277585], [0.7729739253162853, 0.22702607468371472], [0.8513312256199712, 0.14866877438002882], [0.9818137735267503, 0.018186226473249727], [0.9990455447864467, 0.0009544552135533661], [0.9996453701454905, 0.0003546298545094436], [0.9993705179106639, 0.0006294820893360297], [0.00195578713796557, 0.9980442128620344], [0.9274760725851343, 0.07252392741486567], [0.998982737533199, 0.00101726246680108], [0.8944573066771497, 0.10554269332285025], [0.00015316241748738538, 0.9998468375825126], [0.00021533506239218895, 0.9997846649376079], [4.1296582897472624e-09, 0.9999999958703417], [0.970078980163825, 0.02992101983617497], [0.18706711656450004, 0.8129328834355], [6.218089170273921e-06, 0.9999937819108297], [2.21048424272822e-08, 0.9999999778951575], [0.997276229292549, 0.0027237707074509346], [0.991189196428646, 0.008810803571353965], [0.0012615164653984171, 0.9987384835346016], [6.82140016533512e-05, 0.9999317859983468], [0.9998398797005644, 0.00016012029943558769], [1.4508915679653806e-05, 0.9999854910843203], [0.9540703784898846, 0.04592962151011544], [0.5455206447834574, 0.45447935521654265], [7.642444336459828e-05, 0.9999235755566354], [0.36022361708205475, 0.6397763829179453], [0.994633843449636, 0.005366156550364036], [2.483717542366724e-07, 0.9999997516282458], [5.0493173009155296e-12, 0.9999999999949506], [2.1884334321029348e-08, 0.9999999781156657], [0.0025353249790362005, 0.9974646750209637], [0.869910810710256, 0.130089189289744], [0.9930350478289968, 0.006964952171003184], [1.199937281611422e-05, 0.9999880006271838], [0.9983900240776821, 0.0016099759223179152], [2.2015310910037883e-05, 0.9999779846890899], [1.4783920774284132e-08, 0.9999999852160792], [0.9937843393673041, 0.006215660632695761], [1.611335508034054e-05, 0.9999838866449197], [0.9855999435842686, 0.014400056415731444], [0.9892243420557949, 0.01077565794420509], [5.080042856735105e-08, 0.9999999491995714], [0.008082856705034848, 0.9919171432949652], [5.390072277695334e-10, 0.9999999994609928], [0.9826787136222974, 0.017321286377702527], [9.27191951264521e-05, 0.9999072808048736], [0.9989420609951852, 0.001057939004814733], [0.9404443733152406, 0.05955562668475951], [0.0022931362665739156, 0.9977068637334261], [0.9858862088336905, 0.014113791166309569], [0.7257506689957306, 0.2742493310042695], [0.9962897059705272, 0.0037102940294726876], [0.9972687334860479, 0.0027312665139520792], [3.878591609879495e-07, 0.999999612140839], [0.12964329344364575, 0.8703567065563542], [0.8577082232594584, 0.14229177674054164], [0.00031746022459137614, 0.9996825397754086], [0.9957404600267552, 0.00425953997324475], [0.9994905081705481, 0.0005094918294519374], [0.9991910001973483, 0.00080899980265174], [0.9940485250461467, 0.005951474953853319], [6.408406145706599e-05, 0.9999359159385429], [0.9984690625766794, 0.0015309374233205358], [0.00977197822404364, 0.9902280217759565], [0.7736535936144961, 0.2263464063855038], [0.9967293798607828, 0.0032706201392170967], [0.0006222438716752311, 0.9993777561283248], [4.0516668351613456e-05, 0.9999594833316484], [0.0056778816280183605, 0.9943221183719817], [0.12210687060666842, 0.8778931293933315], [0.9992385250337016, 0.0007614749662983325], [0.006544234108997632, 0.9934557658910025], [0.9969293801463507, 0.0030706198536492937], [2.7533919923928674e-07, 0.9999997246608009], [0.8889059215839467, 0.11109407841605339], [0.9991339704063024, 0.0008660295936976353], [1.196444882571673e-05, 0.9999880355511743], [0.8370081913843552, 0.16299180861564475], [0.9443711975310041, 0.05562880246899597], [0.7879513241753814, 0.21204867582461873]]}, {"iter": 15, "mu": [43.977417838560285, 69.02839651553954], "sigma": [5.89253077911242, 6.89449409480272], "pi": [0.5170601115094194, 0.4829398884905806], "ll": -855.289, "r": [[0.9884761595973317, 0.011523840402668304], [0.005702439768422557, 0.9942975602315774], [0.00028793297333480617, 0.9997120670266652], [0.972663556532853, 0.02733644346714705], [0.9994369217233148, 0.0005630782766851421], [6.388243822389895e-07, 0.9999993611756177], [0.9969600938166453, 0.0030399061833545978], [0.023836467398171815, 0.9761635326018282], [0.9988361778264034, 0.0011638221735965396], [0.0007329580343849758, 0.999267041965615], [0.9999578852237848, 4.2114776215150576e-05], [6.495122993055384e-06, 0.9999935048770069], [0.9336684952780253, 0.06633150472197476], [0.9983045090017224, 0.0016954909982775], [0.9967820122618269, 0.0032179877381730143], [0.0003739268158465286, 0.9996260731841535], [0.016050438495578124, 0.9839495615044218], [0.9753464088709823, 0.024653591129017768], [0.9998029636426745, 0.00019703635732547998], [0.9989928180849205, 0.00100718191507954], [0.9892988331288103, 0.010701166871189712], [0.9995147855062194, 0.0004852144937805387], [1.72760162545545e-08, 0.9999999827239837], [0.9997573458917438, 0.00024265410825612973], [0.009165305290106071, 0.9908346947098939], [1.0056292994739203e-06, 0.9999989943707005], [0.0008242708929977921, 0.9991757291070023], [7.042887560222735e-06, 0.9999929571124397], [0.9997620861579071, 0.00023791384209288167], [0.9985525074311047, 0.001447492568895255], [6.406164170420718e-05, 0.9999359383582958], [8.549149540331057e-08, 0.9999999145085046], [2.560516902028284e-06, 0.999997439483098], [0.9915194411032228, 0.00848055889677728], [5.149310772718264e-05, 0.9999485068922728], [2.300610932939616e-05, 0.9999769938906705], [0.8596356693886995, 0.14036433061130052], [1.076594326506639e-05, 0.9999892340567349], [0.8959470505351818, 0.10405294946481836], [0.00021514148713422718, 0.9997848585128658], [0.0004240496876081583, 0.9995759503123918], [1.1854323992611182e-08, 0.999999988145676], [0.999300014584451, 0.0006999854155489622], [2.7903428620498073e-05, 0.9999720965713794], [0.0002740037333305399, 0.9997259962666695], [0.00028200047259062454, 0.9997179995274094], [0.9999590252616124, 4.097473838758902e-05], [1.2034909729019105e-05, 0.999987965090271], [0.945124250032892, 0.05487574996710796], [0.9998207860779855, 0.0001792139220144075], [2.1913175649912738e-05, 0.9999780868243501], [0.658721678144074, 0.3412783218559261], [2.6620629385758273e-06, 0.9999973379370615], [0.9990065131755134, 0.0009934868244867669], [0.9850252731910539, 0.014974726808946027], [0.012846198570871641, 0.9871538014291285], [0.9999404796438871, 5.95203561128255e-05], [0.9961480374750704, 0.003851962524929705], [0.004064510520676695, 0.9959354894793232], [0.7995701114515513, 0.20042988854844862], [4.2149824610275295e-06, 0.9999957850175389], [0.556352047542899, 0.4436479524571009], [0.9144540808792162, 0.08554591912078388], [0.967886561963137, 0.03211343803686296], [2.709328030417368e-07, 0.9999997290671969], [0.0004279702570729984, 0.999572029742927], [0.0017070052843827638, 0.9982929947156172], [0.997653822841225, 0.0023461771587750375], [0.0019362390689957334, 0.9980637609310042], [0.008921254330498948, 0.991078745669501], [0.9999319726420471, 6.802735795287276e-05], [0.9699225272245859, 0.030077472775414053], [0.9988215481571114, 0.0011784518428884913], [0.9987275952291531, 0.0012724047708468455], [8.557960226197529e-05, 0.999914420397738], [0.9999777189711196, 2.2281028880405245e-05], [0.9999774622267048, 2.253777329521876e-05], [0.9809765842239331, 0.019023415776066987], [6.262480408199612e-05, 0.999937375195918], [7.530881282525915e-06, 0.9999924691187175], [2.5007966803624167e-08, 0.9999999749920331], [0.9997251396693536, 0.00027486033064642206], [0.9986934454792866, 0.0013065545207134803], [0.016591002224480685, 0.9834089977755193], [0.9782063042634485, 0.02179369573655155], [0.00010222725822306139, 0.9998977727417769], [0.9986282078031663, 0.0013717921968336936], [0.8752923772064984, 0.1247076227935015], [0.9999577635107177, 4.22364892822448e-05], [0.9463574674500705, 0.05364253254992953], [0.0003150450485371485, 0.9996849549514628], [0.9887008742619587, 0.01129912573804127], [0.003935468873981812, 0.9960645311260181], [0.00010132558247558228, 0.9998986744175243], [7.659719094899832e-08, 0.9999999234028091], [0.9887234874943637, 0.011276512505636356], [1.4868977903103215e-05, 0.999985131022097], [0.007795127498564289, 0.9922048725014357], [0.9992577969862662, 0.0007422030137338286], [0.991380723663773, 0.008619276336226932], [0.994010034889978, 0.00598996511002198], [0.9541610261944298, 0.04583897380557015], [0.9305508769153799, 0.06944912308462019], [1.0038669327108465e-06, 0.9999989961330673], [0.9483759960634558, 0.051624003936544254], [2.5530706672220964e-06, 0.9999974469293329], [1.3677388341283382e-05, 0.9999863226116588], [3.305808821927504e-07, 0.9999996694191178], [0.9986481139796345, 0.0013518860203654962], [4.383238565758194e-05, 0.9999561676143425], [0.9987090036251588, 0.0012909963748411175], [0.9995556337667293, 0.0004443662332706841], [8.639201395615437e-06, 0.9999913607986044], [0.2288134323989893, 0.7711865676010107], [6.000298355666049e-08, 0.9999999399970165], [1.0204016514422572e-06, 0.9999989795983486], [2.828757217875373e-09, 0.9999999971712429], [0.9951352710005797, 0.004864728999420396], [0.050995167297231817, 0.9490048327027683], [0.999988385305413, 1.1614694587045198e-05], [0.004270651869097409, 0.9957293481309025], [0.0022378893761494396, 0.9977621106238506], [0.9749906463851199, 0.02500935361488012], [2.4368378266355208e-05, 0.9999756316217336], [0.0024791710408130726, 0.9975208289591869], [0.9998449997160487, 0.00015500028395138045], [0.0010453239900393226, 0.9989546760099607], [0.9991197717388065, 0.0008802282611936241], [0.9927777038203357, 0.007222296179664376], [0.9999143377203197, 8.56622796803567e-05], [0.9984986311027787, 0.0015013688972213052], [0.9949609191828399, 0.005039080817160097], [0.9807262124821099, 0.019273787517890013], [0.9890928879074647, 0.010907112092535228], [0.0011824829144678444, 0.9988175170855321], [0.002396631091929736, 0.9976033689080702], [0.9737562619402671, 0.026243738059732846], [0.00010443060180375154, 0.9998955693981962], [0.9630464103804972, 0.036953589619502895], [0.8553567571534199, 0.14464324284658014], [0.9120004471433023, 0.08799955285669771], [0.9920289151698373, 0.00797108483016261], [0.9997669404615941, 0.00023305953840590412], [0.9999369181059923, 6.308189400764264e-05], [0.9998638936990176, 0.00013610630098240107], [0.0027330218685626905, 0.9972669781314373], [0.961409599726443, 0.03859040027355699], [0.9997472466603604, 0.0002527533396395121], [0.9407352281027629, 0.05926477189723708], [0.00022128707651055464, 0.9997787129234895], [0.0003090553335729307, 0.999690944666427], [9.416455373711597e-09, 0.9999999905835446], [0.985914199161536, 0.014085800838463914], [0.25642574582239697, 0.743574254177603], [9.84396477395645e-06, 0.999990156035226], [4.562533628893764e-08, 0.9999999543746637], [0.9991436811670271, 0.0008563188329729554], [0.9965510492818143, 0.0034489507181857063], [0.001768116988555287, 0.9982318830114446], [0.00010037142373958313, 0.9998996285762605], [0.9999798791067441, 2.0120893255841443e-05], [2.2313491608245338e-05, 0.9999776865083917], [0.9770562224915635, 0.02294377750843643], [0.6604997259201865, 0.3395002740798135], [0.00011214084242700643, 0.9998878591575731], [0.4671177860308088, 0.5328822139691912], [0.9980728195332654, 0.0019271804667344691], [4.5107375141112033e-07, 0.9999995489262486], [1.8466267570836118e-11, 0.9999999999815338], [4.519595034089066e-08, 0.9999999548040497], [0.0035385667681978113, 0.9964614332318021], [0.9246049031268013, 0.0753950968731986], [0.9973800075391592, 0.0026199924608407746], [1.856899520091971e-05, 0.9999814310047991], [0.9995503570224555, 0.0004496429775444344], [3.341877701097833e-05, 0.999966581222989], [3.122810332586994e-08, 0.9999999687718967], [0.997707999678536, 0.0022920003214640288], [2.469789033272425e-05, 0.9999753021096672], [0.993905666130166, 0.006094333869834087], [0.995641438691215, 0.00435856130878501], [1.0012039744293857e-07, 0.9999998998796026], [0.011273947886520837, 0.9887260521134792], [1.4019385986652537e-09, 0.9999999985980614], [0.9924626238525306, 0.00753737614746943], [0.00013543129412398218, 0.999864568705876], [0.9997343522359466, 0.000265647764053272], [0.9691661239287469, 0.030833876071253204], [0.0032018925506288294, 0.9967981074493711], [0.9940451217018537, 0.005954878298146342], [0.8186094420572761, 0.18139055794272388], [0.9987575452746285, 0.001242454725371522], [0.999140825705475, 0.0008591742945250595], [6.89498117713744e-07, 0.9999993105018823], [0.18023984467761164, 0.8197601553223884], [0.9163638612176443, 0.08363613878235565], [0.00045255387404781163, 0.9995474461259523], [0.9985348460803073, 0.0014651539196928044], [0.9998970579583023, 0.00010294204169771488], [0.999811448071172, 0.00018855192882807206], [0.9978223010612872, 0.0021776989387128115], [9.444111263816586e-05, 0.9999055588873619], [0.999577596728053, 0.00042240327194698773], [0.013637497359324648, 0.9863625026406754], [0.8558715078775139, 0.14412849212248605], [0.9989320584430619, 0.001067941556938118], [0.0008784888428205366, 0.9991215111571795], [6.0431049082496745e-05, 0.9999395689509175], [0.007914888221162469, 0.9920851117788375], [0.170027316544501, 0.829972683455499], [0.9998256221029159, 0.0001743778970840544], [0.009124019973641137, 0.9908759800263589], [0.9990102026608587, 0.000989797339141186], [4.975516495177626e-07, 0.9999995024483506], [0.937141089684635, 0.06285891031536489], [0.9997941915377516, 0.00020580846224827027], [1.851673924926556e-05, 0.9999814832607506], [0.9020610689693543, 0.09793893103064576], [0.9714689371943281, 0.02853106280567185], [0.8666063442551463, 0.13339365574485385]]}, {"iter": 16, "mu": [44.124529916547374, 69.33061807072274], "sigma": [5.971577954418706, 6.56757630059202], "pi": [0.5258683260268803, 0.4741316739731197], "ll": -854.582, "r": [[0.994790022067583, 0.005209977932416964], [0.007805558617443049, 0.992194441382557], [0.00040473112961483365, 0.9995952688703851], [0.9863027250313443, 0.01369727496865566], [0.999839721450214, 0.00016027854978599852], [1.1088099898251986e-06, 0.9999988911900102], [0.9988511346551869, 0.0011488653448131023], [0.032768063990138804, 0.9672319360098612], [0.9996222468862713, 0.0003777531137286846], [0.0010157154567202844, 0.9989842845432797], [0.9999935811481605, 6.418851839519383e-06], [1.0179387232692448e-05, 0.9999898206127673], [0.9631529479457873, 0.03684705205421265], [0.9994142896955586, 0.0005857103044415618], [0.9987736377662753, 0.0012263622337247448], [0.0005232387109603987, 0.9994767612890396], [0.02202611616006985, 0.9779738838399302], [0.9877941926816783, 0.012205807318321655], [0.9999549768623454, 4.5023137654683116e-05], [0.9996811409568175, 0.0003188590431826503], [0.995206211936524, 0.004793788063475944], [0.9998658146693555, 0.00013418533064454835], [3.6779267606938385e-08, 0.9999999632207324], [0.9999419023796307, 5.809762036935192e-05], [0.012553379725142989, 0.9874466202748571], [1.7076840921365808e-06, 0.9999982923159079], [0.0011406467518291464, 0.9988593532481709], [1.1003589460586116e-05, 0.9999889964105395], [0.9999432847722678, 5.671522773208022e-05], [0.9995126720783495, 0.0004873279216504536], [9.313926662061873e-05, 0.9999068607333793], [1.6521720007349011e-07, 0.9999998347828], [4.168404195139898e-06, 0.9999958315958049], [0.9963109051879593, 0.0036890948120407523], [7.531410802684403e-05, 0.9999246858919733], [3.447482967646938e-05, 0.9999655251703234], [0.9141512611961344, 0.08584873880386566], [1.655715505956193e-05, 0.9999834428449405], [0.9388804503678302, 0.061119549632169694], [0.00030408619738266595, 0.9996959138026174], [0.0005921743686415057, 0.9994078256313584], [2.5854225999004995e-08, 0.999999974145774], [0.9997924181833233, 0.00020758181667663973], [4.155825132046352e-05, 0.9999584417486795], [0.0003854997254013932, 0.9996145002745985], [0.0003965418338372891, 0.9996034581661627], [0.9999938064793008, 6.193520699141385e-06], [1.8434968539472968e-05, 0.9999815650314606], [0.9701930642418168, 0.029806935758183203], [0.9999599330598017, 4.006694019833096e-05], [3.288882035395528e-05, 0.999967111179646], [0.7568066309634985, 0.24319336903650143], [4.32648585031569e-06, 0.9999956735141496], [0.9996862279526872, 0.0003137720473127583], [0.9930101158114499, 0.006989884188550021], [0.01761332668451128, 0.9823866733154888], [0.9999899650773895, 1.003492261064198e-05], [0.9984934884178043, 0.001506511582195819], [0.00556510355587636, 0.9944348964441236], [0.8706448600442624, 0.12935513995573755], [6.7201078436276455e-06, 0.9999932798921564], [0.6637736885913212, 0.33622631140867876], [0.9509842096400526, 0.04901579035994746], [0.9836068538691913, 0.016393146130808584], [4.913070870592097e-07, 0.9999995086929129], [0.0005975629682865823, 0.9994024370317134], [0.0023461645149651525, 0.9976538354850348], [0.9991471334266188, 0.0008528665733812242], [0.0026589912019862154, 0.9973410087980138], [0.01221833017694391, 0.987781669823056], [0.9999880954319539, 1.1904568046127687e-05], [0.9847618225581534, 0.015238177441846681], [0.9996166833592557, 0.00038331664074429006], [0.9995807164782611, 0.000419283521739006], [0.00012349351848163674, 0.9998765064815184], [0.9999972317059453, 2.768294054688852e-06], [0.9999971888309249, 2.8111690751056297e-06], [0.9908633303072494, 0.009136669692750574], [9.110560530163496e-05, 0.9999088943946984], [1.1736062051875537e-05, 0.9999882639379482], [5.201732810263837e-08, 0.9999999479826719], [0.9999323789170336, 6.762108296642412e-05], [0.9995675453942775, 0.0004324546057225745], [0.022771143752556518, 0.9772288562474436], [0.9893641895298733, 0.010635810470126732], [0.0001468724415361239, 0.9998531275584639], [0.9995422461502083, 0.0004577538497916716], [0.9249666885942631, 0.07503331140573691], [0.9999935569976276, 6.443002372387597e-06], [0.9709404324324573, 0.029059567567542757], [0.00044213217047655814, 0.9995578678295234], [0.994904046014208, 0.005095953985792059], [0.005388748047455533, 0.9946112519525445], [0.00014560811757062541, 0.9998543918824294], [1.4896950334921515e-07, 0.9999998510304967], [0.9949155063798921, 0.005084493620107935], [2.2608120910120587e-05, 0.9999773918790898], [0.010673120762898166, 0.9893268792371018], [0.9997775127670913, 0.0002224872329087393], [0.9962427754251998, 0.003757224574800211], [0.9975102049319141, 0.002489795068085905], [0.9756185081193298, 0.02438149188067014], [0.9612080337642283, 0.03879196623577172], [1.704832665634421e-06, 0.9999982951673343], [0.9721590795257575, 0.027840920474242376], [4.156802982363615e-06, 0.9999958431970176], [2.085668303169493e-05, 0.9999791433169684], [5.932508679880456e-07, 0.9999994067491321], [0.999549984606822, 0.00045001539317792214], [6.440312513828735e-05, 0.9999355968748617], [0.9995735522384231, 0.00042644776157678866], [0.9998792296282601, 0.0001207703717398203], [1.339403269189472e-05, 0.9999866059673082], [0.3045897381120064, 0.6954102618879937], [1.1837148243819854e-07, 0.9999998816285176], [1.7315767296204093e-06, 0.9999982684232703], [6.794461514010238e-09, 0.9999999932055385], [0.9980342208370172, 0.0019657791629827414], [0.07025271999014684, 0.9297472800098532], [0.9999988634106677, 1.136589332249363e-06], [0.005846874713419058, 0.994153125286581], [0.003070643178652403, 0.9969293568213476], [0.9875974166747713, 0.012402583325228733], [3.644886687337974e-05, 0.9999635511331266], [0.0033999425644032077, 0.9966000574355968], [0.9999665082691781, 3.349173082178771e-05], [0.0014428078337865133, 0.9985571921662134], [0.9997278768686484, 0.0002721231313515014], [0.9969228125185492, 0.00307718748145082], [0.999984047617133, 1.5952382867079463e-05], [0.9994914882994231, 0.000508511700576876], [0.9979538978366148, 0.0020461021633850617], [0.9907287830534883, 0.009271216946511694], [0.9951023503348709, 0.00489764966512901], [0.0016301583873419483, 0.9983698416126581], [0.0032872882898636563, 0.9967127117101363], [0.9869122633472971, 0.01308773665270292], [0.00014996110209225297, 0.9998500388979078], [0.9808281364348698, 0.019171863565130218], [0.9111565011959354, 0.0888434988040647], [0.9494002670866822, 0.050599732913317784], [0.9965600214557825, 0.0034399785442174625], [0.9999446949960114, 5.530500398862584e-05], [0.9999891896030441, 1.0810396955961091e-05], [0.9999714963248386, 2.8503675161462607e-05], [0.0037464451693402165, 0.9962535548306598], [0.9798785780961063, 0.020121421903893696], [0.9999389401631988, 6.105983680115068e-05], [0.967516216377698, 0.03248378362230194], [0.00031259883070730235, 0.9996874011692927], [0.000433872714537091, 0.9995661272854629], [2.0848095857786206e-08, 0.9999999791519042], [0.9934734538778833, 0.00652654612211661], [0.3386120751718839, 0.661387924828116], [1.5188558513836722e-05, 0.9999848114414861], [9.148351478994519e-08, 0.9999999085164852], [0.9997365678852258, 0.0002634321147742121], [0.9986723156372668, 0.001327684362733269], [0.002429563119598678, 0.9975704368804013], [0.00014426997736117044, 0.9998557300226388], [0.9999975866282867, 2.413371713326957e-06], [3.346998062437476e-05, 0.9999665300193757], [0.9887354236207105, 0.011264576379289471], [0.7583453852301478, 0.2416546147698523], [0.00016076025471062697, 0.9998392397452894], [0.5754027603224803, 0.4245972396775197], [0.9993205320832843, 0.0006794679167156727], [7.966643900630765e-07, 0.99999920333561], [6.55587868198522e-11, 0.9999999999344412], [9.06738984433777e-08, 0.9999999093261015], [0.004846459001046872, 0.9951535409989531], [0.9574662132699339, 0.042533786730066137], [0.999031505772584, 0.0009684942274159938], [2.8021968973445475e-05, 0.9999719780310266], [0.9998775081364845, 0.000122491863515529], [4.949736075538395e-05, 0.9999505026392447], [6.407092251796016e-08, 0.9999999359290774], [0.9991698065225909, 0.0008301934774091742], [3.692590912868159e-05, 0.9999630740908713], [0.9974609677797592, 0.0025390322202406964], [0.9982653949616599, 0.0017346050383400561], [1.9174921031534849e-07, 0.9999998082507897], [0.015450627237893366, 0.9845493727621066], [3.539315970579129e-09, 0.999999996460684], [0.9967706590552671, 0.003229340944733004], [0.0001933058752691227, 0.9998066941247309], [0.9999351256430508, 6.487435694925524e-05], [0.9843337338801608, 0.015666266119839206], [0.004386619234704137, 0.9956133807652958], [0.9975267348933137, 0.0024732651066863543], [0.8847719351979941, 0.11522806480200584], [0.9995922255538288, 0.0004077744461712095], [0.9997355318828683, 0.0002644681171315878], [1.1922910938404572e-06, 0.9999988077089061], [0.24308921972291384, 0.756910780277086], [0.9522125259578159, 0.04778747404218408], [0.0006313413600847819, 0.9993686586399152], [0.9995057399343358, 0.0004942600656641867], [0.9999798921133426, 2.0107886657391723e-05], [0.9999573478663876, 4.265213361234489e-05], [0.9992174054134167, 0.0007825945865831884], [0.0001359477633842592, 0.9998640522366158], [0.9998863566704217, 0.00011364332957822307], [0.018702479690795984, 0.981297520309204], [0.9115176420171011, 0.0884823579828989], [0.9996584478641574, 0.0003415521358426513], [0.0012147898278174478, 0.9987852101721826], [8.799870609356828e-05, 0.9999120012939063], [0.010837384031923452, 0.9891626159680765], [0.22989730475730374, 0.7701026952426963], [0.9999612614635008, 3.8738536499087886e-05], [0.012496696226426138, 0.9875033037735739], [0.9996875965941119, 0.0003124034058881178], [8.744098799830743e-07, 0.99999912559012], [0.9653050655706369, 0.03469493442936303], [0.9999525042895907, 4.749571040927044e-05], [2.7945737443274063e-05, 0.9999720542625568], [0.9429183871741086, 0.05708161282589144], [0.9856331999378038, 0.014366800062196244], [0.9189943739522923, 0.08100562604770764]]}, {"iter": 17, "mu": [44.22971498487126, 69.5168484212143], "sigma": [6.039152641501825, 6.369438934472069], "pi": [0.5315475464093403, 0.4684524535906596], "ll": -854.289, "r": [[0.9973270452520789, 0.0026729547479210206], [0.01020629074851544, 0.9897937092514847], [0.0005438130165142566, 0.9994561869834857], [0.9923606132986849, 0.007639386701315153], [0.9999441731974672, 5.582680253270448e-05], [1.7977479403344688e-06, 0.9999982022520597], [0.9994921225472554, 0.0005078774527446458], [0.04283339017740454, 0.9571666098225955], [0.9998530347377341, 0.0001469652622657967], [0.001346550301373308, 0.9986534496986267], [0.9999986816780158, 1.3183219842679958e-06], [1.5082705804727798e-05, 0.9999849172941953], [0.9777188308459719, 0.022281169154028103], [0.9997598695334039, 0.0002401304665960531], [0.9994540633781472, 0.0005459366218528101], [0.0007000919431186405, 0.9992999080568814], [0.028790044205925742, 0.9712099557940742], [0.9932575810249545, 0.0067424189750453925], [0.9999869735599658, 1.3026440034168017e-05], [0.9998785244624644, 0.0001214755375356346], [0.9975590877733981, 0.002440912226601874], [0.9999543861017707, 4.561389822931939e-05], [7.130205895867426e-08, 0.9999999286979412], [0.999982514065503, 1.7485934497065565e-05], [0.01640640897926312, 0.9835935910207368], [2.715934485862053e-06, 0.9999972840655142], [0.0015101071416395314, 0.9984898928583605], [1.6259026264046572e-05, 0.999983740973736], [0.9999829928117983, 1.7007188201721946e-05], [0.9998044814621475, 0.00019551853785249976], [0.0001290593376329042, 0.9998709406623671], [2.9432837724579944e-07, 0.9999997056716228], [6.387469238799916e-06, 0.9999936125307612], [0.9981665352662797, 0.0018334647337203312], [0.00010492257666531695, 0.9998950774233347], [4.908350365466485e-05, 0.9999509164963454], [0.9441970277993266, 0.05580297220067338], [2.4124847407664444e-05, 0.9999758751525923], [0.9614471514361572, 0.03855284856384282], [0.0004106721253057895, 0.9995893278746941], [0.0007908226521372089, 0.9992091773478629], [5.1190307887233706e-08, 0.9999999488096921], [0.9999251553560584, 7.484464394157354e-05], [5.8845482506736846e-05, 0.9999411545174933], [0.0005184070399006681, 0.9994815929600993], [0.0005329961805541918, 0.9994670038194459], [0.9999987368607552, 1.2631392447569337e-06], [2.676575092249897e-05, 0.9999732342490775], [0.98228470792041, 0.017715292079589946], [0.9999886193646043, 1.1380635395711294e-05], [4.689134767929776e-05, 0.9999531086523207], [0.8228265123798743, 0.17717348762012572], [6.619939301340483e-06, 0.9999933800606986], [0.999880702927341, 0.00011929707265900085], [0.9963187858801886, 0.0036812141198113283], [0.02301999984977745, 0.9769800001502226], [0.9999977551270888, 2.2448729111976877e-06], [0.9993146612630727, 0.0006853387369272119], [0.007283083981812016, 0.992716916018188], [0.9125147342193253, 0.08748526578067473], [1.0109448370066641e-05, 0.99998989055163], [0.7428401226793, 0.25715987732070006], [0.9696538363583249, 0.03034616364167521], [0.9907202835170501, 0.009279716482949972], [8.277870213713031e-07, 0.9999991722129786], [0.0007979104373323657, 0.9992020895626677], [0.003084817747148051, 0.9969151822528519], [0.9996350593614944, 0.000364940638505596], [0.003492948965430011, 0.9965070510345699], [0.015968660431211996, 0.984031339568788], [0.9999972515312536, 2.748468746393563e-06], [0.9914258471980181, 0.00857415280198195], [0.9998506028927431, 0.00014939710725684165], [0.9998347906529199, 0.00016520934708005327], [0.0001699626654228008, 0.9998300373345772], [0.9999995218306104, 4.781693896329875e-07], [0.9999995128120666, 4.871879334851224e-07], [0.99507517526796, 0.0049248247320400245], [0.00012631061142800583, 0.9998736893885719], [1.730217454467823e-05, 0.9999826978254552], [9.881867764945812e-08, 0.9999999011813222], [0.9999791751533763, 2.0824846623622996e-05], [0.9998289625658631, 0.000171037434136839], [0.029764282352928204, 0.9702357176470717], [0.9941925080609905, 0.005807491939009566], [0.00020133842675615362, 0.9997986615732439], [0.999817714549456, 0.00018228545054400894], [0.9518157566622517, 0.04818424333774834], [0.9999986757429745, 1.32425702545649e-06], [0.9827644932961811, 0.017235506703818827], [0.0005931829631451543, 0.9994068170368549], [0.997390774725004, 0.002609225274995994], [0.007053055330006259, 0.9929469446699938], [0.00019964399910619822, 0.9998003560008938], [2.668591076640779e-07, 0.9999997331408924], [0.9973971736638646, 0.0026028263361353317], [3.2609113621839184e-05, 0.9999673908863782], [0.013950194384331066, 0.9860498056156689], [0.999919048856348, 8.0951143651998e-05], [0.9981294698713534, 0.001870530128646653], [0.9988083812890759, 0.0011916187109240097], [0.9857437670744067, 0.01425623292559325], [0.9764437069600325, 0.023556293039967435], [2.711597288436643e-06, 0.9999972884027115], [0.9835446425978315, 0.01645535740216851], [6.370396850455223e-06, 0.9999936296031496], [3.0160636888811545e-05, 0.9999698393631112], [9.904431461289683e-07, 0.999999009556854], [0.9998211623301418, 0.00017883766985821517], [9.009156287283421e-05, 0.9999099084371271], [0.9998316229565084, 0.00016837704349168399], [0.9999595443023926, 4.045569760738123e-05], [1.9656349895874345e-05, 0.9999803436501041], [0.3780752738465656, 0.6219247261534344], [2.1470650314269164e-07, 0.9999997852934969], [2.752265603805937e-06, 0.9999972477343962], [1.4632951063790598e-08, 0.9999999853670489], [0.9990810274203927, 0.0009189725796073481], [0.09161230675693764, 0.9083876932430623], [0.9999998396507035, 1.6034929649066384e-07], [0.007650630143473648, 0.9923493698565263], [0.004029891722898311, 0.9959701082771016], [0.9931397093041476, 0.006860290695852472], [5.180852190865035e-05, 0.9999481914780914], [0.004459358723195436, 0.9955406412768046], [0.99999075735055, 9.242649449929842e-06], [0.0019052804204245915, 0.9980947195795753], [0.9998983835964365, 0.00010161640356353125], [0.9984967124444306, 0.0015032875555693272], [0.9999961179502336, 3.882049766448207e-06], [0.9997949496585189, 0.00020505034148105784], [0.9990396167797049, 0.0009603832202951297], [0.994996395500512, 0.005003604499488013], [0.9975013301353288, 0.0024986698646711205], [0.002150089960598079, 0.9978499100394019], [0.00431244073998269, 0.9956875592600174], [0.9927281631959899, 0.007271836804010057], [0.0002054767580248628, 0.9997945232419752], [0.9890071762072967, 0.010992823792703298], [0.9420681813420918, 0.05793181865790818], [0.9685897327235494, 0.0314102672764505], [0.9983015654138044, 0.0016984345861956976], [0.999983479543028, 1.6520456971909827e-05], [0.9999975479983744, 2.4520016255802356e-06], [0.9999923392154615, 7.660784538555555e-06], [0.004911234450059687, 0.9950887655499403], [0.9884171038445783, 0.011582896155421643], [0.9999814829685518, 1.8517031448145648e-05], [0.9805582443164398, 0.01944175568356027], [0.0004219525882237087, 0.9995780474117764], [0.0005822845727828015, 0.9994177154272172], [4.182276420292635e-08, 0.9999999581772359], [0.9965834966867747, 0.00341650331322529], [0.4165238017243895, 0.5834761982756105], [2.219478401668828e-05, 0.9999778052159833], [1.6831197993895588e-07, 0.9999998316880201], [0.9999020359053149, 9.796409468504737e-05], [0.9994039591896124, 0.0005960408103875621], [0.00319363455715376, 0.9968063654428463], [0.0001978503688514979, 0.9998021496311484], [0.9999995954006287, 4.045993713327536e-07], [4.7694915996209894e-05, 0.9999523050840038], [0.9938192954818469, 0.006180704518153074], [0.8240998260093936, 0.17590017399060648], [0.00021993482103080977, 0.9997800651789691], [0.6614115607448938, 0.33858843925510623], [0.9997166173669934, 0.00028338263300670873], [1.311539651012831e-06, 0.9999986884603489], [1.9826579219538823e-10, 0.9999999998017342], [1.6690505137230076e-07, 0.9999998330949486], [0.006345774031899909, 0.9936542259681], [0.9739750994918276, 0.026024900508172466], [0.9995797211916702, 0.0004202788083298637], [4.014725745771962e-05, 0.9999598527425422], [0.9999588862186962, 4.1113781303847084e-05], [6.973992288566458e-05, 0.9999302600771144], [1.2026849499512543e-07, 0.999999879731505], [0.9996458266045479, 0.00035417339545213523], [5.246649525117001e-05, 0.9999475335047487], [0.9987824825833029, 0.0012175174166969948], [0.9991993364136919, 0.0008006635863081478], [3.389058025856922e-07, 0.9999996610941975], [0.020192728010240288, 0.9798072719897598], [7.96023752289274e-09, 0.9999999920397625], [0.9984150949546914, 0.001584905045308532], [0.00026341491158523087, 0.9997365850884147], [0.9999801451478154, 1.9854852184579173e-05], [0.991164802894491, 0.008835197105508962], [0.005746076462165747, 0.9942539235378343], [0.9988170660093801, 0.0011829339906198253], [0.9229744452334433, 0.07702555476655672], [0.9998398671298565, 0.00016013287014338611], [0.9999016012508241, 9.839874917595156e-05], [1.926745674350166e-06, 0.9999980732543255], [0.3064830594244705, 0.6935169405755296], [0.9704768745042837, 0.02952312549571635], [0.0008423266768728548, 0.9991576733231271], [0.9998013670376442, 0.00019863296235574906], [0.9999949049297701, 5.09507022994124e-06], [0.9999877643062408, 1.2235693759227436e-05], [0.9996683346140279, 0.000331665385972055], [0.00018668878058144476, 0.9998133112194186], [0.9999622560499845, 3.774395001551235e-05], [0.024444036665769827, 0.9755559633342301], [0.9423253325708597, 0.05767466742914028], [0.999868759736635, 0.0001312402633649149], [0.0016071209835093424, 0.9983928790164907], [0.00012210893929307933, 0.999877891060707], [0.014164735704678364, 0.9858352642953215], [0.2907786277116384, 0.7092213722883616], [0.9999890557022664, 1.0944297733623075e-05], [0.01633234899711112, 0.983667651002889], [0.9998812883638537, 0.00011871163614626839], [1.4332836281868008e-06, 0.9999985667163719], [0.9791231034685866, 0.02087689653141339], [0.9999861426409486, 1.3857359051352075e-05], [4.004139685500076e-05, 0.999959958603145], [0.9642037825449132, 0.035796217455086876], [0.9919554155292031, 0.008044584470796895], [0.9476223286633823, 0.052377671336617845]]}, {"iter": 18, "mu": [44.29890840017964, 69.62395268217334], "sigma": [6.089664322137245, 6.259616590622344], "pi": [0.5349810189435997, 0.4650189810564002], "ll": -854.184, "r": [[0.9983159865877613, 0.0016840134122386044], [0.012507138119924318, 0.9874928618800757], [0.0006852501153576146, 0.9993147498846424], [0.9949103723246313, 0.0050896276753687126], [0.9999730344724069, 2.6965527593127027e-05], [2.6309441184278108e-06, 0.9999973690558817], [0.9997108813671165, 0.0002891186328835211], [0.05218134915125884, 0.9478186508487411], [0.9999233742109382, 7.662578906183607e-05], [0.0016763909600754395, 0.9983236090399245], [0.999999559066478, 4.40933521945176e-07], [2.0579168057238367e-05, 0.9999794208319427], [0.9843517545428454, 0.01564824545715463], [0.9998701964321289, 0.00012980356787108227], [0.9996877243417299, 0.00031227565827014644], [0.0008789205566827656, 0.9991210794433173], [0.03513635225692205, 0.9648636477430779], [0.9955365112148048, 0.004463488785195217], [0.9999944678166107, 5.53218338934668e-06], [0.9999375749193069, 6.242508069319647e-05], [0.9984700080524616, 0.0015299919475385204], [0.9999783358623653, 2.1664137634760425e-05], [1.1959940469879625e-07, 0.9999998804005953], [0.9999923674689457, 7.632531054255769e-06], [0.020065375657078027, 0.9799346243429219], [3.9160324371518265e-06, 0.9999960839675628], [0.0018775783972961053, 0.9981224216027038], [2.2136028559761692e-05, 0.9999778639714402], [0.9999925953828187, 7.40461718127608e-06], [0.9998958745655359, 0.00010412543446415824], [0.00016689171808935286, 0.9998331082819107], [4.6297760002861517e-07, 0.9999995370224], [8.947764349763495e-06, 0.9999910522356502], [0.9988694569704326, 0.001130543029567355], [0.0001362780107845182, 0.9998637219892155], [6.48823484632725e-05, 0.9999351176515368], [0.9589845363922491, 0.041015463607750775], [3.248354430884874e-05, 0.9999675164556912], [0.9721892014128801, 0.02781079858711994], [0.0005197674875805791, 0.9994802325124195], [0.0009911491584464617, 0.9990088508415536], [8.724608943013972e-08, 0.9999999127539106], [0.9999629740025135, 3.7025997486411536e-05], [7.744497575391117e-05, 0.999922555024246], [0.0006537126577139757, 0.999346287342286], [0.0006718247990940232, 0.999328175200906], [0.9999995795910492, 4.2040895074185024e-07], [3.593810714204257e-05, 0.9999640618928579], [0.9876959595461322, 0.012304040453867784], [0.9999952283417857, 4.7716582143306535e-06], [6.205455951951092e-05, 0.9999379454404805], [0.8602839408565421, 0.13971605914345792], [9.262760766575655e-06, 0.9999907372392335], [0.9999387795640572, 6.122043594266525e-05], [0.9976395261609589, 0.0023604738390411066], [0.028118438160011097, 0.9718815618399889], [0.9999992030069976, 7.969930024641369e-07], [0.9996021288204509, 0.0003978711795491217], [0.008940078127999775, 0.9910599218720002], [0.9341064096503424, 0.0658935903496576], [1.3959016615588982e-05, 0.9999860409833844], [0.7908369881471193, 0.2091630118528806], [0.978365366654317, 0.021634633345683062], [0.9937565888050891, 0.006243411194910912], [1.2477764425105153e-06, 0.9999987522235575], [0.000999910862044121, 0.9990000891379559], [0.0038090146913331057, 0.9961909853086669], [0.9997968426765653, 0.00020315732343465477], [0.004308611215543103, 0.995691388784457], [0.01953201967571004, 0.9804679803242901], [0.9999990025044749, 9.97495524990164e-07], [0.9942541540521657, 0.005745845947834243], [0.9999220099995286, 7.799000047135366e-05], [0.9999131037309991, 8.689626900093417e-05], [0.00021855991967157685, 0.9997814400803284], [0.999999858303077, 1.4169692297623195e-07], [0.9999998552952373, 1.447047626333289e-07], [0.9967925830879575, 0.003207416912042456], [0.00016341071892376924, 0.9998365892810762], [2.3514277166767574e-05, 0.9999764857228332], [1.6322631042127686e-07, 0.9999998367736896], [0.9999907640057013, 9.235994298675065e-06], [0.999909806138656, 9.019386134397452e-05], [0.03632050092079704, 0.9636794990792029], [0.9961849470657433, 0.0038150529342567243], [0.0002580559793468275, 0.9997419440206532], [0.9999034206819035, 9.657931809636758e-05], [0.9648503597970088, 0.03514964020299123], [0.9999995568534964, 4.431465036566802e-07], [0.9880451449117013, 0.011954855088298825], [0.000746489244447531, 0.9992535107555525], [0.9983583581671789, 0.0016416418328210596], [0.008659249638122363, 0.9913407503618777], [0.00025592556696515755, 0.9997440744330348], [4.2154600964299747e-07, 0.9999995784539903], [0.9983626097309073, 0.0016373902690926903], [4.355506465241059e-05, 0.9999564449353476], [0.017072174834216493, 0.9829278251657836], [0.9999597007036217, 4.0299296378308134e-05], [0.998845259863281, 0.0011547401367190439], [0.999283823740652, 0.0007161762593479832], [0.9902026371147998, 0.009797362885200195], [0.9834115469370482, 0.016588453062951772], [3.9099993368736365e-06, 0.9999960900006631], [0.9886119438265405, 0.011388056173459437], [8.92461859561406e-06, 0.9999910753814043], [4.036753138871196e-05, 0.9999596324686113], [1.4825113669810326e-06, 0.9999985174886331], [0.999905380864565, 9.461913543487527e-05], [0.00011740710805521612, 0.9998825928919447], [0.9999113123723061, 8.868762769391648e-05], [0.9999809800536604, 1.9019946339632463e-05], [2.6617370581664198e-05, 0.9999733826294184], [0.4348442206234682, 0.5651557793765317], [3.423976429025564e-07, 0.9999996576023571], [3.966557605245856e-06, 0.9999960334423947], [2.6573748666163573e-08, 0.9999999734262512], [0.9994564660320514, 0.000543533967948668], [0.11089449587630913, 0.8891055041236909], [0.9999999587639691, 4.1236030950599714e-08], [0.009388746485508272, 0.9906112535144918], [0.004965513356290343, 0.9950344866437097], [0.995454443075973, 0.004545556924026997], [6.839388323503854e-05, 0.999931606116765], [0.0054906805071032565, 0.9945093194928968], [0.9999962016832953, 3.7983167048403487e-06], [0.002363074111004077, 0.9976369258889959], [0.9999484969598389, 5.150304016118472e-05], [0.9990838022210946, 0.0009161977789053794], [0.9999985384306839, 1.4615693160911522e-06], [0.9998904178616763, 0.00010958213832359663], [0.9994304097585682, 0.0005695902414318285], [0.996738549728964, 0.0032614502710359775], [0.9984317375400806, 0.0015682624599193103], [0.0026635054830205264, 0.9973364945169796], [0.00531104612520693, 0.9946889538747931], [0.995167388861111, 0.004832611138889085], [0.00026325799487581306, 0.9997367420051242], [0.9925413497406098, 0.007458650259390194], [0.9573366737495671, 0.04266332625043293], [0.9775689969577726, 0.022431003042227483], [0.9989573864930567, 0.0010426135069432918], [0.9999928265419252, 7.17345807474904e-06], [0.9999991210364902, 8.789635097024258e-07], [0.9999969091654352, 3.0908345649454088e-06], [0.006043053948023124, 0.9939569460519769], [0.9921206347459244, 0.007879365254075565], [0.9999918748282064, 8.125171793540266e-06], [0.986435796670779, 0.013564203329221031], [0.0005338101567307822, 0.9994661898432692], [0.0007329756687791204, 0.9992670243312208], [7.199022410803923e-08, 0.9999999280097759], [0.9978181396534427, 0.002181860346557343], [0.4753751821340169, 0.524624817865983], [2.9953273224376727e-05, 0.9999700467267757], [2.7132959879461665e-07, 0.9999997286704012], [0.9999504900432048, 4.9509956795252575e-05], [0.9996570924991616, 0.0003429075008383955], [0.003942245589716878, 0.9960577544102832], [0.00025367012921768115, 0.9997463298707823], [0.9999998825839126, 1.1741608739338516e-07], [6.309144097255338e-05, 0.9999369085590274], [0.9959266517076557, 0.004073348292344301], [0.8613631065727602, 0.13863689342723987], [0.0002814201824859271, 0.9997185798175141], [0.7168999811025327, 0.2831000188974672], [0.9998450004183137, 0.00015499958168630967], [1.9421083350300932e-06, 0.9999980578916648], [4.6426598722463504e-10, 0.9999999995357342], [2.6916282658590745e-07, 0.9999997308371734], [0.007795614435500976, 0.992204385564499], [0.981584326719545, 0.018415673280454996], [0.9997637702675628, 0.00023622973243717384], [5.333693110195323e-05, 0.999946663068898], [0.9999806440956489, 1.9355904351146324e-05], [9.141598429112975e-05, 0.9999085840157088], [1.9685993259454364e-07, 0.9999998031400673], [0.9998032429539558, 0.00019675704604417538], [6.924119062351573e-05, 0.9999307588093764], [0.9992673016384607, 0.0007326983615393518], [0.999530532321426, 0.00046946767857407345], [5.29895109705761e-07, 0.9999994701048903], [0.02467695511961998, 0.97532304488038], [1.493534355181963e-08, 0.9999999850646565], [0.9990310307528276, 0.0009689692471723194], [0.0003359393436507854, 0.9996640606563493], [0.9999912322159368, 8.767784063253941e-06], [0.9940702804043295, 0.00592971959567053], [0.007063135136836437, 0.9929368648631636], [0.9992893597816932, 0.0007106402183068473], [0.9423997402993237, 0.05760025970067634], [0.9999159696596535, 8.403034034654543e-05], [0.9999502531237634, 4.974687623658842e-05], [2.8125788683664514e-06, 0.9999971874211316], [0.3574842878103072, 0.6425157121896927], [0.9789803503332402, 0.021019649666759878], [0.0010548002987545886, 0.9989451997012454], [0.9998940935395386, 0.00010590646046141521], [0.9999980269592562, 1.9730407437861496e-06], [0.9999948343370652, 5.165662934854443e-06], [0.9998165825256305, 0.00018341747436948725], [0.00023962765929533161, 0.9997603723407047], [0.9999823598568445, 1.7640143155574137e-05], [0.02985116625547179, 0.9701488337445282], [0.9575359227828458, 0.04246407721715417], [0.9999321570727802, 6.784292721984136e-05], [0.001996837861783633, 0.9980031621382164], [0.00015808721147733614, 0.9998419127885226], [0.01733367194960136, 0.9826663280503987], [0.3401866783873227, 0.6598133216126774], [0.9999954284158717, 4.571584128317991e-06], [0.019975143303891687, 0.9800248566961083], [0.9999391030370627, 6.0896962937288434e-05], [2.115293592549846e-06, 0.9999978847064075], [0.9853841596140086, 0.014615840385991483], [0.9999940805911313, 5.919408868691313e-06], [5.31998566255607e-05, 0.9999468001433744], [0.9742723036215082, 0.025727696378491732], [0.9946263556530731, 0.005373644346926923], [0.9616279800023577, 0.038372019997642344]]}, {"iter": 19, "mu": [44.341672575115304, 69.68371726454461], "sigma": [6.123566103455681, 6.200680608764848], "pi": [0.5369804506271865, 0.46301954937281353], "ll": -854.15, "r": [[0.9987263301809135, 0.0012736698190864166], [0.01436101454623384, 0.9856389854537662], [0.0008061157007121207, 0.9991938842992878], [0.9960228169800013, 0.003977183019998744], [0.9999825995749716, 1.7400425028408274e-05], [3.442615991676371e-06, 0.9999965573840084], [0.9997940905256881, 0.00020590947431182953], [0.05944197502168814, 0.9405580249783119], [0.9999482250028974, 5.177499710259833e-05], [0.0019532664710097906, 0.9980467335289902], [0.9999997724280807, 2.2757191931656135e-07], [2.564891952801935e-05, 0.999974351080472], [0.9873970058085012, 0.012602994191498854], [0.9999103722575818, 8.962774241822069e-05], [0.9997769621886471, 0.00022303781135290103], [0.0010309780930265282, 0.9989690219069736], [0.04012424115365466, 0.9598757588463452], [0.9965249716456961, 0.0034750283543039007], [0.9999966977352206, 3.3022647794154387e-06], [0.9999581859301099, 4.181406989009626e-05], [0.9988462920834544, 0.0011537079165455377], [0.9999861620766981, 1.3837923301890421e-05], [1.7171190482187524e-07, 0.9999998282880952], [0.999995367583404, 4.632416596007586e-06], [0.022982272777337085, 0.9770177272226629], [5.071959275541589e-06, 0.9999949280407244], [0.0021853472582021955, 0.9978146527417978], [2.754718838793479e-05, 0.9999724528116121], [0.9999955128678282, 4.487132171853684e-06], [0.9999287422722878, 7.125772771214239e-05], [0.00020017441052981081, 0.9997998255894702], [6.364302260647255e-07, 0.9999993635697739], [1.1359371598625257e-05, 0.9999886406284014], [0.9991557055035153, 0.0008442944964847052], [0.00016398188341160304, 0.9998360181165884], [7.90696566372634e-05, 0.9999209303433628], [0.9661164609547498, 0.033883539045250224], [4.010960970108281e-05, 0.999959890390299], [0.977262232650335, 0.022737767349664942], [0.000613516677448307, 0.9993864833225516], [0.0011610775267480978, 0.9988389224732519], [1.2661603142832064e-07, 0.9999998733839686], [0.9999757607488559, 2.4239251144210767e-05], [9.408162183022777e-05, 0.9999059183781698], [0.0007694482258564678, 0.9992305517741435], [0.0007905085222524922, 0.9992094914777475], [0.9999997836705297, 2.1632947029989322e-07], [4.4286737233401553e-05, 0.9999557132627667], [0.9901526957562369, 0.00984730424376308], [0.9999971737876859, 2.8262123141355186e-06], [7.568467523735128e-05, 0.9999243153247626], [0.8800380001747302, 0.11996199982526976], [1.1749859944731408e-05, 0.9999882501400552], [0.9999590271076082, 4.09728923917484e-05], [0.998196136373067, 0.0018038636269329144], [0.03214936803731177, 0.9678506319626883], [0.9999995734024314, 4.2659756860844466e-07], [0.9997133040480277, 0.0002866959519723244], [0.010284774212973729, 0.9897152257870262], [0.9448286767092238, 0.055171323290776265], [1.7543980087153404e-05, 0.9999824560199128], [0.8172834332792716, 0.18271656672072845], [0.9824277308748376, 0.017572269125162413], [0.9950934686471445, 0.004906531352855447], [1.666151526892531e-06, 0.9999983338484731], [0.0011712290230990593, 0.998828770976901], [0.004407053449300796, 0.9955929465506992], [0.9998572308649647, 0.00014276913503539972], [0.00498051514978201, 0.995019484850218], [0.022374496805455436, 0.9776255031945447], [0.9999994588672463, 5.411327537468947e-07], [0.9954948363416917, 0.0045051636583083145], [0.9999472640918731, 5.2735908126882045e-05], [0.9999409754093423, 5.90245906575703e-05], [0.00026107108375551547, 0.9997389289162445], [0.9999999320874852, 6.791251487592002e-08], [0.9999999305472816, 6.945271829589897e-08], [0.9975265091534107, 0.002473490846589399], [0.00019606377584344248, 0.9998039362241565], [2.9225638269487975e-05, 0.9999707743617304], [2.319293413818474e-07, 0.9999997680706587], [0.9999943399783341, 5.66002166593711e-06], [0.9999386406108199, 6.135938918013749e-05], [0.04146862884302785, 0.9585313711569721], [0.9970430831109885, 0.002956916889011466], [0.00030749917821821637, 0.9996925008217818], [0.999934110411618, 6.58895883819623e-05], [0.9710830245784843, 0.02891697542151577], [0.9999997712140415, 2.2878595847662965e-07], [0.9904394177165488, 0.009560582283451208], [0.0008772725760113012, 0.9991227274239887], [0.9987593640358888, 0.0012406359641111383], [0.009963591940732765, 0.9900364080592673], [0.00030499713963309675, 0.9996950028603668], [5.81141759569383e-07, 0.9999994188582404], [0.9987626773382658, 0.0012373226617340915], [5.3473752156249896e-05, 0.9999465262478437], [0.019570322031872107, 0.9804296779681279], [0.9999735177760389, 2.6482223960999904e-05], [0.9991370426664701, 0.0008629573335299917], [0.9994732076596251, 0.0005267923403748858], [0.9922060446746201, 0.007793955325379823], [0.9866193936074864, 0.013380606392513542], [5.064342516819431e-06, 0.9999949356574832], [0.9909043739233011, 0.009095626076698947], [1.1330667716393897e-05, 0.9999886693322837], [4.96327479626396e-05, 0.9999503672520375], [1.970104236658765e-06, 0.9999980298957633], [0.9999355023132146, 6.44976867853571e-05], [0.00014161896676820554, 0.9998583810332318], [0.9999397074805972, 6.029251940281458e-05], [0.9999879254415128, 1.207455848717537e-05], [3.2998288766796775e-05, 0.9999670017112331], [0.4720660655795089, 0.5279339344204912], [4.750783120314405e-07, 0.999999524921688], [5.13573664003868e-06, 0.99999486426336], [4.024488044501162e-08, 0.9999999597551196], [0.9996039809159639, 0.00039601908403608907], [0.12541679999514857, 0.8745832000048515], [0.9999999818816168, 1.8118383168929637e-08], [0.010797824352535167, 0.9892021756474647], [0.0057340297259179315, 0.994265970274082], [0.9964592522735702, 0.0035407477264298606], [8.326995649080581e-05, 0.9999167300435091], [0.006336079215345389, 0.9936639207846547], [0.9999977775208282, 2.222479171737175e-06], [0.0027447403157203516, 0.9972552596842797], [0.9999657874997546, 3.421250024539735e-05], [0.9993204823570977, 0.0006795176429022728], [0.9999991891778583, 8.108221417231409e-07], [0.9999248513548706, 7.514864512931265e-05], [0.9995843180458037, 0.00041568195419613714], [0.9974836125447527, 0.0025163874552473426], [0.9988165151008356, 0.0011834848991645617], [0.003090524731222247, 0.9969094752687778], [0.006130179623196686, 0.9938698203768034], [0.9962291448197335, 0.0037708551802665556], [0.00031360760958275524, 0.9996863923904172], [0.9941098842471564, 0.005890115752843566], [0.9647172103348892, 0.03528278966511075], [0.9817636957000387, 0.018236304299961214], [0.9992234237059366, 0.000776576294063386], [0.9999956600046601, 4.339995339893353e-06], [0.999999526751838, 4.7324816206070535e-07], [0.9999982115980414, 1.7884019586999137e-06], [0.006969023039967853, 0.9930309769600321], [0.9937683876799864, 0.006231612320013522], [0.9999950528551357, 4.9471448644163325e-06], [0.9891162844599866, 0.01088371554001343], [0.000629881147795455, 0.9993701188522045], [0.000861575183244582, 0.9991384248167554], [1.0517502724500456e-07, 0.9999998948249728], [0.9983365945552611, 0.0016634054447388835], [0.5132831080021077, 0.4867168919978922], [3.7045283514622364e-05, 0.9999629547164854], [3.7924026010166316e-07, 0.9999996207597399], [0.9999671681118527, 3.2831888147273876e-05], [0.9997542401210576, 0.0002457598789422838], [0.004560018890853774, 0.9954399811091463], [0.00030234799872150975, 0.9996976520012785], [0.9999999444405321, 5.555946802109905e-08], [7.692613732673493e-05, 0.9999230738626733], [0.9968369548797721, 0.0031630451202279155], [0.8810001372788955, 0.11899986272110455], [0.0003349235632954587, 0.9996650764367045], [0.7487523216972329, 0.251247678302767], [0.9998922163942983, 0.00010778360570183425], [2.5618858356464216e-06, 0.9999974381141644], [8.327618432866402e-10, 0.9999999991672381], [3.763076461207293e-07, 0.9999996236923538], [0.008975565968318515, 0.9910244340316815], [0.9851049705139553, 0.014895029486044776], [0.9998330298337379, 0.00016697016626213433], [6.52336017507019e-05, 0.9999347663982493], [0.9999877019594403, 1.2298040559777033e-05], [0.00011073389056002573, 0.99988926610944], [2.7800744819866273e-07, 0.9999997219925518], [0.9998618991418177, 0.00013810085818229635], [8.428295664388881e-05, 0.9999157170433561], [0.9994606370061879, 0.0005393629938120835], [0.9996597055836953, 0.0003402944163045525], [7.2544128202286e-07, 0.9999992745587181], [0.028233952574137737, 0.9717660474258623], [2.311841773227086e-08, 0.9999999768815823], [0.9992800112527901, 0.0007199887472098346], [0.00039881888114367934, 0.9996011811188563], [0.9999946409734741, 5.359026525814695e-06], [0.9953466111614144, 0.0046533888385856], [0.008137211285196774, 0.9918627887148033], [0.9994774177150688, 0.000522582284931159], [0.9519617518741076, 0.04803824812589241], [0.9999430018462665, 5.699815373335538e-05], [0.9999670041121952, 3.2995887804792896e-05], [3.6738652542948548e-06, 0.9999963261347457], [0.39205251180383355, 0.6079474881961665], [0.9829400794064969, 0.01705992059350326], [0.00123480868787542, 0.9987651913121246], [0.9999274731236115, 7.252687638841274e-05], [0.9999988865065672, 1.113493432803114e-06], [0.9999969275876182, 3.0724123817653382e-06], [0.9998716115120232, 0.0001283884879768953], [0.0002858479287682263, 0.9997141520712318], [0.9999888414529807, 1.115854701926597e-05], [0.03411954089522506, 0.9658804591047749], [0.9648864886338293, 0.035113511366170656], [0.9999543950654064, 4.560493459369591e-05], [0.002322838557135317, 0.9976771614428647], [0.000189775155361442, 0.9998102248446386], [0.01986851207853141, 0.9801314879214685], [0.37392106687054805, 0.6260789331294521], [0.999997298430802, 2.701569198008363e-06], [0.02287945600758677, 0.9771205439924131], [0.9999592528716162, 4.074712838384032e-05], [2.783937456937481e-06, 0.9999972160625431], [0.9882494928640085, 0.011750507135991477], [0.9999964540948186, 3.5459051814129665e-06], [6.506906592196362e-05, 0.999934930934078], [0.9790083264311007, 0.020991673568899423], [0.9957945037028009, 0.004205496297199033], [0.9683574806515183, 0.031642519348481814]]}, {"iter": 20, "mu": [44.367046526835274, 69.71680272705274], "sigma": [6.144721133808782, 6.169058938470925], "pi": [0.5381222577412854, 0.4618777422587145], "ll": -854.139, "r": [[0.9989124717157748, 0.0010875282842251841], [0.015664043144692615, 0.9843359568553075], [0.0008950835460621486, 0.9991049164539378], [0.9965427108937296, 0.003457289106270334], [0.9999864061154117, 1.3593884588330459e-05], [4.0964942237910606e-06, 0.9999959035057763], [0.9998299593460771, 0.00017004065392291199], [0.06438975075175159, 0.9356102492482484], [0.9999584875561088, 4.151244389118672e-05], [0.0021543514582540763, 0.997845648541746], [0.999999843425232, 1.5657476809814684e-07], [2.9586689553287832e-05, 0.9999704133104468], [0.988864202874661, 0.011135797125338937], [0.9999272573698844, 7.27426301156577e-05], [0.9998155206424697, 0.0001844793575304231], [0.00114249151361176, 0.9988575084863882], [0.04355733645601382, 0.9564426635439862], [0.9969853081263351, 0.0030146918736648465], [0.9999975315559241, 2.468444075961999e-06], [0.999966638010194, 3.3361989805906936e-05], [0.9990165333805101, 0.0009834666194898157], [0.9999892513152117, 1.0748684788404202e-05], [2.1659070724414029e-07, 0.9999997834092929], [0.9999965044107473, 3.495589252700429e-06], [0.02501420697958759, 0.9749857930204126], [5.9962133435437995e-06, 0.9999940037866565], [0.0024084828689461125, 0.997591517131054], [3.174509259348176e-05, 0.9999682549074066], [0.999996617016817, 3.3829831830931983e-06], [0.9999424560903591, 5.754390964091469e-05], [0.00022519355748261755, 0.9997748064425174], [7.812238208703514e-07, 0.9999992187761791], [1.3259171809254523e-05, 0.9999867408281907], [0.9992841272367069, 0.0007158727632929985], [0.00018487090343152873, 0.9998151290965684], [8.988898452121639e-05, 0.9999101110154789], [0.9696549414300832, 0.030345058569916837], [4.598907462412231e-05, 0.9999540109253758], [0.9797479437628364, 0.020252056237163554], [0.0006828083705751688, 0.9993171916294248], [0.0012854729850662195, 0.9987145270149338], [1.6078352346817987e-07, 0.9999998392164765], [0.9999809085548389, 1.9091445161141277e-05], [0.00010673420611988438, 0.9998932657938802], [0.0008546996381476034, 0.9991453003618523], [0.0008778960384904297, 0.9991221039615096], [0.9999998514151626, 1.4858483741951315e-07], [5.071287052286258e-05, 0.9999492871294772], [0.9913284581251024, 0.008671541874897581], [0.9999978967259967, 2.103274003250481e-06], [8.608627373307306e-05, 0.9999139137262669], [0.8903707063568571, 0.10962929364314292], [1.370794886886372e-05, 0.9999862920511312], [0.9999673245459397, 3.267545406035923e-05], [0.9984509625631182, 0.0015490374368818717], [0.03493775563033973, 0.9650622443696603], [0.9999997003191405, 2.996808595275477e-07], [0.9997616948324775, 0.00023830516752246204], [0.011235536597233463, 0.9887644634027665], [0.9502412621247734, 0.04975873787522655], [2.0346610306324065e-05, 0.9999796533896936], [0.8314842428955381, 0.16851575710446182], [0.9844032699171015, 0.015596730082898521], [0.9957216654746229, 0.004278334525377113], [2.008181023487023e-06, 0.9999979918189764], [0.0012966253436685995, 0.9987033746563314], [0.004835888840264047, 0.9951641111597359], [0.9998829780825105, 0.00011702191748944423], [0.005461369548994997, 0.994538630451005], [0.02435564638133045, 0.9756443536186695], [0.9999996169357516, 3.830642484743579e-07], [0.9960765394322949, 0.003923460567704987], [0.9999576994492564, 4.230055074357829e-05], [0.9999525345703009, 4.746542969917818e-05], [0.0002928987764645923, 0.9997071012235355], [0.9999999552135096, 4.478649044110862e-08], [0.9999999541604827, 4.5839517371908523e-08], [0.9978653000867271, 0.002134699913272843], [0.00022061737934813913, 0.9997793826206518], [3.3652048205898375e-05, 0.9999663479517942], [2.906574899354108e-07, 0.9999997093425101], [0.999995705515826, 4.294484174083611e-06], [0.9999506140505269, 4.9385949473043586e-05], [0.045009255528014866, 0.9549907444719852], [0.9974410549479985, 0.0025589450520015246], [0.00034442532424759973, 0.9996555746757524], [0.9999468834566693, 5.3116543330830533e-05], [0.974159590556349, 0.02584040944365105], [0.9999998425616609, 1.5743833923632123e-07], [0.9915843794777349, 0.00841562052226508], [0.0009734181843328206, 0.9990265818156672], [0.9989411424382215, 0.0010588575617784199], [0.010886329169679552, 0.9891136708303204], [0.0003416502615189384, 0.9996583497384811], [7.146424956091034e-07, 0.9999992853575044], [0.9989440174913649, 0.001055982508635196], [6.108512026562083e-05, 0.9999389148797343], [0.021316046226521976, 0.978683953773478], [0.999979097317858, 2.090268214200033e-05], [0.9992680249796037, 0.0007319750203964285], [0.9995570770120742, 0.00044292298792582497], [0.9931589055756623, 0.006841094424337776], [0.9881674776077757, 0.011832522392224331], [5.987356741895112e-06, 0.999994012643258], [0.991999175222326, 0.00800082477767413], [1.3226175113489693e-05, 0.9999867738248865], [5.6751218836180865e-05, 0.9999432487811638], [2.367339352655735e-06, 0.9999976326606475], [0.9999480302539855, 5.196974601436765e-05], [0.00015991614183677723, 0.9998400838581633], [0.9999514918080163, 4.850819198354254e-05], [0.9999906535471899, 9.346452810074577e-06], [3.793363238657164e-05, 0.9999620663676134], [0.49440060471448416, 0.5055993952855158], [5.865784789856392e-07, 0.999999413421521], [6.070364563969105e-06, 0.999993929635436], [5.247837893495875e-08, 0.9999999475216211], [0.999668786332715, 0.00033121366728491104], [0.13506575745384086, 0.8649342425461592], [0.9999999886325842, 1.136741576505586e-08], [0.01179326381640011, 0.9882067361836], [0.006282767953662997, 0.9937172320463369], [0.9969274300021669, 0.003072569997833044], [9.460528749657923e-05, 0.9999053947125034], [0.006938724938119561, 0.9930612750618804], [0.9999983574366523, 1.6425633475262284e-06], [0.003020475870269738, 0.9969795241297302], [0.9999728306166903, 2.7169383309713844e-05], [0.9994260380494853, 0.0005739619505146587], [0.9999994186553404, 5.813446597445569e-07], [0.999939242814736, 6.075718526393591e-05], [0.9996520250437828, 0.00034797495621726555], [0.9978276984497596, 0.0021723015502403873], [0.9989907177242096, 0.0010092822757904055], [0.0033984538535525954, 0.9966015461464475], [0.0067144196607355836, 0.9932855803392645], [0.9967246646380856, 0.003275335361914314], [0.0003511995393504863, 0.9996488004606495], [0.9948504495626583, 0.005149550437341759], [0.968383942351685, 0.03161605764831509], [0.9838057642157042, 0.01619423578429589], [0.9993425066250493, 0.0006574933749506439], [0.9999967309633412, 3.2690366587202386e-06], [0.9999996664294334, 3.3357056667762416e-07], [0.9999986866312384, 1.3133687615443098e-06], [0.007628064133027823, 0.9923719358669721], [0.9945475011042235, 0.005452498895776526], [0.9999962601670986, 3.7398329013359413e-06], [0.9904025921546211, 0.00959740784537881], [0.0007008608388096465, 0.9992991391611904], [0.0009561410793015375, 0.9990438589206985], [1.341127969574068e-07, 0.999999865887203], [0.998573446763435, 0.001426553236565018], [0.5357572882916678, 0.4642427117083322], [4.25201491583131e-05, 0.9999574798508417], [4.7040212258637094e-07, 0.9999995295978774], [0.9999739523310489, 2.6047668951166385e-05], [0.9997963359708483, 0.00020366402915180762], [0.005002762925207366, 0.9949972370747927], [0.00033871184118302157, 0.9996612881588169], [0.9999999636278233, 3.637217672037116e-08], [8.74811423680156e-05, 0.999912518857632], [0.997259859248072, 0.0027401407519278918], [0.8912670855893428, 0.10873291441065729], [0.0003748305434241839, 0.9996251694565759], [0.766288581930277, 0.233711418069723], [0.9999121747429935, 8.782525700656858e-05], [3.0641181516401103e-06, 0.9999969358818483], [1.2055138586021408e-09, 0.9999999987944862], [4.6683906645150034e-07, 0.9999995331609335], [0.009811803375926553, 0.9901881966240733], [0.9868090788265259, 0.013190921173474111], [0.9998626994099836, 0.00013730059001638246], [7.433379631970731e-05, 0.9999256662036803], [0.9999904760869766, 9.523913023410482e-06], [0.00012538833076001688, 0.9998746116692401], [3.470688213008915e-07, 0.9999996529311787], [0.9998868826449064, 0.00011311735509351882], [9.574236146628673e-05, 0.9999042576385337], [0.9995463125413595, 0.00045368745864057965], [0.9997162084989487, 0.00028379150105131766], [8.881990563339441e-07, 0.9999991118009437], [0.030701358549197037, 0.9692986414508029], [3.055705490279464e-08, 0.9999999694429451], [0.9993912290710443, 0.0006087709289557092], [0.0004455961415714231, 0.9995544038584286], [0.9999959399335493, 4.0600664506258756e-06], [0.9959455314298314, 0.004054468570168577], [0.008899682565246928, 0.991100317434753], [0.9995606812176089, 0.00043931878239115854], [0.9567636293508913, 0.04323637064910869], [0.9999542001802691, 4.579981973092139e-05], [0.999973819137895, 2.6180862105091925e-05], [4.3668291538880976e-06, 0.999995633170846], [0.4132775048401049, 0.586722495159895], [0.9848640789112587, 0.015135921088741318], [0.0013664603255141917, 0.9986335396744858], [0.999941408355653, 5.859164434689911e-05], [0.9999991938073106, 8.061926893938741e-07], [0.99999770805812, 2.2919418798962778e-06], [0.999894997994982, 0.00010500200501797345], [0.0003204051577866621, 0.9996795948422134], [0.9999913800942973, 8.619905702682872e-06], [0.03706831070551738, 0.9629316892944826], [0.9685377472427701, 0.031462252757229886], [0.9999635405067686, 3.645949323137356e-05], [0.0025589696885285782, 0.9974410303114714], [0.00021361488939904735, 0.9997863851106009], [0.02163936048096708, 0.9783606395190328], [0.3947415528921392, 0.6052584471078608], [0.9999979920783937, 2.0079216063770954e-06], [0.024902804902432487, 0.9750971950975675], [0.9999675087548573, 3.2491245142729085e-05], [3.324865412786116e-06, 0.9999966751345871], [0.9896273657506698, 0.010372634249330227], [0.9999973441135799, 2.6558864201184895e-06], [7.414861978457563e-05, 0.9999258513802154], [0.9813234009410607, 0.01867659905893915], [0.9963412212182088, 0.0036587787817912907], [0.9716888628231678, 0.028311137176832202]]}, {"iter": 21, "mu": [44.38173666770637, 69.73513563612808], "sigma": [6.15733995969565, 6.15191382718824], "pi": [0.538768035234285, 0.461231964765715], "ll": -854.135, "r": [[0.9990035302005519, 0.000996469799448155], [0.016499450928566594, 0.9835005490714335], [0.0009539506724291844, 0.9990460493275708], [0.9968014025109911, 0.0031985974890088244], [0.9999881374306062, 1.1862569393839803e-05], [4.554833445035545e-06, 0.999995445166555], [0.9998470108193176, 0.00015298918068236658], [0.06749321329409462, 0.9325067867059054], [0.9999632515399682, 3.674846003171824e-05], [0.0022862132184766604, 0.9977137867815233], [0.9999998726875694, 1.273124305896374e-07], [3.2284332307274754e-05, 0.9999677156676928], [0.9896072492772019, 0.010392750722798003], [0.9999351721170394, 6.482788296047914e-05], [0.9998338748242344, 0.00016612517576571046], [0.0012160946147256168, 0.9987839053852744], [0.045725990405705186, 0.9542740095942948], [0.9972139043745658, 0.0027860956254342328], [0.9999978980128098, 2.101987190219934e-06], [0.9999705463559142, 2.9453644085714546e-05], [0.999099689161989, 0.0009003108380110383], [0.999990650084731, 9.34991526899112e-06], [2.493729659672537e-07, 0.9999997506270341], [0.9999970077043665, 2.9922956335161936e-06], [0.02630874271784132, 0.9736912572821587], [6.641050460455173e-06, 0.9999933589495394], [0.002554633761974073, 0.9974453662380259], [3.461875620256785e-05, 0.9999653812437974], [0.9999971055102521, 2.89448974788389e-06], [0.9999488585568943, 5.114144310575912e-05], [0.00024197762723047423, 0.9997580223727695], [8.849811363172648e-07, 0.9999991150188636], [1.457232999974456e-05, 0.9999854276700002], [0.9993465583289602, 0.0006534416710396855], [0.00019891200432809505, 0.9998010879956719], [9.721481137191061e-05, 0.9999027851886281], [0.9714778516644242, 0.028522148335575793], [4.999794615933815e-05, 0.9999500020538407], [0.9810192193033413, 0.018980780696658678], [0.000728781161704594, 0.9992712188382954], [0.0013674803971083858, 0.9986325196028917], [1.8585997466477357e-07, 0.9999998141400254], [0.9999832648830429, 1.6735116957180162e-05], [0.00011528631425434677, 0.9998847136857457], [0.0009111339309298965, 0.9990888660690701], [0.0009357287977665868, 0.9990642712022335], [0.9999998792998155, 1.2070018456603474e-07], [5.508996875359119e-05, 0.9999449100312464], [0.9919215999240808, 0.008078400075919263], [0.999998213365392, 1.7866346079460295e-06], [9.313237845387158e-05, 0.9999068676215461], [0.895859287355796, 0.10414071264420395], [1.5060883056200111e-05, 0.9999849391169439], [0.9999711599560194, 2.8840043980685493e-05], [0.9985762744804616, 0.0014237255195383891], [0.03670543290029721, 0.9632945670997027], [0.9999997534803975, 2.4651960249153216e-07], [0.9997848236600386, 0.00021517633996134296], [0.011847633461359036, 0.9881523665386409], [0.9530577897297229, 0.046942210270277104], [2.227450069809489e-05, 0.9999777254993019], [0.8391431354795595, 0.16085686452044043], [0.9854091960182877, 0.014590803981712239], [0.9960352300788811, 0.003964769921118914], [2.2501284611897685e-06, 0.9999977498715388], [0.00137928529878621, 0.9986207147012138], [0.0051146735014647796, 0.9948853264985353], [0.9998951434154252, 0.0001048565845747859], [0.005773549550277166, 0.9942264504497228], [0.025618304094113496, 0.9743816959058864], [0.9999996835395667, 3.1646043325112573e-07], [0.9963665258749735, 0.0036334741250264356], [0.9999625452560316, 3.745474396840719e-05], [0.999957913089947, 4.2086910052910624e-05], [0.0003141943935377981, 0.9996858056064621], [0.9999999644360941, 3.556390592067294e-08], [0.99999996358333, 3.641667009973152e-08], [0.9980326890108998, 0.0019673109891001875], [0.00023709252234881668, 0.9997629074776512], [3.668023113246185e-05, 0.9999633197688675], [3.3336067398759983e-07, 0.999999666639326], [0.9999963126373691, 3.687362630876289e-06], [0.9999561891941599, 4.381080584006336e-05], [0.047244600984600475, 0.9527553990153995], [0.9976382072446419, 0.00236179275535807], [0.0003690924055688867, 0.9996309075944311], [0.9999528384546731, 4.716154532697057e-05], [0.9757398348143842, 0.02426016518561568], [0.9999998719725489, 1.2802745100806728e-07], [0.9921617177358482, 0.007838282264151848], [0.0010369808313193888, 0.9989630191686806], [0.9990300312383729, 0.0009699687616272433], [0.011480611400571814, 0.9885193885994281], [0.0003661369327383155, 0.9996338630672617], [8.104290656062976e-07, 0.9999991895709344], [0.999032688406597, 0.0009673115934029632], [6.625943797526462e-05, 0.9999337405620248], [0.02243072022994703, 0.977569279770053], [0.9999816555521878, 1.834444781228441e-05], [0.9993317221979128, 0.000668277802087321], [0.9995975527627299, 0.0004024472372701736], [0.9936378676058154, 0.006362132394184707], [0.9889522404314078, 0.011047759568592165], [6.631340358098413e-06, 0.9999933686596418], [0.9925507938954626, 0.007449206104537326], [1.4536403350413353e-05, 0.9999854635966495], [6.15941779779911e-05, 0.999938405822022], [2.647733873096904e-06, 0.999997352266127], [0.9999538687673009, 4.613123269920864e-05], [0.00017223300549133432, 0.9998277669945087], [0.9999569771799374, 4.302282006254959e-05], [0.9999918854599519, 8.114540048187279e-06], [4.1305654325584815e-05, 0.9999586943456744], [0.5072763766421201, 0.4927236233578799], [6.668078211139843e-07, 0.9999993331921789], [6.7223424376418355e-06, 0.9999932776575624], [6.162684285603864e-08, 0.999999938373157], [0.9996999213926995, 0.00030007860730056645], [0.14101194578935972, 0.8589880542106403], [0.9999999912219112, 8.778088798078628e-09], [0.01243374440051486, 0.9875662555994852], [0.006638458441773683, 0.9933615415582263], [0.9971599850052569, 0.0028400149947431148], [0.00010227648356269886, 0.9998977235164374], [0.007328916597094313, 0.9926710834029057], [0.9999986100765875, 1.3899234124991076e-06], [0.0032006473453106677, 0.9967993526546893], [0.9999760754232916, 2.3924576708427222e-05], [0.9994771818395206, 0.0005228181604794085], [0.9999995163077356, 4.836922643721009e-07], [0.9999459679411299, 5.40320588701518e-05], [0.9996845791438232, 0.00031542085617667785], [0.9979977470526882, 0.00200225294731188], [0.9990758412797462, 0.0009241587202537241], [0.0035994078166406976, 0.9964005921833593], [0.0070928363759058186, 0.9929071636240943], [0.9969710322164621, 0.003028967783537992], [0.0003763065003543014, 0.9996236934996456], [0.9952211197467963, 0.004778880253203744], [0.970274394492316, 0.02972560550768398], [0.9848462121108154, 0.015153787889184712], [0.9994003235059399, 0.0005996764940601481], [0.9999972044344644, 2.795565535590525e-06], [0.9999997250881941, 2.749118059902476e-07], [0.9999988925630602, 1.1074369398145436e-06], [0.008054304872578199, 0.9919456951274218], [0.9949377975941451, 0.005062202405854935], [0.9999967954145895, 3.2045854104452742e-06], [0.9910525178975813, 0.008947482102418754], [0.0007479412605655008, 0.9992520587394346], [0.0010186706613438022, 0.9989813293386562], [1.5541340904292143e-07, 0.999999844586591], [0.9986897785669226, 0.0013102214330773336], [0.5486171716321974, 0.45138282836780264], [4.625625018819006e-05, 0.9999537437498117], [5.362097481449422e-07, 0.9999994637902518], [0.9999770754708533, 2.2924529146691964e-05], [0.9998164058073526, 0.0001835941926473215], [0.005290481549251527, 0.9947095184507485], [0.0003630073453186912, 0.9996369926546813], [0.999999971235999, 2.8764000989323208e-08], [9.462998573776749e-05, 0.9999053700142623], [0.9974695732474024, 0.0025304267525976484], [0.8967193405385799, 0.10328065946142014], [0.00040146640329050376, 0.9995985335967095], [0.7758856160909455, 0.22411438390905453], [0.9999215598955902, 7.844010440987544e-05], [3.417450895991366e-06, 0.999996582549104], [1.505904852824574e-09, 0.999999998494095], [5.321989413156719e-07, 0.9999994678010588], [0.010351049697220989, 0.9896489503027791], [0.987674434145415, 0.012325565854584985], [0.99987675490023, 0.00012324509976996913], [8.050765034295084e-05, 0.999919492349657], [0.9999917292398652, 8.27076013472935e-06], [0.00013527732936466922, 0.9998647226706353], [3.9714999527107507e-07, 0.9999996028500048], [0.999898680507712, 0.00010131949228794268], [0.00010349657670780266, 0.9998965034232922], [0.9995876752165339, 0.0004123247834659491], [0.9997432891552651, 0.0002567108447348102], [1.004617902389259e-06, 0.9999989953820976], [0.03226864301245175, 0.9677313569875482], [3.6173562309753156e-08, 0.9999999638264377], [0.9994451644349068, 0.0005548355650932405], [0.0004767638280039889, 0.999523236171996], [0.9999965167891877, 3.483210812328053e-06], [0.9962442455133336, 0.0037557544866663934], [0.009391930498982778, 0.9906080695010172], [0.9996008595360708, 0.00039914046392916253], [0.9592548448521268, 0.0407451551478732], [0.9999594075499925, 4.0592450007462155e-05], [0.999976956750401, 2.304324959899925e-05], [4.852180041789739e-06, 0.9999951478199582], [0.4256922091798813, 0.5743077908201186], [0.9858432791027564, 0.014156720897243534], [0.0014531973102028634, 0.9985468026897971], [0.9999479162176789, 5.208378232116103e-05], [0.9999993255691577, 6.744308423573579e-07], [0.9999980505259618, 1.949474038102923e-06], [0.9999060280727339, 9.397192726606632e-05], [0.0003435064069925757, 0.9996564935930075], [0.9999925246430597, 7.4753569403132545e-06], [0.038935922985185695, 0.9610640770148143], [0.9704200468035906, 0.029579953196409336], [0.9999677761715186, 3.2223828481450943e-05], [0.002713533946964772, 0.9972864660530352], [0.00022961619883132248, 0.9997703838011687], [0.022769843578176078, 0.977230156421824], [0.40695990644449737, 0.5930400935555027], [0.9999982955854968, 1.7044145031292732e-06], [0.026191952626222724, 0.9738080473737772], [0.9999713245701035, 2.867542989644973e-05], [3.70502684683171e-06, 0.9999962949731531], [0.9903243983120255, 0.009675601687974588], [0.9999977358768796, 2.2641231204420712e-06], [8.030862927628396e-05, 0.9999196913707237], [0.9825057695315551, 0.017494230468444866], [0.9966134866535739, 0.0033865133464261975], [0.9734028575598728, 0.026597142440127303]]}, {"iter": 22, "mu": [44.39012068087354, 69.74532475035538], "sigma": [6.164667989599111, 6.142516300816509], "pi": [0.53913153392475, 0.46086846607525], "ll": -854.134, "r": [[0.9990504891644845, 0.0009495108355154025], [0.017005503614082942, 0.9829944963859171], [0.0009903249276217063, 0.9990096750723783], [0.9969360998098741, 0.003063900190125817], [0.99998899515189, 1.1004848109998851e-05], [4.84813460640663e-06, 0.9999951518653937], [0.9998556654782026, 0.0001443345217974516], [0.06934691997113698, 0.930653080028863], [0.9999656381768354, 3.436182316467058e-05], [0.0023672369718267337, 0.9976327630281733], [0.9999998864267581, 1.1357324198004835e-07], [3.398700788439706e-05, 0.9999660129921156], [0.9899980760126913, 0.010001923987308725], [0.9999391583653481, 6.0841634651913124e-05], [0.9998431974398388, 0.00015680256016119013], [0.0012615047716394241, 0.9987384952283607], [0.04702722089828674, 0.9529727791017133], [0.9973327951934349, 0.002667204806565155], [0.9999980761984203, 1.923801579706635e-06], [0.9999725001865661, 2.749981343389867e-05], [0.9991425367254352, 0.0008574632745649189], [0.9999913413612375, 8.658638762526064e-06], [2.7087141626906477e-07, 0.9999997291285837], [0.9999972534026754, 2.746597324589433e-06], [0.02708975036981817, 0.9729102496301817], [7.052542702705202e-06, 0.9999929474572973], [0.002644372100276913, 0.9973556278997231], [3.643169700067624e-05, 0.9999635683029994], [0.9999973438948823, 2.656105117702795e-06], [0.9999520760549727, 4.792394502722937e-05], [0.0002524370003282206, 0.9997475629996718], [9.522556660525682e-07, 0.999999047744334], [1.540562618027851e-05, 0.9999845943738197], [0.9993786416235967, 0.0006213583764033964], [0.00020767262615544322, 0.9997923273738446], [0.00010180601144799787, 0.9998981939885521], [0.9724461732412537, 0.027553826758746233], [5.252101930916891e-05, 0.9999474789806908], [0.98169168225767, 0.018308317742330077], [0.0007572357631708465, 0.9992427642368291], [0.0014180380091041412, 0.9985819619908958], [2.0235109693235067e-07, 0.9999997976489031], [0.999984436314111, 1.556368588889369e-05], [0.00012064031677814196, 0.9998793596832218], [0.0009460149659369935, 0.9990539850340631], [0.0009714682349371061, 0.9990285317650629], [0.9999998923826603, 1.0761733972756822e-07], [5.7843073240475264e-05, 0.9999421569267596], [0.9922328822110081, 0.007767117788991867], [0.9999983670409247, 1.632959075291422e-06], [9.754946448357377e-05, 0.9999024505355164], [0.8988266320814481, 0.1011733679185519], [1.5919224141930898e-05, 0.999984080775858], [0.9999730769351156, 2.69230648843893e-05], [0.9986410883649749, 0.0013589116350250612], [0.03776849878385811, 0.9622315012161419], [0.9999997786611728, 2.2133882717735928e-07], [0.9997965980074212, 0.00020340199257885233], [0.012219398757314598, 0.9877806012426854], [0.9545626102786834, 0.045437389721316605], [2.3494347190829996e-05, 0.9999765056528092], [0.8433201440026393, 0.15667985599736065], [0.9859399486283557, 0.014060051371644379], [0.9961987916474642, 0.0038012083525357245], [2.4058021019094354e-06, 0.9999975941978981], [0.0014302424155445343, 0.9985697575844555], [0.0052850463034913855, 0.9947149536965086], [0.999901297339704, 9.870266029598296e-05], [0.00596416845468311, 0.9940358315453169], [0.026380264004412908, 0.9736197359955872], [0.9999997151898834, 2.8481011653842016e-07], [0.9965176783220514, 0.003482321677948675], [0.9999649733244448, 3.502667555527622e-05], [0.999960611065931, 3.9388934068850875e-05], [0.00032744390074674587, 0.9996725560992532], [0.9999999686890709, 3.1310929151722946e-08], [0.9999999679301631, 3.206983694979105e-08], [0.9981194967694723, 0.0018805032305277008], [0.0002473606721595231, 0.9997526393278405], [3.858992981381138e-05, 0.9999614100701862], [3.61289603443511e-07, 0.9999996387103964], [0.9999966097094863, 3.390290513629755e-06], [0.9999589868612881, 4.101313871185147e-05], [0.048585371586554627, 0.9514146284134454], [0.9977406044206231, 0.002259395579376854], [0.0003844243238806631, 0.9996155756761194], [0.9999558288106134, 4.417118938648987e-05], [0.9765778134386323, 0.02342218656136776], [0.9999998857825351, 1.1421746484582663e-07], [0.9924646261818807, 0.007535373818119319], [0.0010762358837399916, 0.99892376411626], [0.9990758610841496, 0.0009241389158504581], [0.011841644940256827, 0.9881583550597433], [0.0003813574702870361, 0.9996186425297129], [8.725823484379493e-07, 0.9999991274176515], [0.9990784048773323, 0.0009215951226677366], [6.951013359261912e-05, 0.9999304898664074], [0.023104177522266324, 0.9768958224777337], [0.9999829285244715, 1.7071475528587173e-05], [0.9993644622772063, 0.0006355377227935519], [0.9996182687799614, 0.00038173122003868807], [0.9938887072434605, 0.006111292756539464], [0.9893652373801076, 0.010634762619892395], [7.042292353183765e-06, 0.9999929577076467], [0.9928400795907896, 0.007159920409210536], [1.5367854478703685e-05, 0.9999846321455214], [6.463812078666236e-05, 0.9999353618792133], [2.8279136107255986e-06, 0.9999971720863894], [0.9999568000207814, 4.3199979218671546e-05], [0.000179924679606075, 0.9998200753203939], [0.9999597293271503, 4.027067284963534e-05], [0.9999924933768255, 7.506623174545039e-06], [4.343054219676949e-05, 0.9999565694578032], [0.5145766446922262, 0.4854233553077738], [7.189545032595289e-07, 0.9999992810454967], [7.138354414151672e-06, 0.9999928616455858], [6.771020063081603e-08, 0.9999999322897993], [0.9997158169928932, 0.00028418300710679077], [0.14452385131663256, 0.8554761486833674], [0.9999999923908227, 7.609177332316664e-09], [0.012822602191110151, 0.9871773978088898], [0.006855428741884875, 0.9931445712581152], [0.9972809539365084, 0.0027190460634916144], [0.00010708259912668906, 0.9998929174008733], [0.007566762117804502, 0.9924332378821955], [0.9999987323336748, 1.2676663252998794e-06], [0.0033111089121471778, 0.9966888910878527], [0.999977694267413, 2.2305732586934123e-05], [0.9995034156447576, 0.0004965843552424728], [0.9999995629629032, 4.3703709675151124e-07], [0.9999493493237409, 5.0650676259111845e-05], [0.999701206299022, 0.00029879370097796865], [0.9980859469079344, 0.0019140530920655834], [0.9991197122638998, 0.0008802877361001226], [0.0037225134615834097, 0.9962774865384165], [0.007323559241930954, 0.992676440758069], [0.9970992545281812, 0.0029007454718188368], [0.0003919099666626982, 0.9996080900333373], [0.9954147725938226, 0.004585227406177341], [0.9712790456107502, 0.028720954389249778], [0.9853953761374743, 0.014604623862525788], [0.9994300142831701, 0.0005699857168298075], [0.9999974353982777, 2.564601722241215e-06], [0.9999997529123914, 2.470876085704064e-07], [0.999998991950339, 1.0080496608645837e-06], [0.008313944971001472, 0.9916860550289985], [0.9951418033897802, 0.004858196610219716], [0.9999970569116607, 2.9430883393387454e-06], [0.9913939080236855, 0.008606091976314486], [0.0007770767171921145, 0.9992229232828078], [0.0010572920400345322, 0.9989427079599655], [1.6944572964461763e-07, 0.9999998305542704], [0.998749906603979, 0.001250093396020956], [0.5558761997661726, 0.4441238002338274], [4.860883235348589e-05, 0.9999513911676465], [5.790649155296907e-07, 0.9999994209350844], [0.9999786329634746, 2.1367036525490383e-05], [0.9998266087843651, 0.00017339121563487845], [0.005466272493341646, 0.9945337275066584], [0.00037810985498012485, 0.9996218901450199], [0.9999999747335534, 2.5266446716318018e-08], [9.911102705740457e-05, 0.9999008889729426], [0.9975785567861415, 0.0024214432138585235], [0.8996666128317309, 0.10033338716826917], [0.0004180134487011851, 0.9995819865512988], [0.7811638448107395, 0.21883615518926056], [0.9999262949837138, 7.370501628617172e-05], [3.644050796244062e-06, 0.9999963559492038], [1.7146438867345792e-09, 0.9999999982853561], [5.747653635913174e-07, 0.9999994252346364], [0.010678909101796323, 0.9893210908982037], [0.9881303004487386, 0.011869699551261477], [0.9998838752611526, 0.00011612473884736426], [8.438149633363183e-05, 0.9999156185036664], [0.999992347761576, 7.65223842407579e-06], [0.00014146211140431882, 0.9998585378885957], [4.2985187929104284e-07, 0.9999995701481207], [0.9999046467030976, 9.535329690231584e-05], [0.00010835434353473416, 0.9998916456564653], [0.9996088495138606, 0.00039115048613934763], [0.9997570963276458, 0.00024290367235434154], [1.0800206715877606e-06, 0.9999989199793284], [0.03321239088119822, 0.9667876091188018], [3.992955393752911e-08, 0.999999960070446], [0.9994728439373578, 0.0005271560626421576], [0.000496105671021861, 0.9995038943289781], [0.9999967988745376, 3.201125462350828e-06], [0.9963999901902557, 0.003600009809744271], [0.009691435523502129, 0.9903085644764978], [0.9996214218883382, 0.000378578111661718], [0.9605835459057019, 0.03941645409429808], [0.9999620187798531, 3.7981220146958234e-05], [0.9999785215397413, 2.1478460258685063e-05], [5.162619146799207e-06, 0.9999948373808532], [0.4327923527356948, 0.5672076472643053], [0.9863597834930397, 0.013640216506960337], [0.0015066499890493824, 0.9984933500109506], [0.9999511872392591, 4.881276074077355e-05], [0.9999993887806248, 6.112193751822079e-07], [0.9999982169037156, 1.7830962842998319e-06], [0.9999116022121384, 8.839778786160052e-05], [0.00035787143194015774, 0.9996421285680598], [0.9999930889618904, 6.911038109580209e-06], [0.04005841764346162, 0.9599415823565384], [0.9714203116560323, 0.02857968834396772], [0.9999698954673727, 3.010453262722601e-05], [0.0028084003266156026, 0.9971915996733843], [0.00023959100269458204, 0.9997604089973053], [0.023452762009956617, 0.9765472379900434], [0.4139616650646032, 0.5860383349353968], [0.9999984428073605, 1.5571926393823079e-06], [0.026969741249141, 0.973030258750859], [0.9999732316498892, 2.676835011069333e-05], [3.9486816009877625e-06, 0.9999960513183991], [0.9906907875469604, 0.009309212453039603], [0.999997926528697, 2.0734713029639286e-06], [8.417384891178728e-05, 0.9999158261510882], [0.9831307036082946, 0.016869296391705417], [0.9967553189824052, 0.003244681017594723], [0.9743126415612037, 0.02568735843879627]]}, {"iter": 23, "mu": [44.39486648279863, 69.75100304724126], "sigma": [6.168857652202399, 6.137323143239676], "pi": [0.539335648594749, 0.46066435140525097], "ll": -854.134, "r": [[0.9990755361801067, 0.0009244638198932396], [0.0173019291635004, 0.9826980708364996], [0.0010118872095028647, 0.998988112790497], [0.9970083358391938, 0.0029916641608062357], [0.9999894426142578, 1.055738574221279e-05], [5.025613100675911e-06, 0.9999949743868993], [0.9998602410191699, 0.00013975898083000592], [0.07042352176146184, 0.9295764782385381], [0.9999668908988052, 3.310910119473719e-05], [0.002415107104299867, 0.9975848928957001], [0.9999998933867359, 1.0661326403981723e-07], [3.500906526105851e-05, 0.999964990934739], [0.9902088830306595, 0.009791116969340536], [0.9999412568386088, 5.874316139134314e-05], [0.9998481280907843, 0.0001518719092157303], [0.0012883989340696067, 0.9987116010659304], [0.04778503755168511, 0.9522149624483149], [0.9973965130640194, 0.002603486935980563], [0.9999981682090002, 1.8317909997223953e-06], [0.9999735245378825, 2.6475462117469135e-05], [0.9991653800497877, 0.000834619950212139], [0.9999917015076164, 8.298492383667167e-06], [2.8406634154175983e-07, 0.9999997159336586], [0.9999973805521314, 2.6194478686578615e-06], [0.02754611256667723, 0.9724538874333228], [7.301134291846214e-06, 0.9999926988657082], [0.0026973678012770196, 0.997302632198723], [3.751964966993422e-05, 0.9999624803503301], [0.9999974672344338, 2.532765566271848e-06], [0.9999537677858547, 4.6232214145407584e-05], [0.00025866849211992254, 0.99974133150788], [9.932755051502826e-07, 0.9999990067244949], [1.5907399803918266e-05, 0.999984092600196], [0.9993957207438965, 0.0006042792561034889], [0.00021289576444226036, 0.9997871042355577], [0.00010455051221020228, 0.9998954494877899], [0.9729714410629883, 0.02702855893701179], [5.403300145528158e-05, 0.9999459669985448], [0.9820555813497767, 0.017944418650223396], [0.0007741202301717008, 0.9992258797698284], [0.0014479674623920154, 0.998552032537608], [2.1248910656396375e-07, 0.9999997875108934], [0.9999850486012096, 1.4951398790376413e-05], [0.0001238387888174924, 0.9998761612111825], [0.0009666956233462409, 0.9990333043766537], [0.0009926557277289512, 0.999007344272271], [0.9999998990075153, 1.0099248463912065e-07], [5.949229991004371e-05, 0.99994050770009], [0.9924005688093802, 0.007599431190619759], [0.9999984463141768, 1.553685823095299e-06], [0.00010019030348975961, 0.9998998096965103], [0.9004525987011155, 0.09954740129888447], [1.6436009822620022e-05, 0.9999835639901773], [0.9999740818537022, 2.5918146297664272e-05], [0.9986757160464099, 0.0013242839535901353], [0.038388473032269166, 0.9616115269677308], [0.9999997914788278, 2.0852117226578e-07], [0.9998028331439449, 0.00019716685605518925], [0.01243751399802008, 0.9875624860019798], [0.9553816216270049, 0.04461837837299504], [2.4227640566412854e-05, 0.9999757723594337], [0.8456203774946216, 0.15437962250537832], [0.986226743689511, 0.013773256310489026], [0.9962865964111541, 0.0037134035888459487], [2.5003001072002806e-06, 0.9999974996998928], [0.0014604073862683924, 0.9985395926137316], [0.005385377441153007, 0.994614622558847], [0.9999045447604266, 9.545523957351946e-05], [0.00607636474801852, 0.9939236352519815], [0.02682556166229935, 0.9731744383377008], [0.9999997313292596, 2.686707403346012e-07], [0.9965987878607518, 0.003401212139248078], [0.9999662479203901, 3.3752079609860735e-05], [0.9999620282089584, 3.7971791041645266e-05], [0.00033533019510215, 0.9996646698048979], [0.9999999708224101, 2.9177589790691687e-08], [0.999999970110996, 2.9889004175856684e-08], [0.998165944635484, 0.0018340553645159405], [0.00025347869135112507, 0.9997465213086488], [3.973569231946586e-05, 0.9999602643076806], [3.7840453293009054e-07, 0.9999996215954671], [0.9999967636399187, 3.2363600812546587e-06], [0.9999604566744583, 3.95433255417835e-05], [0.04936604742253036, 0.9506339525774696], [0.9977954403323652, 0.0022045596676347483], [0.0003935447442766159, 0.9996064552557233], [0.9999574004560845, 4.259954391547377e-05], [0.9770319284908547, 0.022968071509145167], [0.9999998927786691, 1.0722133096376656e-07], [0.9926277771422537, 0.0073722228577462875], [0.0010994986129218706, 0.9989005013870782], [0.9991003027961228, 0.0008996972038771442], [0.012053495150498136, 0.9879465048495019], [0.00039041189963198985, 0.999609588100368], [9.104961276732777e-07, 0.9999990895038724], [0.9991027858147775, 0.0008972141852225685], [7.145608821481333e-05, 0.9999285439117852], [0.0234980371458945, 0.9765019628541056], [0.9999835942195474, 1.6405780452535643e-05], [0.9993818928499069, 0.0006181071500931738], [0.9996292716956217, 0.0003707283043782959], [0.9940236734906632, 0.005976326509336702], [0.9895880733296737, 0.010411926670326269], [7.290559114994967e-06, 0.999992709440885], [0.9929958535303687, 0.0070041464696313765], [1.5868522093652875e-05, 0.9999841314779063], [6.646080643166759e-05, 0.9999335391935684], [2.937205946442236e-06, 0.9999970627940536], [0.9999583404278805, 4.165957211946496e-05], [0.0001845129157985035, 0.9998154870842014], [0.9999611750893571, 3.882491064293725e-05], [0.999992809837821, 7.190162178882684e-06], [4.470483209008426e-05, 0.9999552951679099], [0.5186874548483447, 0.4813125451516553], [7.507953619246603e-07, 0.9999992492046381], [7.389663451778934e-06, 0.9999926103365482], [7.147397804072047e-08, 0.9999999285260218], [0.9997242479308083, 0.00027575206919181665], [0.14654967734292024, 0.8534503226570798], [0.999999992970357, 7.029642983656528e-09], [0.013050693551400795, 0.9869493064485992], [0.0069830585578819476, 0.993016941442118], [0.9973457913754739, 0.002654208624526229], [0.00010995503208012016, 0.9998900449679199], [0.007706611112067635, 0.9922933888879323], [0.9999987952991272, 1.2047008729647109e-06], [0.003376284296294712, 0.9966237157037053], [0.9999785420516998, 2.145794830027782e-05], [0.9995173663416748, 0.00048263365832515204], [0.9999995868238739, 4.131761262028048e-07], [0.9999511277254663, 4.887227453360921e-05], [0.9997100273363041, 0.0002899726636959239], [0.9981331435027814, 0.001866856497218626], [0.9991431040401758, 0.0008568959598240865], [0.0037951147271928307, 0.9962048852728072], [0.007459239701542309, 0.9925407602984577], [0.9971680004756671, 0.002831999524332866], [0.0004011912661665418, 0.9995988087338336], [0.9955188242270623, 0.0044811757729376145], [0.9718241611817034, 0.02817583881829645], [0.9856921809722624, 0.014307819027737588], [0.999445813455681, 0.0005541865443191081], [0.999997554872864, 2.44512713605485e-06], [0.9999997670866159, 2.3291338406243904e-07], [0.9999990430622111, 9.56937788991719e-07], [0.00846654516093861, 0.9915334548390614], [0.9952514482094477, 0.004748551790552345], [0.9999971922935421, 2.807706457924883e-06], [0.9915779084739481, 0.008422091526051851], [0.0007943635327026255, 0.9992056364672974], [0.0010801807776943254, 0.9989198192223057], [1.780808263617614e-07, 0.9999998219191736], [0.9987820184456969, 0.0012179815543030665], [0.5599533086041312, 0.4400466913958688], [5.001906172524256e-05, 0.9999499809382747], [6.052614486843928e-07, 0.9999993947385514], [0.9999794484310116, 2.055156898836282e-05], [0.9998320076655977, 0.00016799233440220547], [0.005569779581883357, 0.9944302204181166], [0.00038709435284929226, 0.9996129056471507], [0.9999999764849637, 2.351503634513659e-08], [0.00010178994477857641, 0.9998982100552214], [0.9976369386547232, 0.0023630613452766966], [0.9012814452238254, 0.09871855477617474], [0.000427853686666294, 0.9995721463133337], [0.7840844877661783, 0.2159155122338217], [0.9999287900685053, 7.120993149472768e-05], [3.781342239712315e-06, 0.9999962186577602], [1.8471100136327304e-09, 0.99999999815289], [6.007863968156343e-07, 0.9999993992136031], [0.0108713857178676, 0.9891286142821324], [0.988376408098457, 0.011623591901543025], [0.9998876356684708, 0.00011236433152924942], [8.669880101353796e-05, 0.9999133011989865], [0.9999926697782712, 7.3302217288113625e-06], [0.00014515471948325077, 0.9998548452805168], [4.4987312812420956e-07, 0.9999995501268719], [0.9999077945236203, 9.220547637958594e-05], [0.00011125751938993363, 0.9998887424806101], [0.9996200971193513, 0.0003799028806487461], [0.999764414134745, 0.00023558586525496987], [1.1259679132248526e-06, 0.9999988740320869], [0.033763203969416185, 0.9662367960305838], [4.226100478629166e-08, 0.9999999577389952], [0.9994875675211451, 0.0005124324788548602], [0.0005076007030581052, 0.9994923992969419], [0.9999969449892018, 3.0550107981517696e-06], [0.9964835770817823, 0.003516422918217722], [0.0098673443518095, 0.9901326556481904], [0.9996323427636489, 0.000367657236351067], [0.9613059823837733, 0.03869401761622666], [0.9999633901005714, 3.6609899428500145e-05], [0.9999793408504409, 2.0659149559037487e-05], [5.350416059292105e-06, 0.9999946495839407], [0.4368107029444168, 0.5631892970555832], [0.9866388338920817, 0.013361166107918265], [0.0015382859727199425, 0.99846171402728], [0.9999529072736691, 4.709272633090716e-05], [0.9999994211820031, 5.788179968765164e-07], [0.9999983027765105, 1.697223489614449e-06], [0.9999145420793829, 8.545792061712468e-05], [0.0003664189198289942, 0.999633581080171], [0.9999933825887206, 6.6174112794114245e-06], [0.040712812638271346, 0.9592871873617287], [0.9719630305419868, 0.028036969458013157], [0.9999710070968612, 2.899290313880939e-05], [0.0028644110506484155, 0.9971355889493515], [0.0002455349329017017, 0.9997544650670983], [0.02385212275771699, 0.9761478772422829], [0.41792894376731643, 0.5820710562326836], [0.99999851872889, 1.4812711099308926e-06], [0.027424233708889682, 0.9725757662911102], [0.9999742313486755, 2.5768651324509058e-05], [4.096253033321685e-06, 0.9999959037469666], [0.9908883406377497, 0.009111659362250397], [0.9999980250221028, 1.974977897243091e-06], [8.648601465560129e-05, 0.9999135139853443], [0.9834687274536856, 0.016531272546314306], [0.9968314019187938, 0.0031685980812061632], [0.974805943175988, 0.025194056824011976]]}, {"iter": 24, "mu": [44.39754029560182, 69.7541735302944], "sigma": [6.171231597488835, 6.134437900942755], "pi": [0.5394501200647932, 0.4605498799352068], "ll": -854.134, "r": [[0.9990891721389393, 0.0009108278610606009], [0.017472222043789825, 0.9825277779562102], [0.0010243611151837895, 0.9989756388848162], [0.9970477826763857, 0.002952217323614187], [0.9999896832409151, 1.0316759084873759e-05], [5.129508495244297e-06, 0.9999948704915047], [0.9998627197356086, 0.00013728026439142652], [0.07103892109745477, 0.9289610789025452], [0.9999675668402953, 3.243315970473662e-05], [0.0024427465836063295, 0.9975572534163937], [0.9999998970693929, 1.0293060711858355e-07], [3.560462569941736e-05, 0.9999643953743006], [0.9903243790196059, 0.009675620980394182], [0.9999423909626699, 5.760903733000181e-05], [0.9998507997759157, 0.00014920022408419553], [0.0013039491323517114, 0.9986960508676482], [0.04821891697184375, 0.9517810830281563], [0.9974312955032467, 0.0025687044967533635], [0.9999982174101291, 1.7825898708932752e-06], [0.9999740768996522, 2.592310034784535e-05], [0.9991778130053668, 0.0008221869946330671], [0.9999918950360335, 8.104963966547317e-06], [2.91853501026756e-07, 0.999999708146499], [0.9999974486249411, 2.5513750589429473e-06], [0.02780790928430699, 0.972192090715693], [7.446523514670268e-06, 0.9999925534764853], [0.0027279589178037214, 0.9972720410821964], [3.815350965689592e-05, 0.9999618464903431], [0.9999975332601201, 2.4667398799201975e-06], [0.9999546814726189, 4.531852738102473e-05], [0.0002622839721493671, 0.9997377160278507], [1.0173932522359633e-06, 0.9999989826067477], [1.6200315063205333e-05, 0.9999837996849368], [0.9994050086606626, 0.0005949913393373127], [0.00021592745377537246, 0.9997840725462247], [0.00010614593045644195, 0.9998938540695436], [0.9732601541237963, 0.026739845876203712], [5.4913197716053864e-05, 0.999945086802284], [0.9822553227484764, 0.017744677251523656], [0.0007838936630221712, 0.9992161063369779], [0.0014652681995032518, 0.9985347318004967], [2.184777073792838e-07, 0.9999997815222926], [0.9999853782102429, 1.4621789757007698e-05], [0.00012569743316601743, 0.999874302566834], [0.0009786606937716694, 0.9990213393062284], [0.0010049133278840492, 0.998995086672116], [0.9999999025120845, 9.74879154857683e-08], [6.045219027651525e-05, 0.9999395478097234], [0.9924923731140591, 0.0075076268859408666], [0.9999984886804052, 1.5113195947256355e-06], [0.00010172560207311485, 0.9998982743979269], [0.9013514611822809, 0.09864853881771903], [1.6737665463615188e-05, 0.9999832623345363], [0.9999746237033172, 2.5376296682811957e-05], [0.99869458537748, 0.0013054146225200312], [0.0387437226107184, 0.9612562773892815], [0.9999997982789313, 2.017210687834449e-07], [0.9998062140145259, 0.00019378598547416375], [0.012562936726615988, 0.987437063273384], [0.9558326452707638, 0.04416735472923613], [2.465529177254498e-05, 0.9999753447082275], [0.8468955871433947, 0.15310441285660523], [0.9863840323914732, 0.013615967608526807], [0.9963345726983791, 0.0036654273016208183], [2.555719254731474e-06, 0.9999974442807453], [0.001477843933525727, 0.9985221560664742], [0.005443196889353501, 0.9945568031106465], [0.9999063021812559, 9.369781874418571e-05], [0.006141002512615175, 0.9938589974873848], [0.027081033206742967, 0.972918966793257], [0.9999997398999858, 2.6010001410347974e-07], [0.9966430954850263, 0.0033569045149736843], [0.9999669357024625, 3.30642975374933e-05], [0.9999627931675199, 3.720683248023263e-05], [0.00033990326737380296, 0.9996600967326262], [0.9999999719450829, 2.8054917022445723e-08], [0.9999999712587824, 2.8741217727764123e-08], [0.9981912764354386, 0.0018087235645614], [0.000257028487567444, 0.9997429715124325], [4.0403147962155406e-05, 0.999959596852038], [3.884961359466129e-07, 0.999999611503864], [0.9999968461081831, 3.1538918169140844e-06], [0.9999612501551857, 3.8749844814441484e-05], [0.049812957926663515, 0.9501870420733365], [0.9978253611930323, 0.002174638806967676], [0.00039883166085518063, 0.9996011683391448], [0.9999582490900195, 4.1750909980598325e-05], [0.9772813920443079, 0.022718607955692284], [0.9999998964805418, 1.0351945823353491e-07], [0.9927170906065175, 0.007282909393482534], [0.0011129537987076086, 0.9988870462012923], [0.9991136082860703, 0.0008863917139296483], [0.012175325864493488, 0.9878246741355065], [0.00039566065164007707, 0.99960433934836], [9.327932157565596e-07, 0.9999990672067842], [0.99911605812582, 0.0008839418741799341], [7.258822944838979e-05, 0.9999274117705517], [0.023724094007228552, 0.9762759059927714], [0.99998395267868, 1.604732131993189e-05], [0.9993913724469741, 0.0006086275530258894], [0.9996352476903253, 0.0003647523096746457], [0.9940975143845708, 0.005902485615429204], [0.9897101817239528, 0.010289818276047268], [7.435758880373456e-06, 0.9999925642411197], [0.9930811162690927, 0.006918883730907273], [1.6160793383240088e-05, 0.9999838392066167], [6.752139784115045e-05, 0.9999324786021588], [3.0012740431039127e-06, 0.9999969987259568], [0.9999591721416952, 4.082785830480344e-05], [0.00018717689462744276, 0.9998128231053726], [0.999961955545517, 3.804445448293406e-05], [0.9999929798156273, 7.020184372738839e-06], [4.544696635381405e-05, 0.9999545530336462], [0.5209955120775933, 0.47900448792240663], [7.695314288807633e-07, 0.9999992304685711], [7.536637617994296e-06, 0.999992463362382], [7.370538727390917e-08, 0.9999999262946127], [0.9997288234712153, 0.0002711765287847901], [0.14770305761052446, 0.8522969423894754], [0.9999999932733797, 6.726620268122521e-09], [0.013181835276704298, 0.9868181647232958], [0.007056561954357623, 0.9929434380456424], [0.9973811867674764, 0.0026188132325234994], [0.00011162463869557866, 0.9998883753613044], [0.007787131311218605, 0.9922128686887814], [0.9999988289203332, 1.171079666663008e-06], [0.003413886273861479, 0.9965861137261386], [0.99997899892319, 2.1001076810075465e-05], [0.9995249485549162, 0.0004750514450837476], [0.9999995995157013, 4.0048429869932324e-07], [0.99995208837223, 4.7911627770109946e-05], [0.9997148152179026, 0.00028518478209746775], [0.9981588848345485, 0.0018411151654515437], [0.9991558363678419, 0.0008441636321580308], [0.0038369893525527924, 0.9961630106474472], [0.007537366365381609, 0.9924626336346184], [0.9972055359878279, 0.0027944640121720463], [0.0004065712211622227, 0.9995934287788378], [0.9955757065887691, 0.00442429341123087], [0.9721238276969091, 0.027876172303091015], [0.9858549785024967, 0.014145021497503301], [0.9994544033919839, 0.0005455966080162532], [0.9999976188220643, 2.3811779356944144e-06], [0.9999997746096336, 2.253903662485791e-07], [0.9999990703319913, 9.29668008603187e-07], [0.008554385602825771, 0.9914456143971743], [0.9953113976705857, 0.004688602329414302], [0.9999972647904782, 2.735209521770691e-06], [0.9916786737962952, 0.008321326203704902], [0.0008043693045013867, 0.9991956306954987], [0.001093420159314887, 0.9989065798406851], [1.831845587223794e-07, 0.9999998168154413], [0.9987995130560656, 0.001200486943934399], [0.5622390868335428, 0.4377609131664572], [5.0840162220144606e-05, 0.9999491598377798], [6.206860087828044e-07, 0.9999993793139913], [0.9999798878313199, 2.0112168680121096e-05], [0.999834933849813, 0.0001650661501870356], [0.005629424317199909, 0.9943705756828002], [0.0003923026607087796, 0.9996076973392912], [0.9999999774057757, 2.2594224234036023e-08], [0.00010334732810916592, 0.9998966526718909], [0.9976688001446624, 0.002331199855337608], [0.9021741099621823, 0.09782589003781762], [0.00043355685369440497, 0.9995664431463056], [0.7857080561417397, 0.21429194385826036], [0.9999301392610274, 6.98607389726527e-05], [3.861770688176936e-06, 0.9999961382293119], [1.9267867489356724e-09, 0.9999999980732132], [6.161079596478881e-07, 0.9999993838920403], [0.010982106321957234, 0.9890178936780428], [0.9885113129132166, 0.0114886870867834], [0.9998896716049673, 0.0001103283950326717], [8.804642673287705e-05, 0.9999119535732671], [0.9999928427505776, 7.157249422362755e-06], [0.00014729978115433332, 0.9998527002188458], [4.6167216931904434e-07, 0.9999995383278306], [0.999909497882661, 9.050211733903102e-05], [0.0001129449527879169, 0.9998870550472121], [0.9996262064009237, 0.0003737935990763207], [0.9997683839267676, 0.00023161607323243953], [1.1529731166340951e-06, 0.9999988470268834], [0.034078966876188846, 0.9659210331238112], [4.364581647073856e-08, 0.9999999563541836], [0.9994955710414684, 0.000504428958531748], [0.0005142605261884907, 0.9994857394738115], [0.9999970232553369, 2.9767446630162424e-06], [0.9965292420700895, 0.0034707579299104617], [0.009968560868186711, 0.9900314391318134], [0.9996382740713924, 0.0003617259286076442], [0.9617035969255959, 0.03829640307440415], [0.9999641302478038, 3.586975219611166e-05], [0.9999797823283422, 2.021767165782897e-05], [5.460334455671081e-06, 0.9999945396655444], [0.43907338522317507, 0.5609266147768249], [0.986791860891742, 0.013208139108257966], [0.001556570712999035, 0.998443429287001], [0.9999538362950874, 4.616370491277111e-05], [0.9999994384379629, 5.615620370943838e-07], [0.999998348683632, 1.6513163679796738e-06], [0.9999161325800111, 8.386741998892939e-05], [0.00037137447047376346, 0.9996286255295262], [0.9999935402608257, 6.459739174307683e-06], [0.04108770541717716, 0.9589122945828228], [0.9722613742773847, 0.027738625722615373], [0.9999716066791339, 2.839332086622509e-05], [0.0028967380486447387, 0.9971032619513553], [0.0002489839518909827, 0.999751016048109], [0.024081326188506662, 0.9759186738114932], [0.4201643612467764, 0.5798356387532235], [0.9999985592971924, 1.440702807646718e-06], [0.027684961619062025, 0.972315038380938], [0.9999747703747386, 2.5229625261492405e-05], [4.182685933579181e-06, 0.9999958173140663], [0.9909965524545796, 0.009003447545420377], [0.9999980777032508, 1.922296749218603e-06], [8.783065896218891e-05, 0.9999121693410379], [0.9836542174990943, 0.01634578250090566], [0.996872955824058, 0.0031270441759420208], [0.9750770194260591, 0.02492298057394104]]}, {"iter": 25, "mu": [44.39904273094385, 69.75594590357943], "sigma": [6.172569841868637, 6.1328296010395915], "pi": [0.5395142743985532, 0.46048572560144674], "ll": -854.134, "r": [[0.9990966858468269, 0.0009033141531731376], [0.017568971630372382, 0.9824310283696276], [0.0010314764346411424, 0.9989685235653588], [0.9970695561947485, 0.002930443805251504], [0.999989814926068, 1.0185073931920873e-05], [5.189172857892322e-06, 0.999994810827142], [0.9998640817954081, 0.00013591820459198732], [0.07138754148906036, 0.9286124585109397], [0.9999679374496003, 3.206255039970083e-05], [0.0024584950782859066, 0.997541504921714], [0.9999998990667511, 1.0093324888633646e-07], [3.594574764838363e-05, 0.9999640542523516], [0.9903882478246716, 0.00961175217532836], [0.9999430133463771, 5.69866536228724e-05], [0.9998522680544111, 0.00014773194558890257], [0.0013128165323067409, 0.9986871834676933], [0.04846493686554926, 0.9515350631344507], [0.9974504904292789, 0.0025495095707210656], [0.9999982442518391, 1.7557481607802708e-06], [0.99997437964363, 2.5620356369938888e-05], [0.9991846628179989, 0.0008153371820012105], [0.9999920009027707, 7.999097229252116e-06], [2.9634603158590183e-07, 0.9999997036539684], [0.9999974857868478, 2.5142131522878784e-06], [0.02795652186508949, 0.9720434781349104], [7.529972578155135e-06, 0.9999924700274219], [0.0027453866587787306, 0.9972546133412212], [3.851653668036098e-05, 0.9999614834633196], [0.9999975693022376, 2.4306977624655454e-06], [0.9999551826981818, 4.481730181808819e-05], [0.0002643497395106739, 0.9997356502604894], [1.03127764875508e-06, 0.9999989687223513], [1.6368261516907498e-05, 0.999983631738483], [0.9994101233534132, 0.0005898766465867445], [0.00021766006995668633, 0.9997823399300433], [0.00010705850253105818, 0.999892941497469], [0.9734201043778196, 0.02657989562218048], [5.541707628335308e-05, 0.9999445829237166], [0.9823658951780424, 0.017634104821957534], [0.0007894704401080693, 0.9992105295598919], [0.0014751323746030442, 0.9985248676253969], [2.219344242856417e-07, 0.9999997780655757], [0.9999855586970778, 1.4441302922138163e-05], [0.00012676034989494287, 0.999873239650105], [0.000985486153682769, 0.9990145138463172], [0.0010119054303405564, 0.9989880945696595], [0.9999999044126227, 9.55873773442076e-08], [6.100162476714638e-05, 0.9999389983752328], [0.9925431195073611, 0.007456880492638998], [0.9999985117861311, 1.4882138689909139e-06], [0.00010260383170719765, 0.9998973961682928], [0.9018510658598867, 0.09814893414011332], [1.6910615817375096e-05, 0.9999830893841827], [0.9999749206755174, 2.5079324482613862e-05], [0.9987049882129526, 0.0012950117870473858], [0.03894525254867147, 0.9610547474513286], [0.9999998019725295, 1.9802747058781658e-07], [0.9998080727596348, 0.0001919272403652244], [0.01263423267138048, 0.9873657673286196], [0.9560827864708278, 0.043917213529172265], [2.490035537947806e-05, 0.9999750996446205], [0.8476055069767147, 0.15239449302328534], [0.9864710628509076, 0.013528937149092495], [0.996361062845153, 0.003638937154846949], [2.5875776734196995e-06, 0.9999974124223265], [0.0014877854339739316, 0.998512214566026], [0.005476105395574808, 0.9945238946044251], [0.9999072673340724, 9.273266592756894e-05], [0.006177785379774394, 0.9938222146202256], [0.027226062455601188, 0.9727739375443988], [0.9999997445578489, 2.554421510809035e-07], [0.996667556730414, 0.003332443269586089], [0.9999673128153227, 3.268718467731753e-05], [0.9999632126747378, 3.6787325262223126e-05], [0.0003425153517794686, 0.9996574846482206], [0.9999999725521538, 2.744784635068416e-08], [0.9999999718794689, 2.812053111040398e-08], [0.9982052487346442, 0.001794751265355747], [0.00025905677502126583, 0.9997409432249788], [4.0785388253911914e-05, 0.9999592146117461], [3.9431520108079875e-07, 0.9999996056847988], [0.9999968911461931, 3.108853807013884e-06], [0.9999616853319484, 3.831466805153544e-05], [0.05006634821314327, 0.9499336517868567], [0.9978418691563504, 0.0021581308436495954], [0.0004018508992095181, 0.9995981491007905], [0.999958714569535, 4.128543046498352e-05], [0.9774195534882052, 0.022580446511794725], [0.9999998984883476, 1.015116523852206e-07], [0.9927664577373929, 0.007233542262607136], [0.0011206280602632597, 0.9988793719397367], [0.9991209396100178, 0.0008790603899821654], [0.012244583405867508, 0.9877554165941325], [0.00039865812411434443, 0.9996013418758857], [9.456312846383186e-07, 0.9999990543687154], [0.9991233711389149, 0.0008766288610852107], [7.323611196083503e-05, 0.9999267638880391], [0.023852456152418072, 0.9761475438475818], [0.999984148993378, 1.5851006622061275e-05], [0.999396592865769, 0.0006034071342308926], [0.9996385362326671, 0.00036146376733289673], [0.9941383156087998, 0.005861684391200144], [0.9897777140767475, 0.010222285923252566], [7.51909936965603e-06, 0.9999924809006303], [0.9931282405399322, 0.006871759460067794], [1.6328371153907772e-05, 0.9999836716288462], [6.812838945230693e-05, 0.9999318716105476], [3.0380955337039606e-06, 0.9999969619044663], [0.9999596283244563, 4.0371675543762975e-05], [0.00018869962707743435, 0.9998113003729227], [0.9999623835667084, 3.761643329153078e-05], [0.9999930727763799, 6.927223619987242e-06], [4.5871910632396666e-05, 0.9999541280893676], [0.5222896838873246, 0.4777103161126755], [7.803225669174339e-07, 0.9999992196774331], [7.6209949723167305e-06, 0.9999923790050277], [7.499604859889129e-08, 0.9999999250039513], [0.999731340266817, 0.0002686597331829053], [0.1483549436649064, 0.8516450563350936], [0.999999993436651, 6.5633490569923275e-09], [0.013256376403942102, 0.9867436235960579], [0.007098381460773763, 0.9929016185392262], [0.997400720516172, 0.0025992794838279954], [0.0001125795874067101, 0.9998874204125934], [0.007832936341087273, 0.9921670636589127], [0.9999988472477536, 1.152752246536873e-06], [0.003435301654985959, 0.996564698345014], [0.9999792492447871, 2.0750755212931535e-05], [0.9995291225864549, 0.00047087741354509343], [0.9999996064194355, 3.9358056447502067e-07], [0.9999526154045826, 4.7384595417432094e-05], [0.9997174490065415, 0.00028255099345858803], [0.9981730833891727, 0.0018269166108273829], [0.9991628513841251, 0.0008371486158749741], [0.0038608343315837605, 0.9961391656684162], [0.007581811947967555, 0.9924181880520325], [0.9972262528116775, 0.0027737471883223894], [0.0004096435199645373, 0.9995903564800355], [0.9956071232321321, 0.004392876767867937], [0.9722898601728508, 0.027710139827149288], [0.9859450630886566, 0.014054936911343411], [0.9994591331261402, 0.0005408668738597761], [0.9999976537283984, 2.346271601525084e-06], [0.9999997786968651, 2.213031349209514e-07], [0.9999990851904966, 9.148095032417352e-07], [0.008604347831223054, 0.991395652168777], [0.9953445112518738, 0.004655488748126135], [0.9999973043726252, 2.6956273747714036e-06], [0.991734382813253, 0.008265617186747053], [0.0008100784737070766, 0.9991899215262929], [0.001100971502888313, 0.9988990284971117], [1.8613146664751983e-07, 0.9999998138685333], [0.9988091568216546, 0.0011908431783454207], [0.5635196998668387, 0.4364803001331613], [5.131025609354882e-05, 0.9999486897439065], [6.295730534954151e-07, 0.9999993704269465], [0.999980128563467, 1.9871436533040994e-05], [0.9998365422346533, 0.00016345776534667256], [0.00566337007735178, 0.9943366299226482], [0.00039527706698899793, 0.999604722933011], [0.9999999779034322, 2.2096567797636974e-08], [0.00010423817352006225, 0.9998957618264799], [0.9976863805979581, 0.0023136194020418823], [0.9026702564358932, 0.09732974356410684], [0.0004368134730270219, 0.9995631865269731], [0.7866133020990603, 0.2133866979009397], [0.9999308798893143, 6.912011068585202e-05], [3.907977634950637e-06, 0.999996092022365], [1.9732497838312113e-09, 0.9999999980267502], [6.249357712219054e-07, 0.9999993750642289], [0.01104505829448814, 0.9889549417055118], [0.9885859362023706, 0.011414063797629449], [0.99989078999038, 0.00010921000962007585], [8.881743939576181e-05, 0.9999111825606042], [0.9999929373521796, 7.0626478203652205e-06], [0.0001485262566897747, 0.9998514737433102], [4.684737519576297e-07, 0.999999531526248], [0.999910433296324, 8.956670367594492e-05], [0.00011391008384190493, 0.9998860899161581], [0.99962956840962, 0.0003704315903800023], [0.9997705670235271, 0.00022943297647284739], [1.1685166636029853e-06, 0.9999988314833365], [0.03425814324987105, 0.9657418567501289], [4.444764418326736e-08, 0.9999999555523558], [0.9994999773867427, 0.0005000226132572987], [0.0005180626246125871, 0.9994819373753874], [0.9999970659939699, 2.9340060300929287e-06], [0.996554453952669, 0.003445546047331061], [0.01002611778506741, 0.9899738822149325], [0.9996415379833177, 0.0003584620166822367], [0.9619240459500952, 0.038075954049904825], [0.9999645361249269, 3.5463875073190066e-05], [0.9999800242007894, 1.9975799210680425e-05], [5.5234520151158096e-06, 0.9999944765479849], [0.4403442016446193, 0.5596557983553807], [0.9868765288062752, 0.013123471193724704], [0.0015669951238708635, 0.9984330048761291], [0.9999543459475496, 4.5654052450357934e-05], [0.999999447830827, 5.521691729859447e-07], [0.9999983737246888, 1.6262753111542639e-06], [0.9999170059157056, 8.299408429427441e-05], [0.0003742047181654822, 0.9996257952818345], [0.9999936264791718, 6.373520828227898e-06], [0.04130035254618347, 0.9586996474538165], [0.9724266722064214, 0.02757332779357854], [0.9999719353521106, 2.8064647889506277e-05], [0.002915153248049128, 0.9970848467519509], [0.00025095473294947705, 0.9997490452670506], [0.024211471511275513, 0.9757885284887244], [0.4214203418405194, 0.5785796581594806], [0.9999985814203527, 1.418579647291764e-06], [0.027832968716176937, 0.972167031283823], [0.9999750657966783, 2.4934203321757304e-05], [4.2323367047569386e-06, 0.9999957676632952], [0.991056386036101, 0.00894361396389894], [0.9999981064475504, 1.8935524495843212e-06], [8.859996820086598e-05, 0.9999114000317991], [0.9837568854176261, 0.016243114582373944], [0.9968958943586952, 0.003104105641304832], [0.9752271777479582, 0.024772822252041738]]}, {"iter": 26, "mu": [44.399885689271656, 69.75693741686025], "sigma": [6.1733220464277965, 6.131931345029643], "pi": [0.539550215712746, 0.4604497842872539], "ll": -854.134, "r": [[0.999100855029964, 0.000899144970036087], [0.017623592585101516, 0.9823764074148985], [0.0010355026224119503, 0.998964497377588], [0.9970816495165435, 0.002918350483456431], [0.9999898877161675, 1.0112283832596653e-05], [5.223062647059885e-06, 0.9999947769373528], [0.9998648364038735, 0.00013516359612644375], [0.07158403412943729, 0.9284159658705626], [0.9999681425210567, 3.185747894327526e-05], [0.002467400706292334, 0.9975325992937076], [0.9999999001653073, 9.983469273156502e-08], [3.6139221961420456e-05, 0.9999638607780386], [0.9904237585935804, 0.00957624140641956], [0.999943357906278, 5.6642093722049446e-05], [0.9998530815664807, 0.00014691843351933776], [0.0013178332683000172, 0.9986821667317], [0.04860367468160964, 0.9513963253183904], [0.9974611503202496, 0.002538849679750393], [0.9999982590630307, 1.7409369693193072e-06], [0.999974547129387, 2.5452870613027305e-05], [0.9991884633052283, 0.0008115366947717434], [0.9999920594081481, 7.940591851854423e-06], [2.98904426588267e-07, 0.9999997010955735], [0.9999975063002977, 2.4936997022040023e-06], [0.028040382811717855, 0.9719596171882822], [7.57735813292957e-06, 0.999992422641867], [0.0027552410671243897, 0.9972447589328757], [3.8722424678084514e-05, 0.9999612775753218], [0.999997589196875, 2.4108031249867398e-06], [0.9999554601257041, 4.453987429583409e-05], [0.0002655197535337128, 0.9997344802464664], [1.0391750572268373e-06, 0.9999989608249428], [1.6463570900865913e-05, 0.9999835364290992], [0.9994129603988016, 0.0005870396011984428], [0.00021864152381204856, 0.999781358476188], [0.00010757568856832791, 0.9998924243114317], [0.9735091282242854, 0.026490871775714596], [5.5702773114375744e-05, 0.9999442972268856], [0.9824274095033461, 0.01757259049665393], [0.0007926266415003364, 0.9992073733584997], [0.0014807125683376293, 0.9985192874316624], [2.2390352468311424e-07, 0.9999997760964753], [0.9999856584951327, 1.4341504867353595e-05], [0.00012736267109931471, 0.9998726373289006], [0.0009893484497646378, 0.9990106515502354], [0.0010158619497247527, 0.9989841380502753], [0.9999999054578567, 9.454214333181403e-08], [6.131313049199107e-05, 0.999938686869508], [0.9925713276813838, 0.007428672318616153], [0.9999985245336054, 1.475466394591733e-06], [0.00010310156935563301, 0.9998968984306443], [0.9021296438099465, 0.09787035619005342], [1.700876250585264e-05, 0.9999829912374942], [0.9999750849650442, 2.4915034955867012e-05], [0.9987107621973301, 0.001289237802669892], [0.03905893174726961, 0.9609410682527303], [0.9999998040056904, 1.959943095766617e-07], [0.9998091028357677, 0.0001908971642321886], [0.012674495982564185, 0.9873255040174358], [0.9562220927712889, 0.04377790722871113], [2.503938532987993e-05, 0.9999749606146702], [0.8480017130064774, 0.1519982869935226], [0.9865194672502838, 0.013480532749716221], [0.9963757785461667, 0.003624221453833374], [2.6056839535890695e-06, 0.9999973943160463], [0.0014934093361862683, 0.9985065906638138], [0.00549470328103608, 0.9945052967189638], [0.99990780187699, 9.21981230098689e-05], [0.00619857077589184, 0.9938014292241082], [0.02730790368575456, 0.9726920963142455], [0.9999997471225666, 2.5287743332938864e-07], [0.9966811443283783, 0.003318855671621739], [0.9999675214889847, 3.247851101535198e-05], [0.99996344483126, 3.655516874004899e-05], [0.00034399452720465626, 0.9996560054727953], [0.9999999728854857, 2.7114514211559828e-08], [0.9999999722202884, 2.7779711668911277e-08], [0.9982130059858677, 0.0017869940141322775], [0.0002602055770187016, 0.9997397944229813], [4.100216401296371e-05, 0.9999589978359871], [3.976280874377481e-07, 0.9999996023719125], [0.9999969160126211, 3.0839873789710612e-06], [0.9999619261686297, 3.8073831370246103e-05], [0.050209236447846896, 0.9497907635521531], [0.9978510355732806, 0.002148964426719428], [0.00040356045069353205, 0.9995964395493064], [0.9999589721932621, 4.10278067379019e-05], [0.9774964364083903, 0.022503563591609748], [0.9999998995926579, 1.0040734217010731e-07], [0.9927938984713929, 0.007206101528607117], [0.0011249702685990222, 0.9988750297314011], [0.9991250075027204, 0.0008749924972795679], [0.012283696672931985, 0.987716303327068], [0.0004003553606491287, 0.9995996446393508], [9.529341249896858e-07, 0.999999047065875], [0.9991274288624576, 0.0008725711375422864], [7.360338634319217e-05, 0.9999263966136568], [0.023924902097799572, 0.9760750979022005], [0.9999842575525512, 1.5742447448866637e-05], [0.9993994886090267, 0.0006005113909732071], [0.999640359614785, 0.0003596403852149887], [0.9941609907172733, 0.005839009282726706], [0.9898152639332944, 0.010184736066705662], [7.566423325878794e-06, 0.9999924335766741], [0.9931544333680953, 0.00684556663190474], [1.6423471485139385e-05, 0.9999835765285149], [6.847250085963624e-05, 0.9999315274991404], [3.0590196592504796e-06, 0.9999969409803408], [0.9999598807978797, 4.011920212031942e-05], [0.00018956227515091632, 0.999810437724849], [0.9999626204395178, 3.737956048216631e-05], [0.9999931241424248, 6.875857575160268e-06], [4.611288440763192e-05, 0.9999538871155924], [0.5230148899091714, 0.4769851100908285], [7.86462118514898e-07, 0.9999992135378815], [7.668895834809637e-06, 0.9999923311041653], [7.573211985184935e-08, 0.9999999242678801], [0.999732735404935, 0.00026726459506503384], [0.14872188595989688, 0.8512781140401031], [0.9999999935261222, 6.4738777643239455e-09], [0.01329847053149938, 0.9867015294685006], [0.0071220102611181625, 0.9928779897388819], [0.9974115687473237, 0.0025884312526762757], [0.00011312077091030243, 0.9998868792290897], [0.007858814893266824, 0.9921411851067332], [0.9999988573562844, 1.1426437154954007e-06], [0.0034474087790988105, 0.9965525912209012], [0.9999793877029142, 2.0612297085784984e-05], [0.9995314374382436, 0.000468562561756428], [0.9999996102226812, 3.897773187864073e-07], [0.9999529071302266, 4.7092869773549254e-05], [0.9997189090576416, 0.0002810909423584511], [0.9981809663699602, 0.001819033630039696], [0.9991667436147155, 0.0008332563852846524], [0.0038743138020010492, 0.996125686197999], [0.007606923141894525, 0.9923930768581055], [0.9972377586992941, 0.0027622413007059553], [0.00041138309231274206, 0.9995886169076872], [0.9956245784994405, 0.004375421500559474], [0.9723822735823534, 0.02761772641764663], [0.9859951680108932, 0.014004831989106774], [0.9994617564563328, 0.0005382435436671949], [0.9999976729954055, 2.3270045944786675e-06], [0.9999997809470005, 2.190529995021549e-07], [0.9999990933836974, 9.066163025571128e-07], [0.008632572824222506, 0.9913674271757775], [0.9953629102721278, 0.004637089727872194], [0.9999973262236034, 2.673776396577121e-06], [0.9917653524478988, 0.008234647552101163], [0.0008133095446405544, 0.9991866904553595], [0.0011052442162201585, 0.9988947557837798], [1.8781046219150678e-07, 0.9999998121895378], [0.9988145091264367, 0.0011854908735633679], [0.5642369709136388, 0.4357630290863611], [5.157681168919691e-05, 0.9999484231883108], [6.346303041488603e-07, 0.9999993653696959], [0.9999802617122547, 1.9738287745261473e-05], [0.9998374334484875, 0.00016256655151246943], [0.005682553632641711, 0.9943174463673583], [0.00039696125279311715, 0.9996030387472069], [0.9999999781766071, 2.1823392802587258e-08], [0.00010474305564486362, 0.9998952569443552], [0.9976961431027462, 0.0023038568972538237], [0.9029469018942257, 0.09705309810577428], [0.0004386573283164804, 0.9995613426716835], [0.7871189578423249, 0.21288104215767498], [0.9999312899787635, 6.871002123651069e-05], [3.934229608167722e-06, 0.9999960657703918], [1.999869817124456e-09, 0.9999999980001302], [6.299593499754291e-07, 0.99999937004065], [0.011080613779066419, 0.9889193862209336], [0.9886274331644114, 0.011372566835588719], [0.999891409485202, 0.00010859051479802549], [8.92544554921211e-05, 0.9999107455445079], [0.9999929896258576, 7.010374142515818e-06], [0.00014922118560339962, 0.9998507788143967], [4.7234534964743216e-07, 0.9999995276546504], [0.9999109513532477, 8.904864675238906e-05], [0.00011445703338503029, 0.999885542966615], [0.9996314325634009, 0.0003685674365991067], [0.9997717770257041, 0.00022822297429588912], [1.1773567882716707e-06, 0.9999988226432117], [0.03435922831129379, 0.9656407716887062], [4.490520196672228e-08, 0.9999999550947981], [0.9995024211949903, 0.0004975788050097951], [0.0005202150695714769, 0.9994797849304285], [0.9999970895894852, 2.910410514774105e-06], [0.9965684589069216, 0.003431541093078367], [0.01005862890641347, 0.9899413710935865], [0.99964334769646, 0.00035665230354002347], [0.9620467940056624, 0.03795320599433759], [0.9999647607312879, 3.5239268712191955e-05], [0.9999801579809106, 1.9842019089399895e-05], [5.559301435139009e-06, 0.9999944406985648], [0.44105698179690156, 0.5589430182030983], [0.986923617805013, 0.013076382194986958], [0.0015728919868682862, 0.9984271080131316], [0.9999546280438807, 4.537195611938949e-05], [0.9999994530073092, 5.469926907713152e-07], [0.9999983875411773, 1.612458822625399e-06], [0.9999174895610448, 8.251043895523729e-05], [0.0003758073380207069, 0.9996241926619793], [0.9999936741158366, 6.3258841634828445e-06], [0.041420294305745474, 0.9585797056942545], [0.9725186762490118, 0.02748132375098824], [0.9999721171972245, 2.7882802775436673e-05], [0.002925565535512543, 0.9970744344644874], [0.0002520709882077818, 0.9997479290117922], [0.0242849227189847, 0.9757150772810154], [0.42212495219764545, 0.5778750478023545], [0.9999985936251266, 1.406374873411607e-06], [0.027916488391993503, 0.9720835116080065], [0.9999752292277291, 2.477077227095811e-05], [4.26054339448516e-06, 0.9999957394566055], [0.9910896510077728, 0.008910348992227172], [0.9999981223098336, 1.8776901663699801e-06], [8.90360195266994e-05, 0.9999109639804733], [0.9838139974550856, 0.016186002544914438], [0.9969086353649947, 0.0030913646350052603], [0.9753107450915726, 0.024689254908427376]]}, {"iter": 27, "mu": [44.400358238642795, 69.75749232963078], "sigma": [6.173744152777545, 6.131429090237081], "pi": [0.5395703470721808, 0.4604296529278192], "ll": -854.134, "r": [[0.9991031776429953, 0.0008968223570048127], [0.017654319511491958, 0.9823456804885081], [0.001037770467001944, 0.9989622295329981], [0.9970883902552913, 0.0029116097447087416], [0.9999899281802342, 1.0071819765671891e-05], [5.242192843395091e-06, 0.9999947578071565], [0.9998652564256072, 0.00013474357439278753], [0.07169446750330778, 0.9283055324966922], [0.9999682565868712, 3.174341312879464e-05], [0.002472415222232323, 0.9975275847777677], [0.9999999007742961, 9.922570382801833e-08], [3.624834436146811e-05, 0.9999637516556386], [0.9904435637178953, 0.009556436282104737], [0.9999435496126554, 5.645038734457519e-05], [0.9998535343920083, 0.00014646560799175848], [0.0013206587881255778, 0.9986793412118744], [0.04868167201435617, 0.9513183279856439], [0.9974670916843417, 0.002532908315658376], [0.9999982672885934, 1.7327114065161273e-06], [0.9999746402787436, 2.5359721256352676e-05], [0.9991905804225758, 0.0008094195774241767], [0.9999920919271814, 7.908072818584055e-06], [3.003506946713533e-07, 0.9999996996493052], [0.9999975176950293, 2.482304970762097e-06], [0.02808754597868697, 0.9719124540213131], [7.604101976667243e-06, 0.9999923958980234], [0.0027607895551581534, 0.9972392104448419], [3.8838545336214516e-05, 0.9999611614546637], [0.999997600247658, 2.3997523419196996e-06], [0.9999556144630386, 4.4385536961311565e-05], [0.0002661791423631153, 0.999733820857637], [1.0436364899677353e-06, 0.9999989563635101], [1.6517344305071868e-05, 0.9999834826556949], [0.9994145405844674, 0.0005854594155325522], [0.00021919468666909724, 0.9997808053133309], [0.00010786726296444558, 0.9998921327370356], [0.9735588077481485, 0.026441192251851518], [5.586388239443295e-05, 0.9999441361176056], [0.9824617288616229, 0.017538271138377217], [0.0007944046348572476, 0.9992055953651426], [0.0014838552892223376, 0.9985161447107777], [2.2501684632789035e-07, 0.9999997749831536], [0.9999857139829967, 1.4286017003295558e-05], [0.00012770221989288986, 0.9998722977801071], [0.000991524018164008, 0.999008475981836], [0.0010180905690300292, 0.99898190943097], [0.9999999060372643, 9.396273561538565e-08], [6.14887871464129e-05, 0.9999385112128535], [0.9925870579205707, 0.007412942079429273], [0.9999985316123751, 1.4683876249025386e-06], [0.00010338218397004193, 0.99989661781603], [0.9022852645946526, 0.09771473540534731], [1.706413595077495e-05, 0.9999829358640492], [0.9999751763358031, 2.4823664196819617e-05], [0.9987139793587831, 0.001286020641216866], [0.039122851051755836, 0.9608771489482442], [0.9999998051332963, 1.948667035302326e-07], [0.999809676276787, 0.00019032372321299936], [0.012697150011699972, 0.9873028499883001], [0.956299858922685, 0.04370014107731498], [2.51178120691452e-05, 0.9999748821879308], [0.8482231561214542, 0.15177684387854576], [0.9865464684128755, 0.01345353158712447], [0.996383981827186, 0.00361601817281403], [2.6159079555684565e-06, 0.9999973840920443], [0.0014965766623023123, 0.9985034233376976], [0.005505171561538067, 0.9944948284384618], [0.9999080993550692, 9.190064493079773e-05], [0.006210269700798781, 0.9937897302992011], [0.027353931711881035, 0.972646068288119], [0.9999997485452168, 2.5145478311156126e-07], [0.9966887184289414, 0.0033112815710586566], [0.999967637559539, 3.236244046110759e-05], [0.9999635739711834, 3.642602881650015e-05], [0.0003448280676924713, 0.9996551719323076], [0.9999999730700969, 2.6929903060546817e-08], [0.9999999724090496, 2.759095037921465e-08], [0.9982173288370856, 0.0017826711629145113], [0.0002608530163733484, 0.9997391469836266], [4.112442253629827e-05, 0.9999588755774638], [3.9950057325596236e-07, 0.9999996004994267], [0.9999969298269866, 3.0701730134045634e-06], [0.999962060139666, 3.7939860333860526e-05], [0.05028956521643905, 0.949710434783561], [0.9978561441413344, 0.0021438558586655545], [0.00040452375236503947, 0.9995954762476349], [0.9999591155077094, 4.088449229064537e-05], [0.9775393363560504, 0.02246066364394974], [0.999999900204839, 9.97951610610271e-08], [0.9928092005118222, 0.007190799488177722], [0.0011274160379198918, 0.9988725839620801], [0.9991272736597424, 0.000872726340257566], [0.012305703987873522, 0.9876942960121265], [0.00040131172602663335, 0.9995986882739734], [9.570598562900696e-07, 0.9999990429401437], [0.9991296893515584, 0.0008703106484415005], [7.381047572934178e-05, 0.9999261895242706], [0.02396564937395896, 0.9760343506260409], [0.9999843179144925, 1.5682085507433284e-05], [0.9994011015049983, 0.0005988984950017654], [0.9996413749814733, 0.00035862501852664333], [0.9941736339180248, 0.005826366081975165], [0.9898362069829808, 0.010163793017019264], [7.5931324212609446e-06, 0.9999924068675787], [0.9931690391465317, 0.006830960853468321], [1.64771269974534e-05, 0.9999835228730025], [6.86665352264364e-05, 0.9999313334647736], [3.0708339000310938e-06, 0.9999969291661001], [0.9999600212457133, 3.997875428688117e-05], [0.00019004850402730585, 0.9998099514959727], [0.9999627522043723, 3.7247795627775344e-05], [0.9999931526910121, 6.847308987826552e-06], [4.624878385763765e-05, 0.9999537512161424], [0.5234211377533085, 0.4765788622466915], [7.899309979340448e-07, 0.999999210069002], [7.695930367950095e-06, 0.9999923040696321], [7.614856265767756e-08, 0.9999999238514374], [0.999733512194978, 0.0002664878050220234], [0.14892796359482502, 0.8510720364051749], [0.9999999935756197, 6.424380362015984e-09], [0.013322154074222152, 0.9866778459257778], [0.007135308712259107, 0.9928646912877409], [0.9974176151389996, 0.002582384861000361], [0.00011342586839895349, 0.999886574131601], [0.00787337883785565, 0.9921266211621443], [0.9999988629687794, 1.1370312205718786e-06], [0.003454224991557478, 0.9965457750084425], [0.9999794647000421, 2.053529995791983e-05], [0.9995327266391767, 0.0004672733608233451], [0.9999996123329329, 3.8766706717340626e-07], [0.9999530694262161, 4.693057378396685e-05], [0.9997197220088987, 0.00028027799110130904], [0.9981853593220532, 0.0018146406779467954], [0.999168911865067, 0.0008310881349330908], [0.0038819022460822097, 0.9961180977539178], [0.007621055452294602, 0.9923789445477054], [0.9972441718397029, 0.0027558281602970466], [0.00041236330289895305, 0.999587636697101], [0.9956343098379544, 0.004365690162045564], [0.9724338460163359, 0.027566153983664052], [0.9860231183594586, 0.013976881640541484], [0.9994632175487849, 0.0005367824512150672], [0.9999976836973454, 2.3163026544760675e-06], [0.999999782195034, 2.178049659774129e-07], [0.9999990979321233, 9.020678766572224e-07], [0.008648456580604903, 0.9913515434193951], [0.995373168044311, 0.004626831955689076], [0.9999973383617803, 2.6616382197837527e-06], [0.9917826235241148, 0.008217376475885283], [0.0008151296959538316, 0.9991848703040462], [0.0011076508592483521, 0.9988923491407516], [1.8875985657220115e-07, 0.9999998112401435], [0.9988174912211328, 0.0011825087788671059], [0.5646386674755599, 0.43536133252444004], [5.172713151405842e-05, 0.999948272868486], [6.374880018759867e-07, 0.9999993625119981], [0.9999803357552192, 1.9664244780873793e-05], [0.9998379295484204, 0.00016207045157959292], [0.00569335140543414, 0.9943066485945659], [0.00039791026742996415, 0.99960208973257], [0.9999999783278766, 2.1672123420356872e-08], [0.00010502769641803062, 0.999894972303582], [0.9977015840551358, 0.0022984159448642097], [0.9031014418167156, 0.09689855818328433], [0.00043969627412763617, 0.9995603037258723], [0.7874017112177631, 0.21259828878223688], [0.9999315181655671, 6.848183443283745e-05], [3.949050323581876e-06, 0.9999960509496765], [2.014969340130579e-09, 0.9999999979850306], [6.327980319239404e-07, 0.9999993672019681], [0.011100620335333667, 0.9888993796646662], [0.9886505790380551, 0.011349420961944925], [0.9998917542662867, 0.00010824573371329462], [8.950085040047194e-05, 0.9999104991495995], [0.9999930186791969, 6.981320803143743e-06], [0.0001496129163987034, 0.9998503870836013], [4.7453341949871994e-07, 0.9999995254665804], [0.9999112396519977, 8.876034800230742e-05], [0.00011476538012397582, 0.9998852346198761], [0.9996324706457327, 0.00036752935426725736], [0.999772450686399, 0.0002275493136010602], [1.1823504650446862e-06, 0.999998817649535], [0.034416071013264014, 0.9655839289867361], [4.516415793617461e-08, 0.999999954835842], [0.999503782252225, 0.0004962177477749482], [0.0005214278139779665, 0.9994785721860221], [0.9999971026973772, 2.897302622858153e-06], [0.9965762657776118, 0.003423734222388177], [0.010076923329611224, 0.9899230766703888], [0.9996443554476314, 0.0003556445523685181], [0.9621153096775519, 0.037884690322448185], [0.9999648856690965, 3.511433090342757e-05], [0.9999802323751513, 1.976762484866457e-05], [5.579537234861013e-06, 0.9999944204627651], [0.44145647771720714, 0.5585435222827929], [0.9869498847630815, 0.013050115236918434], [0.0015762129713852938, 0.9984237870286148], [0.9999547849799563, 4.521502004379869e-05], [0.9999994558801224, 5.441198775586958e-07], [0.9999983952139777, 1.6047860221944845e-06], [0.999917758700054, 8.224129994595588e-05], [0.0003767104105915807, 0.9996232895894084], [0.9999937005904975, 6.2994095025025795e-06], [0.04148773222462761, 0.9585122677753724], [0.9725700200675158, 0.027429979932484076], [0.9999722183373081, 2.7781662691958096e-05], [0.0029314279847740595, 0.9970685720152259], [0.00025270009266420396, 0.9997472999073358], [0.02432623504256417, 0.9756737649574359], [0.4225199169458049, 0.5774800830541952], [0.9999986004023392, 1.399597660652317e-06], [0.02796345975626293, 0.9720365402437371], [0.9999753201207775, 2.4679879222652673e-05], [4.276467068926432e-06, 0.9999957235329312], [0.9911082029017256, 0.008891797098274269], [0.9999981311195186, 1.8688804814048835e-06], [8.928187072198364e-05, 0.999910718129278], [0.9838458592307385, 0.016154140769261367], [0.9969157373124721, 0.0030842626875279304], [0.975357377557589, 0.02464262244241098]]}, {"iter": 28, "mu": [44.40062301575914, 69.75780296847321], "sigma": [6.1739808020082245, 6.13114807598101], "pi": [0.5395816217176856, 0.46041837828231436], "ll": -854.134, "r": [[0.999104474472361, 0.0008955255276390388], [0.017671570156743855, 0.9823284298432561], [0.001039044599606409, 0.9989609554003935], [0.9970921550895792, 0.0029078449104207806], [0.9999899507463047, 1.0049253695335225e-05], [5.252953626224796e-06, 0.9999947470463738], [0.9998654908308319, 0.00013450916916818973], [0.07175643412165071, 0.9282435658783493], [0.9999683202200124, 3.1679779987619414e-05], [0.002475231939322087, 0.9975247680606779], [0.9999999011133898, 9.888661016520056e-08], [3.630969743565769e-05, 0.9999636903025644], [0.990454628924445, 0.009545371075554924], [0.999943656575359, 5.634342464105736e-05], [0.9998537871098084, 0.00014621289019157394], [0.0013222461501238502, 0.9986777538498762], [0.04872544548350136, 0.9512745545164987], [0.9974704099301108, 0.002529590069889129], [0.999998271873352, 1.7281266480176658e-06], [0.9999746922401275, 2.5307759872411982e-05], [0.9991917624827004, 0.0008082375172995371], [0.9999921100611596, 7.889938840448561e-06], [3.0116488692709976e-07, 0.9999996988351131], [0.9999975240469502, 2.4759530498145437e-06], [0.028114020214129034, 0.971885979785871], [7.619144042074941e-06, 0.9999923808559579], [0.0027639061288398563, 0.9972360938711601], [3.890383209275504e-05, 0.9999610961679072], [0.9999976064077809, 2.3935922190802188e-06], [0.9999557005700742, 4.4299429925721736e-05], [0.00026654971467915026, 0.9997334502853209], [1.0461471566447598e-06, 0.9999989538528433], [1.6547583432311502e-05, 0.9999834524165676], [0.9994154227843367, 0.0005845772156632691], [0.00021950557378493845, 0.9997804944262151], [0.00010803115816040561, 0.9998919688418396], [0.9735865730193786, 0.02641342698062134], [5.5954455780612464e-05, 0.9999440455442195], [0.9824809068406494, 0.01751909315935065], [0.0007954036163518851, 0.9992045963836481], [0.0014856208060085867, 0.9985143791939913], [2.2564366072584404e-07, 0.9999997743563394], [0.9999857449306986, 1.4255069301459672e-05], [0.00012789307465008683, 0.9998721069253499], [0.0009927463201957725, 0.9990072536798041], [0.001019342669269526, 0.9989806573307305], [0.9999999063598801, 9.364011997461538e-08], [6.158753674872197e-05, 0.9999384124632513], [0.9925958458217727, 0.0074041541782272294], [0.9999985355577217, 1.4644422782956388e-06], [0.00010353992009561854, 0.9998964600799044], [0.9023722897631526, 0.09762771023684737], [1.709527461009163e-05, 0.9999829047253899], [0.9999752273047309, 2.477269526911224e-05], [0.9987157758241527, 0.0012842241758472448], [0.0391587267650853, 0.9608412732349148], [0.999999805761324, 1.942386761169121e-07], [0.9998099963306574, 0.00019000366934257228], [0.012709869645179887, 0.98729013035482], [0.9563433298330859, 0.0436566701669141], [2.516191050422147e-05, 0.9999748380894958], [0.8483470252682955, 0.15165297473170447], [0.9865615556409674, 0.01343844435903271], [0.9963885637849585, 0.0036114362150414196], [2.6216600305444066e-06, 0.9999973783399694], [0.001498355998318421, 0.9985016440016815], [0.005511050563048994, 0.994488949436951], [0.9999082653546618, 9.173464533821544e-05], [0.006216839628289523, 0.9937831603717105], [0.027379768990360567, 0.9726202310096395], [0.9999997493376453, 2.5066235460721485e-07], [0.9966929488569622, 0.0033070511430377167], [0.9999677023113953, 3.229768860472143e-05], [0.9999636460163398, 3.635398366027388e-05], [0.00034529648575396514, 0.999654703514246], [0.9999999731728374, 2.6827162683779203e-08], [0.9999999725141007, 2.7485899295251694e-08], [0.9982197429236743, 0.001780257076325704], [0.0002612168747590143, 0.999738783125241], [4.119315930627744e-05, 0.9999588068406938], [4.0055461519642703e-07, 0.9999995994453849], [0.9999969375282339, 3.0624717660117807e-06], [0.9999621348808572, 3.7865119142856053e-05], [0.05033464652783464, 0.9496653534721653], [0.9978589971466458, 0.002141002853354201], [0.0004050650724360936, 0.9995949349275639], [0.9999591954631316, 4.080453686838189e-05], [0.9775633112349222, 0.022436688765077803], [0.9999999005457108, 9.945428918007647e-08], [0.9928177491198129, 0.007182250880187134], [0.0011287901074645908, 0.9988712098925353], [0.9991285389581543, 0.0008714610418456854], [0.012318060620805777, 0.9876819393791942], [0.0004018491492349214, 0.9995981508507651], [9.593816654513984e-07, 0.9999990406183346], [0.9991309514844214, 0.0008690485155787111], [7.39268912731441e-05, 0.9999260731087268], [0.02398852338542867, 0.9760114766145713], [0.9999843515815522, 1.5648418447783354e-05], [0.9994020019718551, 0.0005979980281448262], [0.9996419417786293, 0.0003580582213706956], [0.9941806967238828, 0.005819303276117233], [0.989847908167417, 0.01015209183258299], [7.608154947876125e-06, 0.9999923918450521], [0.9931771986627984, 0.006822801337201536], [1.650729984640972e-05, 0.9999834927001535], [6.877561362253606e-05, 0.9999312243863774], [3.0774803664299653e-06, 0.9999969225196336], [0.9999600996013677, 3.99003986323475e-05], [0.00019032178155997277, 0.99980967821844], [0.9999628257143851, 3.7174285614896886e-05], [0.99999316861022, 6.8313897800376465e-06], [4.6325187868161486e-05, 0.9999536748121319], [0.5236486721939684, 0.47635132780603157], [7.918832645819544e-07, 0.9999992081167354], [7.711135886017019e-06, 0.9999922888641141], [7.638311091485132e-08, 0.999999923616889], [0.9997339457812179, 0.0002660542187821709], [0.14904355019291105, 0.850956449807089], [0.9999999936031491, 6.396850993274228e-09], [0.013335451565519726, 0.9866645484344803], [0.0071427766340815884, 0.9928572233659184], [0.9974209920597706, 0.0025790079402294125], [0.00011359736309430213, 0.9998864026369056], [0.007881557198417566, 0.9921184428015823], [0.9999988660966345, 1.1339033654951243e-06], [0.0034580534349210735, 0.9965419465650789], [0.9999795076487116, 2.0492351288412682e-05], [0.9995334463443099, 0.0004665536556900909], [0.9999996135085447, 3.8649145528876957e-07], [0.999953159974868, 4.684002513204611e-05], [0.9997201757853453, 0.0002798242146547362], [0.9981878125676241, 0.0018121874323758255], [0.9991701224826647, 0.0008298775173352682], [0.003886164303871712, 0.9961138356961283], [0.007628991498985683, 0.9923710085010143], [0.9972477536517621, 0.0027522463482379006], [0.0004129141224983936, 0.9995870858775016], [0.9956397455722854, 0.004360254427714567], [0.9724626696431236, 0.02753733035687638], [0.9860387361428847, 0.01396126385711534], [0.9994640332422643, 0.000535966757735697], [0.9999976896629428, 2.3103370571963547e-06], [0.9999997828901629, 2.171098371164419e-07], [0.9999991004667736, 8.995332263483068e-07], [0.008657375851808513, 0.9913426241481914], [0.9953788979251006, 0.004621102074899333], [0.9999973451282796, 2.654871720288987e-06], [0.9917922725205431, 0.008207727479456844], [0.0008161523584110856, 0.9991838476415889], [0.0011090029524648726, 0.9988909970475351], [1.8929440840386536e-07, 0.9999998107055916], [0.9988191563892315, 0.0011808436107685534], [0.564863619379698, 0.43513638062030197], [5.1811640675129406e-05, 0.9999481883593249], [6.3909640107412e-07, 0.999999360903599], [0.9999803770555643, 1.962294443568131e-05], [0.9998382064245309, 0.00016179357546905582], [0.00569941539762047, 0.9943005846023795], [0.00039844356092867174, 0.9996015564390713], [0.9999999784120538, 2.1587946161846914e-08], [0.0001051876951312175, 0.9998948123048688], [0.9977046227439672, 0.0022953772560327457], [0.9031878621374683, 0.09681213786253177], [0.0004402800912172529, 0.9995597199087828], [0.7875599189332955, 0.21244008106670462], [0.9999316454891239, 6.835451087602398e-05], [3.957387622892946e-06, 0.9999960426123772], [2.0234859664929424e-09, 0.999999997976514], [6.34395731993356e-07, 0.9999993656042679], [0.011111853917410217, 0.9888881460825899], [0.9886635114010774, 0.01133648859892246], [0.9998919466703098, 0.00010805332969024592], [8.963935569532236e-05, 0.9999103606443047], [0.9999930348799574, 6.965120042629236e-06], [0.00014983309418820898, 0.9998501669058117], [4.75765041736741e-07, 0.9999995242349583], [0.9999114005278407, 8.859947215940299e-05], [0.00011493870077099012, 0.9998850612992289], [0.9996330501268157, 0.0003669498731842145], [0.9997728266930077, 0.0002271733069923445], [1.1851605509357194e-06, 0.9999988148394491], [0.03444797639227611, 0.965552023607724], [4.531003391539482e-08, 0.999999954689966], [0.9995045420832298, 0.0004954579167702345], [0.0005221092686473945, 0.9994778907313526], [0.9999971100046459, 2.8899953542208953e-06], [0.9965806262557176, 0.0034193737442824385], [0.010087195837876695, 0.9899128041621233], [0.9996449179924641, 0.00035508200753588565], [0.9621536074054892, 0.03784639259451086], [0.9999649553692581, 3.504463074183702e-05], [0.999980273871496, 1.9726128504031645e-05], [5.5909197411437225e-06, 0.9999944090802589], [0.4416802962326288, 0.5583197037673712], [0.9869645616067179, 0.01303543839328226], [0.001578078607139004, 0.9984219213928609], [0.9999548725373065, 4.5127462693466207e-05], [0.9999994574807451, 5.425192548794087e-07], [0.9999983994905313, 1.6005094687648117e-06], [0.9999179088813958, 8.209111860422607e-05], [0.00037721789326183397, 0.9996227821067382], [0.9999937153528773, 6.284647122669141e-06], [0.04152558196577811, 0.9584744180342218], [0.9725987158707314, 0.027401284129268566], [0.9999722747575785, 2.772524242130611e-05], [0.0029347208621833963, 0.9970652791378166], [0.00025305364934828043, 0.9997469463506518], [0.024349426135795642, 0.9756505738642044], [0.4227412119129712, 0.5772587880870287], [0.9999986041795539, 1.3958204460936752e-06], [0.027989826366763636, 0.9720101736332364], [0.9999753708231438, 2.462917685624877e-05], [4.2854246451440295e-06, 0.999995714575355], [0.991118567703194, 0.008881432296806036], [0.9999981360299751, 1.8639700249479728e-06], [8.942007045544777e-05, 0.9999105799295446], [0.9838636634154482, 0.01613633658455186], [0.9969197039495993, 0.0030802960504007003], [0.975383439215288, 0.02461656078471205]]}, {"iter": 29, "mu": [44.40077133480603, 69.75797688720094], "sigma": [6.174113407603692, 6.13099078948728], "pi": [0.5395879357261474, 0.46041206427385256], "ll": -854.134, "r": [[0.9991051994785588, 0.0008948005214413282], [0.017681244029271195, 0.9823187559707289], [0.0010397594032123816, 0.9989602405967877], [0.9970942602198299, 0.0029057397801700957], [0.9999899633536605, 1.0036646339566216e-05], [5.258994634184894e-06, 0.9999947410053659], [0.999865621841996, 0.0001343781580040648], [0.0717911736708812, 0.9282088263291187], [0.9999683557774582, 3.1644222541854564e-05], [0.0024768119731862002, 0.9975231880268138], [0.9999999013026719, 9.86973280274866e-08], [3.634413152537071e-05, 0.9999636558684747], [0.9904608172506055, 0.009539182749394519], [0.9999437163500837, 5.628364991621806e-05], [0.9998539283577463, 0.00014607164225363954], [0.001323136651845834, 0.9986768633481542], [0.048749987984662714, 0.9512500120153373], [0.997472265309337, 0.0025277346906630205], [0.9999982744340172, 1.7255659828622212e-06], [0.9999747212745236, 2.5278725476451304e-05], [0.9991924233162671, 0.0008075766837328559], [0.999992120191962, 7.879808037909014e-06], [3.01622175928044e-07, 0.9999996983778241], [0.9999975275948345, 2.4724051654443906e-06], [0.028128865257377664, 0.9718711347426224], [7.62758807945439e-06, 0.9999923724119205], [0.0027656543409418583, 0.9972343456590581], [3.894047361853941e-05, 0.9999610595263815], [0.9999976098485152, 2.3901514848127868e-06], [0.9999557486881322, 4.425131186769824e-05], [0.0002667576451246433, 0.9997332423548754], [1.0475569687749923e-06, 0.9999989524430312], [1.6564556720976888e-05, 0.9999834354432791], [0.9994159159575474, 0.0005840840424525925], [0.00021968001862207812, 0.999780319981378], [0.00010812313093396531, 0.999891876869066], [0.9736021038830377, 0.026397896116962315], [5.6005286835140184e-05, 0.9999439947131649], [0.9824916334480668, 0.01750836655193324], [0.0007959640757189643, 0.9992040359242811], [0.0014866112367948035, 0.9985133887632052], [2.259957276689713e-07, 0.9999997740042723], [0.9999857622217371, 1.4237778262887183e-05], [0.00012800017405302665, 0.999871999825947], [0.0009934320501795294, 0.9990065679498205], [0.0010200451141552731, 0.9989799548858447], [0.999999906539962, 9.346003799340136e-08], [6.164295574484392e-05, 0.9999383570442552], [0.9926007603384474, 0.007399239661552642], [0.9999985377611978, 1.4622388020642825e-06], [0.00010362843705716394, 0.9998963715629428], [0.9024209843216658, 0.09757901567833423], [1.71127527324026e-05, 0.9999828872472676], [0.9999752557844784, 2.474421552150085e-05], [0.9987167802090184, 0.0012832197909815005], [0.039178842197181964, 0.960821157802818], [0.999999806111939, 1.9388806104106189e-07], [0.9998101752205586, 0.00018982477944141297], [0.012717002998648395, 0.9872829970013517], [0.9563676484779408, 0.0436323515220592], [2.518666168827261e-05, 0.9999748133383117], [0.8484163467923569, 0.151583653207643], [0.986569993813628, 0.013430006186372], [0.9963911258979671, 0.003608874102032923], [2.6248895243659425e-06, 0.9999973751104757], [0.0014993541804041717, 0.9985006458195957], [0.005514348014543292, 0.9944856519854568], [0.9999083581281124, 9.164187188760013e-05], [0.006220524545863859, 0.9937794754541361], [0.027394256943303368, 0.9726057430566967], [0.9999997497800656, 2.5021993449390973e-07], [0.9966953143722522, 0.003304685627747826], [0.9999677384940735, 3.226150592650953e-05], [0.9999636862751706, 3.6313724829271185e-05], [0.0003455593097538146, 0.9996544406902462], [0.9999999732301702, 2.67698297560219e-08], [0.9999999725727234, 2.742727657695424e-08], [0.9982210926777595, 0.0017789073222405551], [0.0002614210384794344, 0.9997385789615205], [4.123173683641206e-05, 0.9999587682631637], [4.011465855137606e-07, 0.9999995988534146], [0.9999969418299501, 3.058170049923064e-06], [0.9999621766464926, 3.782335350758722e-05], [0.05035992210854332, 0.9496400778914567], [0.9978605923500722, 0.002139407649927808], [0.00040536879498324153, 0.9995946312050167], [0.9999592401430066, 4.075985699323984e-05], [0.977576721463054, 0.022423278536946027], [0.9999999007359858, 9.926401420570703e-08], [0.992822529791582, 0.007177470208417932], [0.0011295609687950248, 0.998870439031205], [0.9991292463338873, 0.0008707536661126872], [0.012324990433732431, 0.9876750095662676], [0.00040215068563428594, 0.9995978493143658], [9.606854469031793e-07, 0.9999990393145531], [0.9991316570901482, 0.0008683429098517917], [7.399222303773867e-05, 0.9999260077769623], [0.024001350042046097, 0.9759986499579538], [0.9999843703922258, 1.5629607774159883e-05], [0.9994025053584243, 0.0005974946415756357], [0.9996422586112109, 0.0003577413887889986], [0.9941846463528785, 0.00581535364712143], [0.9898544522377298, 0.010145547762270222], [7.616588018630098e-06, 0.9999923834119814], [0.993181761703809, 0.006818238296190946], [1.6524235938424237e-05, 0.9999834757640615], [6.883682836998009e-05, 0.99993116317163], [3.0812119253049816e-06, 0.9999969187880747], [0.9999601433871274, 3.985661287257949e-05], [0.0001904751255932622, 0.9998095248744068], [0.9999628667919181, 3.713320808181658e-05], [0.9999931775034964, 6.822496503579508e-06], [4.636806788974592e-05, 0.9999536319321103], [0.5237760997896108, 0.4762239002103892], [7.929795687358345e-07, 0.9999992070204312], [7.719671665121103e-06, 0.9999922803283349], [7.651487812038608e-08, 0.9999999234851219], [0.9997341881402644, 0.00026581185973567156], [0.1491083348590185, 0.8508916651409815], [0.9999999936185061, 6.381493916486312e-09], [0.013342908931124494, 0.9866570910688756], [0.007146965129208029, 0.992853034870792], [0.9974228802522023, 0.002577119747797806], [0.00011369359987099555, 0.9998863064001291], [0.007886144085617275, 0.9921138559143827], [0.999998867843459, 1.1321565409097623e-06], [0.003460200897816222, 0.9965397991021838], [0.9999795316462914, 2.0468353708555075e-05], [0.9995338486657249, 0.00046615133427502497], [0.999999614164957, 3.85835043092153e-07], [0.9999532105754033, 4.6789424596680415e-05], [0.99972042943182, 0.0002795705681799273], [0.9981891842196612, 0.0018108157803388431], [0.9991707992839063, 0.0008292007160937027], [0.0038885549524763116, 0.9961114450475237], [0.0076334425048165365, 0.9923665574951834], [0.9972497564276511, 0.0027502435723488817], [0.00041322317429089866, 0.9995867768257091], [0.9956427851821656, 0.004357214817834329], [0.9724787926471575, 0.027521207352842584], [0.9860474711095695, 0.013952528890430515], [0.9994644892309991, 0.0005355107690010274], [0.999997692995004, 2.307004996125776e-06], [0.9999997832782483, 2.1672175172471374e-07], [0.9999991018822476, 8.981177524722534e-07], [0.008662378211838018, 0.991337621788162], [0.995382102047364, 0.004617897952636048], [0.9999973489077749, 2.651092225092826e-06], [0.9917976686832446, 0.00820233131675553], [0.0008167261016801936, 0.9991832738983198], [0.0011097614866449096, 0.998890238513355], [1.89594663256897e-07, 0.9999998104053367], [0.9988200873559514, 0.0011799126440485994], [0.5649895901613243, 0.43501040983867567], [5.1859068859731644e-05, 0.9999481409311403], [6.399996371090046e-07, 0.9999993600003629], [0.9999804001319849, 1.9599868015140034e-05], [0.9998383611771983, 0.0001616388228017351], [0.005702816591248232, 0.9942971834087518], [0.00039874278055035655, 0.9996012572194497], [0.9999999784590256, 2.1540974528406386e-08], [0.00010527748161714721, 0.9998947225183829], [0.9977063217861338, 0.0022936782138661756], [0.9032362181255676, 0.0967637818744324], [0.0004406076545395454, 0.9995593923454604], [0.7876484711240722, 0.21235152887592776], [0.9999317166443047, 6.828335569534737e-05], [3.962068300738894e-06, 0.9999960379316992], [2.028274409896018e-09, 0.9999999979717256], [6.352929607808958e-07, 0.9999993647070393], [0.011118154008727935, 0.9888818459912722], [0.9886707441619385, 0.011329255838061504], [0.9998920542031907, 0.00010794579680916132], [8.971708225143805e-05, 0.9999102829177485], [0.9999930439305528, 6.9560694472148686e-06], [0.00014995664600872362, 0.9998500433539913], [4.7645672403792425e-07, 0.999999523543276], [0.9999114904372816, 8.850956271848635e-05], [0.00011503596206712998, 0.9998849640379329], [0.9996333740506885, 0.00036662594931147874], [0.9997730368623587, 0.00022696313764122394], [1.1867384639876697e-06, 0.999998813261536], [0.03446586614605887, 0.9655341338539412], [4.539199436004111e-08, 0.9999999546080056], [0.9995049668389894, 0.0004950331610107476], [0.0005224916056513141, 0.9994775083943488], [0.999997114086254, 2.8859137459634593e-06], [0.996583064502932, 0.0034169354970679457], [0.010092957021879286, 0.9899070429781206], [0.9996452324476754, 0.0003547675523245416], [0.9621750313575824, 0.03782496864241758], [0.9999649943174873, 3.5005682512635236e-05], [0.9999802970574496, 1.9702942550316024e-05], [5.597309722113558e-06, 0.999994402690278], [0.441805663439577, 0.5581943365604229], [0.9869727702108945, 0.013027229789105527], [0.0015791251951296807, 0.9984208748048704], [0.9999549214659622, 4.5078534037803967e-05], [0.9999994583745251, 5.416254748716555e-07], [0.9999984018790252, 1.5981209746974396e-06], [0.9999179928130046, 8.200718699546096e-05], [0.0003775026328860515, 0.999622497367114], [0.9999937235997757, 6.276400224293362e-06], [0.04154680396294129, 0.9584531960370587], [0.9726147673582876, 0.027385232641712418], [0.9999723062839082, 2.7693716091912747e-05], [0.002936567955163744, 0.9970634320448363], [0.0002532520334734108, 0.9997467479665265], [0.02436243056052991, 0.9756375694394701], [0.4228651703393877, 0.5771348296606124], [0.9999986062891099, 1.3937108902121729e-06], [0.028004611073569444, 0.9719953889264304], [0.9999753991539201, 2.460084607993198e-05], [4.290453496792467e-06, 0.9999957095465033], [0.9911243642518364, 0.008875635748163628], [0.9999981387725856, 1.861227414383004e-06], [8.949762555975127e-05, 0.9999105023744402], [0.9838736214847863, 0.016126378515213705], [0.9969219219381883, 0.0030780780618117638], [0.9753980169363851, 0.024601983063614927]]}, {"iter": 30, "mu": [44.40085440550423, 69.75807426737978], "sigma": [6.174187690947453, 6.130902736505093], "pi": [0.5395914715615511, 0.4604085284384489], "ll": -854.134, "r": [[0.9991056050913251, 0.0008943949086749771], [0.017686665530783206, 0.9823133344692169], [0.001040160090292377, 0.9989598399097076], [0.9970954380711256, 0.002904561928874387], [0.9999899704043419, 1.0029595658072883e-05], [5.262382237062187e-06, 0.9999947376177629], [0.9998656951265066, 0.0001343048734933517], [0.07181063942303682, 0.9281893605769632], [0.9999683756650375, 3.1624334962567524e-05], [0.002477697613839774, 0.9975223023861602], [0.9999999014084767, 9.859152328187955e-08], [3.636343823325359e-05, 0.9999636365617667], [0.9904642800701318, 0.009535719929868286], [0.9999437497842297, 5.625021577029642e-05], [0.9998540073689998, 0.00014599263100025572], [0.0013236358188792804, 0.9986763641811207], [0.04876374072079841, 0.9512362592792015], [0.997473303409252, 0.0025266965907479073], [0.9999982758658298, 1.7241341703247124e-06], [0.9999747375133899, 2.5262486610103435e-05], [0.9991927930239116, 0.000807206976088485], [0.9999921258575014, 7.874142498653911e-06], [3.018786744711299e-07, 0.9999996981213255], [0.9999975295787288, 2.470421271193423e-06], [0.02813718442609406, 0.971862815573906], [7.632323084217192e-06, 0.9999923676769157], [0.0027666342407121265, 0.9972333657592879], [3.896101790334375e-05, 0.9999610389820967], [0.9999976117724871, 2.3882275128780603e-06], [0.99995577560174, 4.4224398259994585e-05], [0.00026687421266464, 0.9997331257873354], [1.048347654819928e-06, 0.9999989516523451], [1.6574073950322548e-05, 0.9999834259260496], [0.9994161918593817, 0.0005838081406183699], [0.00021977781514954137, 0.9997802221848505], [0.00010817469482845874, 0.9998918253051715], [0.9736107954312958, 0.02638920456870413], [5.6033786215695104e-05, 0.9999439662137843], [0.982497636122335, 0.017502363877665076], [0.0007962782502070663, 0.999203721749793], [0.0014871664139846988, 0.9985128335860154], [2.2619321170723888e-07, 0.9999997738067883], [0.9999857718920814, 1.4228107918596643e-05], [0.00012806021788938467, 0.9998719397821106], [0.0009938164411225896, 0.9990061835588775], [0.0010204388740213141, 0.9989795611259786], [0.9999999066406233, 9.335937660602695e-08], [6.167402723143742e-05, 0.9999383259727685], [0.9926035103047266, 0.007396489695273463], [0.9999985389932652, 1.4610067348586387e-06], [0.00010367806362008157, 0.9998963219363799], [0.9024482402846996, 0.09755175971530043], [1.7122553007304977e-05, 0.9999828774469928], [0.9999752717131016, 2.472828689830197e-05], [0.9987173421395413, 0.0012826578604587056], [0.03919011446833739, 0.9608098855316627], [0.999999806307941, 1.936920589033474e-07], [0.9998102752900916, 0.0001897247099083841], [0.012721000848819214, 0.9872789991511808], [0.956381258763568, 0.043618741236431925], [2.520053969520929e-05, 0.9999747994603048], [0.8484551518298984, 0.15154484817010155], [0.986574715740402, 0.013425284259598038], [0.996392559463904, 0.003607440536096026], [2.626700624265594e-06, 0.9999973732993758], [0.0014999137021704844, 0.9985000862978296], [0.005516196186803628, 0.9944838038131965], [0.9999084100217335, 9.158997826655695e-05], [0.006222589866670254, 0.9937774101333298], [0.027402376021758233, 0.9725976239782418], [0.999999750027396, 2.49972603902598e-07], [0.996696637927054, 0.0033033620729460956], [0.9999677587313842, 3.2241268615748526e-05], [0.9999637087925407, 3.6291207459223576e-05], [0.00034570664846692993, 0.9996542933515331], [0.9999999732622129, 2.6737787095033675e-08], [0.9999999726054871, 2.7394512964693342e-08], [0.9982218478544898, 0.001778152145510253], [0.00026153549452016795, 0.9997384645054799], [4.1253366518031263e-05, 0.9999587466334819], [4.0147861900673554e-07, 0.9999995985213809], [0.9999969442354201, 3.055764580038784e-06], [0.9999622000067222, 3.779999327780822e-05], [0.05037408557658763, 0.9496259144234123], [0.9978614848672268, 0.0021385151327731537], [0.0004055390594911287, 0.999594460940509], [0.9999592651333801, 4.073486662007165e-05], [0.9775842261034192, 0.022415773896580855], [0.9999999008423456, 9.915765441172594e-08], [0.992825204856293, 0.007174795143706889], [0.0011299930767952465, 0.9988700069232048], [0.9991296420822322, 0.0008703579177677772], [0.012328874221817993, 0.9876711257781821], [0.00040231972469723115, 0.9995976802753028], [9.614166719225117e-07, 0.9999990385833281], [0.9991320518481582, 0.0008679481518417888], [7.402885179864891e-05, 0.9999259711482014], [0.024008538227676457, 0.9759914617723235], [0.9999843809125429, 1.5619087456979637e-05], [0.9994027869745503, 0.0005972130254495444], [0.9996424358537518, 0.0003575641462481821], [0.9941868563593356, 0.005813143640664468], [0.9898581141431357, 0.010141885856864317], [7.621316874378311e-06, 0.9999923786831256], [0.993184314979663, 0.0068156850203370395], [1.653373231266312e-05, 0.9999834662676874], [6.887114906607453e-05, 0.9999311288509339], [3.0833045550798975e-06, 0.999996916695445], [0.9999601678773568, 3.983212264331803e-05], [0.00019056109351594025, 0.999809438906484], [0.9999628897672445, 3.711023275547866e-05], [0.9999931824768961, 6.8175231038771865e-06], [4.6392109695438936e-05, 0.9999536078903045], [0.5238474603176387, 0.4761525396823612], [7.935944410650065e-07, 0.999999206405559], [7.724458109675509e-06, 0.9999922755418904], [7.658879844265614e-08, 0.9999999234112016], [0.9997343237175845, 0.00026567628241554593], [0.14914463114533374, 0.8508553688546663], [0.9999999936270872, 6.372912703079314e-09], [0.013347088353668886, 0.9866529116463312], [0.0071493126677627345, 0.9928506873322374], [0.9974239367130672, 0.002576063286932849], [0.00011374755416234662, 0.9998862524458376], [0.007888714890770991, 0.992111285109229], [0.9999988688201651, 1.131179834959076e-06], [0.003461404563140743, 0.9965385954368593], [0.9999795450678306, 2.0454932169356378e-05], [0.9995340737371978, 0.0004659262628021963], [0.9999996145319355, 3.854680644224155e-07], [0.9999532388776553, 4.676112234479094e-05], [0.9997205713239794, 0.00027942867602073784], [0.9981899516492335, 0.0018100483507664967], [0.9991711779255698, 0.0008288220744301727], [0.0038898949126184323, 0.9961101050873816], [0.0076359371596691275, 0.992364062840331], [0.9972508770050482, 0.00274912299495185], [0.00041339642610395676, 0.9995866035738961], [0.995644485946756, 0.004355514053244008], [0.9724878156178844, 0.027512184382115498], [0.986052359137993, 0.013947640862007038], [0.9994647443285082, 0.0005352556714918594], [0.9999976948582019, 2.305141798082038e-06], [0.9999997834952, 2.1650479999989283e-07], [0.9999991026736653, 8.973263346235768e-07], [0.008665181853791198, 0.9913348181462087], [0.9953838948711524, 0.0046161051288476545], [0.9999973510211951, 2.648978804840492e-06], [0.9918006881875466, 0.008199311812453284], [0.0008170477220919653, 0.9991829522779081], [0.0011101866851694904, 0.9988898133148305], [1.8976308749354431e-07, 0.9999998102369125], [0.9988206082071701, 0.0011793917928298388], [0.5650601315651061, 0.43493986843489385], [5.1885660501676555e-05, 0.9999481143394984], [6.405062355146511e-07, 0.9999993594937645], [0.9999804130382821, 1.9586961717911567e-05], [0.9998384477434367, 0.0001615522565632292], [0.005704722904199985, 0.9942952770958001], [0.0003989105209430363, 0.999601089479057], [0.9999999784852766, 2.151472341292622e-08], [0.00010532781987731195, 0.9998946721801226], [0.9977072724065579, 0.0022927275934421227], [0.9032632845385434, 0.09673671546145646], [0.00044079128294870565, 0.9995592087170513], [0.7876980454370155, 0.21230195456298442], [0.9999317564445912, 6.824355540886117e-05], [3.964693134591761e-06, 0.9999960353068653], [2.0309619060597055e-09, 0.999999997969038], [6.357961902480405e-07, 0.9999993642038097], [0.011121684904596116, 0.9888783150954039], [0.9886747914843863, 0.011325208515613678], [0.9998921143534352, 0.00010788564656490218], [8.976065966529114e-05, 0.9999102393403346], [0.9999930489919394, 6.95100806062917e-06], [0.00015002591291848587, 0.9998499740870815], [4.768446790805686e-07, 0.999999523155321], [0.99991154072875, 8.845927125001462e-05], [0.00011509049070210242, 0.999884909509298], [0.9996335552605957, 0.00036644473940433507], [0.9997731544310501, 0.00022684556894992362], [1.187623418645961e-06, 0.9999988123765814], [0.03447589134399571, 0.9655241086560044], [4.5437976190032674e-08, 0.9999999545620238], [0.9995052044620909, 0.0004947955379090895], [0.0005227059370668909, 0.9994772940629332], [0.9999971163686291, 2.8836313708384414e-06], [0.9965844287565858, 0.003415571243414085], [0.010096185914129443, 0.9899038140858706], [0.9996454083601501, 0.00035459163984996806], [0.9621870213683915, 0.03781297863160854], [0.9999650161017497, 3.498389825041504e-05], [0.9999803100250132, 1.968997498681436e-05], [5.600892999911421e-06, 0.9999943991070002], [0.4418758766219298, 0.5581241233780703], [0.9869773636595053, 0.013022636340494678], [0.0015797118481737915, 0.9984202881518263], [0.999954948833, 4.5051166999985475e-05], [0.999999458874227, 5.411257729259892e-07], [0.9999984032145569, 1.5967854431736449e-06], [0.999918039760435, 8.196023956497111e-05], [0.00037766225649506067, 0.999622337743505], [0.9999937282116644, 6.271788335624175e-06], [0.04155869624593924, 0.9584413037540608], [0.9726237503009529, 0.027376249699047027], [0.9999723239166466, 2.7676083353391366e-05], [0.0029376032744674917, 0.9970623967255324], [0.0002533632496618615, 0.9997466367503381], [0.024369718357775443, 0.9756302816422245], [0.4229345960058035, 0.5770654039941965], [0.999998607468656, 1.3925313441093858e-06], [0.028012896433706417, 0.9719871035662936], [0.999975414999216, 2.458500078389285e-05], [4.293273561439504e-06, 0.9999957067264386], [0.9911276078216182, 0.0088723921783818], [0.9999981403061459, 1.8596938541275726e-06], [8.954110685647674e-05, 0.9999104588931436], [0.9838791940337855, 0.016120805966214485], [0.9969231629413533, 0.003076837058646608], [0.975406175012673, 0.024593824987326984]]}]}, {"name": "X_data", "value": [46.901884818658225, 63.35772590773907, 67.63236926284246, 48.65420190045929, 40.246800354425645, 75.58943807724546, 44.088420338761, 61.17516223298405, 41.94609684801337, 66.32741920564115, 33.423100220615304, 72.67643320889249, 50.431308504575156, 42.79886199018653, 44.21211612392461, 67.27009911795533, 61.79104480452601, 48.44656802406306, 37.64438171198711, 41.61361350364677, 46.749508773832105, 39.88897721405326, 79.9055675933875, 38.17564857941136, 62.64636541739651, 75.02875940736628, 66.16149080350151, 72.57253863076969, 38.12566029693409, 42.44263026914159, 69.67730469509007, 78.02438864465645, 73.85996076813427, 46.268317528613714, 69.96926879967957, 71.03552750633271, 51.97143022358552, 72.0254472927936, 51.3467778815994, 68.03396143382824, 67.09498339999853, 80.34199432469978, 40.76405832748958, 70.78164712883732, 67.70087607318408, 67.66114118106539, 33.34275344115467, 71.88108308470117, 50.05030580670832, 37.39982356071535, 71.09940662333143, 54.03177834176714, 73.81090568088642, 41.58197882930773, 47.43773663803545, 62.13318080696369, 34.418403101164785, 44.60059271210998, 63.85901504426881, 52.74622683673185, 73.22869262202356, 54.780330709392246, 50.946033369627536, 48.977285952430115, 76.63773226035933, 67.08215254556002, 65.12235342813804, 43.52110109163792, 64.94061837824277, 62.68712163745823, 34.79450941329662, 48.845973271247274, 41.97469956768488, 42.14988823150859, 69.2881700433407, 31.50132452833576, 31.537041827073562, 47.92355251491263, 69.7076895884193, 72.48645659965598, 79.47454753846262, 38.489818174016975, 42.2101994220125, 61.73988311466215, 48.19819381378749, 69.04819097776787, 42.3209197601138, 51.72246509965916, 33.43153716489236, 50.004723151738695, 67.50785643892189, 46.86140969083763, 63.906525512754754, 69.06017261405145, 78.15512545144261, 46.85729058453376, 71.60626877406301, 62.89033740149785, 40.902058167427704, 46.30202452084004, 45.54063255591113, 49.689778650874224, 50.52388283254214, 75.03093522241807, 49.927835380603966, 73.86363275966114, 71.71495683761526, 76.39588138472587, 42.2877353927955, 70.1837889555665, 42.182931596094164, 39.675922341690445, 72.30970579663519, 57.207722315612145, 78.4448911678823, 75.01066747548747, 81.98038535015073, 45.0999529498215, 59.95190233177386, 29.391718490769307, 63.78607748304513, 64.7310857984275, 48.47538914836686, 70.95994968144063, 64.58243693147784, 37.02202537918814, 65.82434432997579, 41.301185658683465, 45.933486473125825, 35.433282835287685, 42.525227682238096, 45.174817164187544, 47.95000627265999, 46.78876439019746, 65.64864361278548, 64.63163788626504, 48.57224940823955, 69.01934260885292, 49.25847348442679, 52.03518379890263, 51.00360956645166, 46.139405888564525, 38.07335107445405, 34.582563945101455, 36.68012715007603, 64.44054435156686, 49.34523414644156, 38.27874818429977, 50.20474230259761, 67.99525935579513, 67.53443661499757, 80.60757948147929, 47.312955189519876, 56.95953048987516, 72.14122635489706, 78.7686657534532, 41.23701876565764, 44.36225431274881, 65.07167992465368, 69.0729659245006, 31.181436614461212, 71.0756538097379, 48.301860892767905, 54.01792965574426, 68.9228847203044, 55.39382638228852, 43.085154980215805, 76.01654695182762, 87.48317479604398, 78.77981734731738, 64.06277127980881, 50.68981263834284, 43.763764143449585, 71.31629500818313, 39.70459247146679, 70.54350944141048, 79.21453595197595, 43.46956540094708, 70.94229140467206, 45.577036061710956, 44.86559073996569, 77.83601045024095, 62.332374554082286, 82.77081839461098, 46.02272322533828, 68.66666381740735, 38.404150274470084, 48.895779846284654, 64.20929942660577, 45.52824558048973, 52.52451773112971, 42.09556922747942, 41.24478127837821, 75.49541525413608, 57.69896739381387, 50.900124547736695, 67.00422640876509, 42.47005926125134, 35.93370228797215, 37.531058559920986, 43.35649953705896, 69.15525468150169, 39.55256364476847, 62.04164369356262, 52.02760241045818, 41.74867986892308, 66.07127382742365, 69.7554248431874, 62.867421674062896, 57.81423113056732, 37.32893919336801, 62.653185809677, 41.573377422695145, 75.89643706613835, 50.32308087178229, 37.75616755711951, 71.31998010383059, 51.222335483431586, 48.74007473801637, 51.86380705005723]}, {"name": "true_labels", "value": [0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0]}, {"name": "true_mu", "value": [45.0, 70.0]}, {"name": "true_sigma", "value": [8.0, 6.0]}]}</script>
</div>
</div>
</section>
<section id="interactive-visualizer" class="level2">
<h2 class="anchored" data-anchor-id="interactive-visualizer">Interactive visualizer</h2>
<p>The slider steps through the iterations of the EM algorithm. The top plot shows how the two Gaussians converge towards the most likely parameter values. The bottom plot shows the log-likelihood.</p>
<div id="ojs-controls" class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb4" data-startfrom="280" data-source-offset="-1" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 279;"><span id="cb4-280">viewof iter <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> Inputs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">range</span>(</span>
<span id="cb4-281">  [<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> history<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb4-282">  { <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">value</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">step</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"EM iteration"</span> }</span>
<span id="cb4-283">)</span>
<span id="cb4-284"></span>
<span id="cb4-285">viewof showTrue <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> Inputs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toggle</span>({ <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Reveal true labels"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">value</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">false</span> })</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-controls-1">
<div id="ojs-cell-1-1" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div id="ojs-controls-2">
<div id="ojs-cell-1-2" data-nodetype="declaration">

</div>
</div>
</div>
</div>
<div id="ojs-plot" class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb5" data-startfrom="293" data-source-offset="-1" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 292;"><span id="cb5-293"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> { gaussPDF<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> makeCurve<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> makeResp<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> linspace } <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"./em-helpers.js"</span></span>
<span id="cb5-294"></span>
<span id="cb5-295"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// Snapshot for the current slider value</span></span>
<span id="cb5-296">snap <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> history[iter <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]</span>
<span id="cb5-297"></span>
<span id="cb5-298"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// x-axis grid for smooth density curves (300 points, score range 10–100)</span></span>
<span id="cb5-299">xs <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">linspace</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">300</span>)</span>
<span id="cb5-300"></span>
<span id="cb5-301"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// Weighted Gaussian curves (area under each curve = pi_k)</span></span>
<span id="cb5-302">curve0 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">makeCurve</span>(xs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> snap<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mu</span>[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> snap<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sigma</span>[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> snap<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pi</span>[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Component 1"</span>)</span>
<span id="cb5-303">curve1 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">makeCurve</span>(xs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> snap<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mu</span>[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> snap<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sigma</span>[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> snap<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pi</span>[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Component 2"</span>)</span>
<span id="cb5-304"></span>
<span id="cb5-305"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// Rug data: one entry per observed score, tagged with r0 and true label</span></span>
<span id="cb5-306">resp <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">makeResp</span>(X_data<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> snap<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">r</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> true_labels)</span>
<span id="cb5-307"></span>
<span id="cb5-308">Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>({</span>
<span id="cb5-309">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">width</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">700</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb5-310">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">height</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">360</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb5-311">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">marginLeft</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">50</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb5-312">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> { <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Score"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">domain</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> [<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>] }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb5-313">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> { <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Density"</span> }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb5-314">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">marks</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> [</span>
<span id="cb5-315">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">line</span>(curve0<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> { <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"x"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"y"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">stroke</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"steelblue"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span>  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">strokeWidth</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2.5</span> })<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb5-316">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">line</span>(curve1<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> { <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"x"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"y"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">stroke</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"darkorange"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">strokeWidth</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2.5</span> })<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb5-317">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tickX</span>(resp<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {</span>
<span id="cb5-318">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"x"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb5-319">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">strokeWidth</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.2</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb5-320">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">strokeOpacity</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.65</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb5-321">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">stroke</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> showTrue</span>
<span id="cb5-322">        <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> (d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">trueLabel</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"steelblue"</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"darkorange"</span>)</span>
<span id="cb5-323">        <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> d3<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">interpolateRdYlBu</span>(d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">r0</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb5-324">    })<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb5-325">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ruleX</span>(true_mu<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {</span>
<span id="cb5-326">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">stroke</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#888"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb5-327">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">strokeDasharray</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"4 3"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb5-328">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">strokeOpacity</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb5-329">    })<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb5-330">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">text</span>(</span>
<span id="cb5-331">      snap<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mu</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>((m<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> k) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> ({ <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> m<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`μ</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>k <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;"> = </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>m<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span> }))<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb5-332">      {</span>
<span id="cb5-333">        <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"x"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb5-334">        <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.058</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb5-335">        <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">text</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"label"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb5-336">        <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">fontSize</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">12</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb5-337">        <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">fill</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> (d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> i) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> (i <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"steelblue"</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"darkorange"</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb5-338">      }</span>
<span id="cb5-339">    )<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb5-340">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">text</span>(</span>
<span id="cb5-341">      snap<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mu</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>((m<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> k) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> ({ <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> m<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`σ</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>k <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;"> = </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>snap<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sigma</span>[k]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span> }))<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb5-342">      {</span>
<span id="cb5-343">        <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"x"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb5-344">        <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.055</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb5-345">        <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">text</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"label"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb5-346">        <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">fontSize</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">12</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb5-347">        <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">fill</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> (d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> i) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> (i <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"steelblue"</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"darkorange"</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb5-348">      }</span>
<span id="cb5-349">    )<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb5-350">  ]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb5-351">})</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-plot-1">
<div id="ojs-cell-2-1" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div id="ojs-plot-2">
<div id="ojs-cell-2-2" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div id="ojs-plot-3">
<div id="ojs-cell-2-3" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div id="ojs-plot-4">
<div id="ojs-cell-2-4" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div id="ojs-plot-5">
<div id="ojs-cell-2-5" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div id="ojs-plot-6">
<div id="ojs-cell-2-6" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div id="ojs-plot-7">
<div id="ojs-cell-2-7" data-nodetype="expression">

</div>
</div>
</div>
<p>The two curves are the fitted Gaussians and the rug marks show each data point coloured by its soft assignment (blue = component 1, orange = component 2, yellow = uncertain). Grey dashed lines are the true means.</p>
</div>
<div id="ojs-loglik" class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb6" data-startfrom="359" data-source-offset="-1" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 358;"><span id="cb6-359"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> { makeLLData } <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"./em-helpers.js"</span></span>
<span id="cb6-360"></span>
<span id="cb6-361">ll_data <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">makeLLData</span>(history)</span>
<span id="cb6-362"></span>
<span id="cb6-363">Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>({</span>
<span id="cb6-364">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">width</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">700</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb6-365">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">height</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">200</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb6-366">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">marginLeft</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">60</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb6-367">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> { <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Iteration"</span> }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb6-368">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> { <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Log-likelihood"</span> }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb6-369">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">marks</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> [</span>
<span id="cb6-370">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">line</span>(ll_data<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> { <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"iter"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ll"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">stroke</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"steelblue"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">strokeWidth</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> })<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb6-371">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ruleX</span>([iter]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {</span>
<span id="cb6-372">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">stroke</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"darkorange"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb6-373">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">strokeOpacity</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb6-374">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">strokeDasharray</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"4 2"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb6-375">    })<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb6-376">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dot</span>([ll_data[iter <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {</span>
<span id="cb6-377">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"iter"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb6-378">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ll"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb6-379">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">fill</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"darkorange"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb6-380">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">r</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb6-381">    })<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb6-382">  ]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb6-383">})</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-loglik-1">
<div id="ojs-cell-3-1" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div id="ojs-loglik-2">
<div id="ojs-cell-3-2" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div id="ojs-loglik-3">
<div id="ojs-cell-3-3" data-nodetype="expression">

</div>
</div>
</div>
<p>Log-likelihood across iterations. It can only ever increase.</p>
</div>
<!-- # Discussion

**What EM does well:**

- Works naturally when data has **missing or hidden structure** — this is its entire reason for existing
- Each iteration is **cheap and closed-form** — no gradient computation or line search needed
- **Monotonic convergence** is guaranteed: $\ell(\theta^{(t+1)}) \geq \ell(\theta^{(t)})$ always holds (the proof uses Jensen's inequality on the concavity of $\log$)
- Generalises far beyond GMMs — name a few to show the breadth:
  - **Hidden Markov Models** (speech recognition, genomics)
  - **Factor analysis** and PCA with missing data
  - **Topic models** like LDA (what is each document "about"?)
  - **Image segmentation** (what pixel belongs to which region?)

**Where EM struggles:**

- Only converges to a **local maximum** — the final answer depends on where you started
  - Common fix: run EM many times with different random initialisations, keep the solution with highest log-likelihood
- Convergence can be **slow** in flat regions of the likelihood surface, or when clusters overlap heavily
- $K$ must be **chosen in advance** — model selection is a separate problem; use BIC or AIC to compare different values of $K$
- Breaks down with **model misspecification** — if the data is not actually Gaussian, fitted components can be arbitrary and misleading -->



</section>
</section>

<div id="quarto-appendix" class="default"><section class="quarto-appendix-contents" id="quarto-bibliography"><h2 class="anchored quarto-appendix-heading">References</h2><div id="refs" class="references csl-bib-body" data-entry-spacing="0">
<div id="ref-bishop2006pattern" class="csl-entry">
<div class="csl-left-margin">[1] </div><div class="csl-right-inline">C. M. Bishop, <em>Pattern recognition and machine learning</em>. Springer, 2006.</div>
</div>
</div></section><section class="quarto-appendix-contents" id="quarto-reuse"><h2 class="anchored quarto-appendix-heading">Reuse</h2><div class="quarto-appendix-contents"><div><a rel="license" href="https://creativecommons.org/licenses/by/4.0/">CC BY 4.0</a></div></div></section><section class="quarto-appendix-contents" id="quarto-citation"><h2 class="anchored quarto-appendix-heading">Citation</h2><div><div class="quarto-appendix-secondary-label">BibTeX citation:</div><div class="code-copy-outer-scaffold"><pre class="sourceCode code-with-copy quarto-appendix-bibtex"><code class="sourceCode bibtex">@online{bogossian2026,
  author = {Bogossian, Andreas},
  title = {The {EM-algorithm}},
  date = {2026-04-14},
  url = {https://andreasbogossian.com/posts/em-algorithm/},
  langid = {en}
}
</code></pre></div><div class="quarto-appendix-secondary-label">For attribution, please cite this work as:</div><div id="ref-bogossian2026" class="csl-entry quarto-appendix-citeas">
<div class="">A.
Bogossian, <span>“The EM-algorithm.”</span> [Online]. Available: <a href="https://andreasbogossian.com/posts/em-algorithm/">https://andreasbogossian.com/posts/em-algorithm/</a></div>
</div></div></section></div> ]]></description>
  <category>probabilistic ML</category>
  <category>algorithms</category>
  <category>variational inference</category>
  <guid>https://andreasbogossian.com/posts/em-algorithm/</guid>
  <pubDate>Mon, 13 Apr 2026 21:00:00 GMT</pubDate>
  <media:content url="https://andreasbogossian.com/posts/em-algorithm/thumbnail.webp" medium="image" type="image/webp"/>
</item>
<item>
  <title>Variational Inference &amp; the ELBO</title>
  <dc:creator>Andreas Bogossian</dc:creator>
  <link>https://andreasbogossian.com/posts/evidence-lower-bound/</link>
  <description><![CDATA[ 




<div class="callout callout-style-default callout-note callout-titled">
<div class="callout-header d-flex align-content-center collapsed" data-bs-toggle="collapse" data-bs-target=".callout-1-contents" aria-controls="callout-1" aria-expanded="false" aria-label="Toggle callout">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
<span class="screen-reader-only">Note</span>Notation Reference
</div>
<div class="callout-btn-toggle d-inline-block border-0 py-1 ps-1 pe-0 float-end"><i class="callout-toggle"></i></div>
</div>
<div id="callout-1" class="callout-1-contents callout-collapse collapse">
<div class="callout-body-container callout-body">
<table class="caption-top table">
<colgroup>
<col style="width: 47%">
<col style="width: 52%">
</colgroup>
<thead>
<tr class="header">
<th>Symbol</th>
<th>Meaning</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td><img src="https://latex.codecogs.com/png.latex?%5Cmathbf%7Bx%7D"></td>
<td>Observed data</td>
</tr>
<tr class="even">
<td><img src="https://latex.codecogs.com/png.latex?%5Cmathbf%7Bz%7D"></td>
<td>Latent variables</td>
</tr>
<tr class="odd">
<td><img src="https://latex.codecogs.com/png.latex?p(%5Cmathbf%7Bz%7D%20%5Cmid%20%5Cmathbf%7Bx%7D)"></td>
<td>True (intractable) posterior</td>
</tr>
<tr class="even">
<td><img src="https://latex.codecogs.com/png.latex?p(%5Cmathbf%7Bx%7D%20%5Cmid%20%5Cmathbf%7Bz%7D)"></td>
<td>Likelihood</td>
</tr>
<tr class="odd">
<td><img src="https://latex.codecogs.com/png.latex?p(%5Cmathbf%7Bz%7D)"></td>
<td>Prior distribution</td>
</tr>
<tr class="even">
<td><img src="https://latex.codecogs.com/png.latex?p(%5Cmathbf%7Bx%7D)"></td>
<td>Marginal likelihood (evidence)</td>
</tr>
<tr class="odd">
<td><img src="https://latex.codecogs.com/png.latex?q_%5Cvarphi(%5Cmathbf%7Bz%7D%20%5Cmid%20%5Cmathbf%7Bx%7D)"></td>
<td>Variational approximation to the posterior</td>
</tr>
<tr class="even">
<td><img src="https://latex.codecogs.com/png.latex?%5Ctheta"></td>
<td>Generative model parameters</td>
</tr>
<tr class="odd">
<td><img src="https://latex.codecogs.com/png.latex?%5Cvarphi"></td>
<td>Variational parameters</td>
</tr>
<tr class="even">
<td><img src="https://latex.codecogs.com/png.latex?%5Cmathcal%7BL%7D(%5Ctheta,%20%5Cvarphi)"></td>
<td>Evidence Lower Bound (ELBO)</td>
</tr>
<tr class="odd">
<td><img src="https://latex.codecogs.com/png.latex?D_%7B%5Cmathrm%7BKL%7D%7D(q%20%5C%7C%20p)"></td>
<td>KL divergence from <img src="https://latex.codecogs.com/png.latex?q"> to <img src="https://latex.codecogs.com/png.latex?p"></td>
</tr>
<tr class="even">
<td><img src="https://latex.codecogs.com/png.latex?%5Cmathbb%7BE%7D_%7Bq%7D%5B%5Ccdot%5D"></td>
<td>Expectation under distribution <img src="https://latex.codecogs.com/png.latex?q"></td>
</tr>
<tr class="odd">
<td><img src="https://latex.codecogs.com/png.latex?%5Cmu_q,%5C%20%5Csigma_q"></td>
<td>Mean and std. dev. of the variational distribution</td>
</tr>
<tr class="even">
<td><img src="https://latex.codecogs.com/png.latex?%5Cmu_*,%5C%20%5Csigma_*"></td>
<td>Mean and std. dev. of the true posterior</td>
</tr>
<tr class="odd">
<td><img src="https://latex.codecogs.com/png.latex?%5Csigma_%5Cell"></td>
<td>Likelihood standard deviation</td>
</tr>
<tr class="even">
<td><img src="https://latex.codecogs.com/png.latex?%5Cmathcal%7BN%7D(%5Cmu,%20%5Csigma%5E2)"></td>
<td>Gaussian distribution with mean <img src="https://latex.codecogs.com/png.latex?%5Cmu"> and variance <img src="https://latex.codecogs.com/png.latex?%5Csigma%5E2"></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>Let’s say we’ve observed the data <img src="https://latex.codecogs.com/png.latex?%5Cmathbf%7Bx%7D"> and we want to know the conditional probability of the latent variables <img src="https://latex.codecogs.com/png.latex?%5Cmathbf%7Bz%7D">. The conditional probability distribution <img src="https://latex.codecogs.com/png.latex?p(%5Cmathbf%7Bz%7D%20%5Cmid%20%5Cmathbf%7Bx%7D)"> can be then formulated with the Bayes’ rule as</p>
<p><img src="https://latex.codecogs.com/png.latex?%0Ap(%5Cmathbf%7Bz%7D%20%5Cmid%20%5Cmathbf%7Bx%7D)%20=%20%5Cfrac%7Bp(%5Cmathbf%7Bx%7D%20%5Cmid%20%5Cmathbf%7Bz%7D)p(%5Cmathbf%7Bz%7D)%7D%7Bp(%5Cmathbf%7Bx%7D)%7D%0A"></p>
<p>Now the problem is that the denominator that acts as a regularizer</p>
<p><img src="https://latex.codecogs.com/png.latex?%0Ap(%5Cmathbf%7Bx%7D)%20=%20%5Cint%20p(%5Cmathbf%7Bx%7D%20%5Cmid%20%5Cmathbf%7Bz%7D)%20p(%5Cmathbf%7Bz%7D)%20d%20%5Cmathbf%7Bz%7D%0A"></p>
<p>is often intractable <span class="citation" data-cites="bishop2006pattern">[1]</span>. When something is intractable, it means that it is theoretically solvable but can’t be solved in a practical amount of time or with practical computational resources.</p>
<section id="variational-inference-approximating-the-posterior" class="level2">
<h2 class="anchored" data-anchor-id="variational-inference-approximating-the-posterior">Variational Inference: Approximating the Posterior</h2>
<p>With variational inference, we introduce a <em>tractable</em> approximation <img src="https://latex.codecogs.com/png.latex?q_%5Cvarphi(%5Cmathbf%7Bz%7D%20%5Cmid%20%5Cmathbf%7Bx%7D)"> and find the parameters <img src="https://latex.codecogs.com/png.latex?%5Cvarphi"> that approximate the intractable posterior <img src="https://latex.codecogs.com/png.latex?p_%5Ctheta(%5Cmathbf%7Bz%7D%20%5Cmid%20%5Cmathbf%7Bx%7D)"> as well as possible. The closeness is measured by <a href="../../posts/KL-divergence/index.html">KL-divergence</a>. Even though KL-divergence is a good measure for determining the closeness of two distributions, it requires knowing the true posterior, which we don’t know because we don’t know the denominator which we’re trying to solve, but we need the posterior to solve the denominator. Using KL-divergence alone will not solve the approximation problem so we maximize a quantity called Evidence Lower BOund (ELBO).</p>
</section>
<section id="derivation-of-the-elbo-jamil2023vae" class="level2">
<h2 class="anchored" data-anchor-id="derivation-of-the-elbo-jamil2023vae">Derivation of the ELBO <span class="citation" data-cites="jamil2023vae">[2]</span></h2>
<p>Now our goal is to transform the intractable integral <img src="https://latex.codecogs.com/png.latex?p_%5Ctheta(%5Cmathbf%7Bx%7D)"> into a tractable approximation <img src="https://latex.codecogs.com/png.latex?q_%5Cvarphi(%5Cmathbf%7Bx%7D)">. Instead of approximating <img src="https://latex.codecogs.com/png.latex?p_%5Ctheta(%5Cmathbf%7Bx%7D)"> we approximate <img src="https://latex.codecogs.com/png.latex?%5Clog%20p_%5Ctheta(%5Cmathbf%7Bx%7D)">. So we start from</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Clog%20p_%5Ctheta(%5Cmathbf%7Bx%7D)%20=%20%5Clog%20p_%5Ctheta(%5Cmathbf%7Bx%7D)%0A"></p>
<p>Now by multiplying by <img src="https://latex.codecogs.com/png.latex?%5Cint%20q_%5Cvarphi%20(%5Cmathbf%7Bz%7D%20%5Cmid%20%5Cmathbf%7Bx%7D)%20d%5Cmathbf%7Bz%7D%20=%201"> we get</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign*%7D%0A%5Clog%20p_%5Ctheta(%5Cmathbf%7Bx%7D)%20&amp;=%20%5Clog%20p_%5Ctheta(%5Cmathbf%7Bx%7D)%5Cint%20q_%5Cvarphi%20(%5Cmathbf%7Bz%7D%20%5Cmid%20%5Cmathbf%7Bx%7D)%20d%5Cmathbf%7Bz%7D%20%5C%5C%0A&amp;=%20%5Cint%20%5Clog%20p_%5Ctheta(%5Cmathbf%7Bx%7D)%20q_%5Cvarphi%20(%5Cmathbf%7Bz%7D%20%5Cmid%20%5Cmathbf%7Bx%7D)%20d%5Cmathbf%7Bz%7D%0A%5Cend%7Balign*%7D%0A"></p>
<p>Using the property <img src="https://latex.codecogs.com/png.latex?%5Cint%20f(x)%20%5C,%20q(z)%20%5C,%20dz%20=%20%5Cmathbb%7BE%7D_%7Bq(z)%7D%5Bf(x)%5D"></p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Clog%20p_%5Ctheta(%5Cmathbf%7Bx%7D)%20=%20%5Cmathbb%7BE%7D_%7Bq_%5Cvarphi(%5Cmathbf%7Bz%7D%7C%5Cmathbf%7Bx%7D)%7D%20%5Cleft%5B%20%5Clog%20p_%5Ctheta(%5Cmathbf%7Bx%7D)%20%5Cright%5D%0A"></p>
<p>Next, we can apply the chain rule of probability: <img src="https://latex.codecogs.com/png.latex?p_%5Ctheta(%5Cmathbf%7Bx%7D,%20%5Cmathbf%7Bz%7D)%20=%20p_%5Ctheta(%5Cmathbf%7Bz%7D%20%5Cmid%20%5Cmathbf%7Bx%7D)%20p_%5Ctheta(%5Cmathbf%7Bx%7D)%20%5CRrightarrow%20p_%5Ctheta(%5Cmathbf%7Bx%7D)%20=%20%5Cfrac%7Bp_%5Ctheta(%5Cmathbf%7Bx%7D,%20%5Cmathbf%7Bz%7D)%7D%7Bp_%5Ctheta(%5Cmathbf%7Bz%7D%7C%5Cmathbf%7Bx%7D)%7D">:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Clog%20p_%5Ctheta(%5Cmathbf%7Bx%7D)%20=%20%5Cmathbb%7BE%7D_%7Bq_%5Cvarphi(%5Cmathbf%7Bz%7D%7C%5Cmathbf%7Bx%7D)%7D%20%5Cleft%5B%20%5Clog%20%5Cfrac%7Bp_%5Ctheta(%5Cmathbf%7Bx%7D,%20%5Cmathbf%7Bz%7D)%7D%7Bp_%5Ctheta(%5Cmathbf%7Bz%7D%7C%5Cmathbf%7Bx%7D)%7D%20%5Cright%5D%0A"></p>
<p>Multiplying by one, by introducing the new approximate tractable distribution <img src="https://latex.codecogs.com/png.latex?q_%5Cvarphi%20(%5Cmathbf%7Bz%7D%20%5Cmid%20%5Cmathbf%7Bx%7D)">:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Clog%20p_%5Ctheta(%5Cmathbf%7Bx%7D)%20=%20%5Cmathbb%7BE%7D_%7Bq_%5Cvarphi(%5Cmathbf%7Bz%7D%7C%5Cmathbf%7Bx%7D)%7D%20%5Cleft%5B%20%5Clog%20%5Cfrac%7Bp_%5Ctheta(%5Cmathbf%7Bx%7D,%20%5Cmathbf%7Bz%7D)%20q_%5Cvarphi%20(%5Cmathbf%7Bz%7D%20%5Cmid%20%5Cmathbf%7Bx%7D)%7D%7Bp_%5Ctheta(%5Cmathbf%7Bz%7D%7C%5Cmathbf%7Bx%7D)%20q_%5Cvarphi%20(%5Cmathbf%7Bz%7D%20%5Cmid%20%5Cmathbf%7Bx%7D)%7D%20%5Cright%5D%0A"></p>
<p>With KL-divergence is defines as <img src="https://latex.codecogs.com/png.latex?D_%7BKL%7D(q_%5Cvarphi(%5Cmathbf%7Bz%7D%7C%5Cmathbf%7Bx%7D)%20%5C%7C%20p_%5Ctheta(%5Cmathbf%7Bz%7D%7C%5Cmathbf%7Bx%7D))%20=%20%5Cmathbb%7BE%7D_%7Bq_%5Cvarphi(%5Cmathbf%7Bz%7D%7C%5Cmathbf%7Bx%7D)%7D%20%5Cleft%5B%20%5Clog%20%5Cfrac%7Bq_%5Cvarphi(%5Cmathbf%7Bz%7D%7C%5Cmathbf%7Bx%7D)%7D%7Bp_%5Ctheta(%5Cmathbf%7Bz%7D%7C%5Cmathbf%7Bx%7D)%7D%20%5Cright%5D">:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Clog%20p_%5Ctheta(%5Cmathbf%7Bx%7D)%20=%20%5Cunderbrace%7B%5Cmathbb%7BE%7D_%7Bq_%5Cvarphi(%5Cmathbf%7Bz%7D%7C%5Cmathbf%7Bx%7D)%7D%20%5Cleft%5B%20%5Clog%20%5Cfrac%7Bp_%5Ctheta(%5Cmathbf%7Bx%7D,%20%5Cmathbf%7Bz%7D)%7D%7Bq_%5Cvarphi(%5Cmathbf%7Bz%7D%7C%5Cmathbf%7Bx%7D)%7D%20%5Cright%5D%7D_%7B%5Ctext%7BELBO%7D%7D%20+%20%5Cunderbrace%7BD_%7B%5Cmathrm%7BKL%7D%7D%5C!%5Cleft(%20q_%5Cvarphi(%5Cmathbf%7Bz%7D%7C%5Cmathbf%7Bx%7D)%20%5C,%5C%7C%5C,%20p_%5Ctheta(%5Cmathbf%7Bz%7D%7C%5Cmathbf%7Bx%7D)%20%5Cright)%7D_%7B%5Cgeq%5C,%200%7D%0A"></p>
<p>Since KL divergence is always non-negative, the ELBO is a lower bound on the log evidence:</p>
<p><img src="https://latex.codecogs.com/png.latex?%5Clog%20p_%5Ctheta(%5Cmathbf%7Bx%7D)%20%5Cgeq%20%5Cmathbb%7BE%7D_%7Bq_%5Cvarphi(%5Cmathbf%7Bz%7D%7C%5Cmathbf%7Bx%7D)%7D%20%5Cleft%5B%20%5Clog%20%5Cfrac%7Bp_%5Ctheta(%5Cmathbf%7Bx%7D,%20%5Cmathbf%7Bz%7D)%7D%7Bq_%5Cvarphi(%5Cmathbf%7Bz%7D%7C%5Cmathbf%7Bx%7D)%7D%20%5Cright%5D"></p>
<p>The notation <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%7BL%7D(%5Ctheta,%20%5Cvarphi)"> is used for the ELBO, so I’ll be also using it to simplify the math notation.</p>
</section>
<section id="what-is-the-elbo-optimising" class="level2">
<h2 class="anchored" data-anchor-id="what-is-the-elbo-optimising">What is the ELBO Optimising?</h2>
<p>Our original goal was to find a tractable distribution <img src="https://latex.codecogs.com/png.latex?q_%5Cvarphi%20(%5Cmathbf%7Bx%7D)"> that approximates <img src="https://latex.codecogs.com/png.latex?p_%5Ctheta%20(%5Cmathbf%7Bx%7D)">. A novel solution to this is to maximize the ELBO. With <img src="https://latex.codecogs.com/png.latex?%5Clog%20p_%5Ctheta%20(%5Cmathbf%7Bx%7D)"> being fixed, maximizing the ELBO minimizes the KL-divergence.</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cunderbrace%7B%5Clog%20p_%5Ctheta(%5Cmathbf%7Bx%7D)%7D_%7B%5Ctext%7Bfixed%7D%7D%20=%20%5Cunderbrace%7B%5Cmathcal%7BL%7D(%5Ctheta,%20%5Cvarphi)%7D_%7B%5Cuparrow%20%5Ctext%7B%20maximise%7D%7D%20+%20%5Cunderbrace%7BD_%7B%5Cmathrm%7BKL%7D%7D(q_%5Cvarphi%20%5C%7C%20p_%5Ctheta)%7D_%7B%5Cdownarrow%20%5Ctext%7B%20minimise%7D%7D%0A"></p>
</section>
<section id="expanding-the-elbo" class="level2">
<h2 class="anchored" data-anchor-id="expanding-the-elbo">Expanding the ELBO</h2>
<p>The ELBO can be further decomposed by factoring using the chain rule of probability and splitting the log. This decomposition is a necessary tool for variational autoencoders (VAEs).</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign*%7D%0A%5Cmathcal%7BL%7D(%5Ctheta,%20%5Cvarphi)%20&amp;=%20%5Cmathbb%7BE%7D_%7Bq_%5Cvarphi(%5Cmathbf%7Bz%7D%7C%5Cmathbf%7Bx%7D)%7D%20%5Cleft%5B%20%5Clog%20%5Cfrac%7Bp_%5Ctheta(%5Cmathbf%7Bx%7D,%20%5Cmathbf%7Bz%7D)%7D%7Bq_%5Cvarphi(%5Cmathbf%7Bz%7D%7C%5Cmathbf%7Bx%7D)%7D%20%5Cright%5D%20%5C%5C%0A%5Cmathcal%7BL%7D(%5Ctheta,%20%5Cvarphi)%20&amp;=%20%5Cmathbb%7BE%7D_%7Bq_%5Cvarphi(%5Cmathbf%7Bz%7D%7C%5Cmathbf%7Bx%7D)%7D%20%5Cleft%5B%20%5Clog%20%5Cfrac%7Bp_%5Ctheta(%5Cmathbf%7Bx%7D%7C%5Cmathbf%7Bz%7D)%5C,%20p(%5Cmathbf%7Bz%7D)%7D%7Bq_%5Cvarphi(%5Cmathbf%7Bz%7D%7C%5Cmathbf%7Bx%7D)%7D%20%5Cright%5D%20%5C%5C%0A&amp;=%20%5Cunderbrace%7B%5Cmathbb%7BE%7D_%7Bq_%5Cvarphi(%5Cmathbf%7Bz%7D%7C%5Cmathbf%7Bx%7D)%7D%20%5Cleft%5B%20%5Clog%20p_%5Ctheta(%5Cmathbf%7Bx%7D%7C%5Cmathbf%7Bz%7D)%20%5Cright%5D%7D_%7B%5Ctext%7Breconstruction%20term%7D%7D%20-%20%5Cunderbrace%7BD_%7B%5Cmathrm%7BKL%7D%7D%5C!%5Cleft(%20q_%5Cvarphi(%5Cmathbf%7Bz%7D%7C%5Cmathbf%7Bx%7D)%20%5C,%5C%7C%5C,%20p(%5Cmathbf%7Bz%7D)%20%5Cright)%7D_%7B%5Ctext%7Bregularisation%20term%7D%7D%0A%5Cend%7Balign*%7D%0A"></p>
<p>Here the <strong>reconstruction term</strong> measures how well the model recovers <img src="https://latex.codecogs.com/png.latex?%5Cmathbf%7Bx%7D"> from samples of the latent space and the <strong>regularisation term</strong> penalises <img src="https://latex.codecogs.com/png.latex?q_%5Cvarphi(%5Cmathbf%7Bz%7D%7C%5Cmathbf%7Bx%7D)"> for deviating from the prior <img src="https://latex.codecogs.com/png.latex?p(%5Cmathbf%7Bz%7D)">.</p>
</section>
<section id="a-simple-example" class="level2">
<h2 class="anchored" data-anchor-id="a-simple-example">A Simple Example</h2>
<p><strong>Model:</strong></p>
<p><img src="https://latex.codecogs.com/png.latex?%0Ap(z)%20=%20%5Cmathcal%7BN%7D(0,%201),%20%5Cqquad%20p(x%20%5Cmid%20z)%20=%20%5Cmathcal%7BN%7D(z,%20%5Csigma_%5Cell%5E2)%0A"></p>
<p><strong>True posterior</strong> (conjugate, so tractable here):</p>
<p><img src="https://latex.codecogs.com/png.latex?%0Ap(z%20%5Cmid%20x)%20=%20%5Cmathcal%7BN%7D%5C!%5Cleft(%5Cmu_*,%20%5Csigma_*%5E2%5Cright),%20%5Cquad%20%5Cmu_*%20=%20%5Cfrac%7Bx%7D%7B%5Csigma_%5Cell%5E2%20+%201%7D,%20%5Cquad%20%5Csigma_*%5E2%20=%20%5Cfrac%7B%5Csigma_%5Cell%5E2%7D%7B%5Csigma_%5Cell%5E2%20+%201%7D%0A"></p>
<p><strong>Variational family:</strong> <img src="https://latex.codecogs.com/png.latex?q(z)%20=%20%5Cmathcal%7BN%7D(%5Cmu_q,%20%5Csigma_q%5E2)">.</p>
<p>We optimise <img src="https://latex.codecogs.com/png.latex?(%5Cmu_q,%20%5Csigma_q)"> by gradient ascent on the ELBO and compare with the truth.</p>
<div id="cell-vi-setup" class="cell" data-execution_count="2">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb1-1">np.random.seed(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">42</span>)</span>
<span id="cb1-2">x_obs   <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.8</span></span>
<span id="cb1-3">sigma_l <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.2</span></span>
<span id="cb1-4">mu_post   <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> x_obs <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> (sigma_l<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">**</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb1-5">sig2_post <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> sigma_l<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">**</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> (sigma_l<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">**</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb1-6"></span>
<span id="cb1-7"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">def</span> elbo_gaussian(mu_q, log_sq):</span>
<span id="cb1-8">    sq <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.exp(log_sq)</span>
<span id="cb1-9">    sq2 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> sq<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">**</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span></span>
<span id="cb1-10">    recon <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> np.log(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> np.pi <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> sigma_l<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">**</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\</span></span>
<span id="cb1-11">            <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> (sq2 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> (mu_q <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> x_obs)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">**</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> sigma_l<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">**</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span></span>
<span id="cb1-12">    kl <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> (sq2 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> mu_q<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">**</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>log_sq)</span>
<span id="cb1-13">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> recon <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> kl</span>
<span id="cb1-14"></span>
<span id="cb1-15">mu_q, log_sq <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.0</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.0</span></span>
<span id="cb1-16">lr <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.08</span></span>
<span id="cb1-17">history <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> []</span>
<span id="cb1-18"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> _ <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">range</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">120</span>):</span>
<span id="cb1-19">    sq <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.exp(log_sq)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> sq2 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> sq<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">**</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span></span>
<span id="cb1-20">    grad_mu  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (x_obs <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> mu_q)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>sigma_l<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">**</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> mu_q</span>
<span id="cb1-21">    grad_lsq <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>sq2<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>sigma_l<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">**</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> sq2</span>
<span id="cb1-22">    mu_q   <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+=</span> lr <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> grad_mu</span>
<span id="cb1-23">    log_sq <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+=</span> lr <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> grad_lsq</span>
<span id="cb1-24">    history.append({</span>
<span id="cb1-25">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"iter"</span>:   <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">len</span>(history) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,</span>
<span id="cb1-26">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mu_q"</span>:   <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">round</span>(mu_q, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>),</span>
<span id="cb1-27">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sq"</span>:     <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">round</span>(np.exp(log_sq), <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>),</span>
<span id="cb1-28">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"elbo"</span>:   <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">round</span>(elbo_gaussian(mu_q, log_sq), <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>),</span>
<span id="cb1-29">    })</span>
<span id="cb1-30"></span>
<span id="cb1-31">ojs_define(</span>
<span id="cb1-32">    history   <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> history,</span>
<span id="cb1-33">    mu_post   <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> mu_post,</span>
<span id="cb1-34">    sig_post  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">float</span>(np.sqrt(sig2_post)),</span>
<span id="cb1-35">)</span></code></pre></div></div>
<div id="vi-setup" class="cell-output cell-output-display">
<script type="ojs-define">{"contents": [{"name": "history", "value": [{"iter": 1, "mu_q": 0.1, "sq": 0.946, "elbo": -2.4234}, {"iter": 2, "mu_q": 0.1864, "sq": 0.9077, "elbo": -2.3175}, {"iter": 3, "mu_q": 0.2612, "sq": 0.8794, "elbo": -2.2413}, {"iter": 4, "mu_q": 0.3258, "sq": 0.8578, "elbo": -2.1858}, {"iter": 5, "mu_q": 0.3816, "sq": 0.841, "elbo": -2.145}, {"iter": 6, "mu_q": 0.4299, "sq": 0.8278, "elbo": -2.115}, {"iter": 7, "mu_q": 0.4716, "sq": 0.8172, "elbo": -2.0928}, {"iter": 8, "mu_q": 0.5077, "sq": 0.8086, "elbo": -2.0764}, {"iter": 9, "mu_q": 0.5389, "sq": 0.8017, "elbo": -2.0642}, {"iter": 10, "mu_q": 0.5658, "sq": 0.796, "elbo": -2.0552}, {"iter": 11, "mu_q": 0.5891, "sq": 0.7913, "elbo": -2.0485}, {"iter": 12, "mu_q": 0.6093, "sq": 0.7875, "elbo": -2.0435}, {"iter": 13, "mu_q": 0.6267, "sq": 0.7843, "elbo": -2.0398}, {"iter": 14, "mu_q": 0.6417, "sq": 0.7816, "elbo": -2.037}, {"iter": 15, "mu_q": 0.6547, "sq": 0.7794, "elbo": -2.0349}, {"iter": 16, "mu_q": 0.666, "sq": 0.7776, "elbo": -2.0334}, {"iter": 17, "mu_q": 0.6757, "sq": 0.7761, "elbo": -2.0322}, {"iter": 18, "mu_q": 0.6841, "sq": 0.7748, "elbo": -2.0314}, {"iter": 19, "mu_q": 0.6914, "sq": 0.7737, "elbo": -2.0307}, {"iter": 20, "mu_q": 0.6977, "sq": 0.7728, "elbo": -2.0303}, {"iter": 21, "mu_q": 0.7031, "sq": 0.7721, "elbo": -2.0299}, {"iter": 22, "mu_q": 0.7078, "sq": 0.7715, "elbo": -2.0296}, {"iter": 23, "mu_q": 0.7118, "sq": 0.7709, "elbo": -2.0295}, {"iter": 24, "mu_q": 0.7153, "sq": 0.7705, "elbo": -2.0293}, {"iter": 25, "mu_q": 0.7184, "sq": 0.7701, "elbo": -2.0292}, {"iter": 26, "mu_q": 0.721, "sq": 0.7698, "elbo": -2.0291}, {"iter": 27, "mu_q": 0.7233, "sq": 0.7696, "elbo": -2.0291}, {"iter": 28, "mu_q": 0.7252, "sq": 0.7694, "elbo": -2.029}, {"iter": 29, "mu_q": 0.7269, "sq": 0.7692, "elbo": -2.029}, {"iter": 30, "mu_q": 0.7284, "sq": 0.769, "elbo": -2.0289}, {"iter": 31, "mu_q": 0.7296, "sq": 0.7689, "elbo": -2.0289}, {"iter": 32, "mu_q": 0.7307, "sq": 0.7688, "elbo": -2.0289}, {"iter": 33, "mu_q": 0.7317, "sq": 0.7687, "elbo": -2.0289}, {"iter": 34, "mu_q": 0.7325, "sq": 0.7686, "elbo": -2.0289}, {"iter": 35, "mu_q": 0.7332, "sq": 0.7686, "elbo": -2.0289}, {"iter": 36, "mu_q": 0.7338, "sq": 0.7685, "elbo": -2.0289}, {"iter": 37, "mu_q": 0.7343, "sq": 0.7685, "elbo": -2.0289}, {"iter": 38, "mu_q": 0.7348, "sq": 0.7684, "elbo": -2.0289}, {"iter": 39, "mu_q": 0.7352, "sq": 0.7684, "elbo": -2.0289}, {"iter": 40, "mu_q": 0.7355, "sq": 0.7684, "elbo": -2.0289}, {"iter": 41, "mu_q": 0.7358, "sq": 0.7683, "elbo": -2.0289}, {"iter": 42, "mu_q": 0.7361, "sq": 0.7683, "elbo": -2.0289}, {"iter": 43, "mu_q": 0.7363, "sq": 0.7683, "elbo": -2.0289}, {"iter": 44, "mu_q": 0.7365, "sq": 0.7683, "elbo": -2.0289}, {"iter": 45, "mu_q": 0.7367, "sq": 0.7683, "elbo": -2.0289}, {"iter": 46, "mu_q": 0.7368, "sq": 0.7683, "elbo": -2.0289}, {"iter": 47, "mu_q": 0.7369, "sq": 0.7683, "elbo": -2.0289}, {"iter": 48, "mu_q": 0.737, "sq": 0.7683, "elbo": -2.0289}, {"iter": 49, "mu_q": 0.7371, "sq": 0.7683, "elbo": -2.0289}, {"iter": 50, "mu_q": 0.7372, "sq": 0.7682, "elbo": -2.0289}, {"iter": 51, "mu_q": 0.7373, "sq": 0.7682, "elbo": -2.0289}, {"iter": 52, "mu_q": 0.7373, "sq": 0.7682, "elbo": -2.0289}, {"iter": 53, "mu_q": 0.7374, "sq": 0.7682, "elbo": -2.0289}, {"iter": 54, "mu_q": 0.7374, "sq": 0.7682, "elbo": -2.0289}, {"iter": 55, "mu_q": 0.7375, "sq": 0.7682, "elbo": -2.0289}, {"iter": 56, "mu_q": 0.7375, "sq": 0.7682, "elbo": -2.0289}, {"iter": 57, "mu_q": 0.7375, "sq": 0.7682, "elbo": -2.0289}, {"iter": 58, "mu_q": 0.7375, "sq": 0.7682, "elbo": -2.0289}, {"iter": 59, "mu_q": 0.7376, "sq": 0.7682, "elbo": -2.0289}, {"iter": 60, "mu_q": 0.7376, "sq": 0.7682, "elbo": -2.0289}, {"iter": 61, "mu_q": 0.7376, "sq": 0.7682, "elbo": -2.0289}, {"iter": 62, "mu_q": 0.7376, "sq": 0.7682, "elbo": -2.0289}, {"iter": 63, "mu_q": 0.7376, "sq": 0.7682, "elbo": -2.0289}, {"iter": 64, "mu_q": 0.7376, "sq": 0.7682, "elbo": -2.0289}, {"iter": 65, "mu_q": 0.7376, "sq": 0.7682, "elbo": -2.0289}, {"iter": 66, "mu_q": 0.7377, "sq": 0.7682, "elbo": -2.0289}, {"iter": 67, "mu_q": 0.7377, "sq": 0.7682, "elbo": -2.0289}, {"iter": 68, "mu_q": 0.7377, "sq": 0.7682, "elbo": -2.0289}, {"iter": 69, "mu_q": 0.7377, "sq": 0.7682, "elbo": -2.0289}, {"iter": 70, "mu_q": 0.7377, "sq": 0.7682, "elbo": -2.0289}, {"iter": 71, "mu_q": 0.7377, "sq": 0.7682, "elbo": -2.0289}, {"iter": 72, "mu_q": 0.7377, "sq": 0.7682, "elbo": -2.0289}, {"iter": 73, "mu_q": 0.7377, "sq": 0.7682, "elbo": -2.0289}, {"iter": 74, "mu_q": 0.7377, "sq": 0.7682, "elbo": -2.0289}, {"iter": 75, "mu_q": 0.7377, "sq": 0.7682, "elbo": -2.0289}, {"iter": 76, "mu_q": 0.7377, "sq": 0.7682, "elbo": -2.0289}, {"iter": 77, "mu_q": 0.7377, "sq": 0.7682, "elbo": -2.0289}, {"iter": 78, "mu_q": 0.7377, "sq": 0.7682, "elbo": -2.0289}, {"iter": 79, "mu_q": 0.7377, "sq": 0.7682, "elbo": -2.0289}, {"iter": 80, "mu_q": 0.7377, "sq": 0.7682, "elbo": -2.0289}, {"iter": 81, "mu_q": 0.7377, "sq": 0.7682, "elbo": -2.0289}, {"iter": 82, "mu_q": 0.7377, "sq": 0.7682, "elbo": -2.0289}, {"iter": 83, "mu_q": 0.7377, "sq": 0.7682, "elbo": -2.0289}, {"iter": 84, "mu_q": 0.7377, "sq": 0.7682, "elbo": -2.0289}, {"iter": 85, "mu_q": 0.7377, "sq": 0.7682, "elbo": -2.0289}, {"iter": 86, "mu_q": 0.7377, "sq": 0.7682, "elbo": -2.0289}, {"iter": 87, "mu_q": 0.7377, "sq": 0.7682, "elbo": -2.0289}, {"iter": 88, "mu_q": 0.7377, "sq": 0.7682, "elbo": -2.0289}, {"iter": 89, "mu_q": 0.7377, "sq": 0.7682, "elbo": -2.0289}, {"iter": 90, "mu_q": 0.7377, "sq": 0.7682, "elbo": -2.0289}, {"iter": 91, "mu_q": 0.7377, "sq": 0.7682, "elbo": -2.0289}, {"iter": 92, "mu_q": 0.7377, "sq": 0.7682, "elbo": -2.0289}, {"iter": 93, "mu_q": 0.7377, "sq": 0.7682, "elbo": -2.0289}, {"iter": 94, "mu_q": 0.7377, "sq": 0.7682, "elbo": -2.0289}, {"iter": 95, "mu_q": 0.7377, "sq": 0.7682, "elbo": -2.0289}, {"iter": 96, "mu_q": 0.7377, "sq": 0.7682, "elbo": -2.0289}, {"iter": 97, "mu_q": 0.7377, "sq": 0.7682, "elbo": -2.0289}, {"iter": 98, "mu_q": 0.7377, "sq": 0.7682, "elbo": -2.0289}, {"iter": 99, "mu_q": 0.7377, "sq": 0.7682, "elbo": -2.0289}, {"iter": 100, "mu_q": 0.7377, "sq": 0.7682, "elbo": -2.0289}, {"iter": 101, "mu_q": 0.7377, "sq": 0.7682, "elbo": -2.0289}, {"iter": 102, "mu_q": 0.7377, "sq": 0.7682, "elbo": -2.0289}, {"iter": 103, "mu_q": 0.7377, "sq": 0.7682, "elbo": -2.0289}, {"iter": 104, "mu_q": 0.7377, "sq": 0.7682, "elbo": -2.0289}, {"iter": 105, "mu_q": 0.7377, "sq": 0.7682, "elbo": -2.0289}, {"iter": 106, "mu_q": 0.7377, "sq": 0.7682, "elbo": -2.0289}, {"iter": 107, "mu_q": 0.7377, "sq": 0.7682, "elbo": -2.0289}, {"iter": 108, "mu_q": 0.7377, "sq": 0.7682, "elbo": -2.0289}, {"iter": 109, "mu_q": 0.7377, "sq": 0.7682, "elbo": -2.0289}, {"iter": 110, "mu_q": 0.7377, "sq": 0.7682, "elbo": -2.0289}, {"iter": 111, "mu_q": 0.7377, "sq": 0.7682, "elbo": -2.0289}, {"iter": 112, "mu_q": 0.7377, "sq": 0.7682, "elbo": -2.0289}, {"iter": 113, "mu_q": 0.7377, "sq": 0.7682, "elbo": -2.0289}, {"iter": 114, "mu_q": 0.7377, "sq": 0.7682, "elbo": -2.0289}, {"iter": 115, "mu_q": 0.7377, "sq": 0.7682, "elbo": -2.0289}, {"iter": 116, "mu_q": 0.7377, "sq": 0.7682, "elbo": -2.0289}, {"iter": 117, "mu_q": 0.7377, "sq": 0.7682, "elbo": -2.0289}, {"iter": 118, "mu_q": 0.7377, "sq": 0.7682, "elbo": -2.0289}, {"iter": 119, "mu_q": 0.7377, "sq": 0.7682, "elbo": -2.0289}, {"iter": 120, "mu_q": 0.7377, "sq": 0.7682, "elbo": -2.0289}]}, {"name": "mu_post", "value": 0.7377049180327869}, {"name": "sig_post", "value": 0.7682212795973759}]}</script>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb2" data-startfrom="193" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 192;"><span id="cb2-193">viewof iter <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> Inputs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">range</span>(</span>
<span id="cb2-194">  [<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">40</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-195">  { <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">value</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">step</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"VI iteration"</span> }</span>
<span id="cb2-196">)</span></code></pre></div></div>
<div id="ojs-controls" class="cell-output cell-output-display">
<div id="ojs-cell-1" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb3" data-startfrom="206" data-source-offset="-1" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 205;"><span id="cb3-206">snap <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> history[iter <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]</span>
<span id="cb3-207"></span>
<span id="cb3-208">z_vals <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Array</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">from</span>({<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">length</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">500</span>}<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> (_<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> i) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> i <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">7</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">499</span>)</span>
<span id="cb3-209"></span>
<span id="cb3-210"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">normalPDF</span>(zArr<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> mu<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> sigma) {</span>
<span id="cb3-211">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> zArr<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(zi <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span></span>
<span id="cb3-212">    <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Math</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">exp</span>(<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> ((zi <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> mu) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> sigma) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">**</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> (sigma <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Math</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Math</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">PI</span>))</span>
<span id="cb3-213">  )</span>
<span id="cb3-214">}</span>
<span id="cb3-215"></span>
<span id="cb3-216">true_curve <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> z_vals<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>((zi<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> i) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> ({</span>
<span id="cb3-217">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">z</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> zi<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb3-218">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">normalPDF</span>(z_vals<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> mu_post<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> sig_post)[i]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb3-219">}))</span>
<span id="cb3-220"></span>
<span id="cb3-221">q_curve <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> z_vals<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>((zi<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> i) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> ({</span>
<span id="cb3-222">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">z</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> zi<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb3-223">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">normalPDF</span>(z_vals<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> snap<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mu_q</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> snap<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sq</span>)[i]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb3-224">}))</span>
<span id="cb3-225"></span>
<span id="cb3-226">Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>({</span>
<span id="cb3-227">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">width</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">700</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb3-228">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">height</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">360</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb3-229">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">marginLeft</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">50</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb3-230">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> { <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"z"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">domain</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> [<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>] }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb3-231">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> { <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"density"</span> }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb3-232">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">marks</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> [</span>
<span id="cb3-233">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">line</span>(true_curve<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {</span>
<span id="cb3-234">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"z"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"y"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb3-235">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">stroke</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"steelblue"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">strokeWidth</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2.5</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">strokeDasharray</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"6 3"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb3-236">    })<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb3-237">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">line</span>(q_curve<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {</span>
<span id="cb3-238">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"z"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"y"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb3-239">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">stroke</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"darkorange"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">strokeWidth</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2.5</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb3-240">    })<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb3-241">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ruleX</span>([mu_post]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {</span>
<span id="cb3-242">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">stroke</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"steelblue"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">strokeDasharray</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"4 3"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">strokeOpacity</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb3-243">    })<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb3-244">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ruleX</span>([snap<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mu_q</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {</span>
<span id="cb3-245">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">stroke</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"darkorange"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">strokeDasharray</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"4 3"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">strokeOpacity</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb3-246">    })<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb3-247">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">text</span>(</span>
<span id="cb3-248">      [{ <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">z</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> mu_post <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.08</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`μ* = </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>mu_post<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">,  σ* = </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>sig_post<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span> }]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb3-249">      { <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"z"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.88</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">text</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"label"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">fontSize</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">12</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">fill</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"steelblue"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">textAnchor</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"start"</span> }</span>
<span id="cb3-250">    )<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb3-251">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">text</span>(</span>
<span id="cb3-252">      [{ <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">z</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> snap<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mu_q</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.08</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`μq = </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>snap<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mu_q</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">,  σq = </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>snap<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sq</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span> }]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb3-253">      { <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"z"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.78</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">text</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"label"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">fontSize</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">12</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">fill</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"darkorange"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">textAnchor</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"start"</span> }</span>
<span id="cb3-254">    )<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb3-255">  ]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb3-256">})</span></code></pre></div></div>
<div id="fig-vi-convergence" class="cell quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-vi-convergence-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<div class="cell-output cell-output-display">
<div id="fig-vi-convergence-1" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-subfloat-fig figure">
<div aria-describedby="fig-vi-convergence-1-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<div id="ojs-cell-2-1" data-nodetype="declaration">

</div>
</div>
<figcaption class="quarto-float-caption-bottom quarto-subfloat-caption quarto-subfloat-fig" id="fig-vi-convergence-1-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
(a)
</figcaption>
</figure>
</div>
</div>
<div class="cell-output cell-output-display">
<div id="fig-vi-convergence-2" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-subfloat-fig figure">
<div aria-describedby="fig-vi-convergence-2-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<div id="ojs-cell-2-2" data-nodetype="declaration">

</div>
</div>
<figcaption class="quarto-float-caption-bottom quarto-subfloat-caption quarto-subfloat-fig" id="fig-vi-convergence-2-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
(b)
</figcaption>
</figure>
</div>
</div>
<div class="cell-output cell-output-display">
<div id="fig-vi-convergence-3" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-subfloat-fig figure">
<div aria-describedby="fig-vi-convergence-3-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<div id="ojs-cell-2-3" data-nodetype="declaration">

</div>
</div>
<figcaption class="quarto-float-caption-bottom quarto-subfloat-caption quarto-subfloat-fig" id="fig-vi-convergence-3-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
(c)
</figcaption>
</figure>
</div>
</div>
<div class="cell-output cell-output-display">
<div id="fig-vi-convergence-4" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-subfloat-fig figure">
<div aria-describedby="fig-vi-convergence-4-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<div id="ojs-cell-2-4" data-nodetype="declaration">

</div>
</div>
<figcaption class="quarto-float-caption-bottom quarto-subfloat-caption quarto-subfloat-fig" id="fig-vi-convergence-4-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
(d)
</figcaption>
</figure>
</div>
</div>
<div class="cell-output cell-output-display">
<div id="fig-vi-convergence-5" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-subfloat-fig figure">
<div aria-describedby="fig-vi-convergence-5-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<div id="ojs-cell-2-5" data-nodetype="declaration">

</div>
</div>
<figcaption class="quarto-float-caption-bottom quarto-subfloat-caption quarto-subfloat-fig" id="fig-vi-convergence-5-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
(e)
</figcaption>
</figure>
</div>
</div>
<div class="cell-output cell-output-display">
<div id="fig-vi-convergence-6" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-subfloat-fig figure">
<div aria-describedby="fig-vi-convergence-6-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<div id="ojs-cell-2-6" data-nodetype="expression">

</div>
</div>
<figcaption class="quarto-float-caption-bottom quarto-subfloat-caption quarto-subfloat-fig" id="fig-vi-convergence-6-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
(f)
</figcaption>
</figure>
</div>
</div>
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-vi-convergence-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;1: VI convergence: the variational q approaches the true posterior. Drag the slider to step through iterations. Dashed blue line is the true posterior; solid orange line is the current q.
</figcaption>
</figure>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb4" data-startfrom="264" data-source-offset="-1" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 263;"><span id="cb4-264">ll_data <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> history<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">slice</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">40</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> ({ <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">iter</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">iter</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">elbo</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">elbo</span> }))</span>
<span id="cb4-265"></span>
<span id="cb4-266">Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>({</span>
<span id="cb4-267">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">width</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">700</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb4-268">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">height</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">200</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb4-269">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">marginLeft</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">60</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb4-270">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> { <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"iteration"</span> }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb4-271">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> { <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ELBO"</span> }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb4-272">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">marks</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> [</span>
<span id="cb4-273">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">line</span>(ll_data<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {</span>
<span id="cb4-274">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"iter"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"elbo"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">stroke</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"steelblue"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">strokeWidth</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb4-275">    })<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb4-276">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ruleX</span>([iter]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {</span>
<span id="cb4-277">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">stroke</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"darkorange"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">strokeOpacity</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">strokeDasharray</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"4 2"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb4-278">    })<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb4-279">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dot</span>([ll_data[iter <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {</span>
<span id="cb4-280">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"iter"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"elbo"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">fill</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"darkorange"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">r</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb4-281">    })<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb4-282">  ]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb4-283">})</span></code></pre></div></div>
<div id="fig-vi-elbo" class="cell quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-vi-elbo-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<div class="cell-output cell-output-display">
<div id="fig-vi-elbo-1" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-subfloat-fig figure">
<div aria-describedby="fig-vi-elbo-1-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<div id="ojs-cell-3-1" data-nodetype="declaration">

</div>
</div>
<figcaption class="quarto-float-caption-bottom quarto-subfloat-caption quarto-subfloat-fig" id="fig-vi-elbo-1-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
(a)
</figcaption>
</figure>
</div>
</div>
<div class="cell-output cell-output-display">
<div id="fig-vi-elbo-2" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-subfloat-fig figure">
<div aria-describedby="fig-vi-elbo-2-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<div id="ojs-cell-3-2" data-nodetype="expression">

</div>
</div>
<figcaption class="quarto-float-caption-bottom quarto-subfloat-caption quarto-subfloat-fig" id="fig-vi-elbo-2-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
(b)
</figcaption>
</figure>
</div>
</div>
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-vi-elbo-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;2: ELBO rises monotonically during VI optimisation.
</figcaption>
</figure>
</div>
</div>
<div id="elbo-verification" class="cell" data-execution_count="3">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb5-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># True log evidence via numerical integration</span></span>
<span id="cb5-2">z_grid <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.linspace(<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10000</span>)</span>
<span id="cb5-3">dz <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> z_grid[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> z_grid[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>]</span>
<span id="cb5-4">log_joint <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> stats.norm.logpdf(z_grid, x_obs, sigma_l) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> stats.norm.logpdf(z_grid, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb5-5">log_evidence_numerical <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> logsumexp(log_joint) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> np.log(dz)</span>
<span id="cb5-6"></span>
<span id="cb5-7"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"True log p(x) (numerical): </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>log_evidence_numerical<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:.4f}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>)</span>
<span id="cb5-8"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"Final ELBO:                </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>history[<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>][<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'elbo'</span>]<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:.4f}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>)</span>
<span id="cb5-9"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"Difference:                </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">abs</span>(log_evidence_numerical <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> history[<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>][<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'elbo'</span>])<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:.4f}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>True log p(x) (numerical): -2.0289
Final ELBO:                -2.0289
Difference:                0.0000</code></pre>
</div>
</div>
<p>As can be seen in Figure&nbsp;1, the approximation approaches the true distribution. This is verified numerically in the code block above. The code block shows that the KL divergence has converged to zero meaning that the distributions are the same up until numerical precision.</p>
</section>
<section id="summary" class="level2">
<h2 class="anchored" data-anchor-id="summary">Summary</h2>
<p>In the beginning, we motivated the need for variational inference to solve intractable posteriors. Then we derived ELBO and showed that maximizing it is equivalent to minimizing the KL divergence between the approximation and the true posterior. Then finally, we used the theory on a simple Gaussian example confirming that we were able to approximate the posterior well.</p>



</section>

<div id="quarto-appendix" class="default"><section class="quarto-appendix-contents" id="quarto-bibliography"><h2 class="anchored quarto-appendix-heading">References</h2><div id="refs" class="references csl-bib-body" data-entry-spacing="0">
<div id="ref-bishop2006pattern" class="csl-entry">
<div class="csl-left-margin">[1] </div><div class="csl-right-inline">C. M. Bishop, <em>Pattern recognition and machine learning</em>. Springer, 2006.</div>
</div>
<div id="ref-jamil2023vae" class="csl-entry">
<div class="csl-left-margin">[2] </div><div class="csl-right-inline">U. Jamil, <span>“<span class="nocase">Variational Autoencoder - Model, ELBO, loss function and maths explained easily!</span>”</span> <a href="https://www.youtube.com/watch?v=iwEzwTTalbg" class="uri">https://www.youtube.com/watch?v=iwEzwTTalbg</a>, Jun. 2023.</div>
</div>
</div></section><section class="quarto-appendix-contents" id="quarto-reuse"><h2 class="anchored quarto-appendix-heading">Reuse</h2><div class="quarto-appendix-contents"><div><a rel="license" href="https://creativecommons.org/licenses/by/4.0/">CC BY 4.0</a></div></div></section><section class="quarto-appendix-contents" id="quarto-citation"><h2 class="anchored quarto-appendix-heading">Citation</h2><div><div class="quarto-appendix-secondary-label">BibTeX citation:</div><div class="code-copy-outer-scaffold"><pre class="sourceCode code-with-copy quarto-appendix-bibtex"><code class="sourceCode bibtex">@online{bogossian2026,
  author = {Bogossian, Andreas},
  title = {Variational {Inference} \&amp; the {ELBO}},
  date = {2026-04-02},
  url = {https://andreasbogossian.com/posts/evidence-lower-bound/},
  langid = {en}
}
</code></pre></div><div class="quarto-appendix-secondary-label">For attribution, please cite this work as:</div><div id="ref-bogossian2026" class="csl-entry quarto-appendix-citeas">
<div class="">A.
Bogossian, <span>“Variational Inference &amp; the ELBO.”</span>
[Online]. Available: <a href="https://andreasbogossian.com/posts/evidence-lower-bound/">https://andreasbogossian.com/posts/evidence-lower-bound/</a></div>
</div></div></section></div> ]]></description>
  <category>variational inference</category>
  <category>probabilistic ML</category>
  <category>deep learning</category>
  <guid>https://andreasbogossian.com/posts/evidence-lower-bound/</guid>
  <pubDate>Wed, 01 Apr 2026 21:00:00 GMT</pubDate>
  <media:content url="https://andreasbogossian.com/posts/evidence-lower-bound/thumbnail.webp" medium="image" type="image/webp"/>
</item>
<item>
  <title>A* Pathfinding Algorithm</title>
  <dc:creator>Andreas Bogossian</dc:creator>
  <link>https://andreasbogossian.com/posts/a-star/</link>
  <description><![CDATA[ 




<p>How does Google Maps find the <em>best</em> route in under a second, across millions of roads? Stripping this question into its basic elements, the question becomes, how to find the shortest path in a graph from the start position to the end position. If one was to approach this problem by trying every single path, the number of paths grow as <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%7BO%7D(b%5Ed)">, where <img src="https://latex.codecogs.com/png.latex?b"> is the branching factor (average number of branches from each node) and <img src="https://latex.codecogs.com/png.latex?d"> is the depth. The brute force method scales extremely poorly so another solution must be used.</p>
<p>Dijkstra’s algorithm improves on the brute force method slightly. Dijkstra always expands the cheapest node so far. The problem with Dijkstra is that it expands the search in every direction including roads that lead away from the destination. Dijkstra can be beaten with algorithms with sense of direction.</p>
<section id="the-idea-behind-the-a-algorithm" class="level2">
<h2 class="anchored" data-anchor-id="the-idea-behind-the-a-algorithm">The idea behind the A* algorithm</h2>
<p>A* assigns every node a single score:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0Af(n)%20=%20g(n)%20+%20h(n)%0A"></p>
<p>where</p>
<ul>
<li><img src="https://latex.codecogs.com/png.latex?g(n)">: the exact cost from start to the current node <img src="https://latex.codecogs.com/png.latex?n">. This is known.</li>
<li><img src="https://latex.codecogs.com/png.latex?h(n)">: the estimated cost from the current node <img src="https://latex.codecogs.com/png.latex?n"> to the goal. This is a heuristic (educated guess).</li>
</ul>
<p>After A* computes the score of each frontier node, the algorithm will always expand the node with the lowest <img src="https://latex.codecogs.com/png.latex?f(n)">. Minimizing both the cost of getting to the current node <img src="https://latex.codecogs.com/png.latex?g(n)"> and the estimate of arriving at the goal <img src="https://latex.codecogs.com/png.latex?h(n)"> makes the algorithm seek the shortest path from start point to the end point.</p>
<p>For a more thorough study of A*, please refer to <span class="citation" data-cites="russell2022artificial">[1]</span>.</p>
</section>
<section id="implementation" class="level2">
<h2 class="anchored" data-anchor-id="implementation">Implementation</h2>
<section id="heuristic" class="level3">
<h3 class="anchored" data-anchor-id="heuristic">Heuristic</h3>
<p>A common heuristic is the Manhattan distance:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0Ah(n)%20=%20%7Cx_1%20-%20x_2%7C%20+%20%7Cy_1%20-%20y_2%7C%0A"></p>
<p>The geometric interpretation of this is amount of grid cells that need to be navigated to go from one point to another without moving diagonally.</p>
<div id="fa6dc493" class="cell" data-execution_count="1">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb1-1"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">def</span> heuristic(a: <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">tuple</span>[<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">int</span>, <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">int</span>], b: <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">tuple</span>[<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">int</span>, <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">int</span>]) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-&gt;</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">int</span>:</span>
<span id="cb1-2">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">abs</span>(a[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> b[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>]) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">abs</span>(a[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> b[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>])</span></code></pre></div></div>
</div>
</section>
<section id="main-loop" class="level3">
<h3 class="anchored" data-anchor-id="main-loop">Main loop</h3>
<p>The open set is a min-heap keyed on <img src="https://latex.codecogs.com/png.latex?f(n)">. At each iteration the node with the lowest <img src="https://latex.codecogs.com/png.latex?f"> is popped. Then check if the goal has been reached. Then the third step is to expand the neighbours:</p>
<div id="ac7e2fde" class="cell" data-execution_count="2">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb2-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> heapq</span>
<span id="cb2-2"></span>
<span id="cb2-3"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">def</span> astar(</span>
<span id="cb2-4">    grid: <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">list</span>[<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">list</span>[<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">int</span>]],</span>
<span id="cb2-5">    start: <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">tuple</span>[<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">int</span>, <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">int</span>],</span>
<span id="cb2-6">    goal: <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">tuple</span>[<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">int</span>, <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">int</span>]</span>
<span id="cb2-7">) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-&gt;</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">dict</span>[<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">tuple</span>[<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">int</span>, <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">int</span>], <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">tuple</span>[<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">int</span>, <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">int</span>]]:</span>
<span id="cb2-8">    rows, cols <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">len</span>(grid), <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">len</span>(grid[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>])</span>
<span id="cb2-9"></span>
<span id="cb2-10">    open_set: <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">list</span>[<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">tuple</span>[<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">int</span>, <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">tuple</span>[<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">int</span>, <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">int</span>]]] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> []</span>
<span id="cb2-11">    heapq.heappush(open_set, (<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, start))</span>
<span id="cb2-12"></span>
<span id="cb2-13">    came_from: <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">dict</span>[<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">tuple</span>[<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">int</span>, <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">int</span>], <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">tuple</span>[<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">int</span>, <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">int</span>]] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> {}</span>
<span id="cb2-14">    g_score: <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">dict</span>[<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">tuple</span>[<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">int</span>, <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">int</span>], <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">int</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> {start: <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>}</span>
<span id="cb2-15"></span>
<span id="cb2-16">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">while</span> open_set:</span>
<span id="cb2-17">        _, current <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> heapq.heappop(open_set)</span>
<span id="cb2-18"></span>
<span id="cb2-19">        <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> current <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> goal:</span>
<span id="cb2-20">            <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">break</span></span>
<span id="cb2-21"></span>
<span id="cb2-22">        r, c <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> current</span>
<span id="cb2-23">        <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> dr, dc <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> [(<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>),(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>),(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>),(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)]:</span>
<span id="cb2-24">            neighbour: <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">tuple</span>[<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">int</span>, <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">int</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (r <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> dr, c <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> dc)</span>
<span id="cb2-25">            nr, nc <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> neighbour</span>
<span id="cb2-26"></span>
<span id="cb2-27">            <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">not</span> (<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;=</span> nr <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> rows <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">and</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;=</span> nc <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> cols):</span>
<span id="cb2-28">                <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">continue</span></span>
<span id="cb2-29">            <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> grid[nr][nc] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>:</span>
<span id="cb2-30">                <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">continue</span></span>
<span id="cb2-31"></span>
<span id="cb2-32">            tentative_g <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> g_score[current] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span></span>
<span id="cb2-33"></span>
<span id="cb2-34">            <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> tentative_g <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> g_score.get(neighbour, <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">float</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'inf'</span>)):</span>
<span id="cb2-35">                came_from[neighbour] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> current</span>
<span id="cb2-36">                g_score[neighbour] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> tentative_g</span>
<span id="cb2-37">                f <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> tentative_g <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> heuristic(neighbour, goal)</span>
<span id="cb2-38">                heapq.heappush(open_set, (f, neighbour))</span>
<span id="cb2-39"></span>
<span id="cb2-40">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> came_from</span></code></pre></div></div>
</div>
</section>
<section id="path-reconstruction" class="level3">
<h3 class="anchored" data-anchor-id="path-reconstruction">Path reconstruction</h3>
<div id="ac86c331" class="cell" data-execution_count="3">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb3-1"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">def</span> reconstruct_path(</span>
<span id="cb3-2">    came_from: <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">dict</span>[<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">tuple</span>[<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">int</span>, <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">int</span>], <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">tuple</span>[<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">int</span>, <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">int</span>]],</span>
<span id="cb3-3">    start: <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">tuple</span>[<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">int</span>, <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">int</span>],</span>
<span id="cb3-4">    goal: <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">tuple</span>[<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">int</span>, <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">int</span>]</span>
<span id="cb3-5">) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-&gt;</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">list</span>[<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">tuple</span>[<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">int</span>, <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">int</span>]]:</span>
<span id="cb3-6">    path: <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">list</span>[<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">tuple</span>[<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">int</span>, <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">int</span>]] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> []</span>
<span id="cb3-7">    node <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> goal</span>
<span id="cb3-8">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">while</span> node <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!=</span> start:</span>
<span id="cb3-9">        path.append(node)</span>
<span id="cb3-10">        node <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> came_from[node]</span>
<span id="cb3-11">    path.append(start)</span>
<span id="cb3-12">    path.reverse()</span>
<span id="cb3-13">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> path</span></code></pre></div></div>
</div>
</section>
<section id="running-the-algorithm-on-a-2d-grid" class="level3">
<h3 class="anchored" data-anchor-id="running-the-algorithm-on-a-2d-grid">Running the algorithm on a 2D grid</h3>
<div id="3aa51621" class="cell" data-execution_count="4">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb4-1">grid <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [</span>
<span id="cb4-2">    [<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>],</span>
<span id="cb4-3">    [<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>],</span>
<span id="cb4-4">    [<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>],</span>
<span id="cb4-5">    [<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>],</span>
<span id="cb4-6">    [<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>],</span>
<span id="cb4-7">]</span>
<span id="cb4-8">start, goal <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>), (<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>)</span>
<span id="cb4-9"></span>
<span id="cb4-10">came_from <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> astar(grid, start, goal)</span>
<span id="cb4-11">path <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> reconstruct_path(came_from, start, goal)</span>
<span id="cb4-12"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(path)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[(0, 0), (0, 1), (0, 2), (1, 2), (2, 2), (2, 3), (2, 4), (3, 4), (4, 4)]</code></pre>
</div>
</div>
</section>
</section>
<section id="weighted-a" class="level2">
<h2 class="anchored" data-anchor-id="weighted-a">Weighted A*</h2>
<p>A useful, greedier A* variant is weighted A*. The variant inflates the heuristic by a weight <img src="https://latex.codecogs.com/png.latex?w%20%3E%201">:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0Af(n)%20=%20g(n)%20+%20w%20%5Ccdot%20h(n)%0A"></p>
<p>The benefit of using the weight is that fewer nodes are expanded because the search prioritizes nodes that are close to the end. The trade-off is that the path found is at most <img src="https://latex.codecogs.com/png.latex?w"> times longer than optimal.</p>
</section>
<section id="demo" class="level2">
<h2 class="anchored" data-anchor-id="demo">Demo</h2>
<p>Start with Dijkstra and then swap to A* with the Manhattan heuristic. Also, test the weight slider to make the algorithm faster with the expense of accuracy.</p>
<ul>
<li><strong>Blue-green cells</strong> — open set: discovered, not yet expanded.</li>
<li><strong>Orange cell</strong> — node currently being expanded.</li>
<li><strong>Dark green cells</strong> — closed set: fully expanded.</li>
<li><strong>Yellow path</strong> — the solution once the algorithm reaches the end node.</li>
<li>Drag <strong>S</strong> or <strong>E</strong> to reposition start and goal. Paint walls by clicking and dragging on empty cells.</li>
</ul>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb6" data-startfrom="159" data-source-offset="-82" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 158;"><span id="cb6-159">COLS <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">19</span></span>
<span id="cb6-160">ROWS <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">11</span></span>
<span id="cb6-161">CELL <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">40</span></span>
<span id="cb6-162">W    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> COLS <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> CELL</span>
<span id="cb6-163">H    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ROWS <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> CELL</span>
<span id="cb6-164">key  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (r<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> c) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>r<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">,</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>c<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span></span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-1-1" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-1-2" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-1-3" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-1-4" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-1-5" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-1-6" data-nodetype="declaration">

</div>
</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb7" data-startfrom="171" data-source-offset="-82" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 170;"><span id="cb7-171">viewof heuristic <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> Inputs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(</span>
<span id="cb7-172">  [<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"zero (Dijkstra)"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"manhattan"</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb7-173">  { <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Heuristic"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">value</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"zero (Dijkstra)"</span> }</span>
<span id="cb7-174">)</span>
<span id="cb7-175"></span>
<span id="cb7-176">viewof weight <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> Inputs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">range</span>([<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {</span>
<span id="cb7-177">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Weight (w)"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb7-178">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">value</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb7-179">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">step</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span></span>
<span id="cb7-180">})</span>
<span id="cb7-181"></span>
<span id="cb7-182">viewof speed <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> Inputs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">range</span>([<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">500</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {</span>
<span id="cb7-183">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Speed (ms/step)"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb7-184">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">value</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">80</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb7-185">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">step</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span></span>
<span id="cb7-186">})</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-2-1" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-2-2" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-2-3" data-nodetype="declaration">

</div>
</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb8" data-startfrom="190" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 189;"><span id="cb8-190"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// ── heuristic function ───────────────────────────────────────────────────────</span></span>
<span id="cb8-191"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">heuristicFn</span>(r1<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> c1<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> r2<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> c2<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> type) {</span>
<span id="cb8-192">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> dr <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Math</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">abs</span>(r1 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> r2)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> dc <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Math</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">abs</span>(c1 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> c2)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb8-193">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (type <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"manhattan"</span>)       <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> dr <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> dc<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb8-194">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (type <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"zero (Dijkstra)"</span>) <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb8-195">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> dr <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> dc<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb8-196">}</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-3" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb9" data-startfrom="205" data-source-offset="-82" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 204;"><span id="cb9-205"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">initSearch</span>(s) {</span>
<span id="cb9-206">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> sk <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">key</span>(s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">start</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">r</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">start</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">c</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb9-207">  s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">openSet</span>   <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [{ <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">r</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">start</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">r</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">c</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">start</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">c</span> }]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb9-208">  s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">closedSet</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">new</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Set</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb9-209">  s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cameFrom</span>  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> {}<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb9-210">  s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">gScore</span>    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> { [sk]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span> }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb9-211">  s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fScore</span>    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> { [sk]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">weight</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">heuristicFn</span>(s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">start</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">r</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">start</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">c</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">end</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">r</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">end</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">c</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">heuristic</span>) }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb9-212">  s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">path</span>      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> []<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb9-213">  s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">current</span>   <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">null</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb9-214">  s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">running</span>   <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">true</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb9-215">  s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">done</span>      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">false</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb9-216">  s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">iter</span>      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb9-217">  s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">status</span>    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"searching…"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb9-218">}</span>
<span id="cb9-219"></span>
<span id="cb9-220"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">stepOnce</span>(s) {</span>
<span id="cb9-221">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">running</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">||</span> s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">done</span>) <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb9-222">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">openSet</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>) {</span>
<span id="cb9-223">    s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">running</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">false</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">done</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">true</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">current</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">null</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">status</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"no path found"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb9-224">  }</span>
<span id="cb9-225">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> bestIdx <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb9-226">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> (<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> i <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> i <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">openSet</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> i<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">++</span>) {</span>
<span id="cb9-227">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> fi <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fScore</span>[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">key</span>(s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">openSet</span>[i]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">r</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">openSet</span>[i]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">c</span>)] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">??</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">Infinity</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb9-228">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> fb <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fScore</span>[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">key</span>(s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">openSet</span>[bestIdx]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">r</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">openSet</span>[bestIdx]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">c</span>)] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">??</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">Infinity</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb9-229">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (fi <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> fb) bestIdx <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> i<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb9-230">  }</span>
<span id="cb9-231">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> cur <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">openSet</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">splice</span>(bestIdx<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb9-232">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> ck  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">key</span>(cur<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">r</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> cur<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">c</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb9-233">  s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">current</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ck<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb9-234"></span>
<span id="cb9-235">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (cur<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">r</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">end</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">r</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;&amp;</span> cur<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">c</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">end</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">c</span>) {</span>
<span id="cb9-236">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> k <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ck<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb9-237">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">while</span> (s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cameFrom</span>[k]) { s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">path</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">push</span>(k)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> k <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cameFrom</span>[k]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> }</span>
<span id="cb9-238">    s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">path</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">push</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">key</span>(s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">start</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">r</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">start</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">c</span>))<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb9-239">    s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">running</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">false</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">done</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">true</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">current</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">null</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb9-240">    s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">status</span>  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`done — </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">path</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;"> steps`</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb9-241">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb9-242">  }</span>
<span id="cb9-243">  s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">closedSet</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">add</span>(ck)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb9-244">  s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">iter</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">++;</span></span>
<span id="cb9-245"></span>
<span id="cb9-246">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> (<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> [dr<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> dc] <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">of</span> [[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span>[<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span>[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span>[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]]) {</span>
<span id="cb9-247">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> nr <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> cur<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">r</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> dr<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> nc <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> cur<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">c</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> dc<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb9-248">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (nr <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">||</span> nr <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> ROWS <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">||</span> nc <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">||</span> nc <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> COLS) <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">continue</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb9-249">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">walls</span>[nr][nc]) <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">continue</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb9-250">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> nk <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">key</span>(nr<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> nc)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb9-251">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">closedSet</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">has</span>(nk)) <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">continue</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb9-252">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> tentG <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">gScore</span>[ck] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">??</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">Infinity</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb9-253">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (tentG <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> (s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">gScore</span>[nk] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">??</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">Infinity</span>)) {</span>
<span id="cb9-254">      s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cameFrom</span>[nk] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ck<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb9-255">      s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">gScore</span>[nk]   <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> tentG<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb9-256">      s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fScore</span>[nk]   <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> tentG <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">weight</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">heuristicFn</span>(nr<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> nc<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">end</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">r</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">end</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">c</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">heuristic</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb9-257">      <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">openSet</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">find</span>(n <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> n<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">r</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> nr <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;&amp;</span> n<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">c</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> nc))</span>
<span id="cb9-258">        s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">openSet</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">push</span>({ <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">r</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> nr<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">c</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> nc })<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb9-259">    }</span>
<span id="cb9-260">  }</span>
<span id="cb9-261">}</span>
<span id="cb9-262"></span>
<span id="cb9-263"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">resetSearch</span>(s) {</span>
<span id="cb9-264">  s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">openSet</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> []<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">closedSet</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">new</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Set</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cameFrom</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> {}<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb9-265">  s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">gScore</span>  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> {}<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fScore</span>   <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> {}<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb9-266">  s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">path</span>    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> []<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">current</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">null</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">running</span>  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">false</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">done</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">false</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">iter</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">status</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"idle"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb9-267">}</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-4-1" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-4-2" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-4-3" data-nodetype="declaration">

</div>
</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb10" data-startfrom="271" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 270;"><span id="cb10-271"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// ── maze generation ──────────────────────────────────────────────────────────</span></span>
<span id="cb10-272"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">generateMaze</span>(s) {</span>
<span id="cb10-273">  s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">walls</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Array</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">from</span>({ <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">length</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> ROWS }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> () <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">new</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Array</span>(COLS)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fill</span>(<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">true</span>))<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb10-274">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> inMaze    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Array</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">from</span>({ <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">length</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> ROWS }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> () <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">new</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Array</span>(COLS)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fill</span>(<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">false</span>))<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb10-275">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> cardinals <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span>[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span>[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span>[<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>]]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb10-276"></span>
<span id="cb10-277">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">neighbours</span>(r<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> c) {</span>
<span id="cb10-278">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> cardinals</span>
<span id="cb10-279">      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(([dr<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> dc]) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> [r <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> dr<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> c <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> dc])</span>
<span id="cb10-280">      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(([nr<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> nc]) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> nr <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;&amp;</span> nr <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> ROWS <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;&amp;</span> nc <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;&amp;</span> nc <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> COLS <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb10-281">  }</span>
<span id="cb10-282"></span>
<span id="cb10-283">  s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">walls</span>[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>][<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">false</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb10-284">  inMaze[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>][<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">true</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb10-285">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> frontier  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">neighbours</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(([nr<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> nc]) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> [nr<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> nc<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>])<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb10-286"></span>
<span id="cb10-287">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">while</span> (frontier<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length</span>) {</span>
<span id="cb10-288">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> idx <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Math</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">floor</span>(<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Math</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">random</span>() <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> frontier<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb10-289">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> [r<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> c<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> pr<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> pc] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> frontier<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">splice</span>(idx<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb10-290">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (inMaze[r][c]) <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">continue</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb10-291">    s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">walls</span>[r][c] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">false</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb10-292">    s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">walls</span>[(r <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> pr) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>][(c <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> pc) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">false</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb10-293">    inMaze[r][c] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">true</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb10-294">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> (<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> [nr<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> nc] <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">of</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">neighbours</span>(r<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> c))</span>
<span id="cb10-295">      <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>inMaze[nr][nc]) frontier<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">push</span>([nr<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> nc<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> r<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> c])<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb10-296">  }</span>
<span id="cb10-297"></span>
<span id="cb10-298">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> dist   <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Array</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">from</span>({ <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">length</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> ROWS }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> () <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">new</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Array</span>(COLS)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fill</span>(<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>))<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb10-299">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> queue  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb10-300">  dist[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>][<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]   <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb10-301">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> furthest <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb10-302">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">while</span> (queue<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length</span>) {</span>
<span id="cb10-303">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> [r<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> c] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> queue<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">shift</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb10-304">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> (<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> [dr<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> dc] <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">of</span> [[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span>[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span>[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span>[<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>]]) {</span>
<span id="cb10-305">      <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> nr <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> r <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> dr<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> nc <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> c <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> dc<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb10-306">      <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (nr <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">||</span> nr <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> ROWS <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">||</span> nc <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">||</span> nc <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> COLS) <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">continue</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb10-307">      <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">walls</span>[nr][nc] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">||</span> dist[nr][nc] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!==</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">continue</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb10-308">      dist[nr][nc] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> dist[r][c] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb10-309">      <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (dist[nr][nc] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> dist[furthest[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>]][furthest[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]]) furthest <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [nr<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> nc]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb10-310">      queue<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">push</span>([nr<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> nc])<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb10-311">    }</span>
<span id="cb10-312">  }</span>
<span id="cb10-313">  s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">start</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> { <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">r</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">c</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb10-314">  s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">end</span>   <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> { <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">r</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> furthest[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">c</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> furthest[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>] }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb10-315">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">resetSearch</span>(s)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb10-316">}</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-5" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb11" data-startfrom="322" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 321;"><span id="cb11-322"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// ── state (runs once, no reactive deps) ──────────────────────────────────────</span></span>
<span id="cb11-323">s <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> {</span>
<span id="cb11-324">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> state <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> {</span>
<span id="cb11-325">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">walls</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>     <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Array</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">from</span>({ <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">length</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> ROWS }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> () <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">new</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Array</span>(COLS)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fill</span>(<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">false</span>))<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb11-326">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">start</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>     { <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">r</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">c</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb11-327">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">end</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>       { <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">r</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> ROWS <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">c</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> COLS <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb11-328">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">openSet</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>   []<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">closedSet</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">new</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Set</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">cameFrom</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> {}<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb11-329">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">gScore</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>    {}<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">fScore</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>    {}<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">path</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> []<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb11-330">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">running</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>   <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">false</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">done</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">false</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">iter</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">status</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"idle"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb11-331">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">heuristic</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"zero (Dijkstra)"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">weight</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">speed</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">80</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb11-332">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">showScores</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">false</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">current</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">null</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb11-333">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">animating</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">false</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">animTimer</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">null</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb11-334">  }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb11-335">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">generateMaze</span>(state)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb11-336">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> state<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb11-337">}</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-6" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb12" data-startfrom="343" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 342;"><span id="cb12-343"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// ── app (D3 implementation — never mentions heuristic or weight) ──────────────</span></span>
<span id="cb12-344">app <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> {</span>
<span id="cb12-345">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> C <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> {</span>
<span id="cb12-346">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">bg</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#f8fafc"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span>  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// very light gray</span></span>
<span id="cb12-347">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">grid</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#cbd5e1"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span>  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// slate-300</span></span>
<span id="cb12-348">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">empty</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>     <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#f1f5f9"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span>  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// slate-100</span></span>
<span id="cb12-349">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">wall</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#334155"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span>  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// slate-700</span></span>
<span id="cb12-350">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">start</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>     <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#3b82f6"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span>  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// blue-500</span></span>
<span id="cb12-351">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">end</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>       <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#ef4444"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span>  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// red-500</span></span>
<span id="cb12-352">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">open</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#93c5fd"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span>  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// blue-300</span></span>
<span id="cb12-353">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">closed</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#86efac"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span>  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// green-300</span></span>
<span id="cb12-354">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">path</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#fbbf24"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span>  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// amber-400</span></span>
<span id="cb12-355">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">current</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>   <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#f97316"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span>  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// orange-500</span></span>
<span id="cb12-356">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">text</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#ffffff"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span>  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// white — for S/E labels on coloured cells</span></span>
<span id="cb12-357">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">scoreText</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#1e293b"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span>  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// slate-800 — dark, readable on all light cell colours</span></span>
<span id="cb12-358">  }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-359"></span>
<span id="cb12-360">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// ── SVG setup ───────────────────────────────────────────────────────────────</span></span>
<span id="cb12-361">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> svg <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> d3<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">create</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"svg"</span>)</span>
<span id="cb12-362">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"width"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span>  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"100%"</span>)</span>
<span id="cb12-363">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"viewBox"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`0 0 </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>W<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;"> </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>H<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>)</span>
<span id="cb12-364">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">style</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"cursor"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"crosshair"</span>)</span>
<span id="cb12-365">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">style</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"max-width"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>W<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">px`</span>)</span>
<span id="cb12-366">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">style</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"display"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"block"</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-367"></span>
<span id="cb12-368">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// background</span></span>
<span id="cb12-369">  svg<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">append</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"rect"</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"width"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> W)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"height"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> H)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"fill"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> C<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">bg</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-370"></span>
<span id="cb12-371">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// ── build flat cell array ────────────────────────────────────────────────</span></span>
<span id="cb12-372">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// Each object is a stable reference — D3 joins on identity, not index.</span></span>
<span id="cb12-373">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> cells <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Array</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">from</span>({ <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">length</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> ROWS }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> (_<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> r) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span></span>
<span id="cb12-374">    <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Array</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">from</span>({ <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">length</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> COLS }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> (_<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> c) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> ({ r<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> c }))</span>
<span id="cb12-375">  )<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">flat</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-376"></span>
<span id="cb12-377">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// ── cell rects ───────────────────────────────────────────────────────────</span></span>
<span id="cb12-378">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> rects <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> svg<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">append</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"g"</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"class"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"cells"</span>)</span>
<span id="cb12-379">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">selectAll</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"rect"</span>)</span>
<span id="cb12-380">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data</span>(cells<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">key</span>(d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">r</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">c</span>))   <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// key by position — stable across updates</span></span>
<span id="cb12-381">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">join</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"rect"</span>)</span>
<span id="cb12-382">      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"x"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span>      d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">c</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> CELL <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb12-383">      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"y"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span>      d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">r</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> CELL <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb12-384">      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"width"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span>  CELL <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span>
<span id="cb12-385">      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"height"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> CELL <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span>
<span id="cb12-386">      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"rx"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-387"></span>
<span id="cb12-388">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// ── tooltip ───────────────────────────────────────────────────────────────</span></span>
<span id="cb12-389">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> tooltip <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Object</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">assign</span>(<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">document</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">createElement</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"div"</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {})<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-390">  tooltip<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">style</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cssText</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span></span>
<span id="cb12-391"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  position: fixed;</span></span>
<span id="cb12-392"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  background: #1e293b;</span></span>
<span id="cb12-393"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  color: #f8fafc;</span></span>
<span id="cb12-394"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  border: 1px solid #475569;</span></span>
<span id="cb12-395"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  border-radius: 4px;</span></span>
<span id="cb12-396"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  padding: 4px 8px;</span></span>
<span id="cb12-397"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  font-size: 0.8em;</span></span>
<span id="cb12-398"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  font-family: monospace;</span></span>
<span id="cb12-399"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  pointer-events: none;</span></span>
<span id="cb12-400"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  opacity: 0;</span></span>
<span id="cb12-401"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  transition: opacity 0.1s;</span></span>
<span id="cb12-402"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  `</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-403">  <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">document</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">body</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">appendChild</span>(tooltip)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-404"></span>
<span id="cb12-405">  invalidation<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">then</span>(() <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> tooltip<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">remove</span>())<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-406"></span>
<span id="cb12-407">  rects<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">on</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mousemove"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(e<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> d) {</span>
<span id="cb12-408">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> k <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">key</span>(d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">r</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">c</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-409">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> g <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">gScore</span>[k] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">??</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"—"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-410">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> h <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">heuristicFn</span>(d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">r</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">c</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">end</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">r</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">end</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">c</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">heuristic</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-411">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> f <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fScore</span>[k] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">??</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"—"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-412">  tooltip<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">innerHTML</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`g=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>g<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;"> &amp;nbsp; h=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>h<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;"> &amp;nbsp; f=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>f<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-413">  tooltip<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">style</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">opacity</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-414">  tooltip<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">style</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">left</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (e<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">clientX</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">12</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"px"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-415">  tooltip<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">style</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">top</span>  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (e<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">clientY</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">28</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"px"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-416">  })<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-417"></span>
<span id="cb12-418">  rects<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">on</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mouseleave"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> () <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> { tooltip<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">style</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">opacity</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> })<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-419"></span>
<span id="cb12-420">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// ── labels (S / E) ────────────────────────────────────────────────────────</span></span>
<span id="cb12-421">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> labels <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> svg<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">append</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"g"</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"class"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"labels"</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-422"></span>
<span id="cb12-423">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">updateLabels</span>() {</span>
<span id="cb12-424">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> data <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [</span>
<span id="cb12-425">      { <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">r</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">start</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">r</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">c</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">start</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">c</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">text</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"S"</span> }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb12-426">      { <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">r</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">end</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">r</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span>   <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">c</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">end</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">c</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span>   <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">text</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"E"</span> }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb12-427">    ]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-428">    labels<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">selectAll</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"text"</span>)</span>
<span id="cb12-429">      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data</span>(data)</span>
<span id="cb12-430">      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">join</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"text"</span>)</span>
<span id="cb12-431">        <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"x"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">c</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> CELL <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> CELL <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span>
<span id="cb12-432">        <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"y"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">r</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> CELL <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> CELL <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span>
<span id="cb12-433">        <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"text-anchor"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"middle"</span>)</span>
<span id="cb12-434">        <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dominant-baseline"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"central"</span>)</span>
<span id="cb12-435">        <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"font-size"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> CELL <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.38</span>)</span>
<span id="cb12-436">        <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"font-family"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"monospace"</span>)</span>
<span id="cb12-437">        <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"font-weight"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bold"</span>)</span>
<span id="cb12-438">        <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"fill"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> C<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">text</span>)</span>
<span id="cb12-439">        <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pointer-events"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"none"</span>)</span>
<span id="cb12-440">        <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">text</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">text</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-441">  }</span>
<span id="cb12-442"></span>
<span id="cb12-443">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// ── score text overlay ───────────────────────────────────────────────────</span></span>
<span id="cb12-444">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> scoreG <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> svg<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">append</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"g"</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"class"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"scores"</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-445"></span>
<span id="cb12-446">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">updateScores</span>() {</span>
<span id="cb12-447">    scoreG<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">selectAll</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"*"</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">remove</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-448">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">showScores</span>) <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-449">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> scored <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> cells<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb12-450">      <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> k <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">key</span>(d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">r</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">c</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-451">      <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">gScore</span>[k] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!==</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">undefined</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;&amp;</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">walls</span>[d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">r</span>][d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">c</span>]</span>
<span id="cb12-452">        <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;&amp;</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>(d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">r</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">start</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">r</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;&amp;</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">c</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">start</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">c</span>)</span>
<span id="cb12-453">        <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;&amp;</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>(d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">r</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">end</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">r</span>   <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;&amp;</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">c</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">end</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">c</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-454">    })<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-455">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// g — top-left</span></span>
<span id="cb12-456">    scoreG<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">selectAll</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"text.gs"</span>)</span>
<span id="cb12-457">      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data</span>(scored<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">key</span>(d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">r</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">c</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"g"</span>)</span>
<span id="cb12-458">      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">join</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"text"</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"class"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"gs"</span>)</span>
<span id="cb12-459">        <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"x"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">c</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> CELL <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"y"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">r</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> CELL <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>)</span>
<span id="cb12-460">        <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"text-anchor"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"start"</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"font-size"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">9</span>)</span>
<span id="cb12-461">        <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"font-family"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"monospace"</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"fill"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> C<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scoreText</span>)</span>
<span id="cb12-462">        <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pointer-events"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"none"</span>)</span>
<span id="cb12-463">        <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">text</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`g:</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">gScore</span>[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">key</span>(d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">r</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">c</span>)]<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-464">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// h — top-right</span></span>
<span id="cb12-465">    scoreG<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">selectAll</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"text.hs"</span>)</span>
<span id="cb12-466">      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data</span>(scored<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">key</span>(d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">r</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">c</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"h"</span>)</span>
<span id="cb12-467">      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">join</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"text"</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"class"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"hs"</span>)</span>
<span id="cb12-468">        <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"x"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">c</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> CELL <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> CELL <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"y"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">r</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> CELL <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>)</span>
<span id="cb12-469">        <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"text-anchor"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"end"</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"font-size"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">9</span>)</span>
<span id="cb12-470">        <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"font-family"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"monospace"</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"fill"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> C<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scoreText</span>)</span>
<span id="cb12-471">        <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pointer-events"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"none"</span>)</span>
<span id="cb12-472">        <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">text</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`h:</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">heuristicFn</span>(d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">r</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">c</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">end</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">r</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">end</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">c</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">heuristic</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-473">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// f — bottom-centre, bold</span></span>
<span id="cb12-474">    scoreG<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">selectAll</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"text.fs"</span>)</span>
<span id="cb12-475">      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data</span>(scored<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">key</span>(d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">r</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">c</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"f"</span>)</span>
<span id="cb12-476">      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">join</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"text"</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"class"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"fs"</span>)</span>
<span id="cb12-477">        <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"x"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">c</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> CELL <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> CELL <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"y"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">r</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> CELL <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> CELL <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>)</span>
<span id="cb12-478">        <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"text-anchor"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"middle"</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"font-size"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"font-weight"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bold"</span>)</span>
<span id="cb12-479">        <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"font-family"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"monospace"</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"fill"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> C<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scoreText</span>)</span>
<span id="cb12-480">        <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pointer-events"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"none"</span>)</span>
<span id="cb12-481">        <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">text</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> { <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> f <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fScore</span>[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">key</span>(d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">r</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">c</span>)]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> f <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!==</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">undefined</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> <span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`f:</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Number</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">isInteger</span>(f) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> f <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> f<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> })<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-482">  }</span>
<span id="cb12-483"></span>
<span id="cb12-484">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// ── grid lines ────────────────────────────────────────────────────────────</span></span>
<span id="cb12-485">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> gridG <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> svg<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">append</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"g"</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"class"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"grid"</span>)</span>
<span id="cb12-486">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"stroke"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> C<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">grid</span>)</span>
<span id="cb12-487">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"stroke-width"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-488"></span>
<span id="cb12-489">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> (<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> r <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> r <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;=</span> ROWS<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> r<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">++</span>)</span>
<span id="cb12-490">    gridG<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">append</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"line"</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"x1"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"y1"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> r<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>CELL)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"x2"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> W)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"y2"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> r<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>CELL)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-491">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> (<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> c <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> c <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;=</span> COLS<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> c<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">++</span>)</span>
<span id="cb12-492">    gridG<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">append</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"line"</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"x1"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> c<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>CELL)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"y1"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"x2"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> c<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>CELL)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"y2"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> H)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-493"></span>
<span id="cb12-494">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// ── draw — only updates fill, no DOM rebuild ──────────────────────────────</span></span>
<span id="cb12-495">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> iterDisplay <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">document</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">createElement</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"div"</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-496">  iterDisplay<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">style</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cssText</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"margin-top:6px;font-size:0.85em"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-497">  iterDisplay<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">textContent</span>   <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"iterations: —"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-498"></span>
<span id="cb12-499">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cellColor</span>(d) {</span>
<span id="cb12-500">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> k         <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">key</span>(d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">r</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">c</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-501">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> isStart   <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">r</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">start</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">r</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;&amp;</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">c</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">start</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">c</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-502">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> isEnd     <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">r</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">end</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">r</span>   <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;&amp;</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">c</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">end</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">c</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-503">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> isWall    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">walls</span>[d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">r</span>][d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">c</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-504">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> isPath    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pathSet<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">has</span>(k)     <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;&amp;</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>isStart <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;&amp;</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>isEnd<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-505">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> isCurrent <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> k <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">current</span>   <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;&amp;</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>isStart <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;&amp;</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>isEnd<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-506">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> isOpen    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> openKeys<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">has</span>(k)    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;&amp;</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>isStart <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;&amp;</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>isEnd<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-507">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> isClosed  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">closedSet</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">has</span>(k) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;&amp;</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>isStart <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;&amp;</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>isEnd<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-508">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> isWall <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> C<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">wall</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> isStart <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> C<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">start</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> isEnd <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> C<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">end</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span></span>
<span id="cb12-509">           isPath <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> C<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">path</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> isCurrent <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> C<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">current</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> isOpen <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> C<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">open</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> isClosed <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> C<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">closed</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> C<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">empty</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-510">  }</span>
<span id="cb12-511"></span>
<span id="cb12-512">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// these are updated before every draw call</span></span>
<span id="cb12-513">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> openKeys <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">new</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Set</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> pathSet <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">new</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Set</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-514"></span>
<span id="cb12-515">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">draw</span>() {</span>
<span id="cb12-516">    openKeys <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">new</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Set</span>(s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">openSet</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(n <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">key</span>(n<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">r</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> n<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">c</span>)))<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-517">    pathSet  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">new</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Set</span>(s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">path</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-518"></span>
<span id="cb12-519">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// D3 only touches the fill attribute — no DOM nodes created or destroyed</span></span>
<span id="cb12-520">    rects<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"fill"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cellColor</span>(d))<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-521"></span>
<span id="cb12-522">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">updateLabels</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-523">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">updateScores</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-524"></span>
<span id="cb12-525">    iterDisplay<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">textContent</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">done</span></span>
<span id="cb12-526">      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> <span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`iterations: </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">iter</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;"> · </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">status</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span></span>
<span id="cb12-527">      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">iter</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> <span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`iterations: </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">iter</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">…`</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"iterations: —"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-528">  }</span>
<span id="cb12-529"></span>
<span id="cb12-530">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// ── pointer / paint / drag ────────────────────────────────────────────────</span></span>
<span id="cb12-531">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> painting <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">false</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> paintValue <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">true</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> dragging <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">null</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-532"></span>
<span id="cb12-533">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cellAt</span>(e) {</span>
<span id="cb12-534">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> svgEl <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> svg<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">node</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-535">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> rect  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> svgEl<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">getBoundingClientRect</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-536">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> scaleX <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> W <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> rect<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-537">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> scaleY <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> H <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> rect<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">height</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-538">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> {</span>
<span id="cb12-539">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">r</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Math</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">floor</span>((e<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">clientY</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> rect<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">top</span>)  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> scaleY <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> CELL)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb12-540">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">c</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Math</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">floor</span>((e<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">clientX</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> rect<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">left</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> scaleX <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> CELL)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb12-541">    }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-542">  }</span>
<span id="cb12-543"></span>
<span id="cb12-544">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">applyEdit</span>(r<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> c) {</span>
<span id="cb12-545">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (r <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">||</span> r <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> ROWS <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">||</span> c <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">||</span> c <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> COLS) <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-546">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> ((r <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">start</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">r</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;&amp;</span> c <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">start</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">c</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">||</span> (r <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">end</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">r</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;&amp;</span> c <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">end</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">c</span>)) <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-547">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">walls</span>[r][c] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> paintValue) <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-548">    s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">walls</span>[r][c] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> paintValue<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-549">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">resetSearch</span>(s)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">draw</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-550">  }</span>
<span id="cb12-551"></span>
<span id="cb12-552">  svg<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">on</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pointerdown"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> e <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb12-553">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">stopAnim</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> svg<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">node</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">setPointerCapture</span>(e<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pointerId</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-554">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> { r<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> c } <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cellAt</span>(e)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-555">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (r <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">||</span> r <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> ROWS <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">||</span> c <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">||</span> c <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> COLS) <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-556">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (r <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">start</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">r</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;&amp;</span> c <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">start</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">c</span>) { dragging <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"start"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> }</span>
<span id="cb12-557">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (r <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">end</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">r</span>   <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;&amp;</span> c <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">end</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">c</span>)   { dragging <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"end"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span>   <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> }</span>
<span id="cb12-558">    painting <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">true</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-559">    paintValue <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">walls</span>[r][c]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">applyEdit</span>(r<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> c)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-560">  })<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-561">  svg<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">on</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pointermove"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> e <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb12-562">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> { r<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> c } <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cellAt</span>(e)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-563">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (dragging) {</span>
<span id="cb12-564">      <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (r <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">||</span> r <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> ROWS <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">||</span> c <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">||</span> c <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> COLS <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">||</span> s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">walls</span>[r][c]) <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-565">      <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (dragging <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"start"</span>) s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">start</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> { r<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> c }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-566">      <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span>                      s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">end</span>   <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> { r<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> c }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-567">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">resetSearch</span>(s)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">draw</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-568">    } <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (painting) {</span>
<span id="cb12-569">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">applyEdit</span>(r<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> c)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-570">    }</span>
<span id="cb12-571">  })<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-572">  svg<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">on</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pointerup"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> () <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> { painting <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">false</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> dragging <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">null</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> })<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-573"></span>
<span id="cb12-574">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// ── animation ─────────────────────────────────────────────────────────────</span></span>
<span id="cb12-575">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">stopAnim</span>() {</span>
<span id="cb12-576">    s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">animating</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">false</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-577">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">animTimer</span>) { <span class="pp" style="color: #AD0000;
background-color: null;
font-style: inherit;">clearTimeout</span>(s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">animTimer</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">animTimer</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">null</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> }</span>
<span id="cb12-578">    btnAnimate<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">textContent</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"▶ Animate"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-579">  }</span>
<span id="cb12-580"></span>
<span id="cb12-581">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">animTick</span>() {</span>
<span id="cb12-582">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">animating</span>) <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-583">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">running</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;&amp;</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">done</span>) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">initSearch</span>(s)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-584">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">stepOnce</span>(s)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">draw</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-585">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">done</span>) s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">animTimer</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="pp" style="color: #AD0000;
background-color: null;
font-style: inherit;">setTimeout</span>(animTick<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">speed</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-586">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">stopAnim</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-587">  }</span>
<span id="cb12-588"></span>
<span id="cb12-589">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">startAnim</span>() {</span>
<span id="cb12-590">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">done</span>) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">resetSearch</span>(s)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-591">    s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">animating</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">true</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-592">    btnAnimate<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">textContent</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"⏸ Pause"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-593">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">animTick</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-594">  }</span>
<span id="cb12-595"></span>
<span id="cb12-596">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// ── buttons ───────────────────────────────────────────────────────────────</span></span>
<span id="cb12-597">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> btnAnimate <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Object</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">assign</span>(<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">document</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">createElement</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"button"</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> { <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">textContent</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"▶ Animate"</span> })<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-598">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> btnStep    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Object</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">assign</span>(<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">document</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">createElement</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"button"</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> { <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">textContent</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Step"</span> })<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-599">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> btnRun     <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Object</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">assign</span>(<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">document</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">createElement</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"button"</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> { <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">textContent</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Run"</span> })<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-600">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> btnReset   <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Object</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">assign</span>(<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">document</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">createElement</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"button"</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> { <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">textContent</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Reset"</span> })<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-601">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> btnClear   <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Object</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">assign</span>(<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">document</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">createElement</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"button"</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> { <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">textContent</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Clear walls"</span> })<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-602">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> btnMaze    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Object</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">assign</span>(<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">document</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">createElement</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"button"</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> { <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">textContent</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"New maze"</span> })<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-603">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> chkScores  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Object</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">assign</span>(<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">document</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">createElement</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"input"</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span>  { <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">type</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"checkbox"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">id</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"chk-scores"</span> })<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-604">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> lblScores  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Object</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">assign</span>(<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">document</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">createElement</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"label"</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span>  { <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">textContent</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Show g/h/f"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">htmlFor</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"chk-scores"</span> })<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-605">  lblScores<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">style</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cssText</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"font-size:0.85em;cursor:pointer;user-select:none"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-606"></span>
<span id="cb12-607">  btnAnimate<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">onclick</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> () <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">animating</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">stopAnim</span>() <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">startAnim</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-608">  btnStep<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">onclick</span>    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> () <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb12-609">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">stopAnim</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-610">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">running</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;&amp;</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">done</span>) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">initSearch</span>(s)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-611">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">stepOnce</span>(s)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">draw</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-612">  }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-613">  btnRun<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">onclick</span>     <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> () <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb12-614">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">stopAnim</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-615">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">running</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;&amp;</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">done</span>) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">initSearch</span>(s)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-616">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">while</span> (<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">done</span>) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">stepOnce</span>(s)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-617">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">draw</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-618">  }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-619">  btnReset<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">onclick</span>   <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> () <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> { <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">stopAnim</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">resetSearch</span>(s)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">draw</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-620">  btnClear<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">onclick</span>   <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> () <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb12-621">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">stopAnim</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-622">    s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">walls</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Array</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">from</span>({ <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">length</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> ROWS }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> () <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">new</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Array</span>(COLS)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fill</span>(<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">false</span>))<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-623">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">resetSearch</span>(s)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">draw</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-624">  }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-625">  btnMaze<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">onclick</span>    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> () <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> { <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">stopAnim</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">generateMaze</span>(s)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">draw</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-626">  chkScores<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">onchange</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> () <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> { s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">showScores</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> chkScores<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">checked</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">draw</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-627"></span>
<span id="cb12-628">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> btnRow <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">document</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">createElement</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"div"</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-629">  btnRow<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">style</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cssText</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"display:flex;flex-wrap:wrap;gap:6px;margin-top:8px;align-items:center"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-630">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> scoreWrap <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">document</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">createElement</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"span"</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-631">  scoreWrap<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">style</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cssText</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"display:flex;align-items:center;gap:4px;margin-left:8px"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-632">  scoreWrap<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">append</span>(chkScores<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> lblScores)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-633">  btnRow<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">append</span>(btnAnimate<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> btnStep<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> btnRun<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> btnReset<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> btnClear<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> btnMaze<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> scoreWrap)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-634"></span>
<span id="cb12-635">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">root</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">document</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">createElement</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"div"</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-636">  <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">root</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">append</span>(svg<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">node</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> btnRow<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> iterDisplay)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-637"></span>
<span id="cb12-638">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">draw</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-639">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> { <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">root</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> draw }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-640">}</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-7" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb13" data-startfrom="646" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 645;"><span id="cb13-646">app<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">root</span></span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-8" data-nodetype="expression">

</div>
</div>
</div>
<div class="cell hidden">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb14" data-startfrom="655" data-source-offset="-83" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 654;"><span id="cb14-655">{</span>
<span id="cb14-656">  s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">heuristic</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> heuristic<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb14-657">  s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">weight</span>    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> weight<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb14-658">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">animating</span>) {</span>
<span id="cb14-659">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">resetSearch</span>(s)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb14-660">    app<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">draw</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb14-661">  }</span>
<span id="cb14-662">}</span></code></pre></div></div>
<div class="cell-output cell-output-display hidden">
<div>
<div id="ojs-cell-9-1" data-nodetype="expression">

</div>
</div>
</div>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb15" data-startfrom="665" data-source-offset="-233" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 664;"><span id="cb15-665">{ s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">speed</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> speed<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> }</span></code></pre></div></div>
<div class="cell-output cell-output-display hidden">
<div>
<div id="ojs-cell-9-2" data-nodetype="expression">

</div>
</div>
</div>
</div>
</section>
<section id="discussion" class="level2">
<h2 class="anchored" data-anchor-id="discussion">Discussion</h2>
<p>A* shines in applications where a cost function and an admissible heuristic (a heuristic that never overestimates the distance to the end) can be defined. Examples of these types of application are GPS routing, NPC path finding in games and network routing.</p>
<p>There is one problem with A*: it doesn’t factor walls into the heuristic when using Manhattan distance. For solving this problem, algorithms like <a href="https://en.wikipedia.org/wiki/Jump_point_search">Jump Point Search</a> (JPS) are used.</p>
</section>
<section id="references" class="level2">




</section>

<div id="quarto-appendix" class="default"><section class="quarto-appendix-contents" id="quarto-bibliography"><h2 class="anchored quarto-appendix-heading">References</h2><div id="refs" class="references csl-bib-body" data-entry-spacing="0">
<div id="ref-russell2022artificial" class="csl-entry">
<div class="csl-left-margin">[1] </div><div class="csl-right-inline">S. Russell and P. Norvig, <em>Artificial intelligence: A modern approach</em>, 4th ed. Pearson Education Limited, 2022.</div>
</div>
</div></section><section class="quarto-appendix-contents" id="quarto-reuse"><h2 class="anchored quarto-appendix-heading">Reuse</h2><div class="quarto-appendix-contents"><div><a rel="license" href="https://creativecommons.org/licenses/by/4.0/">CC BY 4.0</a></div></div></section><section class="quarto-appendix-contents" id="quarto-citation"><h2 class="anchored quarto-appendix-heading">Citation</h2><div><div class="quarto-appendix-secondary-label">BibTeX citation:</div><div class="code-copy-outer-scaffold"><pre class="sourceCode code-with-copy quarto-appendix-bibtex"><code class="sourceCode bibtex">@online{bogossian2026,
  author = {Bogossian, Andreas},
  title = {A* {Pathfinding} {Algorithm}},
  date = {2026-03-19},
  url = {https://andreasbogossian.com/posts/a-star/},
  langid = {en}
}
</code></pre></div><div class="quarto-appendix-secondary-label">For attribution, please cite this work as:</div><div id="ref-bogossian2026" class="csl-entry quarto-appendix-citeas">
<div class="">A.
Bogossian, <span>“A* Pathfinding Algorithm.”</span> [Online]. Available:
<a href="https://andreasbogossian.com/posts/a-star/">https://andreasbogossian.com/posts/a-star/</a></div>
</div></div></section></div> ]]></description>
  <category>algorithms</category>
  <category>search</category>
  <category>graph theory</category>
  <guid>https://andreasbogossian.com/posts/a-star/</guid>
  <pubDate>Wed, 18 Mar 2026 22:00:00 GMT</pubDate>
  <media:content url="https://andreasbogossian.com/posts/a-star/astar.webp" medium="image" type="image/webp"/>
</item>
<item>
  <title>KL Divergence</title>
  <dc:creator>Andreas Bogossian</dc:creator>
  <link>https://andreasbogossian.com/posts/KL-divergence/</link>
  <description><![CDATA[ 




<p>When you fine-tune a large language model, how do you measure whether its output distribution is actually moving closer to the desired distribution? This question is a central to modern alignment techniques like RLHF <span class="citation" data-cites="ziegler2019 ouyang2022">[1], [2]</span>.</p>
<p>Large language models like GPTs output a probability distribution over tokens at each step. They assign a likelihood for each possible next word and then append the most likely next word to the output. During training the model outputs a predicted distribution <img src="https://latex.codecogs.com/png.latex?Q"> of the most likely next words. For ensuring correct output, the distribution <img src="https://latex.codecogs.com/png.latex?Q"> needs to be compared to the true distribution <img src="https://latex.codecogs.com/png.latex?P">. This is exactly what KL-divergence does. KL-divergence takes the original distribution and compares it to a new generated distribution and outputs a value that tells how much the two distributions differ. The closer the value is to zero, the more similar the distributions are.</p>
<section id="theory" class="level2">
<h2 class="anchored" data-anchor-id="theory">Theory</h2>
<p>The <strong>Kullback-Leibler divergence</strong> from Q to P is defined as:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0AD_%7BKL%7D(P%7C%7CQ)%20=%20%5Csum_k%20%5Coperatorname%7Blog%7Dp_k%5Cfrac%7Bp_k%7D%7Bq_k%7D%0A"></p>
<p>where <img src="https://latex.codecogs.com/png.latex?p_k%20=%20P(X%20=%20k)"> and <img src="https://latex.codecogs.com/png.latex?q_k%20=%20Q(X%20=%20k)"> are the probabilities assigned by distributions <img src="https://latex.codecogs.com/png.latex?P"> and <img src="https://latex.codecogs.com/png.latex?Q"> to outcome <img src="https://latex.codecogs.com/png.latex?k">, and the sum is taken over all outcomes <img src="https://latex.codecogs.com/png.latex?k"> in the support of <img src="https://latex.codecogs.com/png.latex?P">.</p>
<p>KL divergence can be interpreted intuitively using the concept of entropy form information theory.</p>
<p>The entropy of <img src="https://latex.codecogs.com/png.latex?P"> is</p>
<p><img src="https://latex.codecogs.com/png.latex?%0AH(P)%20=%20-%20%5Csum_k%20p_k%20%5Coperatorname%7Blog%7Dp_k%0A"></p>
<p>This is the average number of bits needed to encode samples from P using an optimal code for <img src="https://latex.codecogs.com/png.latex?P"> <span class="citation" data-cites="goodfellow2016">[3]</span>.</p>
<p>If instead if a code optimized for <img src="https://latex.codecogs.com/png.latex?Q"> was used to encode samples that came form <img src="https://latex.codecogs.com/png.latex?P">, the average code length is the <strong>cross-entropy</strong>:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0AH(P,%20Q)%20=%20-%20%5Csum_k%20p_k%20%5Coperatorname%7Blog%7Dq_k%0A"></p>
<p>Now combining entropy and cross entropy together, KL divergence is the extra cost you pay for using a code for <img src="https://latex.codecogs.com/png.latex?Q"> to encode samples from <img src="https://latex.codecogs.com/png.latex?P">:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign*%7D%0AD_%7BKL%7D(P%7C%7CQ)%20&amp;=%20H(P,%20Q)%20-%20H(P)%20%5C%5C%0A&amp;=%20-%20%5Csum_k%20p_k%20%5Coperatorname%7Blog%7Dq_k%20-%20(-%20%5Csum_k%20p_k%20%5Coperatorname%7Blog%7Dp_k)%20%5C%5C%0A&amp;=%20-%20%5Csum_k%20p_k%20%5Coperatorname%7Blog%7Dq_k%20+%20%5Csum_k%20p_k%20%5Coperatorname%7Blog%7Dp_k%20%5C%5C%0A&amp;=%20%5Csum_k%20p_k%20%5Coperatorname%7Blog%7Dp_k%20-%20%5Csum_k%20p_k%20%5Coperatorname%7Blog%7Dq_k%20%20%5C%5C%0A&amp;=%20%5Csum_k%20p_k%20(%5Coperatorname%7Blog%7Dp_k%20-%20%5Coperatorname%7Blog%7Dq_k)%20%20%5C%5C%0A&amp;=%20%5Csum_k%20p_k%20%5Coperatorname%7Blog%7D%20%5Cfrac%7Bp_k%7D%7Bq_k%7D%20%5C%5C%0A%5Cend%7Balign*%7D%0A"></p>
<section id="key-properties" class="level3">
<h3 class="anchored" data-anchor-id="key-properties">Key properties</h3>
<ul>
<li><p>Asymmetric: <img src="https://latex.codecogs.com/png.latex?D_%7BKL%7D(P%20%5C%7C%20Q)%20%5Cneq%20D_%7BKL%7D(Q%20%5C%7C%20P)"></p></li>
<li><p>Always non-negative: <img src="https://latex.codecogs.com/png.latex?D_%7BKL%7D(P%20%5C%7C%20Q)%20%5Cgeq%200"></p></li>
<li><p>Equal to zero only when the two distributions are identical. <img src="https://latex.codecogs.com/png.latex?D_%7BKL%7D(P%20%5C%7C%20Q)%20=%200%20%5Ciff%20P%20=%20Q"></p></li>
</ul>
<p>So intuitively, the KL-divergence asks how supriced you would be about the current distribution of the model given you know what the training data looks like. The more suprised you would be, the further the model is from the truth and thus the KL-divergence would be bigger.</p>
</section>
</section>
<section id="code-demo" class="level2">
<h2 class="anchored" data-anchor-id="code-demo">Code demo</h2>
<p>Now imagine a small vocabulary of five tokens: <code>["cat", "sat", "on", "the", "mat"]</code>. We have an imaginary LLM that has a predicted distribution <img src="https://latex.codecogs.com/png.latex?Q"> for the vocabulary and we also know the true distribution <img src="https://latex.codecogs.com/png.latex?P"> from the training data for the vocabulary.</p>
<div id="e62b7ef1" class="cell" data-execution_count="1">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb1-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> numpy <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> np</span>
<span id="cb1-2"></span>
<span id="cb1-3">vocab <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"cat"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sat"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"on"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"the"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mat"</span>]</span>
<span id="cb1-4"></span>
<span id="cb1-5"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># True distribution (training data)</span></span>
<span id="cb1-6">P <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.array([<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.15</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.05</span>])</span>
<span id="cb1-7"></span>
<span id="cb1-8"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Model's predicted distribution</span></span>
<span id="cb1-9">Q <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.array([<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.2</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.25</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.15</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>])</span></code></pre></div></div>
</div>
<p>By plotting <img src="https://latex.codecogs.com/png.latex?P"> and <img src="https://latex.codecogs.com/png.latex?Q"> the mismatch is immediately visible.</p>
<div id="5fba1e59" class="cell" data-execution_count="2">
<details class="code-fold">
<summary>Show code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb2-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> matplotlib.pyplot <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> plt</span>
<span id="cb2-2"></span>
<span id="cb2-3">x <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.arange(<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">len</span>(vocab))</span>
<span id="cb2-4">width <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.35</span></span>
<span id="cb2-5"></span>
<span id="cb2-6">fig, ax <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> plt.subplots(figsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">7</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>))</span>
<span id="cb2-7">ax.bar(x <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> width<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, P, width, label<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"P (true)"</span>, color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"steelblue"</span>)</span>
<span id="cb2-8">ax.bar(x <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> width<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, Q, width, label<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Q (model)"</span>, color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"tomato"</span>)</span>
<span id="cb2-9"></span>
<span id="cb2-10">ax.set_xticks(x)</span>
<span id="cb2-11">ax.set_xticklabels(vocab)</span>
<span id="cb2-12">ax.set_ylabel(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Probability"</span>)</span>
<span id="cb2-13">ax.set_title(<span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"P vs Q"</span>)</span>
<span id="cb2-14">ax.legend()</span>
<span id="cb2-15">plt.tight_layout()</span>
<span id="cb2-16">plt.show()</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div>
<figure class="figure">
<p><a href="index_files/figure-html/cell-3-output-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-1"><img src="https://andreasbogossian.com/posts/KL-divergence/index_files/figure-html/cell-3-output-1.png" width="662" height="374" class="figure-img"></a></p>
</figure>
</div>
</div>
</div>
<p>Directly applying the discrete formula <img src="https://latex.codecogs.com/png.latex?D_%7BKL%7D(P%20%5C%7C%20Q)%20=%20%5Csum_k%20p_k%20%5Clog%20%5Cfrac%7Bp_k%7D%7Bq_k%7D">:</p>
<div id="4bc71c59" class="cell" data-execution_count="3">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb3-1"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">def</span> kl_divergence(p, q):</span>
<span id="cb3-2">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> np.<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">sum</span>(p <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> np.log(p <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> q))</span>
<span id="cb3-3"></span>
<span id="cb3-4">kl_pq <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> kl_divergence(P, Q)</span>
<span id="cb3-5"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"D_KL(P || Q) = </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>kl_pq<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:.4f}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;"> nats"</span>)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>D_KL(P || Q) = 0.1874 nats</code></pre>
</div>
</div>
<p>The KL-divergence is non-zero so there is a difference between the true distribution <img src="https://latex.codecogs.com/png.latex?P"> and the current distribution <img src="https://latex.codecogs.com/png.latex?Q"> of our model. The difference between the true distribution <img src="https://latex.codecogs.com/png.latex?P"> and the predicted distribution <img src="https://latex.codecogs.com/png.latex?Q"> is obvious.</p>
<p>The order of the distributions is not trivial when computing KL-divergence. This can be shown shown numerically:</p>
<div id="06437772" class="cell" data-execution_count="4">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb5-1">kl_qp <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> kl_divergence(Q, P)</span>
<span id="cb5-2"></span>
<span id="cb5-3"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"D_KL(P || Q) = </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>kl_pq<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:.4f}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;"> nats"</span>)</span>
<span id="cb5-4"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"D_KL(Q || P) = </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>kl_qp<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:.4f}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;"> nats"</span>)</span>
<span id="cb5-5"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"Symmetric?   </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>np<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>isclose(kl_pq, kl_qp)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>D_KL(P || Q) = 0.1874 nats
D_KL(Q || P) = 0.2147 nats
Symmetric?   False</code></pre>
</div>
</div>
</section>
<section id="summary" class="level2">
<h2 class="anchored" data-anchor-id="summary">Summary</h2>
<p>KL-divergence can be used answering the question: how different are two probability distributions? The distribution is used, for example, LLM alignment to tell how far away the models predicted vocabulary distribution is from the training data distribution. KL-divergence has a mathematical foundation in information theory.</p>



</section>

<div id="quarto-appendix" class="default"><section class="quarto-appendix-contents" id="quarto-bibliography"><h2 class="anchored quarto-appendix-heading">References</h2><div id="refs" class="references csl-bib-body" data-entry-spacing="0">
<div id="ref-ziegler2019" class="csl-entry">
<div class="csl-left-margin">[1] </div><div class="csl-right-inline">D. M. Ziegler <em>et al.</em>, <span>“Fine-tuning language models from human preferences,”</span> <em>arXiv preprint arXiv:1909.08593</em>, 2019, Available: <a href="https://arxiv.org/abs/1909.08593">https://arxiv.org/abs/1909.08593</a></div>
</div>
<div id="ref-ouyang2022" class="csl-entry">
<div class="csl-left-margin">[2] </div><div class="csl-right-inline"><span class="nocase">L. Ouyang <em>et al.</em></span>, <span>“Training language models to follow instructions with human feedback,”</span> <em>arXiv preprint arXiv:2203.02155</em>, 2022, Available: <a href="https://arxiv.org/abs/2203.02155">https://arxiv.org/abs/2203.02155</a></div>
</div>
<div id="ref-goodfellow2016" class="csl-entry">
<div class="csl-left-margin">[3] </div><div class="csl-right-inline">I. Goodfellow, Y. Bengio, and A. Courville, <em>Deep learning</em>. MIT Press, 2016. Available: <a href="https://www.deeplearningbook.org">https://www.deeplearningbook.org</a></div>
</div>
</div></section><section class="quarto-appendix-contents" id="quarto-reuse"><h2 class="anchored quarto-appendix-heading">Reuse</h2><div class="quarto-appendix-contents"><div><a rel="license" href="https://creativecommons.org/licenses/by/4.0/">CC BY 4.0</a></div></div></section><section class="quarto-appendix-contents" id="quarto-citation"><h2 class="anchored quarto-appendix-heading">Citation</h2><div><div class="quarto-appendix-secondary-label">BibTeX citation:</div><div class="code-copy-outer-scaffold"><pre class="sourceCode code-with-copy quarto-appendix-bibtex"><code class="sourceCode bibtex">@online{bogossian2026,
  author = {Bogossian, Andreas},
  title = {KL {Divergence}},
  date = {2026-03-17},
  url = {https://andreasbogossian.com/posts/KL-divergence/},
  langid = {en}
}
</code></pre></div><div class="quarto-appendix-secondary-label">For attribution, please cite this work as:</div><div id="ref-bogossian2026" class="csl-entry quarto-appendix-citeas">
<div class="">A.
Bogossian, <span>“KL Divergence.”</span> [Online]. Available: <a href="https://andreasbogossian.com/posts/KL-divergence/">https://andreasbogossian.com/posts/KL-divergence/</a></div>
</div></div></section></div> ]]></description>
  <category>information theory</category>
  <category>probabilistic ML</category>
  <category>llms</category>
  <guid>https://andreasbogossian.com/posts/KL-divergence/</guid>
  <pubDate>Mon, 16 Mar 2026 22:00:00 GMT</pubDate>
</item>
</channel>
</rss>
