<?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>Joseph Salmon</title>
<link>https://josephsalmon.eu/blog/</link>
<atom:link href="https://josephsalmon.eu/blog/index.xml" rel="self" type="application/rss+xml"/>
<description>Machine Learning, Data Science Optimization &amp; Image Processing | Research</description>
<image>
<url>https://josephsalmon.eu/img/joseph_2018.png</url>
<title>Joseph Salmon</title>
<link>https://josephsalmon.eu/blog/</link>
<height>154</height>
<width>144</width>
</image>
<generator>quarto-1.6.40</generator>
<lastBuildDate>Sun, 19 Oct 2025 22:00:00 GMT</lastBuildDate>
<item>
  <title>Optimal prediction sets for plant identification: an interactive guide</title>
  <dc:creator>Tiffany Ding</dc:creator>
  <dc:creator>Jean-Baptiste Fermanian</dc:creator>
  <dc:creator>Joseph Salmon</dc:creator>
  <link>https://josephsalmon.eu/blog/long-tail/</link>
  <description><![CDATA[ 
<div class="no-row-height column-margin column-container">
  <div class="">
    <img src="https://josephsalmon.eu/../talks/posts/2026-01-29-slides_citizen_sciences/images/set_prediction.png" style="width:100%">
  </div>
</div>





<!-- Installation, needed steps:

for icones run in terminal:
  quarto add quarto-ext/fontawesome
  quarto add mcanouil/quarto-iconify
  quarto add leovan/quarto-pseudocode
also run the following for javascript:

npm install seedrandom
node generate_samples.js
-->
<div class="hidden">
{{
% thin space, limits underneath in displays % thin space, limits underneath in displays
<p>% Parentheses }} </p>
</div>
<section id="introduction-and-motivation" class="level2">
<h2 class="anchored" data-anchor-id="introduction-and-motivation">Introduction and motivation</h2>
<p>This blog post is an effort led by Joseph Salmon, with contributions from Tiffany Ding and Jean-Baptiste Fermanian, to synthesize joint research by the three authors. The full paper <span class="citation" data-cites="Ding_Fermanian_Salmon25">(Ding, Fermanian, and Salmon 2026)</span> is available on <a href="https://arxiv.org/abs/2507.06867" target="_blank">arXiv</a> and the code is on <a href="https://github.com/tiffanyding/long-tail-conformal" target="_blank">Github</a>.</p>
<section id="why-settle-for-one-label-when-you-could-have-a-set" class="level3">
<h3 class="anchored" data-anchor-id="why-settle-for-one-label-when-you-could-have-a-set">Why settle for one label when you could have a set?</h3>
<p>Traditionally, machine learning models give you a single best guess: but what if the problem is tricky, or multiple answers are plausible? In those cases, a <strong>set</strong> of possible labels is far more useful, especially when it comes with a statistical guarantee that the true answer is included.</p>
<p><strong>Conformal prediction</strong> (often abbreviated CP below) provides a framework for constructing prediction sets with valid coverage guarantees <span class="citation" data-cites="vovk2005algorithmic">(Vovk, Gammerman, and Shafer 2005)</span>. A particular focus on classification was later considered <span class="citation" data-cites="vovk2016criteria">(Vovk et al. 2016)</span>, and methods for minimizing the size of prediction sets, such as the Least Ambiguous Set-Valued Classifiers, were proposed in parallel by <span class="citation" data-cites="sadinle2019least">Sadinle, Lei, and Wasserman (2019)</span>. In this post, we focus on extensions of the later approach.</p>
<p><em>What does it mean for a prediction set to be optimal?</em> Given that we have decided to generate prediction sets, how do we generate an “optimal” prediction set? A reasonable definition, and the one we will use, is that a <strong>prediction-set-generating procedure is optimal if it generates the smallest sets that satisfy a given coverage constraint</strong> (e.g., the probability that the true label is contained within the prediction is at least 90%). What kind of coverage we care about depends on the setting, and the coverage notion you choose can make a big difference in the resulting sets. <span class="citation" data-cites="sadinle2019least">Sadinle, Lei, and Wasserman (2019)</span> have derived the theoretically optimal sets with a minimal constraint on the marginal coverage or class-conditional coverage and show how to approximate the optimal sets using conformal prediction while maintaining a coverage guarantee. We do the same for two new notions of coverage, macro-coverage and weighted macro-coverage, and show that these lead to more useful prediction sets in long-tailed classification settings.</p>
<p>Here is an overview of the four coverage notions we cover below:</p>
<ul>
<li><p><strong>Marginal coverage</strong>: <strong>Guarantees coverage across all data points</strong>, ensuring the true label is included with the desired probability <em>on average over the dataset</em>, but may neglect rare or underrepresented classes.</p></li>
<li><p><strong>Class-conditional coverage</strong>: <strong>Guarantees coverage within each class separately</strong>, guaranteeing the desired inclusion probability <em>for every class</em>, but often producing impractically large sets for classes with high uncertainty or few samples.</p></li>
<li><p><strong>Macro coverage</strong>: <strong>Balances coverage evenly across classes</strong>, by averaging the per-class coverages to emphasize fairness between common and rare classes.</p></li>
<li><p><strong>Weighted macro coverage</strong>: <strong>Balances coverage according to class importance</strong>, extending macro coverage by incorporating user-specified weights on each class that reflect the relative importance of covering each class</p></li>
</ul>
<p>Depending on which coverage notion appears in the constraint, the resulting sets can look very different. We will illustrate this using an artificial 2D example and real-world plant identification data.</p>
</section>
</section>
<section id="motivating-example-plntnet" class="level2">
<h2 class="anchored" data-anchor-id="motivating-example-plntnet"><iconify-icon inline="" icon="hugeicons:plant-04" aria-label="Icon plant-04 from hugeicons Iconify.design set." title="Icon plant-04 from hugeicons Iconify.design set."></iconify-icon> Motivating example: Pl@ntNet</h2>
<p><a href="https://plantnet.org/en/" target="_blank">Pl@ntNet</a>, a leading citizen-science platform for plant identification, serves as our real-world context for exploring these ideas. More precisely we focus on the <strong>Pl@ntNet-300K dataset</strong> <span class="citation" data-cites="garcin2021pl">(Garcin et al. 2021)</span>, a representative and more manageable subset of the full Pl@ntNet collection. The Pl@ntNet-300K dataset is available on <a href="https://zenodo.org/records/5645731#.Yuehg3ZBxPY" target="_blank">Zenodo</a>, with documentation and code provided on the <a href="https://github.com/plantnet/PlantNet-300K" target="_blank">Pl@ntNet-300K GitHub repository</a>. The dataset comprises approximately <strong>300,000 images</strong> spanning <strong>over 1,000 plant species</strong>. Here are a few sample images from the Pl@ntNet-300K dataset (cropped to a consistent size for visualization):</p>
<div id="sample-images-grid" style="max-width:950px; margin:12px auto 20px; display:grid; grid-template-columns:repeat(4,1fr); gap:12px; align-items:start;">
  <figure style="margin:0; position:relative;" class="figure">
    <img src="https://josephsalmon.eu/blog/long-tail/tiny_plantnet300k/1/9cf6b7997a95b2bab8d840e70397b98dc8321106.jpg" alt="Plant species" style="width:100%; height:165px; object-fit:cover; border-radius:6px; display:block;" data-hash="9cf6b7997a95b2bab8d840e70397b98dc8321106" class="figure-img">
    <figcaption style="font-size:12px; margin-top:6px; text-align:center; min-height:2.4em;"></figcaption>
  </figure>

  <figure style="margin:0; position:relative;" class="figure">
    <img src="https://josephsalmon.eu/blog/long-tail/tiny_plantnet300k/57/81141f286ca624ff8685f4a954af48764548a4ca.jpg" alt="Plant species" style="width:100%; height:165px; object-fit:cover; border-radius:6px; display:block;" data-hash="81141f286ca624ff8685f4a954af48764548a4ca" class="figure-img">
    <figcaption style="font-size:12px; margin-top:6px; text-align:center; min-height:2.4em;"></figcaption>
  </figure>

  <figure style="margin:0; position:relative;" class="figure">
    <img src="https://josephsalmon.eu/blog/long-tail/tiny_plantnet300k/710/738b2af661ef2102b8748844939f0034320fc2c2.jpg" alt="Plant species" style="width:100%; height:165px; object-fit:cover; border-radius:6px; display:block;" data-hash="738b2af661ef2102b8748844939f0034320fc2c2" class="figure-img">
    <figcaption style="font-size:12px; margin-top:6px; text-align:center; min-height:2.4em;"></figcaption>
  </figure>

  <figure style="margin:0; position:relative;" class="figure">
    <img src="https://josephsalmon.eu/blog/long-tail/tiny_plantnet300k/397/8d9e895a91786169a299ab25d3a34f417dc07e1b.jpg" alt="Plant species" style="width:100%; height:165px; object-fit:cover; border-radius:6px; display:block;" data-hash="8d9e895a91786169a299ab25d3a34f417dc07e1b" class="figure-img">
    <figcaption style="font-size:12px; margin-top:6px; text-align:center; min-height:2.4em;"></figcaption>
  </figure>

</div>

<script type="module" src="sample_images.js"></script>
<p>The dataset exhibits a <strong>highly imbalanced class distribution</strong>: a few species are well-represented with numerous images, while the majority have only a few examples. This characteristic makes it an ideal benchmark for studying <strong>long-tailed classification</strong> problems, as illustrated in the interactive figure below.</p>
<section id="conservation-status-in-plntnet-300k" class="level3">
<h3 class="anchored" data-anchor-id="conservation-status-in-plntnet-300k"><iconify-icon inline="" icon="fluent:globe-shield-20-regular" aria-label="Icon globe-shield-20-regular from fluent Iconify.design set." title="Icon globe-shield-20-regular from fluent Iconify.design set."></iconify-icon> <strong>Conservation status in Pl@ntNet-300K</strong></h3>
<p>Each species in the dataset has an <strong><a href="https://www.iucnredlist.org/" target="_blank">International Union for Conservation of Nature (IUCN) conservation status</a></strong>, which indicates its risk of extinction. We categorize these statuses into two groups for later analysis:</p>
<table class="table-striped table-hover caption-top table">
<caption>IUCN conservation status</caption>
<colgroup>
<col style="width: 33%">
<col style="width: 25%">
<col style="width: 41%">
</colgroup>
<thead>
<tr class="header">
<th><strong>At Risk</strong></th>
<th><strong>Not at Risk</strong></th>
<th><strong>Unknown/unclear</strong></th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>Critically Endangered (CR)</td>
<td>Least Concern (LC)</td>
<td>Not assessed (or missing data)</td>
</tr>
<tr class="even">
<td>Endangered (EN)</td>
<td></td>
<td>Data Deficient (DD)</td>
</tr>
<tr class="odd">
<td>Vulnerable (VU)</td>
<td></td>
<td></td>
</tr>
<tr class="even">
<td>Near Threatened (NT)</td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
<p><br></p>
<p>This metadata allows us to analyze species distributions both in terms of their popularity and their conservation status, adding a critical ecological perspective to our study. This dual focus serves as a key motivation for introducing our weighted macro coverage metric.</p>
</section>
<section id="plant-species-visualization" class="level3">
<h3 class="anchored" data-anchor-id="plant-species-visualization"><iconify-icon inline="" icon="carbon:chart-line-smooth" aria-label="Icon chart-line-smooth from carbon Iconify.design set." title="Icon chart-line-smooth from carbon Iconify.design set."></iconify-icon> <strong>Plant species visualization</strong></h3>
<p>The interactive visualization below lets you explore the species distribution in the Pl@ntNet-300K training set, enriched with their IUCN conservation statuses.</p>
<div id="plantnet-viz" style="max-width: 1200px; margin: 0 auto;">

  <div id="filter-container" style="margin-bottom: 20px;"></div>

  <!-- Main content area with side-by-side layout -->
  <div style="display: flex; flex-direction: row; align-items: flex-start; gap: 20px;">
  <!-- Plot container on the left (wider and shorter) -->
  <div id="plotly-container" style="flex: 4; height: 400px; width: 48vw; max-width: 48vw; min-width: 200px;"></div>

    <!-- Right sidebar with controls and image preview -->
    <div style="flex: 1; min-width: 280px; display: flex; flex-direction: column;">
      <!-- Controls for plot options (moved to align with plot head) -->
      <div style="display: flex; justify-content: flex-end; margin-bottom: 15px;">
        <div class="scale-toggle">
          <span class="scale-label">Y-Scale:</span>
          <button type="button" id="log-scale-btn" class="scale-btn" onclick="window.setScale('log'); return false;">Log</button>
          <button type="button" id="linear-scale-btn" class="scale-btn active" onclick="window.setScale('linear'); return false;">Linear</button>
        </div>
      </div>

      <!-- Image preview container -->
      <div id="image-preview-container" style="display: flex; flex-direction: column; justify-content: flex-start; align-items: center; flex: 1;">
        <div style="margin-bottom: 10px;">Species Preview</div>
        <img id="preview-image" src="" style="width: 100%; height: 250px; border: 1px solid #ccc; display: none; border-radius: 5px; box-shadow: 0 2px 5px rgba(0,0,0,0.1); object-fit: cover;">
        <div id="image-label" style="font-weight: bold; font-size: 13px; min-height: 3.5em; margin-top: 1px; text-align: center; width: 100%; line-height: 1.2;"></div>
      </div>
    </div>
</div>

<script type="module" src="plantnet_viz.js"></script>

<p>This visualization provides a dynamic way to explore the intersection of species popularity and ecological importance. <strong>“At-risk” species</strong> are highlighted and typically have far fewer observations, reflecting the challenges in documenting rare or threatened flora. Use the interactive features (<strong>hover</strong> the points on the left!) to navigate observation counts, conservation status, and the distribution of both common and rare species.</p>
</div></section>
</section>
<section id="notation-and-model" class="level2">
<h2 class="anchored" data-anchor-id="notation-and-model"><iconify-icon inline="" icon="fluent:clipboard-math-formula-20-regular" aria-label="Icon clipboard-math-formula-20-regular from fluent Iconify.design set." title="Icon clipboard-math-formula-20-regular from fluent Iconify.design set."></iconify-icon> Notation and model</h2>
<p>Let <img src="https://latex.codecogs.com/png.latex?(X,Y)%20%5Cin%20%5Cmathcal%7BX%7D%20%5Ctimes%20%5Cmathcal%7BY%7D"> be a (feature, label) pair. In our example, <img src="https://latex.codecogs.com/png.latex?X"> is an image, and <img src="https://latex.codecogs.com/png.latex?Y"> is the true label (species) associated with it. Let <img src="https://latex.codecogs.com/png.latex?%5Chat%7Bp%7D(y%7Cx)"> be an estimate of the probability <img src="https://latex.codecogs.com/png.latex?p(y%7Cx)"> that the label is <img src="https://latex.codecogs.com/png.latex?y"> given features <img src="https://latex.codecogs.com/png.latex?x">. Let <img src="https://latex.codecogs.com/png.latex?%5Calpha%20%5Cin%20%5B0,1%5D"> be a user-specified miscoverage probability, so <img src="https://latex.codecogs.com/png.latex?1-%5Calpha"> corresponds to the desired <strong>coverage</strong> level.</p>
<p>The available data is randomly split into four distinct sets: a <strong>training set</strong> for fitting the model <img src="https://latex.codecogs.com/png.latex?%5Chat%7Bp%7D(y%7Cx)">, a <strong>validation set</strong> for hyperparameter tuning (in our experiments, the only hyperparameter is the number of training epochs), a <strong>calibration set</strong> <img src="https://latex.codecogs.com/png.latex?(X_i,%20Y_i)%20%5Cin%20%5Cmathcal%7BX%7D%20%5Ctimes%20%5Cmathcal%7BY%7D"> for <img src="https://latex.codecogs.com/png.latex?i%20%5Cin%20%5Bn%5D"> to evaluate coverage, and a <strong>test set</strong> for final evaluation. Note that in order for the coverage guarantees from conformal prediction to hold, the calibration set must be exchangeable with the test set. The random splitting procedure ensure this is satisfied.</p>
</section>
<section id="marginal-coverage" class="level2">
<h2 class="anchored" data-anchor-id="marginal-coverage">Marginal coverage</h2>
<p>In classification setting, suppose our aim is to control the <strong>size</strong> (here the <strong>cardinality</strong>) of our prediction sets while ensuring marginal coverage. This corresponds to the following optimization problem:</p>
<p><span id="eq-min_st_margcoverage"><img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign%7D%0A&amp;%5Cmin_%7B%5Cmathcal%7BC%7D%20:%20%5Cmathcal%7BX%7D%20%5Cmapsto%202%5E%5Cmathcal%7BY%7D%7D%20%5Cmathbb%7BE%7D%5B%7C%5Cmathcal%7BC%7D(X)%7C%5D%20%5C%5C%0A%5Ctext%7B%20s.t.%20%7D%20&amp;%20%7B%5Cmathbb%20P%7D%5Cleft(%20%20Y%20%5Cin%20%5Cmathcal%7BC%7D(X)%20%5Cright)%20%5Cgeq%201-%5Calpha,%0A%5Cend%7Balign%7D%0A%5Ctag%7B1%7D"></span> The following result due to <span class="citation" data-cites="sadinle2019least">Sadinle, Lei, and Wasserman (2019)</span> describes the optimal set.</p>
<div id="prp-margcoverage" class="theorem proposition">
<p><span class="theorem-title"><strong>Proposition 1 (Marginal coverage and prediction set)</strong></span> Assuming that <img src="https://latex.codecogs.com/png.latex?p(Y%7CX)"> does not have point mass at its <img src="https://latex.codecogs.com/png.latex?%5Calpha">-quantile, denoted <img src="https://latex.codecogs.com/png.latex?t%5E*_%7B%5Calpha%7D">, the solution of (1) is given by <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign*%7D%0A%5Cmathcal%7BC%7D%5E*(x)%20&amp;%20=%20%5Cleft%5C%7B%20y%20%5Cin%20%5Cmathcal%7BY%7D%20:%20p(y%7Cx)%20%5Cgeq%20t%5E*_%7B%5Calpha%7D%5Cright%5C%7D.%0A%5Cend%7Balign*%7D%0A"> <!--for some threshold $t_{\alpha}$.--></p>
</div>
<div class="proof-container">
<div class="proof-header" onclick="toggleProof('marg-coverage')">
<p><span id="proof-arrow-marg-coverage" class="proof-arrow">▶</span> <span class="proof-title">Proof</span></p>
</div>
<div id="proof-content-marg-coverage" class="proof-content">
<p>This result is a direct consequence of Proposition&nbsp;4 stated below with the particular choice of <img src="https://latex.codecogs.com/png.latex?%5Comega(y)%20=%20%5Cfrac%7B1%7D%7B%7C%5Cmathcal%7BY%7D%7C%7D">.</p>
</div>
</div>
<p><u>Interpretation</u>: This result implies that the smallest sets that achieve marginal coverage are created by including the classes with the highest probability of being the correct class. Specifically, we include all labels <img src="https://latex.codecogs.com/png.latex?y"> where <img src="https://latex.codecogs.com/png.latex?p(y%7Cx)"> exceeds some threshold <img src="https://latex.codecogs.com/png.latex?t%5E*_%7B%5Calpha%7D"> chosen to ensure the desired coverage level of <img src="https://latex.codecogs.com/png.latex?1-%5Calpha">.</p>
<p><u>In practice</u>: While we do not have direct access to <img src="https://latex.codecogs.com/png.latex?p(y%7Cx)">, we can use an estimate <img src="https://latex.codecogs.com/png.latex?%5Chat%7Bp%7D(y%7Cx)"> to approximate the optimal prediction set for a chosen threshold <img src="https://latex.codecogs.com/png.latex?t_%5Calpha">:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cwidehat%7B%7B%5Cmathcal%20C%7D%7D(X)%20=%20%5C%7By%20%5Cin%20%7B%5Cmathcal%20Y%7D:%20%5Chat%7Bp%7D(y%7CX)%20%5Cgeq%20t_%5Calpha%5C%7D,%0A"> To ensure marginal coverage of <img src="https://latex.codecogs.com/png.latex?1-%5Calpha">, we select <img src="https://latex.codecogs.com/png.latex?t_%5Calpha"> by rewriting <img src="https://latex.codecogs.com/png.latex?%5Cwidehat%7B%7B%5Cmathcal%20C%7D%7D(x)"> in terms of a conformal score: <img src="https://latex.codecogs.com/png.latex?%0A%5Cwidehat%7B%7B%5Cmathcal%20C%7D%7D(x)%20=%20%5C%7By%20%5Cin%20%7B%5Cmathcal%20Y%7D:%20s(x,y)%20%5Cleq%20-t_%5Calpha%5C%7D,%0A"> where the <strong>score</strong> is defined as <img src="https://latex.codecogs.com/png.latex?%0As(x,y)%20=%20-%5Chat%7Bp%7D(y%7Cx).%0A"></p>
<p>By setting <img src="https://latex.codecogs.com/png.latex?-t_%5Calpha"> as the <img src="https://latex.codecogs.com/png.latex?(1-%5Calpha)(1+%5Ctfrac%7B1%7D%7Bn%7D)">-level quantile of the calibration scores <img src="https://latex.codecogs.com/png.latex?s(X_%7Bi%7D,Y_%7Bi%7D)"> for <img src="https://latex.codecogs.com/png.latex?i=1,%5Cdots,%20n">, i.e., <img src="https://latex.codecogs.com/png.latex?%5Chat%7Bq%7D%20=%20%5Clceil%20(n+1)(1-%5Calpha)%20%5Crceil">-th largest value in <img src="https://latex.codecogs.com/png.latex?%5C%7Bs(X_%7B1%7D,Y_%7B1%7D),%20%5Cdots,%20s(X_%7Bn%7D,Y_%7Bn%7D)%5C%7D">, the conformal prediction set <img src="https://latex.codecogs.com/png.latex?%5Csmash%7B%5Cwidehat%7B%7B%5Cmathcal%20C%7D%7D%7D"> achieves a <strong>marginal coverage</strong> guarantee <span class="citation" data-cites="vovk2005algorithmic">(Vovk, Gammerman, and Shafer 2005)</span>, that is,</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign%7D%0A%7B%5Cmathbb%20P%7D(Y%20%5Cin%20%5Cwidehat%7B%7B%5Cmathcal%20C%7D%7D(X))%0A%5Cgeq%201-%5Calpha.%0A%5Cend%7Balign%7D%0A"> We will refer to the above procedure as Standard Conformal Prediction (<strong>Standard CP</strong>) with the <strong>softmax</strong> score function (so named because the <img src="https://latex.codecogs.com/png.latex?%5Chat%7Bp%7D"> that appears in <img src="https://latex.codecogs.com/png.latex?s(x,y)%20=%20-%5Chat%20p(y%7Cx)"> is frequently obtained from a softmax vector). Note that other scores have also been considered in the literature, see for instance <span class="citation" data-cites="romano2020classification">Romano, Sesia, and Candès (2020)</span>.</p>
<p>We generalize this procedure for generating prediction sets in Algorithm 1. Standard CP is a special case where the threshold function <img src="https://latex.codecogs.com/png.latex?%5Chat%7B%5Cmathbf%7Bq%7D%7D=(%5Chat%7Bq%7D,%5Cdots,%5Chat%7Bq%7D)%20%5Cin%0A%7B%5Cmathbb%20R%7D%5E%7B%7C%7B%5Cmathcal%20Y%7D%7C%7D"> applies the same threshold to all classes. However, the other conformal procedures we present below, such as Classwise CP, impose different thresholds for each class.</p>
<div id="algo-conformal" class="pseudocode-container quarto-float" data-no-end="false" data-caption-prefix="Algorithm" data-pseudocode-number="1" data-line-number-punc=":" data-line-number="true" data-indent-size="1.2em" data-comment-delimiter="//">
<div class="pseudocode">
\begin{algorithm} \caption{Conformal prediction meta-algorithm} \begin{algorithmic} \REQUIRE Score function $s: \mathcal{X} \times \mathcal{Y} \to \mathbb{R}$, miscoverage level $\alpha \in [0,1]$, calibration set $\mathcal{D}_{\mathrm{cal}} = \{(X_i, Y_i)\}_{i=1}^n$, test point $X_{n+1}$, threshold function $\hat{\mathbf{q}}: \mathbb{R}^n \times [0,1] \to \mathbb{R}^{|\mathcal{Y}|}$ \STATE Compute scores: $S_i \gets s(X_i, Y_i)$ for $i = 1, \ldots, n$ \STATE Compute thresholds: $\mathbf{q} \gets \hat{\mathbf{q}}((S_i)_{i=1}^n, \alpha)$ \RETURN Prediction set $\mathcal{C}(X_{n+1}) = \{ y : s(X_{n+1}, y) \leq q_y \}$, where $q_y$ is the $y$-th entry of $\mathbf{q}$ \end{algorithmic} \end{algorithm}
</div>
</div>
<p>Currently (as of October 2025), Standard CP with softmax is more or less the strategy used to generate prediction sets in the Pl@ntNet app. This performs reasonably well, but can we do better?</p>
<section id="d-example" class="level3">
<h3 class="anchored" data-anchor-id="d-example"><iconify-icon inline="" icon="gis:map-edit" aria-label="Icon map-edit from gis Iconify.design set." title="Icon map-edit from gis Iconify.design set."></iconify-icon> 2D example</h3>
<p>To build intuition, let’s visualize the Standard CP prediction sets for a simple 2D Gaussian mixture model.</p>
<section id="parameters" class="level4">
<h4 class="anchored" data-anchor-id="parameters"><iconify-icon inline="" icon="fa:sliders" aria-label="Icon sliders from fa Iconify.design set." title="Icon sliders from fa Iconify.design set."></iconify-icon> Parameters</h4>
<p>We generate <img src="https://latex.codecogs.com/png.latex?n=900"> samples from a mixture of <img src="https://latex.codecogs.com/png.latex?%7C%5Cmathcal%7BY%7D%7C=3"> Gaussian distributions with the following parameters:</p>
<table class="table-striped table-hover caption-top table">
<caption>Parameters</caption>
<colgroup>
<col style="width: 33%">
<col style="width: 33%">
<col style="width: 33%">
</colgroup>
<thead>
<tr class="header">
<th><img src="https://latex.codecogs.com/png.latex?%5Cpi_1%20=%200.6"></th>
<th><img src="https://latex.codecogs.com/png.latex?%5Cpi_2%20=%200.1"></th>
<th><img src="https://latex.codecogs.com/png.latex?%5Cpi_3%20=%200.3"></th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td><img src="https://latex.codecogs.com/png.latex?%5Cmu_1%20=%20%5Cbegin%7Bpmatrix%7D%200%20%5C%5C%203.5%20%5Cend%7Bpmatrix%7D"></td>
<td><img src="https://latex.codecogs.com/png.latex?%5Cmu_2%20=%20%5Cbegin%7Bpmatrix%7D%20-2%20%5C%5C%200%20%5Cend%7Bpmatrix%7D"></td>
<td><img src="https://latex.codecogs.com/png.latex?%5Cmu_3%20=%20%5Cbegin%7Bpmatrix%7D%201%20%5C%5C%201%20%5Cend%7Bpmatrix%7D"></td>
</tr>
<tr class="even">
<td><img src="https://latex.codecogs.com/png.latex?%5CSigma_1%20=%20%5Cbegin%7Bpmatrix%7D%201%20&amp;%200.8%20%5C%5C%200.8%20&amp;%201%20%5Cend%7Bpmatrix%7D"></td>
<td><img src="https://latex.codecogs.com/png.latex?%5CSigma_2%20=%20%5Cbegin%7Bpmatrix%7D%200.25%20&amp;%200%20%5C%5C%200%20&amp;%200.25%20%5Cend%7Bpmatrix%7D"></td>
<td><img src="https://latex.codecogs.com/png.latex?%5CSigma_3%20=%20%5Cbegin%7Bpmatrix%7D%201.85%20&amp;%201.4%20%5C%5C%201.4%20&amp;%201.85%20%5Cend%7Bpmatrix%7D"></td>
</tr>
</tbody>
</table>
</section>
<section id="visualizing-the-data" class="level4">
<h4 class="anchored" data-anchor-id="visualizing-the-data"><iconify-icon inline="" icon="lucide:chart-spline" aria-label="Icon chart-spline from lucide Iconify.design set." title="Icon chart-spline from lucide Iconify.design set."></iconify-icon> Visualizing the data</h4>
<p>The data-generating model is a <strong>three-class Gaussian mixture</strong> with known parameters (means, covariances, mixing proportions) given above, enabling exact density and theoretical boundary computation. We provide an <em>interactive visualization</em> below.</p>
<p>In both plots, the <em>red boundary</em> is the decision boundary of the Bayes classifier (the theoretically optimal boundary).</p>
<ul>
<li><em>Left plot:</em> Individual class densities (color-filled contours) and mixture density (grey level lines).</li>
<li><em>Right plot:</em> The points are samples from the mixture distribution, colored by true class. The colored shading indicates the Bayes classifier’s predicted class for each region.</li>
</ul>
<div id="plots" style="width:100%; max-width:800px; overflow-x:auto;"></div>
<script type="module" src="mixture_viz.js"></script>

</section>
<section id="visualizing-standard-cp-sets" class="level4">
<h4 class="anchored" data-anchor-id="visualizing-standard-cp-sets"><iconify-icon inline="" icon="fluent:laptop-shield-16-filled" aria-label="Icon laptop-shield-16-filled from fluent Iconify.design set." title="Icon laptop-shield-16-filled from fluent Iconify.design set."></iconify-icon> Visualizing Standard CP sets</h4>
<p>Concerning the distribution <img src="https://latex.codecogs.com/png.latex?p(y%7Cx)">, we provide three candidates in our Gaussian mixture model visualization, though for the moment only the first (true density function) is used:</p>
<ul>
<li><strong>Theoretical</strong>: <img src="https://latex.codecogs.com/png.latex?%5Chat%20p(y%7Cx)=p(y%7Cx)"> (only available in simulations),</li>
<li><strong>Empirical</strong>: <img src="https://latex.codecogs.com/png.latex?%5Chat%20p(y%7Cx)"> is a Gaussian mixture whose parameters are estimated with vanilla estimators (empirical means, empirical covariances and empirical proportions),</li>
<li><strong>Logistic Reg.</strong>: <img src="https://latex.codecogs.com/png.latex?%5Chat%20p(y%7Cx)"> is obtained by logistic regression.</li>
</ul>
<p>We now provide a visualization for the <strong>Standard conformal prediction</strong>, as decribed in the previous section. Hence, our classifier can output multiple classes, forming <strong>prediction sets</strong> rather than a single label. The size of these sets is controlled by the allowed <strong>miscoverage level</strong> <img src="https://latex.codecogs.com/png.latex?%5Calpha"> (accessible through the slider), which reflects the confidence of the predictions.</p>
<p>As <img src="https://latex.codecogs.com/png.latex?%5Calpha"> varies, the prediction sets shrink:small <img src="https://latex.codecogs.com/png.latex?%5Calpha"> yields larger, conservative sets, while large <img src="https://latex.codecogs.com/png.latex?%5Calpha"> allows smaller, selective ones. This reflects the core principle of conformal prediction, balancing coverage and uncertainty.</p>


  <div id="plots2mono" style="width: 100%; max-width: 800px"></div>
  <div id="alphaControlMono" style="margin-top: 15px; display:flex; align-items:center; justify-content:center; gap:12px;">
    <label for="alphaSliderMono"><img src="https://latex.codecogs.com/png.latex?%5Calpha="> <span id="alphaValueMono">0.15</span></label>
    <input type="range" id="alphaSliderMono" min="0.001" max="0.20" step="0.001" value="0.15">
  </div>

<script type="module" src="subplot_viz_mono.js"></script>
<p><br></p>
<p>Using the <img src="https://latex.codecogs.com/png.latex?%5Calpha"> <strong>slider</strong> above reveals two extremes of this trade-off:</p>
<ul>
<li>When <img src="https://latex.codecogs.com/png.latex?%5Calpha"> is <strong>small</strong> (high coverage), the classifier may need to include <strong>all classes</strong> in some regions to meet the coverage requirement. For example, at <img src="https://latex.codecogs.com/png.latex?%5Calpha%20=%200.0001">, the <strong>central area</strong> contains full prediction sets.</li>
<li>When <img src="https://latex.codecogs.com/png.latex?%5Calpha"> is <strong>large</strong> (low coverage), it may output <strong>empty sets</strong> in uncertain regions (shown in white), as seen around <img src="https://latex.codecogs.com/png.latex?%5Calpha%20=%200.15">. If a <strong>non-empty output</strong> is required, one can instead return the class with the <strong>highest conditional probability</strong>.</li>
</ul>
<p>Together, these extremes illustrate how <img src="https://latex.codecogs.com/png.latex?%5Calpha"> directly controls the <strong>size–coverage trade-off</strong> in conformal prediction.</p>
</section>
</section>
</section>
<section id="conditional-coverage" class="level2">
<h2 class="anchored" data-anchor-id="conditional-coverage">Conditional coverage</h2>
<p>A concern with the standard conformal prediction approach is that all classes are treated similarly. If certain rare classes behave differently from the majority, they may never appear in the prediction set. For instance, the classifier may consistently assign low probabilities to rare classes, as these are not sufficiently represented during training and then, they never get above the threshold.</p>
<p>For this reason, it makes sense to control the conditional coverage for all classes <img src="https://latex.codecogs.com/png.latex?y%20%5Cin%20%7B%5Cmathcal%20Y%7D">, while targeting sets of minimum size. Then the optimization formulation now becomes:</p>
<p><span id="eq-min_st_condcoverage"><img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign%7D%0A&amp;%20%5Cmin_%7B%5Cmathcal%7BC%7D%20:%20%5Cmathcal%7BX%7D%20%5Cmapsto%202%5E%5Cmathcal%7BY%7D%7D%20%5Cmathbb%7BE%7D%5B%7C%5Cmathcal%7BC%7D(X)%7C%5D%20%5C,%20.%20%5C%5C%0A%5Ctext%7B%20s.t.%20%7D%20&amp;%20%7B%5Cmathbb%20P%7D%5Cleft(%20%20y%20%5Cin%20%5Cmathcal%7BC%7D(X)%20%5Cmid%20Y=y%20%20%5Cright)%20%5Cgeq%201-%5Calpha,%20%5Cforall%20y%20%5Cin%20%5Cmathcal%7BY%7D%0A%5Cend%7Balign%7D%0A%5Ctag%7B2%7D"></span></p>
<p><span class="citation" data-cites="sadinle2019least">Sadinle, Lei, and Wasserman (2019)</span> have shown that the optimal solution for such a set:</p>
<div id="prp-concoverage" class="theorem proposition">
<p><span class="theorem-title"><strong>Proposition 2 (Conditional-coverage and prediction set)</strong></span> The solutions of (Equation&nbsp;2) can be written</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign*%7D%0A%5Cmathcal%7BC%7D%5E*(x)%20=%20%5Cleft%5C%7B%20y%20%5Cin%20%5Cmathcal%7BY%7D%20:%20p(y%7Cx)%20%5Cgeq%20t_%7B%5Calpha,y%7D%5Cright%5C%7D,%0A%5Cend%7Balign*%7D%0A"> where the threshold <img src="https://latex.codecogs.com/png.latex?t_%7B%5Calpha,y%7D"> is fixed as the <img src="https://latex.codecogs.com/png.latex?%5Calpha">-quantile of the conditional distribution <img src="https://latex.codecogs.com/png.latex?p(Y%7CX)"> knowing <img src="https://latex.codecogs.com/png.latex?Y=y">, <em>i.e,</em> <img src="https://latex.codecogs.com/png.latex?%7B%5Cmathbb%20P%7D(p(Y%7CX)%20%5Cgeq%20t_%7B%5Calpha,y%7D%20%7CY%20=%20y)%20=%201%20%E2%88%92%20%5Calpha">.</p>
</div>
<!-- :::: {.proof-container}

::: {.proof-header onclick="toggleProof('macro-coverage')"}
[▶]{#proof-arrow-macro-coverage .proof-arrow} [Proof]{.proof-title}
:::

::: {#proof-content-macro-coverage .proof-content}
This result is a direct consequence of @{prp-wmacrocoverage} stated below with the particular choice of $\omega(y) = \frac{1}{|\mathcal{Y}|}$.
:::
:::: -->
<div class="proof-container">
<div class="proof-header" onclick="toggleProof('cond-coverage')">
<p><span id="proof-arrow-cond-coverage" class="proof-arrow">▶</span> <span class="proof-title">Proof</span></p>
</div>
<div id="proof-content-cond-coverage" class="proof-content">
<p>This result also follows from the Neyman-Pearson lemma applied to each class separately. We refer to Theorem 6 of <span class="citation" data-cites="sadinle2019least">Sadinle, Lei, and Wasserman (2019)</span> for the complete proof.</p>
</div>
</div>
<p><u>Interpretation</u>: the optimal way to get conditional coverage is to select the labels whose probability is larger than a particular threshold <img src="https://latex.codecogs.com/png.latex?t_%7B%5Calpha,y%7D">, where now the threshold <img src="https://latex.codecogs.com/png.latex?t_%7B%5Calpha,y%7D"> can be adapted in a class-wise fashion, and is fixed as the <img src="https://latex.codecogs.com/png.latex?%5Calpha">-quantile of the conditional distribution <img src="https://latex.codecogs.com/png.latex?p(Y%7CX)"> knowing <img src="https://latex.codecogs.com/png.latex?Y=y">, <em>i.e,</em> <img src="https://latex.codecogs.com/png.latex?%7B%5Cmathbb%20P%7D(p(Y%7CX)%20%5Cgeq%20t_%7B%5Calpha,y%7D%20%7CY%20=%20y)%20=%201%20%E2%88%92%20%5Calpha">.</p>
<p>In practice, the threshold of each class <img src="https://latex.codecogs.com/png.latex?y"> is now computed as the quantile of the scores on class <img src="https://latex.codecogs.com/png.latex?y">. This is known under the name Mondrian conformal prediction <span class="citation" data-cites="vovk2005algorithmic">(Vovk, Gammerman, and Shafer 2005)</span>. Formally, for any class <img src="https://latex.codecogs.com/png.latex?y%5Cin%20%5Cmathcal%7BY%7D">, we set <img src="https://latex.codecogs.com/png.latex?t_%7B%5Calpha,y%7D"> as the <img src="https://latex.codecogs.com/png.latex?(n_y+1)(1-%5Calpha)"> score of the calibration points over class <img src="https://latex.codecogs.com/png.latex?y">, where <img src="https://latex.codecogs.com/png.latex?n_y"> is the number of these points. It corresponds to applying Algorithm 1 with the threshold function <img src="https://latex.codecogs.com/png.latex?%5Chat%7B%5Cmathbf%7Bq%7D%7D"> equal to the vector of these conditional quantiles. We refer to this method as Conditional conformal prediction.</p>
<p>For classes whose number of calibration points <img src="https://latex.codecogs.com/png.latex?n_y"> is not large enough (i.e., <img src="https://latex.codecogs.com/png.latex?n_y%3C%20%5Calpha%5E%7B-1%7D">), this threshold is fixed as the maximum possible value of the score function, or formally to <img src="https://latex.codecogs.com/png.latex?+%5Cinfty">. It implies that <strong>these rare classes will always be included</strong> in the prediction sets. It can be observed below in the plots for <img src="https://latex.codecogs.com/png.latex?%5Calpha"> small enough.</p>

<div id="plots2" style="width:100%; max-width:800px; overflow-x:auto;"></div>
<div id="alphaControl" style="display:flex; align-items:center; justify-content:center; gap:12px;">
  <label for="alphaSlider"><img src="https://latex.codecogs.com/png.latex?%5Calpha="> <span id="alphaValue">0.15</span></label>
  <input type="range" id="alphaSlider" min="0.001" max="0.20" step="0.001" value="0.15">
</div>
<script type="module" src="subplot_viz.js"></script>
<p><br></p>
<p>The figure above illustrates the influence of <strong>conditional modeling</strong>: overall, the predicted sets tend to be larger, especially when the miscoverage rate <img src="https://latex.codecogs.com/png.latex?%5Calpha"> is close to 0, and often include the marginal prediction sets. In practice, estimating the <strong>conditional distribution</strong> in high-dimensional spaces with limited data is challenging, which can lead to excessively large prediction sets. We also include bar plots showing per-class coverage, which reveal that Standard CP tends to under-cover rare classes (e.g., Class 2 in green). This poor class-conditional behavior motivates our next proposal.</p>
</section>
<section id="macro-coverage" class="level2">
<h2 class="anchored" data-anchor-id="macro-coverage">Macro-coverage</h2>
<p>Standard conformal prediction often under-covers rare classes, despite producing compact prediction sets. On the other end of the spectrum, conditional conformal prediction ensures equal coverage across all classes, but at the cost of unwieldy, oversized sets. What if we could find a middle ground?</p>
<p>This is what we tackle by introducing a macro-coverage constraint, inspired by the macro-accuracy metric in multi-class classification. Our objective is to minimize the expected size of prediction sets while ensuring that all classes (including those with limited data) benefit from equitable and reliable coverage.</p>
<p>The macro-coverage formulation reads as follows: <span id="eq-min_st_macrocoverage"><img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign%7D%0A&amp;%5Cmin_%7B%5Cmathcal%7BC%7D%20:%20%5Cmathcal%7BX%7D%20%5Cmapsto%202%5E%5Cmathcal%7BY%7D%7D%20%5Cmathbb%7BE%7D%5B%7C%5Cmathcal%7BC%7D(X)%7C%5D%20%20%5C%5C%0A%5Ctext%7B%20s.t.%20%7D%20&amp;%20%5Ctext%7BMacroCov%7D(%7B%5Cmathcal%20C%7D)%20%5Cgeq%201-%5Calpha,%0A%5Cend%7Balign%7D%0A%5Ctag%7B3%7D"></span> where we defined the macro-coverage as <span id="eq-def_macrocov"><img src="https://latex.codecogs.com/png.latex?%0A%5Ctext%7BMacroCov%7D(%7B%5Cmathcal%20C%7D)%20=%20%5Cfrac%7B1%7D%7B%7C%5Cmathcal%7BY%7D%7C%7D%5Csum_%7By%20%5Cin%20%5Cmathcal%7BY%7D%7D%20%7B%5Cmathbb%20P%7D(Y%20%5Cin%20%5Cmathcal%7BC%7D(X)%20%5Cmid%20Y%20=%20y).%0A%5Ctag%7B4%7D"></span> The motivation of this program is to treat all classes equally. We provide an adaptation of the previous proposition for this new constraints:</p>
<div id="prp-macrocoverage" class="theorem proposition">
<p><span class="theorem-title"><strong>Proposition 3 (Macro-coverage and prediction set)</strong></span> The solutions of (Equation&nbsp;3) are given by <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign*%7D%0A%5Cmathcal%7BC%7D%5E*(x)%20=%20%5Cleft%5C%7B%20y%20%5Cin%20%5Cmathcal%7BY%7D%20:%20%5Cfrac%7Bp(y%7Cx)%7D%7Bp(y)%7D%20%5Cgeq%20t%5Cright%5C%7D,%0A%5Cend%7Balign*%7D%0A"> for some threshold <img src="https://latex.codecogs.com/png.latex?t"> that depends on <img src="https://latex.codecogs.com/png.latex?%5Calpha">.</p>
</div>
<div class="proof-container">
<div class="proof-header" onclick="toggleProof('macro-coverage')">
<p><span id="proof-arrow-macro-coverage" class="proof-arrow">▶</span> <span class="proof-title">Proof</span></p>
</div>
<div id="proof-content-macro-coverage" class="proof-content">
<p>This result is a direct consequence of Proposition&nbsp;4 stated below with the particular choice of <img src="https://latex.codecogs.com/png.latex?%5Comega(y)%20=%20%5Cfrac%7B1%7D%7B%7C%5Cmathcal%7BY%7D%7C%7D">.</p>
</div>
</div>
<p>Though we do not have access to <img src="https://latex.codecogs.com/png.latex?p(y%7Cx)"> and <img src="https://latex.codecogs.com/png.latex?p(y)"> in practice, we have estimates <img src="https://latex.codecogs.com/png.latex?%5Chat%7Bp%7D(y%7Cx)"> and <img src="https://latex.codecogs.com/png.latex?%5Chat%7Bp%7D(y)"> from our classifier and the distribution of empirical training labels, respectively. By creating prediction sets as <img src="https://latex.codecogs.com/png.latex?%5Csmash%7B%5Cwidehat%7B%7B%5Cmathcal%20C%7D%7D_%7B%5Cmathsf%7BPAS%7D%7D(X)%20=%20%5C%7By%20%5Cin%20%7B%5Cmathcal%20Y%7D:%20%5Chat%7Bp%7D(y%7CX)/%5Chat%7Bp%7D(y)%20%5Cgeq%20t%5C%7D%7D"> for a threshold <img src="https://latex.codecogs.com/png.latex?t">. We choose <img src="https://latex.codecogs.com/png.latex?t"> to achieve <img src="https://latex.codecogs.com/png.latex?1-%5Calpha"> marginal coverage in the following way: Observe that <img src="https://latex.codecogs.com/png.latex?%5Csmash%7B%5Cwidehat%7B%7B%5Cmathcal%20C%7D%7D%7D"> can be rewritten as <img src="https://latex.codecogs.com/png.latex?%5Csmash%7B%5Cwidehat%7B%7B%5Cmathcal%20C%7D%7D(x)%20=%20%5C%7By%20%5Cin%20%7B%5Cmathcal%20Y%7D:%20s_%7B%5Cmathsf%7BPAS%7D%7D(x,y)%20%5Cleq%20-t%5C%7D%7D">, where <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign%7D%0A%20%20%20%20s_%7B%5Cmathsf%7BPAS%7D%7D(x,y)%20=%20-%20%5Cfrac%7B%5Chat%7Bp%7D(y%7Cx)%7D%7B%5Chat%7Bp%7D(y)%7D,%0A%5Cend%7Balign%7D%0A"> and <img src="https://latex.codecogs.com/png.latex?%5Cmathsf%7BPAS%7D"> stands for <strong>prevalence-adjusted softmax</strong>.</p>
<p>In summary, the method we propose is simply running Algorithm 1 with the <img src="https://latex.codecogs.com/png.latex?%5Cmathsf%7BPAS%7D"> score function (which we will refer to as Standard with <img src="https://latex.codecogs.com/png.latex?%5Cmathsf%7BPAS%7D">) and <img src="https://latex.codecogs.com/png.latex?%5Chat%7B%5Cmathbf%7Bq%7D%7D=(%5Chat%7Bq%7D,%5Cdots,%5Chat%7Bq%7D)"> as the vector of quantile of the scores, where <img src="https://latex.codecogs.com/png.latex?%5Chat%7Bq%7D"> is the <img src="https://latex.codecogs.com/png.latex?%5Clceil%20(n+1)(1-%5Calpha)%20%5Crceil">-th largest value in <img src="https://latex.codecogs.com/png.latex?%5C%7Bs_%7B%5Cmathsf%7BPAS%7D%7D(X_%7B1%7D,Y_%7B1%7D),%20%5Cdots,%20s_%7B%5Cmathsf%7BPAS%7D%7D(X_%7Bn%7D,Y_%7Bn%7D)%5C%7D">. This corresponds to running Standard CP with the new <img src="https://latex.codecogs.com/png.latex?s_%7B%5Cmathsf%7BPAS%7D%7D"> score. Note that for <strong>fair comparisons</strong> with Standard CP, we set the threshold in Standard with PAS to achieve marginal coverage <img src="https://latex.codecogs.com/png.latex?1-%5Calpha">, i.e., we fix <img src="https://latex.codecogs.com/png.latex?t"> so <img src="https://latex.codecogs.com/png.latex?%7B%5Cmathbb%20P%7D(Y%20%5Cin%20%5Cwidehat%7B%7B%5Cmathcal%20C%7D%7D_%7B%5Cmathsf%7BPAS%7D%7D(X))%0A=%201-%5Calpha">.</p>
<p>Then, this achieves the desired marginal coverage guarantee while (approximately) optimally trading off set size and macro-coverage. In the visualization below, we also illustrate the variation of the <strong>(empirical) coverage per class</strong> w.r.t. <img src="https://latex.codecogs.com/png.latex?%5Calpha"> (evaluated on the test set).</p>
<p><br></p>

<div id="plots3" style="width:100%; max-width:800px; overflow-x:auto;"></div>
<div id="alphaControl2" style="display:flex; align-items:center; justify-content:center; gap:2px;">
  <label for="alphaSlider2"><img src="https://latex.codecogs.com/png.latex?%5Calpha">: <span id="alphaValue2">0.15</span></label>
  <input type="range" id="alphaSlider2" min="0.001" max="0.20" step="0.001" value="0.15">
</div>
<script type="module" src="subplot_viz_3.js"></script>

</section>
<section id="weighted-macro-coverage" class="level2">
<h2 class="anchored" data-anchor-id="weighted-macro-coverage">Weighted-macro coverage</h2>
<p>Recall that macro-coverage is the unweighted average of the class-conditional coverages. However, in some settings it may be more important to cover some classes than others; in these settings, it makes sense to instead optimize a <em>weighted</em> average of the class-conditional coverages. Given user-chosen class weights <img src="https://latex.codecogs.com/png.latex?%5Comega(y)"> for <img src="https://latex.codecogs.com/png.latex?y%20%5Cin%20%7B%5Cmathcal%20Y%7D"> that sum to one, we can define the <em><img src="https://latex.codecogs.com/png.latex?%5Comega">-weighted macro-coverage</em> as</p>
<p><span id="eq-min_st_wmacrocoverage"><img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign%7D%0A%20%20%20%20%5Cmathrm%7BMacroCov%7D_%7B%5Comega%7D(%7B%5Cmathcal%20C%7D)%20=%0A%20%20%20%20%5Csum_%7By%20%5Cin%20%7B%5Cmathcal%20Y%7D%7D%20%5Comega(y)%20%7B%5Cmathbb%20P%7D(Y%20%5Cin%20%7B%5Cmathcal%20C%7D(X)%20%5Cmid%20Y%20=%20y).%0A%5Cend%7Balign%7D%0A%5Ctag%7B5%7D"></span></p>
<div id="prp-wmacrocoverage" class="theorem proposition">
<p><span class="theorem-title"><strong>Proposition 4 (Weighted macro-coverage and prediction set)</strong></span> The solutions of Equation&nbsp;3 when <img src="https://latex.codecogs.com/png.latex?%5Cmathrm%7BMacroCov%7D"> is replaced with <img src="https://latex.codecogs.com/png.latex?%5Cmathrm%7BMacroCov%7D_%7B%5Comega%7D"> are of the form <img src="https://latex.codecogs.com/png.latex?%0A%20%20%5Cbegin%7Balign%7D%0A%20%20%20%20%7B%5Cmathcal%20C%7D%5E*(x)%20=%20%5Cleft%5C%7B%20y%20%5Cin%20%7B%5Cmathcal%20Y%7D:%20%5Comega(y)%20%5Cdfrac%7Bp(y%7Cx)%7D%7Bp(y)%7D%20%5Cgeq%20t%5Cright%5C%7D,%0A%20%20%5Cend%7Balign%7D%0A"> for some threshold <img src="https://latex.codecogs.com/png.latex?t"> that depends on <img src="https://latex.codecogs.com/png.latex?%5Comega"> and <img src="https://latex.codecogs.com/png.latex?%5Calpha">, respectively.</p>
</div>
<div class="proof-container">
<div class="proof-header" onclick="toggleProof('weighted-macro-coverage')">
<p><span id="proof-arrow-weighted-macro-coverage" class="proof-arrow">▶</span> <span class="proof-title">Proof</span></p>
</div>
<div id="proof-content-weighted-macro-coverage" class="proof-content">
<p>This proof mainly realies on Lemma&nbsp;1. We assume that <img src="https://latex.codecogs.com/png.latex?X"> has a density <img src="https://latex.codecogs.com/png.latex?p"> with respect to the Lebesgue measure <img src="https://latex.codecogs.com/png.latex?%5Clambda">, but the proof can be adapted for any measure. Define the functions <img src="https://latex.codecogs.com/png.latex?f(x,y)%20:=%20%5Comega(y)p(x%7Cy)"> and <img src="https://latex.codecogs.com/png.latex?g(x,y)%20=%20%20p(x)"> and the measure <img src="https://latex.codecogs.com/png.latex?%5Cmu%20=%20%5Clambda%20%5Ctimes%20%5CBig(%20%5Csum_%7By%5Cin%20%7B%5Cmathcal%20Y%7D%7D%20%5Cdelta_y%5CBig)">, which is the product measure between the Lebesgue measure (denoted by <img src="https://latex.codecogs.com/png.latex?%5Clambda">) and the counting measure on <img src="https://latex.codecogs.com/png.latex?%7B%5Cmathcal%20Y%7D">. Let <img src="https://latex.codecogs.com/png.latex?%5Cnu%20=%201-%5Calpha">. Observe that plugging these values of <img src="https://latex.codecogs.com/png.latex?f">, <img src="https://latex.codecogs.com/png.latex?g">, <img src="https://latex.codecogs.com/png.latex?%5Cmu">, and <img src="https://latex.codecogs.com/png.latex?%5Cnu"> into Equation&nbsp;6 yields Equation&nbsp;3, because <img src="https://latex.codecogs.com/png.latex?%5Cbegin%7Balign*%7D%0A%20%20%20%20%5Cint_%7B%7B%5Cmathcal%20X%7D%5Ctimes%20%7B%5Cmathcal%20Y%7D%7D1_%7By%5Cin%20%7B%5Cmathcal%20C%7D(x)%7Df(x,y)d%20%5Cmu(x,y)%20&amp;=%20%5Csum_%7By%5Cin%20%7B%5Cmathcal%20Y%7D%7D%20%5Comega(y)%20%5Cint_%7B%5Cmathcal%20X%7D1_%7By%5Cin%20%7B%5Cmathcal%20C%7D(x)%7D%20p(x%7Cy)%20dx%20%5C%5C%0A%20%20%20%20&amp;=%20%20%5Csum_%7By%5Cin%20%7B%5Cmathcal%20Y%7D%7D%20%5Comega(y)%20%20%7B%5Cmathbb%20P%7D%5Cleft(%20y%20%5Cin%20%7B%5Cmathcal%20C%7D(X)%20%5Cmid%20Y=y%20%5Cright),%0A%5Cend%7Balign*%7D"> and <img src="https://latex.codecogs.com/png.latex?%5Cbegin%7Balign*%7D%0A%20%20%20%20%5Cint_%7B%7B%5Cmathcal%20X%7D%5Ctimes%20%7B%5Cmathcal%20Y%7D%7D1_%7By%5Cin%20%7B%5Cmathcal%20C%7D(x)%7D%20g(x,y)d%5Cmu(x,y)%20&amp;=%20%5Csum_%7By%5Cin%20%7B%5Cmathcal%20Y%7D%7D%20%5Cint_%7B%5Cmathcal%20X%7D1_%7By%5Cin%20%7B%5Cmathcal%20C%7D(x)%7D%20p(x)%20dx%20%5C%5C%0A%20%20%20%20&amp;=%20%20%5Cint_%7B%5Cmathcal%20X%7D%5Csum_%7By%5Cin%20%7B%5Cmathcal%20Y%7D%7D%201_%7By%5Cin%20%7B%5Cmathcal%20C%7D(x)%7D%20p(x)%20dx%20%5C%5C%0A%20%20%20%20&amp;=%20%20%5Cint_%7B%5Cmathcal%20X%7D%7C%7B%5Cmathcal%20C%7D(X)%7C%20p(x)%20dx%20%5C%5C%0A%20%20%20%20&amp;=%20%5Cmathbb%7BE%7D%5Cleft(%20%7C%7B%5Cmathcal%20C%7D(X)%7C%20%5Cright).%0A%5Cend%7Balign*%7D"> By Lemma&nbsp;1, it follows that the optimal solution to Equation&nbsp;3 is given by Equation&nbsp;8, which for our choice of <img src="https://latex.codecogs.com/png.latex?f"> and <img src="https://latex.codecogs.com/png.latex?g"> can be rewritten as <img src="https://latex.codecogs.com/png.latex?%7B%5Cmathcal%20C%7D_%7B1-%5Calpha%7D%5E*(x)%20=%20%5C%7By%20%5Cin%20%7B%5Cmathcal%20Y%7D:%20%5Cfrac%7B%5Comega(y)p(y%7Cx)%7D%7Bp(y)%7D%20%5Cgeq%20t_%7B1-%5Calpha%7D%5C%7D"> by observing that <img src="https://latex.codecogs.com/png.latex?%5Cbegin%7Bequation*%7D%0A%20%20%20%20%5Cfrac%7Bf(x,y)%7D%7Bg(x,y)%7D%20=%20%5Cfrac%7B%5Comega(y)p(x%7Cy)%7D%7Bp(x)%7D%20%20=%20%5Cfrac%7B%5Comega(y)p(x,y)%7D%7Bp(x)p(y)%7D%20=%5Cfrac%7B%5Comega(y)p(y%7Cx)%7D%7Bp(y)%7D%5C,.%0A%5Cend%7Bequation*%7D"></p>
</div>
</div>
<p>We can approximate these optimal sets by running standard CP with the <em>weighted prevalence-adjusted softmax</em> (WPAS), <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign%7D%0A%20%20%20%20s_%7B%5Cmathsf%7BWPAS%7D%7D(x,y)%20:=%20-%20%5Comega(y)%20%5Cfrac%7B%5Chat%7Bp%7D(y%7Cx)%7D%7B%5Chat%7Bp%7D(y)%7D,%0A%5Cend%7Balign%7D%0A"> as the score function.</p>
<p>Again, for <strong>fair comparisons</strong> with Standard CP, we set the threshold in Standard with WPAS to achieve marginal coverage <img src="https://latex.codecogs.com/png.latex?1-%5Calpha">, i.e., we fix <img src="https://latex.codecogs.com/png.latex?t"> so <img src="https://latex.codecogs.com/png.latex?%7B%5Cmathbb%20P%7D(Y%20%5Cin%20%5Cwidehat%7B%7B%5Cmathcal%20C%7D%7D_%7B%5Cmathsf%7BWPAS%7D%7D(X))%0A=%201-%5Calpha">.</p>
<section id="weighted-score-adapted-to-handle-endangered-species" class="level3">
<h3 class="anchored" data-anchor-id="weighted-score-adapted-to-handle-endangered-species">Weighted score adapted to handle endangered species</h3>
<p>Motivated by plant conservation, we design weights for the weighted prevalence-adjusted softmax (WPAS) score to target coverage of at-risk species in Pl@ntNet-300K.</p>
<p>Let <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%7BY%7D_%7B%5Ctext%7Bat-risk%7D%7D%20%5Csubseteq%20%5Cmathcal%7BY%7D"> be the set of at-risk species. The coverage of at-risk species is weighted <img src="https://latex.codecogs.com/png.latex?%5Cgamma%20%5Cgeq%201"> times more than the coverage of other species, so</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Comega(y)%20=%20%5Cbegin%7Bcases%7D%0A%20%20%20%20%5Cfrac%7B%5Cgamma%7D%7BW%7D%20&amp;%20%5Ctext%7Bif%20%7D%20y%20%5Cin%20%5Cmathcal%7BY%7D_%7B%5Ctext%7Bat-risk%7D%7D%20%5C%5C%0A%20%20%20%20%5Cfrac%7B1%7D%7BW%7D%20&amp;%20%5Ctext%7Botherwise%7D,%0A%5Cend%7Bcases%7D%0A"></p>
<p>where <img src="https://latex.codecogs.com/png.latex?W%20=%20%5Cgamma%7C%5Cmathcal%7BY%7D_%7B%5Ctext%7Bat-risk%7D%7D%7C%20+%20%7C%5Cmathcal%7BY%7D%20%5Csetminus%20%5Cmathcal%7BY%7D_%7B%5Ctext%7Bat-risk%7D%7D%7C"> is a normalizing factor to ensure <img src="https://latex.codecogs.com/png.latex?%5Csum_%7By%20%5Cin%20%5Cmathcal%7BY%7D%7D%20%5Comega(y)%20=%201">. We will show the result of running WPAS with this <img src="https://latex.codecogs.com/png.latex?%5Comega"> in the Pl@ntNet-300K experimental results below.</p>
</section>
</section>
<section id="summary-of-propositions-1-4" class="level2">
<h2 class="anchored" data-anchor-id="summary-of-propositions-1-4">Summary of Propositions 1-4</h2>
<p>It might help readers to compare at a glance the objective and the quantity being thresholded in each approach (for instance <img src="https://latex.codecogs.com/png.latex?p(y%5Cmid%20x)"> vs <img src="https://latex.codecogs.com/png.latex?p(y%5Cmid%20x)/p(y)">). Below is a compact synthesis of the propositions discussed above.</p>
<table class="table-striped table-hover caption-top table">
<caption>Theoretical synthesis (coverage <img src="https://latex.codecogs.com/png.latex?%5Cgeq%201-%5Calpha">)</caption>
<colgroup>
<col style="width: 50%">
<col style="width: 50%">
</colgroup>
<thead>
<tr class="header">
<th>Constraint</th>
<th>Quantity thresholded</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>Marginal coverage</td>
<td><img src="https://latex.codecogs.com/png.latex?p(y%5Cmid%20x)%20%5Cge%20t_%7B%5Calpha%7D"> (same for all y)</td>
</tr>
<tr class="even">
<td>Class-conditional coverage</td>
<td><img src="https://latex.codecogs.com/png.latex?p(y%5Cmid%20x)%20%5Cgeq%20t_%7B%5Calpha,y%7D"> (class-specific)</td>
</tr>
<tr class="odd">
<td>Macro-coverage</td>
<td><img src="https://latex.codecogs.com/png.latex?%5Cdfrac%7Bp(y%5Cmid%20x)%7D%7Bp(y)%7D%20%5Cgeq%20t_%7B%5Calpha%7D"> (prevalence-adjusted)</td>
</tr>
<tr class="even">
<td>Weighted macro coverage</td>
<td><img src="https://latex.codecogs.com/png.latex?%5Comega(y)%5Cdfrac%7Bp(y%5Cmid%20x)%7D%7Bp(y)%7D%20%5Cgeq%20t_%7B%5Calpha%7D"> (weights <img src="https://latex.codecogs.com/png.latex?%5Comega">)</td>
</tr>
</tbody>
</table>
<p>In each case, <img src="https://latex.codecogs.com/png.latex?t_%7B%5Calpha%7D"> is the threshold that ensures <img src="https://latex.codecogs.com/png.latex?1-%5Calpha"> marginal coverage (or in the case of class-conditional coverage, <img src="https://latex.codecogs.com/png.latex?t_%7B%5Calpha,y%7D"> is chosen to ensure <img src="https://latex.codecogs.com/png.latex?1-%5Calpha"> class-conditional coverage for class <img src="https://latex.codecogs.com/png.latex?y">, which implies <img src="https://latex.codecogs.com/png.latex?1-%5Calpha"> marginal coverage after marginalizing over classes).</p>
</section>
<section id="conformal-prediction-in-action-on-plntnet-300k" class="level2">
<h2 class="anchored" data-anchor-id="conformal-prediction-in-action-on-plntnet-300k">Conformal prediction in action on Pl@ntNet-300K</h2>
<p>We will now turn back on the Pl@ntNet-300K dataset presented earlier.</p>
<section id="evaluation-metrics" class="level3">
<h3 class="anchored" data-anchor-id="evaluation-metrics"><iconify-icon inline="" icon="hugeicons:tape-measure" aria-label="Icon tape-measure from hugeicons Iconify.design set." title="Icon tape-measure from hugeicons Iconify.design set."></iconify-icon> Evaluation metrics</h3>
<p>We introduce here some evaluation metrics of interest. Let <img src="https://latex.codecogs.com/png.latex?%5Chat%7Bc%7D_y"> denote the <strong>empirical coverage for class</strong> <img src="https://latex.codecogs.com/png.latex?y"> (evaluated on the test set), and let <img src="https://latex.codecogs.com/png.latex?1-%5Calpha"> be the target coverage level. We leverage in particular the per-class coverage <img src="https://latex.codecogs.com/png.latex?%5Chat%7Bc%7D_y">, through class-balanced averages: the <strong>at‑risk class-coverage average</strong> <img src="https://latex.codecogs.com/png.latex?%5Ctfrac%7B1%7D%7B%7C%5Cmathcal%7BY%7D_%7B%5Cmathrm%7Bat%5Ctext%7B-%7Drisk%7D%7D%7C%7D%5Csum_%7By%5Cin%5Cmathcal%7BY%7D_%7B%5Cmathrm%7Bat%5Ctext%7B-%7Drisk%7D%7D%7D%5Chat%7Bc%7D_y"> and the <strong>not‑at‑risk average</strong> computed analogously.</p>
<table class="table-striped table-hover caption-top table">
<caption>Evaluation metrics (<img src="https://latex.codecogs.com/png.latex?%5Chat%7Bc%7D_y"> : empirical coverage for class <img src="https://latex.codecogs.com/png.latex?y">)</caption>
<colgroup>
<col style="width: 30%">
<col style="width: 52%">
<col style="width: 17%">
</colgroup>
<thead>
<tr class="header">
<th><strong>Metric</strong></th>
<th><strong>Definition</strong></th>
<th><strong>Target</strong></th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>Avg. set size</td>
<td><img src="https://latex.codecogs.com/png.latex?%5Cfrac%7B1%7D%7BN%7D%5Csum_%7Bi=1%7D%5E%7BN%7D%7C%5Cmathcal%7BC%7D(X_i%5E%7B%5Cmathcal%7BT%7D%7D)%7C"></td>
<td>Lower</td>
</tr>
<tr class="even">
<td>MarginalCov</td>
<td><img src="https://latex.codecogs.com/png.latex?%5Cfrac%7B1%7D%7BN%7D%5Csum_%7Bi=1%7D%5E%7BN%7D%5Cmathbb%7B1%7D%5C%7BY_i%5E%7B%5Cmathcal%7BT%7D%7D%5Cin%5Cmathcal%7BC%7D(X_i%5E%7B%5Cmathcal%7BT%7D%7D)%5C%7D"></td>
<td>Higher</td>
</tr>
<tr class="odd">
<td>MacroCov</td>
<td><img src="https://latex.codecogs.com/png.latex?%5Cfrac%7B1%7D%7B%7C%5Cmathcal%7BY%7D%7C%7D%5Csum_%7By%5Cin%20%5Cmathcal%7BY%7D%7D%5Chat%7Bc%7D_y"></td>
<td>Higher</td>
</tr>
<tr class="even">
<td>FracBelow50%</td>
<td><img src="https://latex.codecogs.com/png.latex?%5Cfrac%7B1%7D%7B%7C%5Cmathcal%7BY%7D%7C%7D%5Csum_%7By%5Cin%20%5Cmathcal%7BY%7D%7D%20%5Cmathbb%7B1%7D%5C%7B%5Chat%7Bc%7D_y%20%5Cle%200.5%5C%7D"></td>
<td>Lower</td>
</tr>
<tr class="odd">
<td>UnderCovGap</td>
<td><img src="https://latex.codecogs.com/png.latex?%5Cfrac%7B1%7D%7B%7C%5Cmathcal%7BY%7D%7C%7D%5Csum_%7By%5Cin%20%5Cmathcal%7BY%7D%7D%20%5Cmax(1-%5Calpha-%5Chat%7Bc%7D_y,0)"></td>
<td>Lower</td>
</tr>
<tr class="even">
<td>At-risk average <img src="https://latex.codecogs.com/png.latex?%5Chat%7Bc%7D_y"></td>
<td><img src="https://latex.codecogs.com/png.latex?%5Ctfrac%7B1%7D%7B%7C%5Cmathcal%7BY%7D_%7B%5Cmathrm%7Bat%5Ctext%7B-%7Drisk%7D%7D%7C%7D%20%5Csum_%7By%20%5Cin%20%5Cmathcal%7BY%7D_%7B%5Cmathrm%7Bat%5Ctext%7B-%7Drisk%7D%7D%7D%20%5Chat%7Bc%7D_y"></td>
<td>Higher</td>
</tr>
<tr class="odd">
<td>Not-at-risk average <img src="https://latex.codecogs.com/png.latex?%5Chat%7Bc%7D_y"></td>
<td><img src="https://latex.codecogs.com/png.latex?%5Ctfrac%7B1%7D%7B%7C%5Cmathcal%7BY%7D%20%5Csetminus%20%5Cmathcal%7BY%7D_%7B%5Cmathrm%7Bat%5Ctext%7B-%7Drisk%7D%7D%7C%7D%20%5Csum_%7By%20%5Cin%20%5Cmathcal%7BY%7D%20%5Csetminus%20%5Cmathcal%7BY%7D_%7B%5Cmathrm%7Bat%5Ctext%7B-%7Drisk%7D%7D%7D%20%5Chat%7Bc%7D_y"></td>
<td>Higher</td>
</tr>
</tbody>
</table>
</section>
<section id="results" class="level3">
<h3 class="anchored" data-anchor-id="results"><iconify-icon inline="" icon="carbon:result-new" aria-label="Icon result-new from carbon Iconify.design set." title="Icon result-new from carbon Iconify.design set."></iconify-icon> Results</h3>
<p>We present a summary of the result obtained on such a dataset. We consider the softmax score function described as an initial conformal score, and the base model is a ResNet-50 <span class="citation" data-cites="he2016deep">He et al. (2016)</span> trained using the standard cross-entropy loss. Code for reproducing the experiments is available at <a href="" target="_blank">https://github.com/tiffanyding/long-tail-conformal</a>. We consider four different values of <img src="https://latex.codecogs.com/png.latex?%5Calpha"> in the following, but the behaviors remain similar irrespective to this choice.</p>
<section id="overall-analysis" class="level4">
<h4 class="anchored" data-anchor-id="overall-analysis">Overall analysis</h4>
<p>Let us start with a synthesis over all classes/species.</p>
<div id="all-metrics-softmax-container" style="width: 100%; height: 450px; margin: 20px 0;">
</div>

<script type="module" src="all_metrics_softmax_viz.js"></script>
<p>When targeting set size and class-conditional or macro-coverage, it is more effective to optimize for this trade-off directly than trading off set size and marginal coverage. Adjusting <img src="https://latex.codecogs.com/png.latex?%5Calpha"> in Standard CP is a plausible solution to target class-conditional coverage, but the results show that this does not optimally navigate the set size/class-conditional coverage trade-off (Pareto front), which is our goal. In comparison, our methods, which explicitly optimize macro-coverage, consistently achieve better trade-offs than Standard CP.</p>
<p><strong>Classwise should generally be avoided</strong> in long-tail settings, as comparable class-conditional and macro-coverage can be achieved with significantly smaller sets using our proposed methods (above their associated sets almost reach the full set of classes).</p>
<p>Standard with <img src="https://latex.codecogs.com/png.latex?%5Cmathsf%7BPAS%7D"> is Pareto optimal, in the sense that at any marginal coverage level, there is no method that simultaneously achieves better set size and class-conditional/macro- coverage. This suggests that Standard with <img src="https://latex.codecogs.com/png.latex?%5Cmathsf%7BPAS%7D"> is a good starting place for practitioners due to its simplicity and strong performance on all metrics.</p>
</section>
<section id="at-risk-species-analysis" class="level4">
<h4 class="anchored" data-anchor-id="at-risk-species-analysis">At-risk species analysis</h4>
<p>We now turn to a more detailed analysis of at-risk species. To this end, we present results for the Standard method applied to the Pl@ntNet-300K dataset, using three conformal score functions: softmax, PAS, and WPAS with <img src="https://latex.codecogs.com/png.latex?%5Cgamma%20%5Cin%20%5C%7B1,%2010,%2010%5E2,%2010%5E3%5C%7D">. Our findings show that increasing <img src="https://latex.codecogs.com/png.latex?%5Cgamma"> in WPAS enhances the class-conditional coverage for at-risk classes, as measured by <img src="https://latex.codecogs.com/png.latex?%5Chat%7Bc%7D_y">, the empirical class-conditional coverage for class <img src="https://latex.codecogs.com/png.latex?y">. We summarize these results by computing the “at-risk average <img src="https://latex.codecogs.com/png.latex?%5Chat%7Bc%7D_y">” as <img src="https://latex.codecogs.com/png.latex?(1/%7C%5Cmathcal%7BY%7D_%7B%5Ctext%7Bat-risk%7D%7D%7C)%5Csum_%7By%20%5Cin%20%5Cmathcal%7BY%7D_%7B%5Ctext%7Bat-risk%7D%7D%7D%20%5Chat%7Bc%7D_y">, and similarly for the “not-at-risk average <img src="https://latex.codecogs.com/png.latex?%5Chat%7Bc%7D_y">”.</p>
<div id="plantnet-comparison-container" style="width: 100%; height: 500px; margin: 20px 0;">
</div>

<script type="module" src="plantnet_comparison_viz.js"></script>
<p>We observe that Standard with <img src="https://latex.codecogs.com/png.latex?%5Cmathsf%7BWPAS%7D"> improves the class-conditional coverage of at-risk classes relative to Standard with softmax or <img src="https://latex.codecogs.com/png.latex?%5Cmathsf%7BPAS%7D">. Comparing <img src="https://latex.codecogs.com/png.latex?%5Cmathsf%7BWPAS%7D"> to <img src="https://latex.codecogs.com/png.latex?%5Cmathsf%7BPAS%7D">, we see that increasing <img src="https://latex.codecogs.com/png.latex?%5Cgamma">, the amount we up-weight at-risk classes, leads to larger improvements in the class-conditional coverage of at-risk classes, as expected. These increases are “paid for’’ in terms of a mild increase in average set size and have no discernible effect on the class-conditional coverage of not-at-risk classes, which is appealing from a practical perspective.</p>
</section>
</section>
</section>
<section id="conclusion" class="level2">
<h2 class="anchored" data-anchor-id="conclusion">Conclusion</h2>
<p>In summary, conformal prediction provides a principled and flexible framework for uncertainty quantification in plant species identification, especially in the presence of long-tailed and imbalanced data. By carefully choosing the coverage notion, we can achieve both reliable guarantees and practical interpretability, empowering both researchers and practitioners to make more informed decisions in challenging real-world settings. For the interested reader the associated paper not only consider new conformal score function approaches, we also propose another approach that requires modifying the conformal procedure itself.</p>
</section>
<section id="references" class="level1">
<h1><i class="fa-solid fa-link" title="link" aria-label="link"></i> References</h1>
<div id="refs" class="references csl-bib-body hanging-indent" data-entry-spacing="0">
<div id="ref-Ding_Fermanian_Salmon25" class="csl-entry">
Ding, T., J.-B. Fermanian, and J. Salmon. 2026. <span>“<span class="nocase">Conformal Prediction for Long-Tailed Classification</span>.”</span> In <em>ICLR</em>.
</div>
<div id="ref-garcin2021pl" class="csl-entry">
Garcin, Camille, Alexis Joly, Pierre Bonnet, Jean-Christophe Lombardo, Antoine Affouard, Mathias Chouet, Maximilien Servajean, Titouan Lorieul, and Joseph Salmon. 2021. <span>“<span class="nocase">Pl@ntNet-300K</span>: A Plant Image Dataset with High Label Ambiguity and a Long-Tailed Distribution.”</span> In <em>NeurIPS Datasets and Benchmarks 2021</em>.
</div>
<div id="ref-he2016deep" class="csl-entry">
He, Kaiming, Xiangyu Zhang, Shaoqing Ren, and Jian Sun. 2016. <span>“Deep Residual Learning for Image Recognition.”</span> In <em>CVPR</em>, 770–78.
</div>
<div id="ref-neyman1933ix" class="csl-entry">
Neyman, Jerzy, and Egon Sharpe Pearson. 1933. <span>“<span class="nocase">IX. On the problem of the most efficient tests of statistical hypotheses</span>.”</span> <em>Philosophical Transactions of the Royal Society of London. Series A, Containing Papers of a Mathematical or Physical Character</em> 231 (694-706): 289–337.
</div>
<div id="ref-romano2020classification" class="csl-entry">
Romano, Yaniv, Matteo Sesia, and Emmanuel J. Candès. 2020. <span>“Classification with Valid and Adaptive Coverage.”</span> In <em>NeurIPS</em>.
</div>
<div id="ref-sadinle2019least" class="csl-entry">
Sadinle, Mauricio, Jing Lei, and Larry Wasserman. 2019. <span>“Least Ambiguous Set-Valued Classifiers with Bounded Error Levels.”</span> <em>J. Amer. Statist. Assoc.</em> 114 (525): 223–34.
</div>
<div id="ref-vovk2016criteria" class="csl-entry">
Vovk, Vladimir, Valentina Fedorova, Ilia Nouretdinov, and Alexander Gammerman. 2016. <span>“Criteria of Efficiency for Conformal Prediction.”</span> In <em>Conformal and Probabilistic Prediction with Applications: 5th International Symposium, COPA 2016, Madrid, Spain, April 20-22, 2016, Proceedings 5</em>, 23–39. Springer.
</div>
<div id="ref-vovk2005algorithmic" class="csl-entry">
Vovk, Vladimir, Alex Gammerman, and Glenn Shafer. 2005. <em>Algorithmic Learning in a Random World</em>. Springer.
</div>
</div>
<section id="appendix" class="level2">
<h2 class="anchored" data-anchor-id="appendix">Appendix</h2>
<section id="technical-detour" class="level3">
<h3 class="anchored" data-anchor-id="technical-detour"><iconify-icon inline="" icon="hugeicons:curvy-right-direction" aria-label="Icon curvy-right-direction from hugeicons Iconify.design set." title="Icon curvy-right-direction from hugeicons Iconify.design set."></iconify-icon> Technical detour</h3>
<p>As a key technical tool for our proofs, we state the following version of the Neyman–Pearson Lemma. The proof may be skipped on first reading.</p>
<div id="lem-neyman_pearson" class="theorem lemma">
<p><span class="theorem-title"><strong>Lemma 1 (<span class="citation" data-cites="neyman1933ix">Neyman and Pearson (1933)</span>)</strong></span> Let <img src="https://latex.codecogs.com/png.latex?%5Cmu"> be a measure on <img src="https://latex.codecogs.com/png.latex?%7B%5Cmathcal%20X%7D%5Ctimes%20%7B%5Cmathcal%20Y%7D"> and let <img src="https://latex.codecogs.com/png.latex?f,g:%20%7B%5Cmathcal%20X%7D%5Ctimes%20%7B%5Cmathcal%20Y%7D%5Cto%20%7B%5Cmathbb%20R%7D_%7B%5Cgeq%200%7D"> be two non-negative functions. For <img src="https://latex.codecogs.com/png.latex?%5Cnu%20%5Cgeq%200">, consider the problem <span id="eq-neyman"><img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign*%7D%0A&amp;%5Cmin_%7B%7B%5Cmathcal%20C%7D:%7B%5Cmathcal%20X%7D%5Cto%202%5E%7B%7B%5Cmathcal%20Y%7D%7D%7D%20%5Cint_%7B%7B%5Cmathcal%20X%7D%5Ctimes%20%7B%5Cmathcal%20Y%7D%7D%5Cmathbb%7B1%7D%5C%7By%20%5Cin%20%7B%5Cmathcal%20C%7D(x)%5C%7D%20g(x,y)d%5Cmu(x,y)%20%5C%5C%0A&amp;%5C,%20%5Ctext%7Bs.t.%7D%20%20%5Cint_%7B%7B%5Cmathcal%20X%7D%5Ctimes%20%7B%5Cmathcal%20Y%7D%7D%5Cmathbb%7B1%7D%5C%7By%5Cin%7B%5Cmathcal%20C%7D(x)%5C%7D%20f(x,y)d%5Cmu(x,y)%5Cgeq%20%5Cnu.%0A%5Cend%7Balign*%7D%0A%5Ctag%7B6%7D"></span></p>
<p>If there exists <img src="https://latex.codecogs.com/png.latex?t_%5Cnu"> such that <span id="eq-neyman_condition"><img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Bequation%7D%0A%20%20%20%20%5Cint_%7B%7B%5Cmathcal%20X%7D%5Ctimes%20%7B%5Cmathcal%20Y%7D%7D%20%5Cmathbb%7B1%7D%5C%7Bf(x,y)%20%5Cgeq%20t_%5Cnu%20%5Ccdot%20g(x,y)%5C%7D%20f(x,y)%20d%5Cmu(x,y)%20=%20%5Cnu,%0A%5Cend%7Bequation%7D%0A%5Ctag%7B7%7D"></span> then <span id="eq-neyman_solution"><img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign%7D%0A%20%20%20%20%7B%5Cmathcal%20C%7D%5E%7B*%7D_%7B%5Cnu%7D(x)%20=%20%5C%7By%20%5Cin%20%7B%5Cmathcal%20Y%7D:%20f(x,y)%20%5Cgeq%20t_%5Cnu%20%5Ccdot%20g(x,y)%20%5C%7D%0A%5Cend%7Balign%7D%0A%5Ctag%7B8%7D"></span></p>
<p>is the optimal solution to (6). Moreover, any other minimizer <img src="https://latex.codecogs.com/png.latex?%7B%5Cmathcal%20C%7D"> of (6) is equal to <img src="https://latex.codecogs.com/png.latex?%7B%5Cmathcal%20C%7D_%7B%5Cnu%7D%5E*">, <img src="https://latex.codecogs.com/png.latex?%5Cmu_f"> and <img src="https://latex.codecogs.com/png.latex?%5Cmu_g">-almost everywhere, i.e., for <img src="https://latex.codecogs.com/png.latex?h%5Cin%20%5C%7Bf,g%5C%7D">, <img src="https://latex.codecogs.com/png.latex?%5Cmu_h%5Cbig(%20%5C%7B%20(x,y)%20:%20y%5Cin%20%7B%5Cmathcal%20C%7D%5E*_%5Cnu(x)%20%5C%7D%5CDelta%20%5C%7B%20(x,y)%20:%20y%5Cin%20%7B%5Cmathcal%20C%7D(x)%20%5C%7D%5Cbig)=0"> where <img src="https://latex.codecogs.com/png.latex?%5CDelta"> denotes the symmetric distance between the sets and <img src="https://latex.codecogs.com/png.latex?%5Cmu_h"> is defined as <img src="https://latex.codecogs.com/png.latex?%5Cmu_h(A)%20=%20%5Cint_A%20h%20d%5Cmu">.</p>
</div>
<div class="proof-container">
<div class="proof-header" onclick="toggleProof('marginal-coverage')">
<p><span id="proof-arrow-marginal-coverage" class="proof-arrow">▶</span> <span class="proof-title">Proof</span></p>
</div>
<div id="proof-content-marginal-coverage" class="proof-content">
<p>We will show that <img src="https://latex.codecogs.com/png.latex?%7B%5Cmathcal%20C%7D%5E*(x)%20=%20%5C%7By%20:f(x,y)%20%5Cgeq%20t_%5Cnu%20g(x,y)%20%5C%7D"> is the optimal solution to (6). We first demonstrate that it is an optimal solution and then that it is unique.</p>
<p><em>Optimality</em>. By definition of <img src="https://latex.codecogs.com/png.latex?t_%5Cnu">, we have <span id="eq-np_equality"><img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Bequation%7D%0A%20%20%20%20%5Cint_%7B%7B%5Cmathcal%20X%7D%5Ctimes%20%7B%5Cmathcal%20Y%7D%7D%20%5Cmathbb%7B1%7D%5C%7B%20y%20%5Cin%20%7B%5Cmathcal%20C%7D%5E*(x)%5C%7D%20f(x,y)%20d%5Cmu(x,y)%20=%20%5Cnu,%0A%5Cend%7Bequation%7D%0A%5Ctag%7B9%7D"></span> which is trivially greater than or equal to $`, so <img src="https://latex.codecogs.com/png.latex?%7B%5Cmathcal%20C%7D%5E*(x)"> is indeed a feasible solution. To show that <img src="https://latex.codecogs.com/png.latex?%7B%5Cmathcal%20C%7D%5E*(x)"> is optimal, we must argue that it achieves a smaller objective value than any other feasible solution. Let <img src="https://latex.codecogs.com/png.latex?%7B%5Cmathcal%20C%7D:%20%7B%5Cmathcal%20X%7D%5Cto%202%5E%7B%5Cmathcal%20Y%7D"> be any other set-generating procedure that satisfies the constraint in (6). We want to show that <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Bequation*%7D%0A%20%20%20%20%5Cint_%7B%7B%5Cmathcal%20X%7D%5Ctimes%20%7B%5Cmathcal%20Y%7D%7D%20%5Cmathbb%7B1%7D%5C%7B%20y%20%5Cin%20%7B%5Cmathcal%20C%7D%5E*(x)%5C%7D%20g(x,y)%20d%5Cmu(x,y)%20%5Cleq%20%20%5Cint_%7B%7B%5Cmathcal%20X%7D%5Ctimes%20%7B%5Cmathcal%20Y%7D%7D%20%5Cmathbb%7B1%7D%5C%7B%20y%20%5Cin%20%7B%5Cmathcal%20C%7D(x)%5C%7D%20g(x,y)%20d%5Cmu(x,y)%5C,.%0A%5Cend%7Bequation*%7D%0A"> We prove this by showing their difference is negative: <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign*%7D%0A%20%20%20%20%20&amp;%5Cint_%7B%7B%5Cmathcal%20X%7D%5Ctimes%20%7B%5Cmathcal%20Y%7D%7D%20%5Cmathbb%7B1%7D%5C%7B%20y%20%5Cin%20%7B%5Cmathcal%20C%7D%5E*(x)%5C%7D%20g(x,y)%20d%5Cmu(x,y)%20-%20%20%5Cint_%7B%7B%5Cmathcal%20X%7D%5Ctimes%20%7B%5Cmathcal%20Y%7D%7D%20%5Cmathbb%7B1%7D%5C%7B%20y%20%5Cin%20%7B%5Cmathcal%20C%7D(x)%5C%7D%20g(x,y)%20d%5Cmu(x,y)%20%5C%5C%0A%20%20%20%20%20&amp;=%20%5Cint_%7B%7B%5Cmathcal%20X%7D%5Ctimes%20%7B%5Cmathcal%20Y%7D%7D%20%5CBig(%5Cmathbb%7B1%7D%5C%7B%20y%20%5Cin%20%7B%5Cmathcal%20C%7D%5E*(x)%20%5Cbackslash%20%7B%5Cmathcal%20C%7D(x)%5C%7D%20-%20%20%5Cmathbb%7B1%7D%5C%7B%20y%20%5Cin%20%7B%5Cmathcal%20C%7D(x)%5Cbackslash%20%7B%5Cmathcal%20C%7D%5E*(x)%5C%7D%5CBig)%20g(x,y)%20d%5Cmu(x,y)%20%5C%5C%0A%20%20%20%20%20&amp;%20%5Cleq%20%20%5Cfrac%7B1%7D%7Bt_%5Cnu%7D%5Cint_%7B%7B%5Cmathcal%20X%7D%5Ctimes%20%7B%5Cmathcal%20Y%7D%7D%20%5CBig(%5Cmathbb%7B1%7D%5C%7B%20y%20%5Cin%20%7B%5Cmathcal%20C%7D%5E*(x)%20%5Cbackslash%20%7B%5Cmathcal%20C%7D(x)%5C%7D%20-%20%5Cmathbb%7B1%7D%5C%7B%20y%20%5Cin%20%7B%5Cmathcal%20C%7D(x)%5Cbackslash%20%7B%5Cmathcal%20C%7D%5E*(x)%5C%7D%20%5CBig)%20f(x,y)%20d%5Cmu(x,y)%20%5C%5C%0A%20%20%20%20%20&amp;=%20%5Cfrac%7B1%7D%7Bt_%5Cnu%7D%20%5Cint_%7B%7B%5Cmathcal%20X%7D%5Ctimes%20%7B%5Cmathcal%20Y%7D%7D%20%5CBig(%20%5Cmathbb%7B1%7D%5C%7B%20y%20%5Cin%20%7B%5Cmathcal%20C%7D%5E*(x)%20%5C%7D%20%20-%20%20%5Cmathbb%7B1%7D%5C%7B%20y%20%5Cin%20%7B%5Cmathcal%20C%7D(x)%5C%7D%5CBig)%20f(x,y)%20d%5Cmu(x,y)%20%20%5C%5C%0A%20%20%20%20%20&amp;%20%5Cleq%20%5Cfrac%7B1%7D%7Bt_%5Cnu%7D%20%5Cleft(%20%20%5Cnu%20-%20%5Cnu%20%5Cright)%20%5Cleq%200%5C,.%0A%5Cend%7Balign*%7D%0A"> The first inequality follows from <img src="https://latex.codecogs.com/png.latex?y%20%5Cin%20%7B%5Cmathcal%20C%7D%5E*(x)%5CLongleftrightarrow%20g(x,y)"> <img src="https://latex.codecogs.com/png.latex?%5Cleq%20t_%5Cnu%5E%7B-1%7Df(x,y)">. The second inequality comes from applying the equality stated in (9) to the first integral and then using the definition of <img src="https://latex.codecogs.com/png.latex?%7B%5Cmathcal%20C%7D"> as satisfying the constraint of (6) to lower bound the second integral.</p>
<p><em>Uniqueness</em>. Let <img src="https://latex.codecogs.com/png.latex?%7B%5Cmathcal%20C%7D:%20%7B%5Cmathcal%20X%7D%5Cto%202%5E%7B%7B%5Cmathcal%20Y%7D%7D"> be another optimal set-generating procedure, so it achieves the same objective value as <img src="https://latex.codecogs.com/png.latex?%7B%5Cmathcal%20C%7D%5E*">, <span id="eq-aux_uniq1"><img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Bequation%7D%0A%20%20%20%20%5Cint_%7B%7B%5Cmathcal%20X%7D%5Ctimes%20%7B%5Cmathcal%20Y%7D%7D%20%5C!%5C!%5C!%5C!%20%5Cmathbb%7B1%7D%5C%7B%20y%20%5Cin%20%7B%5Cmathcal%20C%7D(x)%5C%7D%20g(x,y)%20d%5Cmu(x,y)%20=%20%5C!%20%5Cint_%7B%7B%5Cmathcal%20X%7D%5Ctimes%20%7B%5Cmathcal%20Y%7D%7D%20%5C!%5C!%5C!%5C!%5Cmathbb%7B1%7D%5C%7B%20y%20%5Cin%20%7B%5Cmathcal%20C%7D%5E*(x)%5C%7D%20g(x,y)%20d%5Cmu(x,y)%5C,,%0A%5Cend%7Bequation%7D%0A%5Ctag%7B10%7D"></span> and it is a feasible solution, <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Bequation*%7D%0A%20%20%20%20%20%5Cint_%7B%7B%5Cmathcal%20X%7D%5Ctimes%20%7B%5Cmathcal%20Y%7D%7D%20%5Cmathbb%7B1%7D%5C%7B%20y%20%5Cin%20%7B%5Cmathcal%20C%7D(x)%5C%7D%20f(x,y)%20d%5Cmu(x,y)%20%5Cgeq%20%5Cnu%5C,.%0A%5Cend%7Bequation*%7D%0A"> Let us first note the following non-negativity relationship, for all <img src="https://latex.codecogs.com/png.latex?(x,y)%20%5Cin%20%7B%5Cmathcal%20X%7D%5Ctimes%20%7B%5Cmathcal%20Y%7D">: <span id="eq-aux_uniq2"><img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Bequation%7D%5Clabel%7Beq:aux_uniq2%7D%0A%20%20%20%20%5Cleft(%20%5Cmathbb%7B1%7D%20%5C%7B%20y%20%5Cin%20%7B%5Cmathcal%20C%7D%5E*(x)%5C%7D%20-%20%5Cmathbb%7B1%7D%5C%7B%20y%20%5Cin%20%7B%5Cmathcal%20C%7D(x)%5C%7D%20%5Cright)%5Cleft(%20%20f(x,y)%20-%20t_%5Cnu%20g(x,y)%20%5Cright)%20%5Cgeq%200,%20%5C,.%0A%5Cend%7Bequation%7D%0A%5Ctag%7B11%7D"></span> Integrating (11) over <img src="https://latex.codecogs.com/png.latex?%7B%5Cmathcal%20X%7D%5Ctimes%20%7B%5Cmathcal%20Y%7D">, then applying (10), we get <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Bequation*%7D%0A%20%20%20%20%20%20%20%5Cint_%7B%7B%5Cmathcal%20X%7D%5Ctimes%20%7B%5Cmathcal%20Y%7D%7D%20%5Cmathbb%7B1%7D%5C%7B%20y%20%5Cin%20%7B%5Cmathcal%20C%7D%5E*(x)%5C%7D%20f(x,y)%20d%5Cmu(x,y)%20-%20%20%5Cint_%7B%7B%5Cmathcal%20X%7D%5Ctimes%20%7B%5Cmathcal%20Y%7D%7D%20%5Cmathbb%7B1%7D%5C%7B%20y%20%5Cin%20%7B%5Cmathcal%20C%7D(x)%5C%7D%20f(x,y)%20d%5Cmu(x,y)%5Cgeq%200%5C,.%0A%5Cend%7Bequation*%7D%0A"></p>
<p>Combining this with the definition of <img src="https://latex.codecogs.com/png.latex?%7B%5Cmathcal%20C%7D%5E*"> and the feasibility of <img src="https://latex.codecogs.com/png.latex?%7B%5Cmathcal%20C%7D">, we must have $_{} { y (x)} f(x,y) d(x,y) = `. Thus, (11) integrates to zero. Since we also know that (11) is nonnegative, it must be true that, <img src="https://latex.codecogs.com/png.latex?%5Cmu">-almost everywhere, <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Bequation*%7D%0A%20%20%20%20%5Cleft(%20%5Cmathbb%7B1%7D%5C%7B%20y%20%5Cin%20%7B%5Cmathcal%20C%7D%5E*(x)%5C%7D%20-%20%5Cmathbb%7B1%7D%5C%7B%20y%20%5Cin%20%7B%5Cmathcal%20C%7D(x)%5C%7D%20%20%20%20%5Cright)%5Cleft(%20%20f(x,y)%20-%20t_%5Cnu%20g(x,y)%20%5Cright)%20=%200.%0A%5Cend%7Bequation*%7D%0A"> For <img src="https://latex.codecogs.com/png.latex?(x,y)%20%5Cin%20%7B%5Cmathcal%20X%7D%5Ctimes%20%7B%5Cmathcal%20Y%7D"> such that <img src="https://latex.codecogs.com/png.latex?f(x,y)%20%5Cneq%20t_%5Cnu%20g(x,y)">, then <img src="https://latex.codecogs.com/png.latex?%5Cmathbb%7B1%7D%5C%7B%20y%20%5Cin%20%7B%5Cmathcal%20C%7D%5E*(x)%5C%7D=%20%5Cmathbb%7B1%7D%5C%7B%20y%20%5Cin%20%7B%5Cmathcal%20C%7D(x)%5C%7D">, and in turn it implies, using the definition of <img src="https://latex.codecogs.com/png.latex?%7B%5Cmathcal%20C%7D%5E*(x)%20=%20%5C%7By%20:f(x,y)%20%5Cgeq%20t_%5Cnu%20g(x,y)%20%5C%7D">, that <img src="https://latex.codecogs.com/png.latex?%5Cmu">-almost everywhere, <img src="https://latex.codecogs.com/png.latex?%7B%5Cmathcal%20C%7D(x)%20%5Csubseteq%20%7B%5Cmathcal%20C%7D%5E*(x)"> and <img src="https://latex.codecogs.com/png.latex?%7B%5Cmathcal%20C%7D%5E*(x)%20%5Csubseteq%20%7B%5Cmathcal%20C%7D(x)%20%5Ccup%20%5C%7B%20y%20:%20f(x,y)%20=%20t_%5Cnu%20g(x,y)%5C%7D">. It remains to show that the sets are equal almost everywhere by showing that the set <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign*%7D%0A%20%20%20%20D%20&amp;:=%20%5Cbig%5C%7B%20(x,y)%20:%20y%20%5Cnotin%20%7B%5Cmathcal%20C%7D(x)%20%5Ctext%7B%20and%20%7D%20%20y%20%5Cin%20%7B%5Cmathcal%20C%7D%5E*(x)%20%5Cbig%5C%7D%20%5C%5C%0A%20%20%20%20%20%20%20&amp;=%20%5Cbig%5C%7B%20(x,y)%20:%20y%20%5Cnotin%20%7B%5Cmathcal%20C%7D(x)%20%5Ctext%7B%20and%20%7D%20f(x,y)%20=%20t_%5Cnu%20g(x,y)%5Cbig%5C%7D%0A%20%20%20%20%5Cend%7Balign*%7D%0A"> is of measure <img src="https://latex.codecogs.com/png.latex?0"> under <img src="https://latex.codecogs.com/png.latex?%5Cmu_f">. By definition of <img src="https://latex.codecogs.com/png.latex?%7B%5Cmathcal%20C%7D%5E*">, <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign*%7D%0A%20%20%20%20%5Cnu%20&amp;=%20%20%5Cint_%7B%7B%5Cmathcal%20X%7D%5Ctimes%20%7B%5Cmathcal%20Y%7D%7D%20%5Cmathbb%7B1%7D%5C%7B%20y%20%5Cin%20%7B%5Cmathcal%20C%7D%5E*(x)%5C%7D%20f(x,y)%20d%5Cmu(x,y)%20%5C%5C%0A%20%20%20%20&amp;=%20%20%5Cint_%7B%7B%5Cmathcal%20X%7D%5Ctimes%20%7B%5Cmathcal%20Y%7D%7D%20%5Cmathbb%7B1%7D%5C%7B%20y%20%5Cin%20%7B%5Cmathcal%20C%7D(x)%5C%7D%20f(x,y)%20d%5Cmu(x,y)%20+%20%20%5Cint_%7B%7B%5Cmathcal%20X%7D%5Ctimes%20%7B%5Cmathcal%20Y%7D%7D%20%5Cmathbb%7B1%7D%5C%7B%20(x,y)%20%5Cin%20D%5C%7D%20f(x,y)%20d%5Cmu(x,y)%20%5C%5C%0A%20%20%20%20&amp;=%20%5Cnu%20+%20%5Cint_%7BD%7D%20f%20d%5Cmu%20%5C,.%0A%5Cend%7Balign*%7D%0A"> Thus, we must have <img src="https://latex.codecogs.com/png.latex?%5Cmu_f(D)%20=%200">. Since <img src="https://latex.codecogs.com/png.latex?t_%5Cnu%20g=f"> on <img src="https://latex.codecogs.com/png.latex?D">, we also get that <img src="https://latex.codecogs.com/png.latex?%5Cmu_g(D)%20=0">.</p>
</div>
</div>


<!-- -->

</section>
</section>
</section>

<div id="quarto-appendix" class="default"><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><pre class="sourceCode code-with-copy quarto-appendix-bibtex"><code class="sourceCode bibtex">@online{ding2025,
  author = {Ding, Tiffany and Fermanian, Jean-Baptiste and Salmon,
    Joseph},
  title = {Optimal Prediction Sets for Plant Identification: An
    Interactive Guide},
  date = {2025-10-20},
  url = {https://josephsalmon.eu/blog/long-tail/},
  langid = {en}
}
</code></pre></div></section></div> ]]></description>
  <category>Conformal prediction</category>
  <category>classification</category>
  <category>machine learning</category>
  <category>Pl@ntNet</category>
  <guid>https://josephsalmon.eu/blog/long-tail/</guid>
  <pubDate>Sun, 19 Oct 2025 22:00:00 GMT</pubDate>
  <media:content url="https://josephsalmon.eu/talks/posts/2026-01-29-slides_citizen_sciences/images/set_prediction.png" medium="image" type="image/png" height="129" width="144"/>
</item>
<item>
  <title>Gaussian elimination in a glimpse</title>
  <dc:creator>Joseph Salmon</dc:creator>
  <link>https://josephsalmon.eu/blog/gaussian_elimination/</link>
  <description><![CDATA[ 
<div class="no-row-height column-margin column-container">
  <div class="">
    <img src="https://josephsalmon.eu/blog/gaussian_elimination/gaussian_elimination.gif" style="width:100%">
  </div>
</div>





<section id="gaussian-elimination" class="level1">
<h1>Gaussian elimination</h1>
<p>Here is a simple visualisation of the Gaussian elimination steps: <img src="https://josephsalmon.eu/blog/gaussian_elimination/gauss_pivot.gif" title="Evolution of a random square matrix along the steps of a Gaussian elimination" style="width:100%"></p>
<p>and a more complete one: <img src="https://josephsalmon.eu/blog/gaussian_elimination/gauss_pivot_4figs.gif" title="Evolution of a random square matrix along the steps of a Gaussian elimination: on the top left you have the transvection matrix used at each step, on the top right the original matrix, on the bottom left the matrix display the approximation of the inverse matrix, on the bottom right the remaining extra-diagonal terms of the matrix that need to be canceled to find the inverse." style="width:100%"></p>
<p>For more details, the Python source code is available here: <a href="https://github.com/josephsalmon/Tweets/tree/master/Pivot_Gauss_video" target="_blank">https://github.com/josephsalmon/Tweets/tree/master/Pivot_Gauss_video</a></p>


<!-- -->

</section>

<div id="quarto-appendix" class="default"><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><pre class="sourceCode code-with-copy quarto-appendix-bibtex"><code class="sourceCode bibtex">@online{salmon2025,
  author = {Salmon, Joseph},
  title = {Gaussian Elimination in a Glimpse},
  date = {2025-09-09},
  url = {https://josephsalmon.eu/blog/gaussian_elimination/},
  langid = {en}
}
</code></pre></div></section></div> ]]></description>
  <category>linear algebra</category>
  <category>math visualization</category>
  <guid>https://josephsalmon.eu/blog/gaussian_elimination/</guid>
  <pubDate>Mon, 08 Sep 2025 22:00:00 GMT</pubDate>
  <media:content url="https://josephsalmon.eu/blog/gaussian_elimination/gaussian_elimination.gif" medium="image" type="image/gif"/>
</item>
<item>
  <title>Isotonic regression</title>
  <dc:creator>Joseph Salmon</dc:creator>
  <link>https://josephsalmon.eu/blog/isotonic/</link>
  <description><![CDATA[ 
<div class="no-row-height column-margin column-container">
  <div class="">
    <img src="https://josephsalmon.eu/blog/isotonic/isotonic.png" style="width:100%">
  </div>
</div>





<div class="hidden">
{{
<p>% thin space, limits underneath in displays % thin space, limits underneath in displays }}</p>
</div>
<p><strong><u>Note</u></strong>: This blog is mainly inspired by the post by <span class="citation" data-cites="Pedregosa13">Pedregosa (2013)</span> on Isotonic regression, a version of the PAVA algorithm provided by <span class="citation" data-cites="Best_Chakravarti90">Best and Chakravarti (1990)</span>.</p>
<section id="introduction-formulation" class="level1">
<h1>Introduction &amp; formulation</h1>
<p>Isotonic regression is a technique used to fit a non-decreasing function to a set of data points. We can think of isotonic regression as a generalization of linear regression where the function is constrained to be non-decreasing.</p>
<p>More formally suppose that one collects <img src="https://latex.codecogs.com/png.latex?n"> sample points <img src="https://latex.codecogs.com/png.latex?y_1,%5Cdots,%20y_n"> and has weights <img src="https://latex.codecogs.com/png.latex?w_1,%20%5Cdots,%20w_n"> associated with each data point.</p>
<p><strong><u>Note</u></strong>: when no a priori weights are given, we can set <img src="https://latex.codecogs.com/png.latex?w_i%20=%201"> for all <img src="https://latex.codecogs.com/png.latex?i%20%5Cin%20%5Cllbracket%201,%20n%20%5Crrbracket">.</p>
<p>Then, the isotonic regression problem can be formulated as follows: <span id="eq-isotonic"><img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign%7D%0A%5Cmin_%7Bx%20%5Cin%20%5Cmathbb%7BR%7D%5En%7D%0A%5Cfrac%7B1%7D%7B2%7D%0A&amp;%20%5Csum_%7Bi=1%7D%5E%7Bn%7D%20w_i%20(x_i%20-%20y_i)%5E2%20%5C%5C%0A%5Ctext%7Bs.t.%7D%20&amp;%20%5Cquad%20x_1%20%5Cleq%20x_2%20%5Cleq%20%5Cldots%20%5Cleq%20x_n%20%5Cnonumber%0A%5Cend%7Balign%7D%0A%5Ctag%7B1%7D"></span></p>
<section id="visualization" class="level2">
<h2 class="anchored" data-anchor-id="visualization">Visualization</h2>
<p>Below you’ll find a visualization, on a synthetic dataset, of the most common algorithm, the Pools Adjacent Violators Algorithm (PAVA) to solve isotonic regression algorithm. The top plot shows the evolution of the PAVA algorithm, while the bottom plot shows the primal and dual objectives until convergence. Note that the essence of the algorithm is simple: it Pools Adjacent Violators, <em>i.e.,</em> it replaces adjacent points that are not in increasing order by averaging.</p>
<div id="c8d5fd76" class="cell" data-execution_count="2">
<div class="cell-output cell-output-display">
<div>                            <div id="6c24e920-8816-47c4-913f-411654d8f980" class="plotly-graph-div" style="height:600px; width:100%;"></div>            <script type="text/javascript">                require(["plotly"], function(Plotly) {                    window.PLOTLYENV=window.PLOTLYENV || {};                                    if (document.getElementById("6c24e920-8816-47c4-913f-411654d8f980")) {                    Plotly.newPlot(                        "6c24e920-8816-47c4-913f-411654d8f980",                        [{"legendgroup":"1","marker":{"color":"black","opacity":1,"size":10},"mode":"markers","name":"Raw data","showlegend":true,"x":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24],"y":[-3.0,35.657359027997266,79.93061443340548,114.31471805599453,33.471895621705016,53.587973461402754,129.29550745276566,147.9720770839918,83.86122886681098,96.12925464970229,155.89476363991855,116.24533248940001,105.24746787307683,163.9528664807629,110.4025100551105,128.62943611198907,155.6606672028108,148.51858789480823,105.221948958322,101.78661367769953,188.22612188617114,179.5521226679158,189.7747107964575,161.9026915173973,191.94379124341003],"type":"scatter","xaxis":"x","yaxis":"y"},{"legendgroup":"1","marker":{"color":"red"},"mode":"lines+markers","name":"PAVA iterations","showlegend":true,"x":[0],"y":[-3.0],"type":"scatter","xaxis":"x","yaxis":"y"},{"legendgroup":"2","marker":{"color":"green"},"mode":"lines+markers","name":"Duals","showlegend":true,"x":[0],"y":[0],"type":"scatter","xaxis":"x2","yaxis":"y2"},{"legendgroup":"2","marker":{"color":"blue"},"mode":"lines+markers","name":"Primals","showlegend":true,"x":[0],"y":[19218.89901471994],"type":"scatter","xaxis":"x2","yaxis":"y2"}],                        {"template":{"data":{"barpolar":[{"marker":{"line":{"color":"white","width":0.5},"pattern":{"fillmode":"overlay","size":10,"solidity":0.2}},"type":"barpolar"}],"bar":[{"error_x":{"color":"rgb(36,36,36)"},"error_y":{"color":"rgb(36,36,36)"},"marker":{"line":{"color":"white","width":0.5},"pattern":{"fillmode":"overlay","size":10,"solidity":0.2}},"type":"bar"}],"carpet":[{"aaxis":{"endlinecolor":"rgb(36,36,36)","gridcolor":"white","linecolor":"white","minorgridcolor":"white","startlinecolor":"rgb(36,36,36)"},"baxis":{"endlinecolor":"rgb(36,36,36)","gridcolor":"white","linecolor":"white","minorgridcolor":"white","startlinecolor":"rgb(36,36,36)"},"type":"carpet"}],"choropleth":[{"colorbar":{"outlinewidth":1,"tickcolor":"rgb(36,36,36)","ticks":"outside"},"type":"choropleth"}],"contourcarpet":[{"colorbar":{"outlinewidth":1,"tickcolor":"rgb(36,36,36)","ticks":"outside"},"type":"contourcarpet"}],"contour":[{"colorbar":{"outlinewidth":1,"tickcolor":"rgb(36,36,36)","ticks":"outside"},"colorscale":[[0.0,"#440154"],[0.1111111111111111,"#482878"],[0.2222222222222222,"#3e4989"],[0.3333333333333333,"#31688e"],[0.4444444444444444,"#26828e"],[0.5555555555555556,"#1f9e89"],[0.6666666666666666,"#35b779"],[0.7777777777777778,"#6ece58"],[0.8888888888888888,"#b5de2b"],[1.0,"#fde725"]],"type":"contour"}],"heatmapgl":[{"colorbar":{"outlinewidth":1,"tickcolor":"rgb(36,36,36)","ticks":"outside"},"colorscale":[[0.0,"#440154"],[0.1111111111111111,"#482878"],[0.2222222222222222,"#3e4989"],[0.3333333333333333,"#31688e"],[0.4444444444444444,"#26828e"],[0.5555555555555556,"#1f9e89"],[0.6666666666666666,"#35b779"],[0.7777777777777778,"#6ece58"],[0.8888888888888888,"#b5de2b"],[1.0,"#fde725"]],"type":"heatmapgl"}],"heatmap":[{"colorbar":{"outlinewidth":1,"tickcolor":"rgb(36,36,36)","ticks":"outside"},"colorscale":[[0.0,"#440154"],[0.1111111111111111,"#482878"],[0.2222222222222222,"#3e4989"],[0.3333333333333333,"#31688e"],[0.4444444444444444,"#26828e"],[0.5555555555555556,"#1f9e89"],[0.6666666666666666,"#35b779"],[0.7777777777777778,"#6ece58"],[0.8888888888888888,"#b5de2b"],[1.0,"#fde725"]],"type":"heatmap"}],"histogram2dcontour":[{"colorbar":{"outlinewidth":1,"tickcolor":"rgb(36,36,36)","ticks":"outside"},"colorscale":[[0.0,"#440154"],[0.1111111111111111,"#482878"],[0.2222222222222222,"#3e4989"],[0.3333333333333333,"#31688e"],[0.4444444444444444,"#26828e"],[0.5555555555555556,"#1f9e89"],[0.6666666666666666,"#35b779"],[0.7777777777777778,"#6ece58"],[0.8888888888888888,"#b5de2b"],[1.0,"#fde725"]],"type":"histogram2dcontour"}],"histogram2d":[{"colorbar":{"outlinewidth":1,"tickcolor":"rgb(36,36,36)","ticks":"outside"},"colorscale":[[0.0,"#440154"],[0.1111111111111111,"#482878"],[0.2222222222222222,"#3e4989"],[0.3333333333333333,"#31688e"],[0.4444444444444444,"#26828e"],[0.5555555555555556,"#1f9e89"],[0.6666666666666666,"#35b779"],[0.7777777777777778,"#6ece58"],[0.8888888888888888,"#b5de2b"],[1.0,"#fde725"]],"type":"histogram2d"}],"histogram":[{"marker":{"line":{"color":"white","width":0.6}},"type":"histogram"}],"mesh3d":[{"colorbar":{"outlinewidth":1,"tickcolor":"rgb(36,36,36)","ticks":"outside"},"type":"mesh3d"}],"parcoords":[{"line":{"colorbar":{"outlinewidth":1,"tickcolor":"rgb(36,36,36)","ticks":"outside"}},"type":"parcoords"}],"pie":[{"automargin":true,"type":"pie"}],"scatter3d":[{"line":{"colorbar":{"outlinewidth":1,"tickcolor":"rgb(36,36,36)","ticks":"outside"}},"marker":{"colorbar":{"outlinewidth":1,"tickcolor":"rgb(36,36,36)","ticks":"outside"}},"type":"scatter3d"}],"scattercarpet":[{"marker":{"colorbar":{"outlinewidth":1,"tickcolor":"rgb(36,36,36)","ticks":"outside"}},"type":"scattercarpet"}],"scattergeo":[{"marker":{"colorbar":{"outlinewidth":1,"tickcolor":"rgb(36,36,36)","ticks":"outside"}},"type":"scattergeo"}],"scattergl":[{"marker":{"colorbar":{"outlinewidth":1,"tickcolor":"rgb(36,36,36)","ticks":"outside"}},"type":"scattergl"}],"scattermapbox":[{"marker":{"colorbar":{"outlinewidth":1,"tickcolor":"rgb(36,36,36)","ticks":"outside"}},"type":"scattermapbox"}],"scatterpolargl":[{"marker":{"colorbar":{"outlinewidth":1,"tickcolor":"rgb(36,36,36)","ticks":"outside"}},"type":"scatterpolargl"}],"scatterpolar":[{"marker":{"colorbar":{"outlinewidth":1,"tickcolor":"rgb(36,36,36)","ticks":"outside"}},"type":"scatterpolar"}],"scatter":[{"fillpattern":{"fillmode":"overlay","size":10,"solidity":0.2},"type":"scatter"}],"scatterternary":[{"marker":{"colorbar":{"outlinewidth":1,"tickcolor":"rgb(36,36,36)","ticks":"outside"}},"type":"scatterternary"}],"surface":[{"colorbar":{"outlinewidth":1,"tickcolor":"rgb(36,36,36)","ticks":"outside"},"colorscale":[[0.0,"#440154"],[0.1111111111111111,"#482878"],[0.2222222222222222,"#3e4989"],[0.3333333333333333,"#31688e"],[0.4444444444444444,"#26828e"],[0.5555555555555556,"#1f9e89"],[0.6666666666666666,"#35b779"],[0.7777777777777778,"#6ece58"],[0.8888888888888888,"#b5de2b"],[1.0,"#fde725"]],"type":"surface"}],"table":[{"cells":{"fill":{"color":"rgb(237,237,237)"},"line":{"color":"white"}},"header":{"fill":{"color":"rgb(217,217,217)"},"line":{"color":"white"}},"type":"table"}]},"layout":{"annotationdefaults":{"arrowhead":0,"arrowwidth":1},"autotypenumbers":"strict","coloraxis":{"colorbar":{"outlinewidth":1,"tickcolor":"rgb(36,36,36)","ticks":"outside"}},"colorscale":{"diverging":[[0.0,"rgb(103,0,31)"],[0.1,"rgb(178,24,43)"],[0.2,"rgb(214,96,77)"],[0.3,"rgb(244,165,130)"],[0.4,"rgb(253,219,199)"],[0.5,"rgb(247,247,247)"],[0.6,"rgb(209,229,240)"],[0.7,"rgb(146,197,222)"],[0.8,"rgb(67,147,195)"],[0.9,"rgb(33,102,172)"],[1.0,"rgb(5,48,97)"]],"sequential":[[0.0,"#440154"],[0.1111111111111111,"#482878"],[0.2222222222222222,"#3e4989"],[0.3333333333333333,"#31688e"],[0.4444444444444444,"#26828e"],[0.5555555555555556,"#1f9e89"],[0.6666666666666666,"#35b779"],[0.7777777777777778,"#6ece58"],[0.8888888888888888,"#b5de2b"],[1.0,"#fde725"]],"sequentialminus":[[0.0,"#440154"],[0.1111111111111111,"#482878"],[0.2222222222222222,"#3e4989"],[0.3333333333333333,"#31688e"],[0.4444444444444444,"#26828e"],[0.5555555555555556,"#1f9e89"],[0.6666666666666666,"#35b779"],[0.7777777777777778,"#6ece58"],[0.8888888888888888,"#b5de2b"],[1.0,"#fde725"]]},"colorway":["#1F77B4","#FF7F0E","#2CA02C","#D62728","#9467BD","#8C564B","#E377C2","#7F7F7F","#BCBD22","#17BECF"],"font":{"color":"rgb(36,36,36)"},"geo":{"bgcolor":"white","lakecolor":"white","landcolor":"white","showlakes":true,"showland":true,"subunitcolor":"white"},"hoverlabel":{"align":"left"},"hovermode":"closest","mapbox":{"style":"light"},"margin":{"b":0,"l":0,"r":0,"t":30},"paper_bgcolor":"white","plot_bgcolor":"white","polar":{"angularaxis":{"gridcolor":"rgb(232,232,232)","linecolor":"rgb(36,36,36)","showgrid":false,"showline":true,"ticks":"outside"},"bgcolor":"white","radialaxis":{"gridcolor":"rgb(232,232,232)","linecolor":"rgb(36,36,36)","showgrid":false,"showline":true,"ticks":"outside"}},"scene":{"xaxis":{"backgroundcolor":"white","gridcolor":"rgb(232,232,232)","gridwidth":2,"linecolor":"rgb(36,36,36)","showbackground":true,"showgrid":false,"showline":true,"ticks":"outside","zeroline":false,"zerolinecolor":"rgb(36,36,36)"},"yaxis":{"backgroundcolor":"white","gridcolor":"rgb(232,232,232)","gridwidth":2,"linecolor":"rgb(36,36,36)","showbackground":true,"showgrid":false,"showline":true,"ticks":"outside","zeroline":false,"zerolinecolor":"rgb(36,36,36)"},"zaxis":{"backgroundcolor":"white","gridcolor":"rgb(232,232,232)","gridwidth":2,"linecolor":"rgb(36,36,36)","showbackground":true,"showgrid":false,"showline":true,"ticks":"outside","zeroline":false,"zerolinecolor":"rgb(36,36,36)"}},"shapedefaults":{"fillcolor":"black","line":{"width":0},"opacity":0.3},"ternary":{"aaxis":{"gridcolor":"rgb(232,232,232)","linecolor":"rgb(36,36,36)","showgrid":false,"showline":true,"ticks":"outside"},"baxis":{"gridcolor":"rgb(232,232,232)","linecolor":"rgb(36,36,36)","showgrid":false,"showline":true,"ticks":"outside"},"bgcolor":"white","caxis":{"gridcolor":"rgb(232,232,232)","linecolor":"rgb(36,36,36)","showgrid":false,"showline":true,"ticks":"outside"}},"title":{"x":0.05},"xaxis":{"automargin":true,"gridcolor":"rgb(232,232,232)","linecolor":"rgb(36,36,36)","showgrid":false,"showline":true,"ticks":"outside","title":{"standoff":15},"zeroline":false,"zerolinecolor":"rgb(36,36,36)"},"yaxis":{"automargin":true,"gridcolor":"rgb(232,232,232)","linecolor":"rgb(36,36,36)","showgrid":false,"showline":true,"ticks":"outside","title":{"standoff":15},"zeroline":false,"zerolinecolor":"rgb(36,36,36)"}}},"xaxis":{"anchor":"y","domain":[0.0,1.0],"title":{"text":"X"},"range":[-0.5,25.5]},"yaxis":{"anchor":"x","domain":[0.625,1.0],"title":{"text":"Y"},"range":[0,250]},"xaxis2":{"anchor":"y2","domain":[0.0,1.0],"range":[0,25]},"yaxis2":{"anchor":"x2","domain":[0.0,0.375],"range":[0,25000]},"annotations":[{"font":{"size":16},"showarrow":false,"text":"PAVA output evolution","x":0.5,"xanchor":"center","xref":"paper","y":1.0,"yanchor":"bottom","yref":"paper"},{"font":{"size":16},"showarrow":false,"text":"Primal and dual objectives","x":0.5,"xanchor":"center","xref":"paper","y":0.375,"yanchor":"bottom","yref":"paper"}],"legend":{"tracegroupgap":180},"height":600,"sliders":[{"active":1,"currentvalue":{"prefix":"Iteration: #"},"steps":[{"args":[["0"],{"mode":"immediate","frame":{"duration":300,"redraw":true},"transition":{"duration":0}}],"label":"0","method":"animate"},{"args":[["1"],{"mode":"immediate","frame":{"duration":300,"redraw":true},"transition":{"duration":0}}],"label":"1","method":"animate"},{"args":[["2"],{"mode":"immediate","frame":{"duration":300,"redraw":true},"transition":{"duration":0}}],"label":"2","method":"animate"},{"args":[["3"],{"mode":"immediate","frame":{"duration":300,"redraw":true},"transition":{"duration":0}}],"label":"3","method":"animate"},{"args":[["4"],{"mode":"immediate","frame":{"duration":300,"redraw":true},"transition":{"duration":0}}],"label":"4","method":"animate"},{"args":[["5"],{"mode":"immediate","frame":{"duration":300,"redraw":true},"transition":{"duration":0}}],"label":"5","method":"animate"},{"args":[["6"],{"mode":"immediate","frame":{"duration":300,"redraw":true},"transition":{"duration":0}}],"label":"6","method":"animate"},{"args":[["7"],{"mode":"immediate","frame":{"duration":300,"redraw":true},"transition":{"duration":0}}],"label":"7","method":"animate"},{"args":[["8"],{"mode":"immediate","frame":{"duration":300,"redraw":true},"transition":{"duration":0}}],"label":"8","method":"animate"},{"args":[["9"],{"mode":"immediate","frame":{"duration":300,"redraw":true},"transition":{"duration":0}}],"label":"9","method":"animate"},{"args":[["10"],{"mode":"immediate","frame":{"duration":300,"redraw":true},"transition":{"duration":0}}],"label":"10","method":"animate"},{"args":[["11"],{"mode":"immediate","frame":{"duration":300,"redraw":true},"transition":{"duration":0}}],"label":"11","method":"animate"},{"args":[["12"],{"mode":"immediate","frame":{"duration":300,"redraw":true},"transition":{"duration":0}}],"label":"12","method":"animate"},{"args":[["13"],{"mode":"immediate","frame":{"duration":300,"redraw":true},"transition":{"duration":0}}],"label":"13","method":"animate"},{"args":[["14"],{"mode":"immediate","frame":{"duration":300,"redraw":true},"transition":{"duration":0}}],"label":"14","method":"animate"},{"args":[["15"],{"mode":"immediate","frame":{"duration":300,"redraw":true},"transition":{"duration":0}}],"label":"15","method":"animate"},{"args":[["16"],{"mode":"immediate","frame":{"duration":300,"redraw":true},"transition":{"duration":0}}],"label":"16","method":"animate"},{"args":[["17"],{"mode":"immediate","frame":{"duration":300,"redraw":true},"transition":{"duration":0}}],"label":"17","method":"animate"},{"args":[["18"],{"mode":"immediate","frame":{"duration":300,"redraw":true},"transition":{"duration":0}}],"label":"18","method":"animate"},{"args":[["19"],{"mode":"immediate","frame":{"duration":300,"redraw":true},"transition":{"duration":0}}],"label":"19","method":"animate"},{"args":[["20"],{"mode":"immediate","frame":{"duration":300,"redraw":true},"transition":{"duration":0}}],"label":"20","method":"animate"},{"args":[["21"],{"mode":"immediate","frame":{"duration":300,"redraw":true},"transition":{"duration":0}}],"label":"21","method":"animate"},{"args":[["22"],{"mode":"immediate","frame":{"duration":300,"redraw":true},"transition":{"duration":0}}],"label":"22","method":"animate"},{"args":[["23"],{"mode":"immediate","frame":{"duration":300,"redraw":true},"transition":{"duration":0}}],"label":"23","method":"animate"},{"args":[["24"],{"mode":"immediate","frame":{"duration":300,"redraw":true},"transition":{"duration":0}}],"label":"24","method":"animate"},{"args":[["25"],{"mode":"immediate","frame":{"duration":300,"redraw":true},"transition":{"duration":0}}],"label":"25","method":"animate"}]}],"updatemenus":[{"buttons":[{"args":[null,{"frame":{"duration":500,"redraw":false},"fromcurrent":true,"transition":{"duration":50,"easing":"linear"}}],"label":"Play","method":"animate"},{"args":[[null],{"frame":{"duration":0,"redraw":false},"mode":"immediate","transition":{"duration":0}}],"label":"Pause","method":"animate"}],"direction":"left","pad":{"b":20,"r":5,"t":5},"showactive":false,"type":"buttons","x":0.5,"xanchor":"center","y":-0.28,"yanchor":"top"}]},                        {"responsive": true}                    ).then(function(){
                            Plotly.addFrames('6c24e920-8816-47c4-913f-411654d8f980', [{"data":[{"legendgroup":"1","marker":{"color":"black","opacity":1},"mode":"markers","showlegend":true,"x":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24],"y":[-3.0,35.657359027997266,79.93061443340548,114.31471805599453,33.471895621705016,53.587973461402754,129.29550745276566,147.9720770839918,83.86122886681098,96.12925464970229,155.89476363991855,116.24533248940001,105.24746787307683,163.9528664807629,110.4025100551105,128.62943611198907,155.6606672028108,148.51858789480823,105.221948958322,101.78661367769953,188.22612188617114,179.5521226679158,189.7747107964575,161.9026915173973,191.94379124341003],"type":"scatter"},{"legendgroup":"1","marker":{"color":"red"},"mode":"lines+markers","showlegend":true,"x":[0],"y":[-3.0],"type":"scatter"},{"legendgroup":"2","marker":{"color":"green"},"mode":"lines+markers","showlegend":true,"x":[0],"y":[0.0],"type":"scatter"},{"legendgroup":"2","marker":{"color":"blue"},"mode":"lines+markers","showlegend":true,"x":[0],"y":[19218.899014719937],"type":"scatter"}],"name":"0"},{"data":[{"legendgroup":"1","marker":{"color":"black","opacity":1},"mode":"markers","showlegend":true,"x":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24],"y":[-3.0,35.657359027997266,79.93061443340548,114.31471805599453,33.471895621705016,53.587973461402754,129.29550745276566,147.9720770839918,83.86122886681098,96.12925464970229,155.89476363991855,116.24533248940001,105.24746787307683,163.9528664807629,110.4025100551105,128.62943611198907,155.6606672028108,148.51858789480823,105.221948958322,101.78661367769953,188.22612188617114,179.5521226679158,189.7747107964575,161.9026915173973,191.94379124341003],"type":"scatter"},{"legendgroup":"1","marker":{"color":"red"},"mode":"lines+markers","showlegend":true,"x":[0,1],"y":[-3.0,35.657359027997266],"type":"scatter"},{"legendgroup":"2","marker":{"color":"green"},"mode":"lines+markers","showlegend":true,"x":[0,1],"y":[0.0,0.0],"type":"scatter"},{"legendgroup":"2","marker":{"color":"blue"},"mode":"lines+markers","showlegend":true,"x":[0,1],"y":[19218.899014719937,19218.899014719937],"type":"scatter"}],"name":"1"},{"data":[{"legendgroup":"1","marker":{"color":"black","opacity":1},"mode":"markers","showlegend":true,"x":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24],"y":[-3.0,35.657359027997266,79.93061443340548,114.31471805599453,33.471895621705016,53.587973461402754,129.29550745276566,147.9720770839918,83.86122886681098,96.12925464970229,155.89476363991855,116.24533248940001,105.24746787307683,163.9528664807629,110.4025100551105,128.62943611198907,155.6606672028108,148.51858789480823,105.221948958322,101.78661367769953,188.22612188617114,179.5521226679158,189.7747107964575,161.9026915173973,191.94379124341003],"type":"scatter"},{"legendgroup":"1","marker":{"color":"red"},"mode":"lines+markers","showlegend":true,"x":[0,1,2],"y":[-3.0,35.657359027997266,79.93061443340548],"type":"scatter"},{"legendgroup":"2","marker":{"color":"green"},"mode":"lines+markers","showlegend":true,"x":[0,1,2],"y":[0.0,0.0,0.0],"type":"scatter"},{"legendgroup":"2","marker":{"color":"blue"},"mode":"lines+markers","showlegend":true,"x":[0,1,2],"y":[19218.899014719937,19218.899014719937,19218.899014719937],"type":"scatter"}],"name":"2"},{"data":[{"legendgroup":"1","marker":{"color":"black","opacity":1},"mode":"markers","showlegend":true,"x":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24],"y":[-3.0,35.657359027997266,79.93061443340548,114.31471805599453,33.471895621705016,53.587973461402754,129.29550745276566,147.9720770839918,83.86122886681098,96.12925464970229,155.89476363991855,116.24533248940001,105.24746787307683,163.9528664807629,110.4025100551105,128.62943611198907,155.6606672028108,148.51858789480823,105.221948958322,101.78661367769953,188.22612188617114,179.5521226679158,189.7747107964575,161.9026915173973,191.94379124341003],"type":"scatter"},{"legendgroup":"1","marker":{"color":"red"},"mode":"lines+markers","showlegend":true,"x":[0,1,2,3],"y":[-3.0,35.657359027997266,79.93061443340548,114.31471805599453],"type":"scatter"},{"legendgroup":"2","marker":{"color":"green"},"mode":"lines+markers","showlegend":true,"x":[0,1,2,3],"y":[0.0,0.0,0.0,0.0],"type":"scatter"},{"legendgroup":"2","marker":{"color":"blue"},"mode":"lines+markers","showlegend":true,"x":[0,1,2,3],"y":[19218.899014719937,19218.899014719937,19218.899014719937,19218.899014719937],"type":"scatter"}],"name":"3"},{"data":[{"legendgroup":"1","marker":{"color":"black","opacity":1},"mode":"markers","showlegend":true,"x":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24],"y":[-3.0,35.657359027997266,79.93061443340548,114.31471805599453,33.471895621705016,53.587973461402754,129.29550745276566,147.9720770839918,83.86122886681098,96.12925464970229,155.89476363991855,116.24533248940001,105.24746787307683,163.9528664807629,110.4025100551105,128.62943611198907,155.6606672028108,148.51858789480823,105.221948958322,101.78661367769953,188.22612188617114,179.5521226679158,189.7747107964575,161.9026915173973,191.94379124341003],"type":"scatter"},{"legendgroup":"1","marker":{"color":"red"},"mode":"lines+markers","showlegend":true,"x":[0,1,2,3,4],"y":[-3.0,35.657359027997266,75.90574270370168,75.90574270370168,75.90574270370168],"type":"scatter"},{"legendgroup":"2","marker":{"color":"green"},"mode":"lines+markers","showlegend":true,"x":[0,1,2,3,4],"y":[0.0,0.0,0.0,0.0,1646.040179115953],"type":"scatter"},{"legendgroup":"2","marker":{"color":"blue"},"mode":"lines+markers","showlegend":true,"x":[0,1,2,3,4],"y":[19218.899014719937,19218.899014719937,19218.899014719937,19218.899014719937,15889.415926489995],"type":"scatter"}],"name":"4"},{"data":[{"legendgroup":"1","marker":{"color":"black","opacity":1},"mode":"markers","showlegend":true,"x":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24],"y":[-3.0,35.657359027997266,79.93061443340548,114.31471805599453,33.471895621705016,53.587973461402754,129.29550745276566,147.9720770839918,83.86122886681098,96.12925464970229,155.89476363991855,116.24533248940001,105.24746787307683,163.9528664807629,110.4025100551105,128.62943611198907,155.6606672028108,148.51858789480823,105.221948958322,101.78661367769953,188.22612188617114,179.5521226679158,189.7747107964575,161.9026915173973,191.94379124341003],"type":"scatter"},{"legendgroup":"1","marker":{"color":"red"},"mode":"lines+markers","showlegend":true,"x":[0,1,2,3,4,5],"y":[-3.0,35.657359027997266,70.32630039312696,70.32630039312696,70.32630039312696,70.32630039312696],"type":"scatter"},{"legendgroup":"2","marker":{"color":"green"},"mode":"lines+markers","showlegend":true,"x":[0,1,2,3,4,5],"y":[0.0,0.0,0.0,0.0,1646.040179115953,1832.821238098084],"type":"scatter"},{"legendgroup":"2","marker":{"color":"blue"},"mode":"lines+markers","showlegend":true,"x":[0,1,2,3,4,5],"y":[19218.899014719937,19218.899014719937,19218.899014719937,19218.899014719937,15889.415926489995,12439.088303163002],"type":"scatter"}],"name":"5"},{"data":[{"legendgroup":"1","marker":{"color":"black","opacity":1},"mode":"markers","showlegend":true,"x":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24],"y":[-3.0,35.657359027997266,79.93061443340548,114.31471805599453,33.471895621705016,53.587973461402754,129.29550745276566,147.9720770839918,83.86122886681098,96.12925464970229,155.89476363991855,116.24533248940001,105.24746787307683,163.9528664807629,110.4025100551105,128.62943611198907,155.6606672028108,148.51858789480823,105.221948958322,101.78661367769953,188.22612188617114,179.5521226679158,189.7747107964575,161.9026915173973,191.94379124341003],"type":"scatter"},{"legendgroup":"1","marker":{"color":"red"},"mode":"lines+markers","showlegend":true,"x":[0,1,2,3,4,5,6],"y":[-3.0,35.657359027997266,70.32630039312696,70.32630039312696,70.32630039312696,70.32630039312696,129.29550745276566],"type":"scatter"},{"legendgroup":"2","marker":{"color":"green"},"mode":"lines+markers","showlegend":true,"x":[0,1,2,3,4,5,6],"y":[0.0,0.0,0.0,0.0,1646.040179115953,1832.821238098084,1832.821238098084],"type":"scatter"},{"legendgroup":"2","marker":{"color":"blue"},"mode":"lines+markers","showlegend":true,"x":[0,1,2,3,4,5,6],"y":[19218.899014719937,19218.899014719937,19218.899014719937,19218.899014719937,15889.415926489995,12439.088303163002,12439.088303163002],"type":"scatter"}],"name":"6"},{"data":[{"legendgroup":"1","marker":{"color":"black","opacity":1},"mode":"markers","showlegend":true,"x":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24],"y":[-3.0,35.657359027997266,79.93061443340548,114.31471805599453,33.471895621705016,53.587973461402754,129.29550745276566,147.9720770839918,83.86122886681098,96.12925464970229,155.89476363991855,116.24533248940001,105.24746787307683,163.9528664807629,110.4025100551105,128.62943611198907,155.6606672028108,148.51858789480823,105.221948958322,101.78661367769953,188.22612188617114,179.5521226679158,189.7747107964575,161.9026915173973,191.94379124341003],"type":"scatter"},{"legendgroup":"1","marker":{"color":"red"},"mode":"lines+markers","showlegend":true,"x":[0,1,2,3,4,5,6,7],"y":[-3.0,35.657359027997266,70.32630039312696,70.32630039312696,70.32630039312696,70.32630039312696,129.29550745276566,147.9720770839918],"type":"scatter"},{"legendgroup":"2","marker":{"color":"green"},"mode":"lines+markers","showlegend":true,"x":[0,1,2,3,4,5,6,7],"y":[0.0,0.0,0.0,0.0,1646.040179115953,1832.821238098084,1832.821238098084,1832.821238098084],"type":"scatter"},{"legendgroup":"2","marker":{"color":"blue"},"mode":"lines+markers","showlegend":true,"x":[0,1,2,3,4,5,6,7],"y":[19218.899014719937,19218.899014719937,19218.899014719937,19218.899014719937,15889.415926489995,12439.088303163002,12439.088303163002,12439.088303163002],"type":"scatter"}],"name":"7"},{"data":[{"legendgroup":"1","marker":{"color":"black","opacity":1},"mode":"markers","showlegend":true,"x":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24],"y":[-3.0,35.657359027997266,79.93061443340548,114.31471805599453,33.471895621705016,53.587973461402754,129.29550745276566,147.9720770839918,83.86122886681098,96.12925464970229,155.89476363991855,116.24533248940001,105.24746787307683,163.9528664807629,110.4025100551105,128.62943611198907,155.6606672028108,148.51858789480823,105.221948958322,101.78661367769953,188.22612188617114,179.5521226679158,189.7747107964575,161.9026915173973,191.94379124341003],"type":"scatter"},{"legendgroup":"1","marker":{"color":"red"},"mode":"lines+markers","showlegend":true,"x":[0,1,2,3,4,5,6,7,8],"y":[-3.0,35.657359027997266,70.32630039312696,70.32630039312696,70.32630039312696,70.32630039312696,120.37627113452281,120.37627113452281,120.37627113452281],"type":"scatter"},{"legendgroup":"2","marker":{"color":"green"},"mode":"lines+markers","showlegend":true,"x":[0,1,2,3,4,5,6,7,8],"y":[0.0,0.0,0.0,0.0,1646.040179115953,1832.821238098084,1832.821238098084,1832.821238098084,2920.0360352551797],"type":"scatter"},{"legendgroup":"2","marker":{"color":"blue"},"mode":"lines+markers","showlegend":true,"x":[0,1,2,3,4,5,6,7,8],"y":[19218.899014719937,19218.899014719937,19218.899014719937,19218.899014719937,15889.415926489995,12439.088303163002,12439.088303163002,12439.088303163002,11841.668995911108],"type":"scatter"}],"name":"8"},{"data":[{"legendgroup":"1","marker":{"color":"black","opacity":1},"mode":"markers","showlegend":true,"x":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24],"y":[-3.0,35.657359027997266,79.93061443340548,114.31471805599453,33.471895621705016,53.587973461402754,129.29550745276566,147.9720770839918,83.86122886681098,96.12925464970229,155.89476363991855,116.24533248940001,105.24746787307683,163.9528664807629,110.4025100551105,128.62943611198907,155.6606672028108,148.51858789480823,105.221948958322,101.78661367769953,188.22612188617114,179.5521226679158,189.7747107964575,161.9026915173973,191.94379124341003],"type":"scatter"},{"legendgroup":"1","marker":{"color":"red"},"mode":"lines+markers","showlegend":true,"x":[0,1,2,3,4,5,6,7,8,9],"y":[-3.0,35.657359027997266,70.32630039312696,70.32630039312696,70.32630039312696,70.32630039312696,114.31451701331767,114.31451701331767,114.31451701331767,114.31451701331767],"type":"scatter"},{"legendgroup":"2","marker":{"color":"green"},"mode":"lines+markers","showlegend":true,"x":[0,1,2,3,4,5,6,7,8,9],"y":[0.0,0.0,0.0,0.0,1646.040179115953,1832.821238098084,1832.821238098084,1832.821238098084,2920.0360352551797,3140.5052134108846],"type":"scatter"},{"legendgroup":"2","marker":{"color":"blue"},"mode":"lines+markers","showlegend":true,"x":[0,1,2,3,4,5,6,7,8,9],"y":[19218.899014719937,19218.899014719937,19218.899014719937,19218.899014719937,15889.415926489995,12439.088303163002,12439.088303163002,12439.088303163002,11841.668995911108,10811.879845480918],"type":"scatter"}],"name":"9"},{"data":[{"legendgroup":"1","marker":{"color":"black","opacity":1},"mode":"markers","showlegend":true,"x":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24],"y":[-3.0,35.657359027997266,79.93061443340548,114.31471805599453,33.471895621705016,53.587973461402754,129.29550745276566,147.9720770839918,83.86122886681098,96.12925464970229,155.89476363991855,116.24533248940001,105.24746787307683,163.9528664807629,110.4025100551105,128.62943611198907,155.6606672028108,148.51858789480823,105.221948958322,101.78661367769953,188.22612188617114,179.5521226679158,189.7747107964575,161.9026915173973,191.94379124341003],"type":"scatter"},{"legendgroup":"1","marker":{"color":"red"},"mode":"lines+markers","showlegend":true,"x":[0,1,2,3,4,5,6,7,8,9,10],"y":[-3.0,35.657359027997266,70.32630039312696,70.32630039312696,70.32630039312696,70.32630039312696,114.31451701331767,114.31451701331767,114.31451701331767,114.31451701331767,155.89476363991855],"type":"scatter"},{"legendgroup":"2","marker":{"color":"green"},"mode":"lines+markers","showlegend":true,"x":[0,1,2,3,4,5,6,7,8,9,10],"y":[0.0,0.0,0.0,0.0,1646.040179115953,1832.821238098084,1832.821238098084,1832.821238098084,2920.0360352551797,3140.5052134108846,3140.5052134108846],"type":"scatter"},{"legendgroup":"2","marker":{"color":"blue"},"mode":"lines+markers","showlegend":true,"x":[0,1,2,3,4,5,6,7,8,9,10],"y":[19218.899014719937,19218.899014719937,19218.899014719937,19218.899014719937,15889.415926489995,12439.088303163002,12439.088303163002,12439.088303163002,11841.668995911108,10811.879845480918,10811.879845480918],"type":"scatter"}],"name":"10"},{"data":[{"legendgroup":"1","marker":{"color":"black","opacity":1},"mode":"markers","showlegend":true,"x":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24],"y":[-3.0,35.657359027997266,79.93061443340548,114.31471805599453,33.471895621705016,53.587973461402754,129.29550745276566,147.9720770839918,83.86122886681098,96.12925464970229,155.89476363991855,116.24533248940001,105.24746787307683,163.9528664807629,110.4025100551105,128.62943611198907,155.6606672028108,148.51858789480823,105.221948958322,101.78661367769953,188.22612188617114,179.5521226679158,189.7747107964575,161.9026915173973,191.94379124341003],"type":"scatter"},{"legendgroup":"1","marker":{"color":"red"},"mode":"lines+markers","showlegend":true,"x":[0,1,2,3,4,5,6,7,8,9,10,11],"y":[-3.0,35.657359027997266,70.32630039312696,70.32630039312696,70.32630039312696,70.32630039312696,114.31451701331767,114.31451701331767,114.31451701331767,114.31451701331767,136.0700480646593,136.0700480646593],"type":"scatter"},{"legendgroup":"2","marker":{"color":"green"},"mode":"lines+markers","showlegend":true,"x":[0,1,2,3,4,5,6,7,8,9,10,11],"y":[0.0,0.0,0.0,0.0,1646.040179115953,1832.821238098084,1832.821238098084,1832.821238098084,2920.0360352551797,3140.5052134108846,3140.5052134108846,3533.5245610508136],"type":"scatter"},{"legendgroup":"2","marker":{"color":"blue"},"mode":"lines+markers","showlegend":true,"x":[0,1,2,3,4,5,6,7,8,9,10,11],"y":[19218.899014719937,19218.899014719937,19218.899014719937,19218.899014719937,15889.415926489995,12439.088303163002,12439.088303163002,12439.088303163002,11841.668995911108,10811.879845480918,10811.879845480918,10721.13678514058],"type":"scatter"}],"name":"11"},{"data":[{"legendgroup":"1","marker":{"color":"black","opacity":1},"mode":"markers","showlegend":true,"x":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24],"y":[-3.0,35.657359027997266,79.93061443340548,114.31471805599453,33.471895621705016,53.587973461402754,129.29550745276566,147.9720770839918,83.86122886681098,96.12925464970229,155.89476363991855,116.24533248940001,105.24746787307683,163.9528664807629,110.4025100551105,128.62943611198907,155.6606672028108,148.51858789480823,105.221948958322,101.78661367769953,188.22612188617114,179.5521226679158,189.7747107964575,161.9026915173973,191.94379124341003],"type":"scatter"},{"legendgroup":"1","marker":{"color":"red"},"mode":"lines+markers","showlegend":true,"x":[0,1,2,3,4,5,6,7,8,9,10,11,12],"y":[-3.0,35.657359027997266,70.32630039312696,70.32630039312696,70.32630039312696,70.32630039312696,114.31451701331767,114.31451701331767,114.31451701331767,114.31451701331767,125.79585466746512,125.79585466746512,125.79585466746512],"type":"scatter"},{"legendgroup":"2","marker":{"color":"green"},"mode":"lines+markers","showlegend":true,"x":[0,1,2,3,4,5,6,7,8,9,10,11,12],"y":[0.0,0.0,0.0,0.0,1646.040179115953,1832.821238098084,1832.821238098084,1832.821238098084,2920.0360352551797,3140.5052134108846,3140.5052134108846,3533.5245610508136,3850.20171093964],"type":"scatter"},{"legendgroup":"2","marker":{"color":"blue"},"mode":"lines+markers","showlegend":true,"x":[0,1,2,3,4,5,6,7,8,9,10,11,12],"y":[19218.899014719937,19218.899014719937,19218.899014719937,19218.899014719937,15889.415926489995,12439.088303163002,12439.088303163002,12439.088303163002,11841.668995911108,10811.879845480918,10811.879845480918,10721.13678514058,9947.091120346347],"type":"scatter"}],"name":"12"},{"data":[{"legendgroup":"1","marker":{"color":"black","opacity":1},"mode":"markers","showlegend":true,"x":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24],"y":[-3.0,35.657359027997266,79.93061443340548,114.31471805599453,33.471895621705016,53.587973461402754,129.29550745276566,147.9720770839918,83.86122886681098,96.12925464970229,155.89476363991855,116.24533248940001,105.24746787307683,163.9528664807629,110.4025100551105,128.62943611198907,155.6606672028108,148.51858789480823,105.221948958322,101.78661367769953,188.22612188617114,179.5521226679158,189.7747107964575,161.9026915173973,191.94379124341003],"type":"scatter"},{"legendgroup":"1","marker":{"color":"red"},"mode":"lines+markers","showlegend":true,"x":[0,1,2,3,4,5,6,7,8,9,10,11,12,13],"y":[-3.0,35.657359027997266,70.32630039312696,70.32630039312696,70.32630039312696,70.32630039312696,114.31451701331767,114.31451701331767,114.31451701331767,114.31451701331767,125.79585466746512,125.79585466746512,125.79585466746512,163.9528664807629],"type":"scatter"},{"legendgroup":"2","marker":{"color":"green"},"mode":"lines+markers","showlegend":true,"x":[0,1,2,3,4,5,6,7,8,9,10,11,12,13],"y":[0.0,0.0,0.0,0.0,1646.040179115953,1832.821238098084,1832.821238098084,1832.821238098084,2920.0360352551797,3140.5052134108846,3140.5052134108846,3533.5245610508136,3850.20171093964,3850.20171093964],"type":"scatter"},{"legendgroup":"2","marker":{"color":"blue"},"mode":"lines+markers","showlegend":true,"x":[0,1,2,3,4,5,6,7,8,9,10,11,12,13],"y":[19218.899014719937,19218.899014719937,19218.899014719937,19218.899014719937,15889.415926489995,12439.088303163002,12439.088303163002,12439.088303163002,11841.668995911108,10811.879845480918,10811.879845480918,10721.13678514058,9947.091120346347,9947.091120346347],"type":"scatter"}],"name":"13"},{"data":[{"legendgroup":"1","marker":{"color":"black","opacity":1},"mode":"markers","showlegend":true,"x":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24],"y":[-3.0,35.657359027997266,79.93061443340548,114.31471805599453,33.471895621705016,53.587973461402754,129.29550745276566,147.9720770839918,83.86122886681098,96.12925464970229,155.89476363991855,116.24533248940001,105.24746787307683,163.9528664807629,110.4025100551105,128.62943611198907,155.6606672028108,148.51858789480823,105.221948958322,101.78661367769953,188.22612188617114,179.5521226679158,189.7747107964575,161.9026915173973,191.94379124341003],"type":"scatter"},{"legendgroup":"1","marker":{"color":"red"},"mode":"lines+markers","showlegend":true,"x":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14],"y":[-3.0,35.657359027997266,70.32630039312696,70.32630039312696,70.32630039312696,70.32630039312696,114.31451701331767,114.31451701331767,114.31451701331767,114.31451701331767,125.79585466746512,125.79585466746512,125.79585466746512,137.1776882679367,137.1776882679367],"type":"scatter"},{"legendgroup":"2","marker":{"color":"green"},"mode":"lines+markers","showlegend":true,"x":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14],"y":[0.0,0.0,0.0,0.0,1646.040179115953,1832.821238098084,1832.821238098084,1832.821238098084,2920.0360352551797,3140.5052134108846,3140.5052134108846,3533.5245610508136,3850.20171093964,3850.20171093964,4567.111879268254],"type":"scatter"},{"legendgroup":"2","marker":{"color":"blue"},"mode":"lines+markers","showlegend":true,"x":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14],"y":[19218.899014719937,19218.899014719937,19218.899014719937,19218.899014719937,15889.415926489995,12439.088303163002,12439.088303163002,12439.088303163002,11841.668995911108,10811.879845480918,10811.879845480918,10721.13678514058,9947.091120346347,9947.091120346347,9754.99983674713],"type":"scatter"}],"name":"14"},{"data":[{"legendgroup":"1","marker":{"color":"black","opacity":1},"mode":"markers","showlegend":true,"x":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24],"y":[-3.0,35.657359027997266,79.93061443340548,114.31471805599453,33.471895621705016,53.587973461402754,129.29550745276566,147.9720770839918,83.86122886681098,96.12925464970229,155.89476363991855,116.24533248940001,105.24746787307683,163.9528664807629,110.4025100551105,128.62943611198907,155.6606672028108,148.51858789480823,105.221948958322,101.78661367769953,188.22612188617114,179.5521226679158,189.7747107964575,161.9026915173973,191.94379124341003],"type":"scatter"},{"legendgroup":"1","marker":{"color":"red"},"mode":"lines+markers","showlegend":true,"x":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15],"y":[-3.0,35.657359027997266,70.32630039312696,70.32630039312696,70.32630039312696,70.32630039312696,114.31451701331767,114.31451701331767,114.31451701331767,114.31451701331767,125.79585466746512,125.79585466746512,125.79585466746512,134.3282708826208,134.3282708826208,134.3282708826208],"type":"scatter"},{"legendgroup":"2","marker":{"color":"green"},"mode":"lines+markers","showlegend":true,"x":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15],"y":[0.0,0.0,0.0,0.0,1646.040179115953,1832.821238098084,1832.821238098084,1832.821238098084,2920.0360352551797,3140.5052134108846,3140.5052134108846,3533.5245610508136,3850.20171093964,3850.20171093964,4567.111879268254,4591.469417575514],"type":"scatter"},{"legendgroup":"2","marker":{"color":"blue"},"mode":"lines+markers","showlegend":true,"x":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15],"y":[19218.899014719937,19218.899014719937,19218.899014719937,19218.899014719937,15889.415926489995,12439.088303163002,12439.088303163002,12439.088303163002,11841.668995911108,10811.879845480918,10811.879845480918,10721.13678514058,9947.091120346347,9947.091120346347,9754.99983674713,9386.194758063913],"type":"scatter"}],"name":"15"},{"data":[{"legendgroup":"1","marker":{"color":"black","opacity":1},"mode":"markers","showlegend":true,"x":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24],"y":[-3.0,35.657359027997266,79.93061443340548,114.31471805599453,33.471895621705016,53.587973461402754,129.29550745276566,147.9720770839918,83.86122886681098,96.12925464970229,155.89476363991855,116.24533248940001,105.24746787307683,163.9528664807629,110.4025100551105,128.62943611198907,155.6606672028108,148.51858789480823,105.221948958322,101.78661367769953,188.22612188617114,179.5521226679158,189.7747107964575,161.9026915173973,191.94379124341003],"type":"scatter"},{"legendgroup":"1","marker":{"color":"red"},"mode":"lines+markers","showlegend":true,"x":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16],"y":[-3.0,35.657359027997266,70.32630039312696,70.32630039312696,70.32630039312696,70.32630039312696,114.31451701331767,114.31451701331767,114.31451701331767,114.31451701331767,125.79585466746512,125.79585466746512,125.79585466746512,134.3282708826208,134.3282708826208,134.3282708826208,155.6606672028108],"type":"scatter"},{"legendgroup":"2","marker":{"color":"green"},"mode":"lines+markers","showlegend":true,"x":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16],"y":[0.0,0.0,0.0,0.0,1646.040179115953,1832.821238098084,1832.821238098084,1832.821238098084,2920.0360352551797,3140.5052134108846,3140.5052134108846,3533.5245610508136,3850.20171093964,3850.20171093964,4567.111879268254,4591.469417575514,4591.469417575514],"type":"scatter"},{"legendgroup":"2","marker":{"color":"blue"},"mode":"lines+markers","showlegend":true,"x":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16],"y":[19218.899014719937,19218.899014719937,19218.899014719937,19218.899014719937,15889.415926489995,12439.088303163002,12439.088303163002,12439.088303163002,11841.668995911108,10811.879845480918,10811.879845480918,10721.13678514058,9947.091120346347,9947.091120346347,9754.99983674713,9386.194758063913,9386.194758063913],"type":"scatter"}],"name":"16"},{"data":[{"legendgroup":"1","marker":{"color":"black","opacity":1},"mode":"markers","showlegend":true,"x":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24],"y":[-3.0,35.657359027997266,79.93061443340548,114.31471805599453,33.471895621705016,53.587973461402754,129.29550745276566,147.9720770839918,83.86122886681098,96.12925464970229,155.89476363991855,116.24533248940001,105.24746787307683,163.9528664807629,110.4025100551105,128.62943611198907,155.6606672028108,148.51858789480823,105.221948958322,101.78661367769953,188.22612188617114,179.5521226679158,189.7747107964575,161.9026915173973,191.94379124341003],"type":"scatter"},{"legendgroup":"1","marker":{"color":"red"},"mode":"lines+markers","showlegend":true,"x":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17],"y":[-3.0,35.657359027997266,70.32630039312696,70.32630039312696,70.32630039312696,70.32630039312696,114.31451701331767,114.31451701331767,114.31451701331767,114.31451701331767,125.79585466746512,125.79585466746512,125.79585466746512,134.3282708826208,134.3282708826208,134.3282708826208,152.08962754880952,152.08962754880952],"type":"scatter"},{"legendgroup":"2","marker":{"color":"green"},"mode":"lines+markers","showlegend":true,"x":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17],"y":[0.0,0.0,0.0,0.0,1646.040179115953,1832.821238098084,1832.821238098084,1832.821238098084,2920.0360352551797,3140.5052134108846,3140.5052134108846,3533.5245610508136,3850.20171093964,3850.20171093964,4567.111879268254,4591.469417575514,4591.469417575514,4604.221741785936],"type":"scatter"},{"legendgroup":"2","marker":{"color":"blue"},"mode":"lines+markers","showlegend":true,"x":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17],"y":[19218.899014719937,19218.899014719937,19218.899014719937,19218.899014719937,15889.415926489995,12439.088303163002,12439.088303163002,12439.088303163002,11841.668995911108,10811.879845480918,10811.879845480918,10721.13678514058,9947.091120346347,9947.091120346347,9754.99983674713,9386.194758063913,9386.194758063913,9343.53676762003],"type":"scatter"}],"name":"17"},{"data":[{"legendgroup":"1","marker":{"color":"black","opacity":1},"mode":"markers","showlegend":true,"x":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24],"y":[-3.0,35.657359027997266,79.93061443340548,114.31471805599453,33.471895621705016,53.587973461402754,129.29550745276566,147.9720770839918,83.86122886681098,96.12925464970229,155.89476363991855,116.24533248940001,105.24746787307683,163.9528664807629,110.4025100551105,128.62943611198907,155.6606672028108,148.51858789480823,105.221948958322,101.78661367769953,188.22612188617114,179.5521226679158,189.7747107964575,161.9026915173973,191.94379124341003],"type":"scatter"},{"legendgroup":"1","marker":{"color":"red"},"mode":"lines+markers","showlegend":true,"x":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18],"y":[-3.0,35.657359027997266,70.32630039312696,70.32630039312696,70.32630039312696,70.32630039312696,114.31451701331767,114.31451701331767,114.31451701331767,114.31451701331767,125.79585466746512,125.79585466746512,125.79585466746512,134.3282708826208,134.3282708826208,134.3282708826208,136.467068018647,136.467068018647,136.467068018647],"type":"scatter"},{"legendgroup":"2","marker":{"color":"green"},"mode":"lines+markers","showlegend":true,"x":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18],"y":[0.0,0.0,0.0,0.0,1646.040179115953,1832.821238098084,1832.821238098084,1832.821238098084,2920.0360352551797,3140.5052134108846,3140.5052134108846,3533.5245610508136,3850.20171093964,3850.20171093964,4567.111879268254,4591.469417575514,4591.469417575514,4604.221741785936,5336.414840606332],"type":"scatter"},{"legendgroup":"2","marker":{"color":"blue"},"mode":"lines+markers","showlegend":true,"x":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18],"y":[19218.899014719937,19218.899014719937,19218.899014719937,19218.899014719937,15889.415926489995,12439.088303163002,12439.088303163002,12439.088303163002,11841.668995911108,10811.879845480918,10811.879845480918,10721.13678514058,9947.091120346347,9947.091120346347,9754.99983674713,9386.194758063913,9386.194758063913,9343.53676762003,8339.863786042017],"type":"scatter"}],"name":"18"},{"data":[{"legendgroup":"1","marker":{"color":"black","opacity":1},"mode":"markers","showlegend":true,"x":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24],"y":[-3.0,35.657359027997266,79.93061443340548,114.31471805599453,33.471895621705016,53.587973461402754,129.29550745276566,147.9720770839918,83.86122886681098,96.12925464970229,155.89476363991855,116.24533248940001,105.24746787307683,163.9528664807629,110.4025100551105,128.62943611198907,155.6606672028108,148.51858789480823,105.221948958322,101.78661367769953,188.22612188617114,179.5521226679158,189.7747107964575,161.9026915173973,191.94379124341003],"type":"scatter"},{"legendgroup":"1","marker":{"color":"red"},"mode":"lines+markers","showlegend":true,"x":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19],"y":[-3.0,35.657359027997266,70.32630039312696,70.32630039312696,70.32630039312696,70.32630039312696,114.31451701331767,114.31451701331767,114.31451701331767,114.31451701331767,125.79585466746512,125.79585466746512,125.79585466746512,130.59609005450042,130.59609005450042,130.59609005450042,130.59609005450042,130.59609005450042,130.59609005450042,130.59609005450042],"type":"scatter"},{"legendgroup":"2","marker":{"color":"green"},"mode":"lines+markers","showlegend":true,"x":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19],"y":[0.0,0.0,0.0,0.0,1646.040179115953,1832.821238098084,1832.821238098084,1832.821238098084,2920.0360352551797,3140.5052134108846,3140.5052134108846,3533.5245610508136,3850.20171093964,3850.20171093964,4567.111879268254,4591.469417575514,4591.469417575514,4604.221741785936,5336.414840606332,5824.004139142984],"type":"scatter"},{"legendgroup":"2","marker":{"color":"blue"},"mode":"lines+markers","showlegend":true,"x":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19],"y":[19218.899014719937,19218.899014719937,19218.899014719937,19218.899014719937,15889.415926489995,12439.088303163002,12439.088303163002,12439.088303163002,11841.668995911108,10811.879845480918,10811.879845480918,10721.13678514058,9947.091120346347,9947.091120346347,9754.99983674713,9386.194758063913,9386.194758063913,9343.53676762003,8339.863786042017,6105.701541579706],"type":"scatter"}],"name":"19"},{"data":[{"legendgroup":"1","marker":{"color":"black","opacity":1},"mode":"markers","showlegend":true,"x":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24],"y":[-3.0,35.657359027997266,79.93061443340548,114.31471805599453,33.471895621705016,53.587973461402754,129.29550745276566,147.9720770839918,83.86122886681098,96.12925464970229,155.89476363991855,116.24533248940001,105.24746787307683,163.9528664807629,110.4025100551105,128.62943611198907,155.6606672028108,148.51858789480823,105.221948958322,101.78661367769953,188.22612188617114,179.5521226679158,189.7747107964575,161.9026915173973,191.94379124341003],"type":"scatter"},{"legendgroup":"1","marker":{"color":"red"},"mode":"lines+markers","showlegend":true,"x":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20],"y":[-3.0,35.657359027997266,70.32630039312696,70.32630039312696,70.32630039312696,70.32630039312696,114.31451701331767,114.31451701331767,114.31451701331767,114.31451701331767,125.79585466746512,125.79585466746512,125.79585466746512,130.59609005450042,130.59609005450042,130.59609005450042,130.59609005450042,130.59609005450042,130.59609005450042,130.59609005450042,188.22612188617114],"type":"scatter"},{"legendgroup":"2","marker":{"color":"green"},"mode":"lines+markers","showlegend":true,"x":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20],"y":[0.0,0.0,0.0,0.0,1646.040179115953,1832.821238098084,1832.821238098084,1832.821238098084,2920.0360352551797,3140.5052134108846,3140.5052134108846,3533.5245610508136,3850.20171093964,3850.20171093964,4567.111879268254,4591.469417575514,4591.469417575514,4604.221741785936,5336.414840606332,5824.004139142984,5824.004139142984],"type":"scatter"},{"legendgroup":"2","marker":{"color":"blue"},"mode":"lines+markers","showlegend":true,"x":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20],"y":[19218.899014719937,19218.899014719937,19218.899014719937,19218.899014719937,15889.415926489995,12439.088303163002,12439.088303163002,12439.088303163002,11841.668995911108,10811.879845480918,10811.879845480918,10721.13678514058,9947.091120346347,9947.091120346347,9754.99983674713,9386.194758063913,9386.194758063913,9343.53676762003,8339.863786042017,6105.701541579706,6105.701541579706],"type":"scatter"}],"name":"20"},{"data":[{"legendgroup":"1","marker":{"color":"black","opacity":1},"mode":"markers","showlegend":true,"x":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24],"y":[-3.0,35.657359027997266,79.93061443340548,114.31471805599453,33.471895621705016,53.587973461402754,129.29550745276566,147.9720770839918,83.86122886681098,96.12925464970229,155.89476363991855,116.24533248940001,105.24746787307683,163.9528664807629,110.4025100551105,128.62943611198907,155.6606672028108,148.51858789480823,105.221948958322,101.78661367769953,188.22612188617114,179.5521226679158,189.7747107964575,161.9026915173973,191.94379124341003],"type":"scatter"},{"legendgroup":"1","marker":{"color":"red"},"mode":"lines+markers","showlegend":true,"x":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21],"y":[-3.0,35.657359027997266,70.32630039312696,70.32630039312696,70.32630039312696,70.32630039312696,114.31451701331767,114.31451701331767,114.31451701331767,114.31451701331767,125.79585466746512,125.79585466746512,125.79585466746512,130.59609005450042,130.59609005450042,130.59609005450042,130.59609005450042,130.59609005450042,130.59609005450042,130.59609005450042,183.88912227704347,183.88912227704347],"type":"scatter"},{"legendgroup":"2","marker":{"color":"green"},"mode":"lines+markers","showlegend":true,"x":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21],"y":[0.0,0.0,0.0,0.0,1646.040179115953,1832.821238098084,1832.821238098084,1832.821238098084,2920.0360352551797,3140.5052134108846,3140.5052134108846,3533.5245610508136,3850.20171093964,3850.20171093964,4567.111879268254,4591.469417575514,4591.469417575514,4604.221741785936,5336.414840606332,5824.004139142984,5824.004139142984,5842.813704752596],"type":"scatter"},{"legendgroup":"2","marker":{"color":"blue"},"mode":"lines+markers","showlegend":true,"x":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21],"y":[19218.899014719937,19218.899014719937,19218.899014719937,19218.899014719937,15889.415926489995,12439.088303163002,12439.088303163002,12439.088303163002,11841.668995911108,10811.879845480918,10811.879845480918,10721.13678514058,9947.091120346347,9947.091120346347,9754.99983674713,9386.194758063913,9386.194758063913,9343.53676762003,8339.863786042017,6105.701541579706,6105.701541579706,6068.430622939655],"type":"scatter"}],"name":"21"},{"data":[{"legendgroup":"1","marker":{"color":"black","opacity":1},"mode":"markers","showlegend":true,"x":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24],"y":[-3.0,35.657359027997266,79.93061443340548,114.31471805599453,33.471895621705016,53.587973461402754,129.29550745276566,147.9720770839918,83.86122886681098,96.12925464970229,155.89476363991855,116.24533248940001,105.24746787307683,163.9528664807629,110.4025100551105,128.62943611198907,155.6606672028108,148.51858789480823,105.221948958322,101.78661367769953,188.22612188617114,179.5521226679158,189.7747107964575,161.9026915173973,191.94379124341003],"type":"scatter"},{"legendgroup":"1","marker":{"color":"red"},"mode":"lines+markers","showlegend":true,"x":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22],"y":[-3.0,35.657359027997266,70.32630039312696,70.32630039312696,70.32630039312696,70.32630039312696,114.31451701331767,114.31451701331767,114.31451701331767,114.31451701331767,125.79585466746512,125.79585466746512,125.79585466746512,130.59609005450042,130.59609005450042,130.59609005450042,130.59609005450042,130.59609005450042,130.59609005450042,130.59609005450042,183.88912227704347,183.88912227704347,189.7747107964575],"type":"scatter"},{"legendgroup":"2","marker":{"color":"green"},"mode":"lines+markers","showlegend":true,"x":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22],"y":[0.0,0.0,0.0,0.0,1646.040179115953,1832.821238098084,1832.821238098084,1832.821238098084,2920.0360352551797,3140.5052134108846,3140.5052134108846,3533.5245610508136,3850.20171093964,3850.20171093964,4567.111879268254,4591.469417575514,4591.469417575514,4604.221741785936,5336.414840606332,5824.004139142984,5824.004139142984,5842.813704752596,5842.813704752596],"type":"scatter"},{"legendgroup":"2","marker":{"color":"blue"},"mode":"lines+markers","showlegend":true,"x":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22],"y":[19218.899014719937,19218.899014719937,19218.899014719937,19218.899014719937,15889.415926489995,12439.088303163002,12439.088303163002,12439.088303163002,11841.668995911108,10811.879845480918,10811.879845480918,10721.13678514058,9947.091120346347,9947.091120346347,9754.99983674713,9386.194758063913,9386.194758063913,9343.53676762003,8339.863786042017,6105.701541579706,6105.701541579706,6068.430622939655,6068.430622939655],"type":"scatter"}],"name":"22"},{"data":[{"legendgroup":"1","marker":{"color":"black","opacity":1},"mode":"markers","showlegend":true,"x":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24],"y":[-3.0,35.657359027997266,79.93061443340548,114.31471805599453,33.471895621705016,53.587973461402754,129.29550745276566,147.9720770839918,83.86122886681098,96.12925464970229,155.89476363991855,116.24533248940001,105.24746787307683,163.9528664807629,110.4025100551105,128.62943611198907,155.6606672028108,148.51858789480823,105.221948958322,101.78661367769953,188.22612188617114,179.5521226679158,189.7747107964575,161.9026915173973,191.94379124341003],"type":"scatter"},{"legendgroup":"1","marker":{"color":"red"},"mode":"lines+markers","showlegend":true,"x":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23],"y":[-3.0,35.657359027997266,70.32630039312696,70.32630039312696,70.32630039312696,70.32630039312696,114.31451701331767,114.31451701331767,114.31451701331767,114.31451701331767,125.79585466746512,125.79585466746512,125.79585466746512,130.59609005450042,130.59609005450042,130.59609005450042,130.59609005450042,130.59609005450042,130.59609005450042,130.59609005450042,179.86391171698543,179.86391171698543,179.86391171698543,179.86391171698543],"type":"scatter"},{"legendgroup":"2","marker":{"color":"green"},"mode":"lines+markers","showlegend":true,"x":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23],"y":[0.0,0.0,0.0,0.0,1646.040179115953,1832.821238098084,1832.821238098084,1832.821238098084,2920.0360352551797,3140.5052134108846,3140.5052134108846,3533.5245610508136,3850.20171093964,3850.20171093964,4567.111879268254,4591.469417575514,4591.469417575514,4604.221741785936,5336.414840606332,5824.004139142984,5824.004139142984,5842.813704752596,5842.813704752596,6069.430709531298],"type":"scatter"},{"legendgroup":"2","marker":{"color":"blue"},"mode":"lines+markers","showlegend":true,"x":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23],"y":[19218.899014719937,19218.899014719937,19218.899014719937,19218.899014719937,15889.415926489995,12439.088303163002,12439.088303163002,12439.088303163002,11841.668995911108,10811.879845480918,10811.879845480918,10721.13678514058,9947.091120346347,9947.091120346347,9754.99983674713,9386.194758063913,9386.194758063913,9343.53676762003,8339.863786042017,6105.701541579706,6105.701541579706,6068.430622939655,6068.430622939655,6069.430709531276],"type":"scatter"}],"name":"23"},{"data":[{"legendgroup":"1","marker":{"color":"black","opacity":1},"mode":"markers","showlegend":true,"x":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24],"y":[-3.0,35.657359027997266,79.93061443340548,114.31471805599453,33.471895621705016,53.587973461402754,129.29550745276566,147.9720770839918,83.86122886681098,96.12925464970229,155.89476363991855,116.24533248940001,105.24746787307683,163.9528664807629,110.4025100551105,128.62943611198907,155.6606672028108,148.51858789480823,105.221948958322,101.78661367769953,188.22612188617114,179.5521226679158,189.7747107964575,161.9026915173973,191.94379124341003],"type":"scatter"},{"legendgroup":"1","marker":{"color":"red"},"mode":"lines+markers","showlegend":true,"x":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24],"y":[-3.0,35.657359027997266,70.32630039312696,70.32630039312696,70.32630039312696,70.32630039312696,114.31451701331767,114.31451701331767,114.31451701331767,114.31451701331767,125.79585466746512,125.79585466746512,125.79585466746512,130.59609005450042,130.59609005450042,130.59609005450042,130.59609005450042,130.59609005450042,130.59609005450042,130.59609005450042,179.86391171698543,179.86391171698543,179.86391171698543,179.86391171698543,191.94379124341003],"type":"scatter"},{"legendgroup":"2","marker":{"color":"green"},"mode":"lines+markers","showlegend":true,"x":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24],"y":[0.0,0.0,0.0,0.0,1646.040179115953,1832.821238098084,1832.821238098084,1832.821238098084,2920.0360352551797,3140.5052134108846,3140.5052134108846,3533.5245610508136,3850.20171093964,3850.20171093964,4567.111879268254,4591.469417575514,4591.469417575514,4604.221741785936,5336.414840606332,5824.004139142984,5824.004139142984,5842.813704752596,5842.813704752596,6069.430709531298,6069.430709531298],"type":"scatter"},{"legendgroup":"2","marker":{"color":"blue"},"mode":"lines+markers","showlegend":true,"x":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24],"y":[19218.899014719937,19218.899014719937,19218.899014719937,19218.899014719937,15889.415926489995,12439.088303163002,12439.088303163002,12439.088303163002,11841.668995911108,10811.879845480918,10811.879845480918,10721.13678514058,9947.091120346347,9947.091120346347,9754.99983674713,9386.194758063913,9386.194758063913,9343.53676762003,8339.863786042017,6105.701541579706,6105.701541579706,6068.430622939655,6068.430622939655,6069.430709531276,6069.430709531276],"type":"scatter"}],"name":"24"},{"data":[{"legendgroup":"1","marker":{"color":"black","opacity":1},"mode":"markers","showlegend":true,"x":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24],"y":[-3.0,35.657359027997266,79.93061443340548,114.31471805599453,33.471895621705016,53.587973461402754,129.29550745276566,147.9720770839918,83.86122886681098,96.12925464970229,155.89476363991855,116.24533248940001,105.24746787307683,163.9528664807629,110.4025100551105,128.62943611198907,155.6606672028108,148.51858789480823,105.221948958322,101.78661367769953,188.22612188617114,179.5521226679158,189.7747107964575,161.9026915173973,191.94379124341003],"type":"scatter"},{"legendgroup":"1","marker":{"color":"red"},"mode":"lines+markers","showlegend":true,"x":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24],"y":[-3.0,35.657359027997266,70.32630039312696,70.32630039312696,70.32630039312696,70.32630039312696,114.31451701331767,114.31451701331767,114.31451701331767,114.31451701331767,125.79585466746512,125.79585466746512,125.79585466746512,130.59609005450042,130.59609005450042,130.59609005450042,130.59609005450042,130.59609005450042,130.59609005450042,130.59609005450042,179.86391171698546,179.86391171698546,179.86391171698546,179.86391171698546,191.94379124341003],"type":"scatter"},{"legendgroup":"2","marker":{"color":"green"},"mode":"lines+markers","showlegend":true,"x":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24],"y":[0.0,0.0,0.0,0.0,1646.040179115953,1832.821238098084,1832.821238098084,1832.821238098084,2920.0360352551797,3140.5052134108846,3140.5052134108846,3533.5245610508136,3850.20171093964,3850.20171093964,4567.111879268254,4591.469417575514,4591.469417575514,4604.221741785936,5336.414840606332,5824.004139142984,5824.004139142984,5842.813704752596,5842.813704752596,6069.430709531298,6069.430709531298],"type":"scatter"},{"legendgroup":"2","marker":{"color":"blue"},"mode":"lines+markers","showlegend":true,"x":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24],"y":[19218.899014719937,19218.899014719937,19218.899014719937,19218.899014719937,15889.415926489995,12439.088303163002,12439.088303163002,12439.088303163002,11841.668995911108,10811.879845480918,10811.879845480918,10721.13678514058,9947.091120346347,9947.091120346347,9754.99983674713,9386.194758063913,9386.194758063913,9343.53676762003,8339.863786042017,6105.701541579706,6105.701541579706,6068.430622939655,6068.430622939655,6069.430709531276,6069.430709531276],"type":"scatter"}],"name":"24"}]);
                        }).then(function(){
                            
var gd = document.getElementById('6c24e920-8816-47c4-913f-411654d8f980');
var x = new MutationObserver(function (mutations, observer) {{
        var display = window.getComputedStyle(gd).display;
        if (!display || display === 'none') {{
            console.log([gd, 'removed!']);
            Plotly.purge(gd);
            observer.disconnect();
        }}
}});

// Listen for the removal of the full notebook cells
var notebookContainer = gd.closest('#notebook-container');
if (notebookContainer) {{
    x.observe(notebookContainer, {childList: true});
}}

// Listen for the clearing of the current output cell
var outputEl = gd.closest('.output');
if (outputEl) {{
    x.observe(outputEl, {childList: true});
}}

                        })                };                });            </script>        </div>
</div>
</div>
</section>
<section id="applications" class="level2">
<h2 class="anchored" data-anchor-id="applications">Applications</h2>
<p>Isotonic regression is used in a variety of applications, including:</p>
<ul>
<li><p><strong>Monotonicity constraints</strong>: In many applications, it is important to ensure that the relationship between two variables is monotonic. This is the case in physics or biology for instance.</p></li>
<li><p><strong>Calibration</strong> for machine learning models: Isotonic regression can be used to calibrate the output of a machine learning model to ensure that it is well-calibrated. It is common for binary classifiers to output probabilities that are not well-calibrated, and isotonic regression can be used to correct this. You will find a some details and examples in the <a href="https://scikit-learn.org/1.5/modules/calibration.html" target="_blank">scikit-learn documentation</a>.</p></li>
<li><p><strong>Sparse regression</strong>: isotonic regression has some links with the Slope penalty <span class="citation" data-cites="Bogdan_vandenBerg_Sabatti_Su_Candes15">Bogdan et al. (2015)</span>, a generalization of the Lasso penalty. The Slope estimator has been introduced to improve False Discovery Rate control in high-dimensional settings. It is a weighted ordered <img src="https://latex.codecogs.com/png.latex?%5Cell_1"> penalty, whose proximity operator can be computing thanks to the PAVA algorithm <span class="citation" data-cites="Zeng_Figueiredo14">Zeng and Figueiredo (2014)</span> (using Moreau’s identity). I became aware of this while working on <span class="citation" data-cites="Bellec_Salmon_Vaiter17">Bellec, Salmon, and Vaiter (2017)</span> : we were using that property to compute efficiently the GSlope estimator (and to control duality gap in this context).</p></li>
</ul>
</section>
</section>
<section id="optimization-duality-etc." class="level1">
<h1>Optimization, duality, etc.</h1>
<p>The formulation of the isotonic regression problem given in Equation&nbsp;1 is a quadratic program (QP) with linear constraints. Using a matrix notation, introducing the matrix <img src="https://latex.codecogs.com/png.latex?A%20=%20%5Cbegin%7Bpmatrix%7D%201%20&amp;%20-1%20&amp;%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20&amp;%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20&amp;%20%20%20%20%5C%5C%0A%20%20&amp;%201%20%20&amp;%20-1%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20&amp;%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20&amp;%20%20%20%20%5C%5C%0A%20%20&amp;%20%20%20%20&amp;%20%5Cddots%20&amp;%20%5Cddots%20&amp;%20%20%20%20%5C%5C%0A%20%20&amp;%20%20%20%20&amp;%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20&amp;%201%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20&amp;%20-1%5Cend%7Bpmatrix%7D%0A=%0A%5Cbegin%7Bpmatrix%7D%0Aa_1%5E%5Ctop%20%5C%5C%0A%5Cvdots%20%20%20%5C%5C%0Aa_%7Bn-1%7D%5E%5Ctop%0A%5Cend%7Bpmatrix%7D%0A%5Cin%20%5Cmathbb%7BR%7D%5E%7Bn-1%20%5Ctimes%20n%7D%5Censpace,%0A"> the isotonic regression problem can be formulated as follows: <span id="eq-isotonic-matrix"><img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign%7D%0A%5Cmin_%7Bx%20%5Cin%20%5Cmathbb%7BR%7D%5En%7D%0A%5Cfrac%7B1%7D%7B2%7D%0A&amp;%20%5Csum_%7Bi=1%7D%5E%7Bn%7D%20w_i%20(x_i%20-%20y_i)%5E2%20%5C%5C%0A%5Ctext%7Bs.t.%7D%20&amp;%20%5Cquad%20Ax%20%5Cleq%200%20%5Cnonumber%0A%5Cend%7Balign%7D%0A%5Ctag%7B2%7D"></span></p>
<p>In what follows we will write <img src="https://latex.codecogs.com/png.latex?W=%5Cmathop%7B%5Cmathrm%7Bdiag%7D%7D(w_1,%5Cdots,w_n)">, assuming that <img src="https://latex.codecogs.com/png.latex?w_i%20%3E%200"> for all <img src="https://latex.codecogs.com/png.latex?i%20%5Cin%20%5Cllbracket%201,%20n%20%5Crrbracket">, so <img src="https://latex.codecogs.com/png.latex?W%5E%7B-1%7D=%20%5Cmathop%7B%5Cmathrm%7Bdiag%7D%7D(1/w_1,%5Cdots,1/w_n)">. Hence, we can rewrite the isotonic regression problem as</p>
<p><span id="eq-isotonic-matrix-2"><img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign%7D%0A%5Cmin_%7Bx%20%5Cin%20%5Cmathbb%7BR%7D%5En%7D%0A%5Cfrac%7B1%7D%7B2%7D%0A&amp;%20(x-y)%5E%5Ctop%20W%20(x-y)%20%5C%5C%0A%5Ctext%7Bs.t.%7D%20&amp;%20%5Cquad%20Ax%20%5Cleq%200%20%5Censpace.%0A%5Cend%7Balign%7D%0A%5Ctag%7B3%7D"></span></p>
<p>Hence, the isotonic regression problem can be formulated as a convex quadratic program with linear constraints.</p>
<section id="notation" class="level3">
<h3 class="anchored" data-anchor-id="notation">Notation</h3>
<p>The set of <strong>isotonic vectors</strong> <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%7BK%7D%20=%20%5Cleft%5C%7B%20x%20%5Cin%20%5Cmathbb%7BR%7D%5En%20:%20Ax%20%5Cleq%200%20%5Cright%5C%7D"> is a cone (stable by positive scalar multiplication). We remind also that the <strong>polar cone</strong> of <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%7BK%7D"> is <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%7BK%7D%5E%5Ccirc=%20%5Cleft%5C%7Bv%20%5Cin%20%5Cmathbb%7BR%7D%5En%20:%20%5Clangle%20v,%20x%20%5Crangle%20%5Cleq%200%20%5Ctext%7B%20for%20all%20%7D%20x%20%5Cin%20%5Cmathcal%7BK%7D%5Cright%5C%7D">.</p>
<p>For any set <img src="https://latex.codecogs.com/png.latex?S%20%5Csubset%20%5Cllbracket%201,%20n%5Crrbracket">, the weighted average of <img src="https://latex.codecogs.com/png.latex?y_i"> over the indices in <img src="https://latex.codecogs.com/png.latex?i%20%5Cin%20S"> reads: <img src="https://latex.codecogs.com/png.latex?%0A%5Cbar%7By%7D_S%20%5Ctriangleq%20%5Cfrac%7B%5Csum_%7Bi%20%5Cin%20S%7D%20w_i%20y_i%7D%7B%5Csum_%7Bi'%20%5Cin%20S%7D%20w_%7B'i'%7D%7D%20%5Censpace.%0A"></p>
<div id="lem-polar" class="theorem lemma">
<p><span class="theorem-title"><strong>Lemma 1 (Polar cone of the isotonic cone)</strong></span> The polar cone of <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%7BK%7D"> is <img src="https://latex.codecogs.com/png.latex?%0A%5Cmathcal%7BK%7D%5E%5Ccirc%20=%5Cleft%5C%7B%20%5Csum_%7Bi=1%7D%5E%7Bn-1%7D%20%5Calpha_i%20a_i,%20%5Ctext%7B%20for%20%7D%20%5Calpha_1%20%5Cgeq%200,%20%5Cdots,%20%5Calpha_%7Bn-1%7D%20%5Cgeq%200%20%5Cright%5C%7D%20=%20A%5E%5Ctop%20%5Cmathbb%7BR%7D_+%5E%7Bn-1%7D%5Censpace.%0A"></p>
</div>
<div class="proof-container">
<div class="proof-header" onclick="toggleProof('lem-polar')">
<p><span id="proof-arrow-lem-polar" class="proof-arrow">▶</span> <span class="proof-title">Proof</span></p>
</div>
<div id="proof-content-lem-polar" class="proof-content">
<p>Let <img src="https://latex.codecogs.com/png.latex?x%20%5Cin%20%5Cmathcal%7BK%7D"> and <img src="https://latex.codecogs.com/png.latex?v%20=%20%5Csum_%7Bi=1%7D%5E%7Bn-1%7D%20%5Calpha_i%20a_i"> with <img src="https://latex.codecogs.com/png.latex?%5Calpha_1%20%5Cgeq%200,%20%5Cdots,%20%5Calpha_%7Bn-1%7D%20%5Cgeq%200">. Then, note that <img src="https://latex.codecogs.com/png.latex?A%20x%20%5Cleq%200"> is equivalent to <img src="https://latex.codecogs.com/png.latex?%5Clangle%20a_i,%20x%20%5Crangle%20%5Cleq%200"> for all <img src="https://latex.codecogs.com/png.latex?i%20%5Cin%20%5Cllbracket%201,%20n-1%20%5Crrbracket">. Hence, we have <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign*%7D%0A%5Clangle%20v,%20x%20%5Crangle%0A&amp;%20=%20%5Csum_%7Bi=1%7D%5E%7Bn-1%7D%20%5Calpha_i%20%5Clangle%20a_i,%20x%20%5Crangle%5C%5C%0A&amp;%20%5Cleq%200%20%5Censpace.%0A%5Cend%7Balign*%7D%0A"> So <img src="https://latex.codecogs.com/png.latex?%5Cleft%5C%7B%20%5Csum_%7Bi=1%7D%5E%7Bn-1%7D%20%5Calpha_i%20a_i,%20%5Ctext%7B%20with%20%7D%20%5Calpha_1%20%5Cgeq%200,%20%5Cdots,%20%5Calpha_%7Bn-1%7D%20%5Cgeq%200%20%5Cright%5C%7D%20%5Csubset%20%5Cmathcal%7BK%7D%5E%5Ccirc">.</p>
<p>For the converse, let <img src="https://latex.codecogs.com/png.latex?v%20%5Cin%20%5Cmathcal%7BK%7D%5E%5Ccirc">. One can check that <img src="https://latex.codecogs.com/png.latex?(a_i)_%7Bi=1,%5Cdots,n-1%7D"> are linearly independant, so adding the vector <img src="https://latex.codecogs.com/png.latex?%5Cmathbf%7B1%7D_n=(1,%5Cdots,1)%5E%5Ctop/n"> create a basis of <img src="https://latex.codecogs.com/png.latex?%5Cmathbb%7BR%7D%5En">.</p>
<p>Hence one can write <img src="https://latex.codecogs.com/png.latex?v=%20%5Calpha_n%20%5Cmathbf%7B1%7D_n%20+%20%5Csum_%7Bi=1%7D%5E%7Bn-1%7D%20%5Calpha_i%20a_i">. Now choosing <img src="https://latex.codecogs.com/png.latex?x=%5Cmathbf%7B1%7D_n%20%5Cin%20%5Cmathcal%7BK%7D"> yields <img src="https://latex.codecogs.com/png.latex?%5Clangle%20v,%20%5Cmathbf%7B1%7D_n%20%5Crangle%20=%20%5Calpha_n%20%5Cleq%200">. Choosing <img src="https://latex.codecogs.com/png.latex?x%20=%20-%20%5Cmathbf%7B1%7D_n%20%5Cin%20%5Cmathcal%7BK%7D"> yields <img src="https://latex.codecogs.com/png.latex?%5Clangle%20v,%20-%20%5Cmathbf%7B1%7D_n%20%5Crangle%20=%20-%20%5Calpha_n%20%5Cleq%200">. Hence, <img src="https://latex.codecogs.com/png.latex?%5Calpha_n%20=%200">.</p>
<p>Now, for all <img src="https://latex.codecogs.com/png.latex?i%20%5Cin%20%5Cllbracket%201,%20n-1%20%5Crrbracket">, choosing <img src="https://latex.codecogs.com/png.latex?x%20=%20%5Csum_%7Bk=i%7D%5En%20e_i"> for <img src="https://latex.codecogs.com/png.latex?i%20%5Cin%20%5Cllbracket%202,%20n%20%5Crrbracket"> yields <img src="https://latex.codecogs.com/png.latex?%5Clangle%20v,%20x%20%5Crangle%20=%20-%5Calpha_%7Bi%7D%5Cleq%200">. Hence, for all <img src="https://latex.codecogs.com/png.latex?i%20%5Cin%20%5Cllbracket%201,%20n-1%20%5Crrbracket">, we have <img src="https://latex.codecogs.com/png.latex?%5Calpha_i%20%5Cgeq%200">, so <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%7BK%7D%5E%5Ccirc%20%5Csubset%20%5Cleft%5C%7B%20%5Csum_%7Bi=1%7D%5E%7Bn-1%7D%20%5Calpha_i%20a_i,%20%5Ctext%7B%20with%20%7D%20%5Calpha_1%20%5Cgeq%200,%20%5Cdots,%20%5Calpha_%7Bn-1%7D%20%5Cgeq%200%20%5Cright%5C%7D"> and the lemma is proved.</p>
</div>
</div>
</section>
<section id="conic-duality-fenchel-transform" class="level2">
<h2 class="anchored" data-anchor-id="conic-duality-fenchel-transform">Conic duality / Fenchel transform</h2>
<p>Here we remind the definition of the Fenchel transform of a function <img src="https://latex.codecogs.com/png.latex?f"> defined on <img src="https://latex.codecogs.com/png.latex?%5Cmathbb%7BR%7D%5En">: <img src="https://latex.codecogs.com/png.latex?%0Af%5E*(v)%20=%20%5Csup_%7Bx%20%5Cin%20%5Cmathbb%7BR%7D%5En%7D%20%5Cleft%5C%7B%20%5Clangle%20v,%20x%20%5Crangle%20-%20f(x)%20%5Cright%5C%7D%5Censpace.%0A"></p>
<p>We also write <img src="https://latex.codecogs.com/png.latex?%5Ciota_%7B%5Cmathcal%7BK%7D%7D"> the indicator function of the set <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%7BK%7D">, that is <img src="https://latex.codecogs.com/png.latex?%5Ciota_%7B%5Cmathcal%7BK%7D%7D(x)%20=%200"> if <img src="https://latex.codecogs.com/png.latex?x%20%5Cin%20%5Cmathcal%7BK%7D"> and <img src="https://latex.codecogs.com/png.latex?+%5Cinfty"> otherwise.</p>
<div id="lem-fenchel" class="theorem lemma">
<p><span class="theorem-title"><strong>Lemma 2 (Fenchel transform of indicator of a cone)</strong></span> The Fenchel transform of the indicator function of a convex cone <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%7BK%7D"> is <img src="https://latex.codecogs.com/png.latex?%0A%5Ciota_%7B%5Cmathcal%7BK%7D%7D%5E*(v)%20=%20%5Ciota_%7B%5Cmathcal%7BK%7D%5E%5Ccirc%7D(v)%5Censpace,%0A"> where <img src="https://latex.codecogs.com/png.latex?%5Ciota_%7B%5Cmathcal%7BK%7D%5E%5Ccirc%7D"> is the indicator function of the set <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%7BK%7D%5E%5Ccirc">.</p>
</div>
</section>
<section id="dual-problem" class="level2">
<h2 class="anchored" data-anchor-id="dual-problem">Dual problem</h2>
<p>Let us now derive the dual problem of the isotonic regression problem given in Equation&nbsp;2.</p>
<div id="thm-dual" class="theorem">
<p><span class="theorem-title"><strong>Theorem 1 (Dual problem of isotonic regression&gt;)</strong></span> The dual problem of the isotonic regression problem given in Equation&nbsp;2 is <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign*%7D%0A%5Cmax_%7B%5Calpha%20%5Cin%20%5Cmathbb%7BR%7D_+%5E%7Bn-1%7D%7D%20&amp;%0A%5Cleft%5B%0A%20%20%20%20-%20%5Cfrac%7B1%7D%7B2%7D%20(A%5E%5Ctop%20%5Calpha-W%20y)%5E%5Ctop%20W%5E%7B-1%7D%20(A%5E%5Ctop%20%5Calpha-W%20y)%0A%20%20%20%20+%20%5Cfrac%7B1%7D%7B2%7D%20y%5E%5Ctop%20W%20y%0A%5Cright%5D%20%5Censpace.%0A%5Cend%7Balign*%7D%0A"></p>
</div>
<div class="proof-container">
<div class="proof-header" onclick="toggleProof('thm-dual')">
<p><span id="proof-arrow-thm-dual" class="proof-arrow">▶</span> <span class="proof-title">Proof</span></p>
</div>
<div id="proof-content-thm-dual" class="proof-content">
<p>With such ingredient we can write the isotonic regression problem as: <span id="eq-isotonic-matrix-2"><img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign%7D%0A%5Cmin_%7Bx%20%5Cin%20%5Cmathbb%7BR%7D%5En%7D%0A%5Cfrac%7B1%7D%7B2%7D%0A(y-x)%5E%5Ctop%20W%20(y-x)%20+%20%5Ciota_%7B%5Cmathcal%7BK%7D%7D(x)%20%5Censpace.%0A%5Cend%7Balign%7D%0A%5Ctag%7B4%7D"></span> We can now rewrite the formulation as</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign*%7D%0A%5Cmin_%7Bx%20%5Cin%20%5Cmathbb%7BR%7D%5En%7D%20&amp;%0A%5Cfrac%7B1%7D%7B2%7D%0Az%5E%5Ctop%20W%20z%20+%20%5Ciota_%7B%5Cmathcal%7BK%7D%7D(x)%5C%5C%0A%5Ctext%7Bs.t.%7D%20&amp;%20%5Cquad%20z%20=%20y%20-%20x%20%20%5Censpace.%0A%5Cend%7Balign*%7D%0A"> We can now introduce the Lagrangian of the problem: <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign*%7D%0A%5Cmathcal%7BL%7D(x,%20z,%20%5Clambda)%20&amp;%20=%20%5Cfrac%7B1%7D%7B2%7D%20z%5E%5Ctop%20W%20z%20+%20%5Ciota_%7B%5Cmathcal%7BK%7D%7D(x)%20+%20%5Clambda%5E%5Ctop%20(y%20-%20z%20-%20x)%5C%5C%0A&amp;%20=%20%5Cfrac%7B1%7D%7B2%7D%20z%5E%5Ctop%20W%20z%20+%20%5Ciota_%7B%5Cmathcal%7BK%7D%7D(x)%20+%20%5Clambda%5E%5Ctop%20y%20-%20%5Clambda%5E%5Ctop%20z%20-%20%5Clambda%5E%5Ctop%20x%20%5Censpace.%0A%5Cend%7Balign*%7D%0A"> Assuming strong duality holds, we can write the dual problem as <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign*%7D%0A%5Cmin_%7Bx%20%5Cin%20%5Cmathbb%7BR%7D%5En,%20z%20%5Cin%20%5Cmathbb%7BR%7D%5En%7D%20%5Cmax_%7B%5Clambda%20%5Cin%20%5Cmathbb%7BR%7D%5En%7D%20~%0A%5Cmathcal%7BL%7D(x,%20z,%20%5Clambda)%20=%0A%5Cmax_%7B%5Clambda%20%5Cin%20%5Cmathbb%7BR%7D%5En%7D%20%5Cmin_%7Bx%20%5Cin%20%5Cmathbb%7BR%7D%5En,%20z%20%5Cin%20%5Cmathbb%7BR%7D%5En%7D%20&amp;%0A%5Cmathcal%7BL%7D(x,%20z,%20%5Clambda)%20%5Censpace.%0A%5Cend%7Balign*%7D%0A"> Now, one can check that the dual problem is equivalent to</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cmax_%7B%5Clambda%20%5Cin%20%5Cmathbb%7BR%7D%5En%7D%20%5Cmin_%7Bx%20%5Cin%20%5Cmathbb%7BR%7D%5En,%20z%20%5Cin%20%5Cmathbb%7BR%7D%5En%7D%20%5Cleft%5C%7B%20%5Cfrac%7B1%7D%7B2%7D%20z%5E%5Ctop%20W%20z%20+%20%5Ciota_%7B%5Cmathcal%7BK%7D%7D(x)%20+%20%5Clambda%5E%5Ctop%20y%20-%20%5Clambda%5E%5Ctop%20z%20-%20%5Clambda%5E%5Ctop%20x%20%5Cright%5C%7D%20%5Censpace.%0A"> Separating the terms in <img src="https://latex.codecogs.com/png.latex?x"> and <img src="https://latex.codecogs.com/png.latex?z"> yields <img src="https://latex.codecogs.com/png.latex?%0A%5Cmax_%7B%5Clambda%20%5Cin%20%5Cmathbb%7BR%7D%5En%7D%0A%5Cleft%5B%0A%20%20%20%20%5Cmin_%7Bx%20%5Cin%20%5Cmathbb%7BR%7D%5En%7D%20%5Cleft%5C%7B%20%5Ciota_%7B%5Cmathcal%7BK%7D%7D(x)%20-%20%5Clambda%5E%5Ctop%20x%20+%20%5Clambda%5E%5Ctop%20y%20%5Cright%5C%7D%20+%20%5Cmin_%7Bz%20%5Cin%20%5Cmathbb%7BR%7D%5En%7D%20%5Cleft%5C%7B%20%5Cfrac%7B1%7D%7B2%7D%20z%5E%5Ctop%20W%20z%20-%20%5Clambda%5E%5Ctop%20z%20%5Cright%5C%7D%0A%5Cright%5D%0A%5Censpace.%0A"> The second term is a simple quadratic problem with a unique solution given by <img src="https://latex.codecogs.com/png.latex?z%20=%20W%5E%7B-1%7D%20%5Clambda">, hence this can be rewritten as <img src="https://latex.codecogs.com/png.latex?%0A%5Cleft%5B%0A-%20%5Cfrac%7B1%7D%7B2%7D%20%5Clambda%5E%5Ctop%20W%5E%7B-1%7D%20%5Clambda%0A%5Cright%5D%0A%5Censpace.%0A"> The first term is linked to the Fenchel transform of the indicator function of the cone <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%7BK%7D">, and reads <img src="https://latex.codecogs.com/png.latex?%0A%5Cleft%5B%0A%20%20%20%20-%20%5Ciota_%7B%5Cmathcal%7BK%7D%5E%5Ccirc%7D(%5Clambda)%20+%20%5Clambda%5E%5Ctop%20y%20=%20-%20%5Ciota_%7B%5Cmathcal%7BK%7D%5E%5Ccirc%7D(%5Clambda)%20+%20%5Clambda%5E%5Ctop%20W%5E%7B-1%7D%20W%20y%0A%5Cright%5D%0A%5Censpace.%0A"></p>
<p>Hence the dual problem reads: <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign*%7D%0A%5Cmax_%7B%5Clambda%20%5Cin%20%5Cmathbb%7BR%7D%5En%7D%20&amp;%0A%5Cleft%5B%0A%20%20%20%20-%20%5Ciota_%7B%5Cmathcal%7BK%7D%5E%5Ccirc%7D(%5Clambda)%20+%20%5Clambda%5E%5Ctop%20y%20-%20%5Cfrac%7B1%7D%7B2%7D%20%5Clambda%5E%5Ctop%20W%5E%7B-1%7D%20%5Clambda%0A%5Cright%5D%20%5Censpace,%0A%5Cend%7Balign*%7D%0A"> the later can be rewritten as</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign*%7D%0A%5Cmax_%7B%5Clambda%20%5Cin%20%5Cmathcal%7BK%7D%5E%7B%5Ccirc%7D%7D%20&amp;%0A%5Cleft%5B%0A%20%20%20%20-%20%5Cfrac%7B1%7D%7B2%7D%20(%5Clambda-W%20y)%5E%5Ctop%20W%5E%7B-1%7D%20(%5Clambda-W%20y)%0A%20%20%20%20+%20%5Cfrac%7B1%7D%7B2%7D%20y%5E%5Ctop%20W%20y%0A%5Cright%5D%20%5Censpace.%0A%5Cend%7Balign*%7D%0A"> Eventually, using the formulation of <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%7BK%7D%5E%7B%5Ccirc%7D"> given in Lemma&nbsp;1, the dual problem can be rewritten as <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign*%7D%0A%5Cmax_%7B%5Calpha%20%5Cin%20%5Cmathbb%7BR%7D_+%5E%7Bn-1%7D%7D%20&amp;%0A%5Cleft%5B%0A%20%20%20%20-%20%5Cfrac%7B1%7D%7B2%7D%20(A%5E%5Ctop%20%5Calpha-W%20y)%5E%5Ctop%20W%5E%7B-1%7D%20(A%5E%5Ctop%20%5Calpha-W%20y)%0A%20%20%20%20+%20%5Cfrac%7B1%7D%7B2%7D%20y%5E%5Ctop%20W%20y%0A%5Cright%5D%20%5Censpace,%0A%5Cend%7Balign*%7D%0A"> which is the targeted formulation.</p>
</div>
</div>
</section>
<section id="karush-kuhn-tucker-kkt-conditions" class="level2">
<h2 class="anchored" data-anchor-id="karush-kuhn-tucker-kkt-conditions">Karush-Kuhn-Tucker (KKT) conditions</h2>
<p>The KKT conditions for the isotonic regression problem are given by</p>
<div id="thm-kkt" class="theorem">
<p><span class="theorem-title"><strong>Theorem 2 (KKT conditions for isotonic regression)</strong></span> Let <img src="https://latex.codecogs.com/png.latex?x%5E%7B%5Cstar%7D%20%5Cin%20%5Cmathcal%7BK%7D"> and <img src="https://latex.codecogs.com/png.latex?%5Calpha%5E%7B%5Cstar%7D%20%5Cin%20%5Cmathbb%7BR%7D_+%5E%7Bn-1%7D"> be primal and dual optimal solutions, then the KKT conditions for the isotonic regression problem reads <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign*%7D%0AW%20(x%5E%7B%5Cstar%7D-y)%20+%20A%5E%5Ctop%20%5Calpha%5E%7B%5Cstar%7D%20&amp;%20=%200%20&amp;%20~%20(%5Ctextbf%7Bstationarity%7D)%5C%5C%0A%5Clangle%20%5Calpha%5E%7B%5Cstar%7D%20,%20A%20x%5E%7B%5Cstar%7D%20%5Crangle%20&amp;%20=%200%20&amp;%20~%20(%5Ctextbf%7Bcomplementary%20slackness%7D)%5C%5C%0A%5Calpha%5E%7B%5Cstar%7D%20&amp;%20%5Cgeq%200%20&amp;%20~%20(%5Ctextbf%7Bdual%20feasibility%7D)%5C%5C%0AA%20x%5E%7B%5Cstar%7D%20&amp;%20%5Cleq%200%20&amp;%20~%20%20(%5Ctextbf%7Bprimal%20feasibility%7D)%0A%5Cend%7Balign*%7D%0A"></p>
</div>
<div class="proof-container">
<div class="proof-header" onclick="toggleProof('thm-kkt')">
<p><span id="proof-arrow-thm-kkt" class="proof-arrow">▶</span> <span class="proof-title">Proof</span></p>
</div>
<div id="proof-content-thm-kkt" class="proof-content">
<p>See <span class="citation" data-cites="Boyd_Vandenberghe04">(Boyd and Vandenberghe 2004, sec. 5.5.3)</span></p>
</div>
</div>
<p>In this convex setting (a primal strictly feasible point exists, say <img src="https://latex.codecogs.com/png.latex?x=(1,%5Cdots,n)%5E%5Ctop">, so the Slater condition holds), the KKT conditions are necessary and sufficient for optimality.</p>
<p><strong>Stationarity</strong> can be rephrased as:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign*%7D%0Aw_1%20(x%5E%7B%5Cstar%7D_1-%20y_1)%20+%20%5Calpha%5E%7B%5Cstar%7D_1%20&amp;%20=%200%20%5C%5C%0Aw_i%20(x%5E%7B%5Cstar%7D_i-%20y_i)%20+%20%5Calpha%5E%7B%5Cstar%7D_%7Bi%7D%20-%20%5Calpha%5E%7B%5Cstar%7D_%7Bi-1%7D%20&amp;%20=%200,%20%5Cquad%20%5Ctext%7Bfor%20all%20%7D%20i%20%5Cin%20%5Cllbracket%202,%20n-1%20%5Crrbracket%5C%5C%0Aw_n%20(x%5E%7B%5Cstar%7D_n%20-%20y_n)%20-%20%5Calpha%5E%7B%5Cstar%7D_%7Bn-1%7D%20&amp;%20=%200%20%5Censpace.%0A%5Cend%7Balign*%7D%0A"> With the convention <img src="https://latex.codecogs.com/png.latex?%5Calpha_0%5E%7B%5Cstar%7D%20=%20%5Calpha_n%5E%7B%5Cstar%7D%20=%200">, this reduces to <span id="eq-stationarity"><img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign*%7D%0Aw_i%20(x%5E%7B%5Cstar%7D_i%20-%20y_i)%20+%20%5Calpha%5E%7B%5Cstar%7D_%7Bi%7D%20-%20%5Calpha%5E%7B%5Cstar%7D_%7Bi-1%7D%20&amp;%20=%200,%20%5Cquad%20%5Ctext%7Bfor%20all%20%7D%20i%20%5Cin%20%5Cllbracket%201,%20n%20%5Crrbracket%5C%5C%0A%5Cend%7Balign*%7D%0A%5Ctag%7B5%7D"></span></p>
<p><strong>Complementarity slackness</strong> can also be rephrased: <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign*%7D%0A&amp;%20%5Calpha_i%5E%7B%5Cstar%7D%20(A%20x%5E%7B%5Cstar%7D)_i%20%20=%200%20%5Cquad%20%5Ctext%7Bfor%20all%20%7D%20i%20%5Cin%20%5Cllbracket%201,%20n-1%20%5Crrbracket%20%5C%5C%0A%5Ciff%20&amp;%20%5Calpha_i%5E%7B%5Cstar%7D%20(x%5E%7B%5Cstar%7D_i-x%5E%7B%5Cstar%7D_%7Bi+1%7D)%20%20=%200%20%5Cquad%20%5Ctext%7Bfor%20all%20%7D%20i%20%5Cin%20%5Cllbracket%201,%20n-1%20%5Crrbracket%20%5Censpace.%0A%5Cend%7Balign*%7D%0A"></p>
<p>A simple consequence of the complementarity slackness is as follows: if <img src="https://latex.codecogs.com/png.latex?%5Calpha_i%5E%7B%5Cstar%7D%20%3E%200"> for some <img src="https://latex.codecogs.com/png.latex?i%20%5Cin%20%5Cllbracket%201,%20n-1%20%5Crrbracket">, then <img src="https://latex.codecogs.com/png.latex?x%5E%7B%5Cstar%7D_i%20=%20x%5E%7B%5Cstar%7D_%7Bi+1%7D">. Hence, the set of (<img src="https://latex.codecogs.com/png.latex?n-1">) constraints can be partitioned into contiguous blocks where <img src="https://latex.codecogs.com/png.latex?x%5E%5Cstar"> has constant value. Each block B can be written as <img src="https://latex.codecogs.com/png.latex?B%20=%20%5Cllbracket%20%5Cunderline%7Bb%7D,%20%5Coverline%7Bb%7D%20%5Crrbracket"> for some <img src="https://latex.codecogs.com/png.latex?%5Cunderline%7Bb%7D%20%5Cleq%20%5Coverline%7Bb%7D"> and <img src="https://latex.codecogs.com/png.latex?x%5E%7B%5Cstar%7D_%7B%5Cunderline%7Bb%7D%7D%20=%20x%5E%7B%5Cstar%7D_%7B%5Cunderline%7Bb%7D+1%7D%20=%20%5Cldots%20=%20x%5E%7B%5Cstar%7D_%7B%5Coverline%7Bb%7D%7D">. When needed, we use the convention <img src="https://latex.codecogs.com/png.latex?x%5E%7B%5Cstar%7D_%7B0%7D=0"> and <img src="https://latex.codecogs.com/png.latex?x%5E%7B%5Cstar%7D_%7Bn+1%7D=0">. Then, note that by definition of a block, <img src="https://latex.codecogs.com/png.latex?x%5E%7B%5Cstar%7D_%7B%5Cunderline%7Bb%7D-1%7D%3Cx%5E%7B%5Cstar%7D_%7B%5Cunderline%7Bb%7D%7D"> and <img src="https://latex.codecogs.com/png.latex?x%5E%7B%5Cstar%7D_%7B%5Coverline%7Bb%7D%7D%3Cx%5E%7B%5Cstar%7D_%7B%5Coverline%7Bb%7D+1%7D">, and by complementarity <img src="https://latex.codecogs.com/png.latex?%5Calpha%5E%7B%5Cstar%7D_%7B%5Cunderline%7Bb%7D-1%7D%20=%20%5Calpha%5E%7B%5Cstar%7D_%7B%5Coverline%7Bb%7D%7D%20=%200">.</p>
<p>Summing over the elements of <img src="https://latex.codecogs.com/png.latex?B"> in Equation&nbsp;5 yields (telescopic sum): <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign*%7D%0A%5Csum_%7Bi%20%5Cin%20B%20%7Dw_i%20(x%5E%7B%5Cstar%7D_i%20-%20y_i)%20+%20%20%5Calpha_%7B%5Coverline%7Bb%7D%7D%5E%7B%5Cstar%7D%20-%20%5Calpha_%7B%5Cunderline%7Bb%7D-1%7D%5E%7B%5Cstar%7D%20&amp;%20=%200%20%5Censpace.%0A%5Cend%7Balign*%7D%0A"> Hence, noticing that the <img src="https://latex.codecogs.com/png.latex?x_i%5E%7B%5Cstar%7D"> in block <img src="https://latex.codecogs.com/png.latex?B"> are all equal, we have that:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign*%7D%0Ax%5E%7B%5Cstar%7D_%7B%5Cunderline%7Bb%7D%7D%20=%20%5Cldots%20=%20x%5E%7B%5Cstar%7D_%7B%5Coverline%7Bb%7D%7D%20=%20%5Cbar%7By%7D_B%20%20%5Cbig(=%20%5Cbar%7By%7D_%7B%5Cllbracket%20%5Cunderline%7Bb%7D,%20%5Coverline%7Bb%7D%20%5Crrbracket%7D%20%5Cbig)%5Censpace.%0A%5Cend%7Balign*%7D%0A"></p>
<p>Now, from the values of <img src="https://latex.codecogs.com/png.latex?x%5E%7B%5Cstar%7D_%7B%5Cunderline%7Bb%7D%7D%20=%20%5Cldots%20=%20x%5E%7B%5Cstar%7D_%7B%5Coverline%7Bb%7D%7D"> on the block <img src="https://latex.codecogs.com/png.latex?B">, one can infer (by recursion) the <img src="https://latex.codecogs.com/png.latex?%5Calpha_i">’s for <img src="https://latex.codecogs.com/png.latex?i%5Cin%20B">.</p>
<div id="lem-lambda" class="theorem lemma">
<p><span class="theorem-title"><strong>Lemma 3 (Expression of the dual variables)</strong></span> Let <img src="https://latex.codecogs.com/png.latex?B%20=%5Cllbracket%20%5Cunderline%7Bb%7D,%20%5Coverline%7Bb%7D%20%5Crrbracket"> be partitionning block for <img src="https://latex.codecogs.com/png.latex?x%5E%5Cstar"> (into constants pieces). For any <img src="https://latex.codecogs.com/png.latex?i%20%5Cin%20B">:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign*%7D%0A%5Calpha%5E%7B%5Cstar%7D_%7Bi%7D%20&amp;%20=%20%5CBig(%5Csum_%7Bj%20%5Cin%20B%20%5Ccap%20%5Cllbracket%201,%20i%20%5Crrbracket%7D%20w_j%20%5CBig)%5Cleft(%5Cbar%7By%7D_%7BB%20%5Ccap%20%5Cllbracket%201,%20i+1%20%5Crrbracket%7D%20-%20%5Cbar%7By%7D_%7BB%7D%5Cright)%20%5Censpace.%0A%5Cend%7Balign*%7D%0A"></p>
</div>
<div class="proof-container">
<div class="proof-header" onclick="toggleProof('lem-lambda')">
<p><span id="proof-arrow-lem-lambda" class="proof-arrow">▶</span> <span class="proof-title">Proof</span></p>
</div>
<div id="proof-content-lem-lambda" class="proof-content">
<p>The proof is a simple induction on the element of block <img src="https://latex.codecogs.com/png.latex?B">. For <img src="https://latex.codecogs.com/png.latex?i=%5Cunderline%7Bb%7D"> then Equation&nbsp;5 leads to <img src="https://latex.codecogs.com/png.latex?%5Calpha%5E%7B%5Cstar%7D_%7B%5Cunderline%7Bb%7D%7D%20=%20w_%7B%5Cunderline%7Bb%7D%7D%20(%5Cbar%7By%7D_%7B%5Cunderline%7Bb%7D%7D%20-%20x%5E%7B%5Cstar%7D_%7B%5Cunderline%7Bb%7D%7D)%20=%20%5CBig(%5Csum_%7Bj%20%5Cin%20B%20%5Ccap%20%5Cllbracket%201,%20i%20%5Crrbracket%7D%20w_j%20%5CBig)%5Cleft(%5Cbar%7By%7D_%7BB%20%5Ccap%20%5Cllbracket%201,%20i%20%5Crrbracket%7D%20-%20%5Cbar%7By%7D_%7BB%7D%20%5Cright)">. Now by induction assume the result for <img src="https://latex.codecogs.com/png.latex?i%5Cin%20B">, <img src="https://latex.codecogs.com/png.latex?%5Calpha%5E%7B%5Cstar%7D_%7Bi%7D%20%20=%20%5CBig(%5Csum_%7Bj%20%5Cin%20B%20%5Ccap%20%5Cllbracket%201,%20i%20%5Crrbracket%7D%20w_j%20%5CBig)%5Cleft(%5Cbar%7By%7D_%7BB%20%5Ccap%20%5Cllbracket%201,%20i%20%5Crrbracket%7D%20-%20%5Cbar%7By%7D_%7BB%7D%5Cright)">. Using Equation&nbsp;5 for <img src="https://latex.codecogs.com/png.latex?i+1%20%5Cin%20B"> yields</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign*%7D%0A%5Calpha%5E%7B%5Cstar%7D_%7Bi+1%7D%0A&amp;%20=%20w_%7Bi+1%7D%20(y_%7Bi+1%7D%20-%20x%5E%7B%5Cstar%7D_%7Bi+1%7D)%20+%20%5Calpha%5E%7B%5Cstar%7D_i%5C%5C%0A&amp;%20=%20w_%7Bi+1%7D%20(y_%7Bi+1%7D%20-%20%5Coverline%7By%7D_%7BB%7D)%20+%20%5Calpha%5E%7B%5Cstar%7D_i%5C%5C%0A&amp;%20=%20w_%7Bi+1%7D%20(y_%7Bi+1%7D%20-%20%5Coverline%7By%7D_%7BB%7D)%20+%20%5CBig(%5Csum_%7Bj%20%5Cin%20B%20%5Ccap%20%5Cllbracket%201,%20i%20%5Crrbracket%7D%20w_j%20%20%5CBig)%5Cleft(%5Cbar%7By%7D_%7BB%20%5Ccap%20%5Cllbracket%201,%20i%20%5Crrbracket%7D%20-%5Cbar%7By%7D_%7BB%7D%5Cright)%5C%5C%0A&amp;%20=%20%5CBig(%5Csum_%7Bj%20%5Cin%20B%20%5Ccap%20%5Cllbracket%201,%20i%20+%201%20%5Crrbracket%7D%20w_j%20%20%5CBig)%5Cleft(%5Cbar%7By%7D_%7BB%20%5Ccap%20%5Cllbracket%201,%20i+1%20%5Crrbracket%7D%20-%20%5Cbar%7By%7D_%7BB%7D%5Cright)%20%5Censpace,%0A%5Cend%7Balign*%7D%0A"> hence the result.</p>
</div>
</div>
</section>
</section>
<section id="algorithm" class="level1">
<h1>Algorithm</h1>
<p>The intuition behind the PAVA algorithm is to merge adjacent blocks of constant values in the primal vector, as the targeted solution is simply the average of the observe signal over each block. Hence, the algorithm aims at creating the blocks of constant values in the primal vector. The dual variables can be inferred from the solution from the previous lemma.</p>
<section id="pseudo-code-and-python-implementation" class="level2">
<h2 class="anchored" data-anchor-id="pseudo-code-and-python-implementation">Pseudo-code and Python implementation</h2>
<div class="pseudocode-container quarto-float" data-line-number-punc=":" data-line-number="true" data-caption-prefix="Algorithm" data-no-end="false" data-comment-delimiter="//" data-pseudocode-number="1" data-indent-size="1.2em">
<div class="pseudocode">
\begin{algorithm} \caption{PAVA} \begin{algorithmic} \REQUIRE $y \in\mathbb{R}^n, w \in \mathbb{R}^n_{+}$ \STATE $r \leftarrow y$ \STATE $W \leftarrow y$ \STATE $J = [\{1\},\dots, \{n\}]$ \COMMENT{lists of blocks} \STATE $i=1$ (index of list start at 0 here) \WHILE{$i&lt;n$} \IF{$r_i &lt; r_{i-1}$} \COMMENT{Find adjacent violators and merge groups} \STATE $r_i \leftarrow \frac{W_i r_i + W_{i-1} r_{i-1}}{W_i + W_{i-1}}$ \STATE $W_i \leftarrow W_i + W_{i-1}$ \STATE $J_i \leftarrow J_i \cup J_{i-1}$ \STATE Remove $r_{i-1}$, $W_{i-1}$ and $J_{i-1}$ from the lists \IF{$i &gt; 1$} \STATE{$i\leftarrow i-1$} \ENDIF \ELSE \STATE{$i \leftarrow i + 1$} \ENDIF \ENDWHILE \FOR{$i=1$ to len($J$)} \STATE{$r_{J_i} \leftarrow \bar{y}_{J_i} \mathbf{1}_{J_i}$} \COMMENT{Set the block to the average value} \ENDFOR \RETURN{$r, J$} \end{algorithmic} \end{algorithm}
</div>
</div>
<p>Below you will find a simple version of the PAVA algorithm coded in Python. The <code>sklearn</code> version (in particular the <code>_isotonic.pyx</code> file, as available in October 2024, see <a href="https://github.com/scikit-learn/scikit-learn/blob/04fbe04fedda0e86e67867854900a49fb53c4c01/sklearn/_isotonic.pyx" target="_blank">source</a>). is more efficient but a little less readable.</p>
<div id="790809d5" class="cell" data-execution_count="3">
<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"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">def</span> PAVA(y, w):</span>
<span id="cb1-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;">len</span>(y)</span>
<span id="cb1-5">    r <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> y.copy()</span>
<span id="cb1-6">    ws <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> w.copy()</span>
<span id="cb1-7">    target <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [[i] <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> i <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)]</span>
<span id="cb1-8">    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>
<span id="cb1-9">    counter <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="cb1-10">    <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> n:</span>
<span id="cb1-11">        <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> r[i] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> r[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="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Find adjacent violators</span></span>
<span id="cb1-12">            <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Pool the violators</span></span>
<span id="cb1-13">            r[i] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (ws[i] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> r[i] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> ws[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> r[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> (ws[i] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> ws[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>
<span id="cb1-14">            ws[i] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+=</span> ws[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>
<span id="cb1-15">            target[i] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> target[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> target[i]</span>
<span id="cb1-16">            r.pop(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>
<span id="cb1-17">            ws.pop(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>
<span id="cb1-18">            target.pop(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>
<span id="cb1-19">            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>
<span id="cb1-20">            <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Move back one step if possible</span></span>
<span id="cb1-21">            <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> i <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>
<span id="cb1-22">                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>
<span id="cb1-23">        <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span>:</span>
<span id="cb1-24">            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>
<span id="cb1-25">            counter <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>
<span id="cb1-27">    sol <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.zeros_like(y)</span>
<span id="cb1-28">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> i, block <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;">enumerate</span>(target):</span>
<span id="cb1-29">        sol[block] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> r[i]</span>
<span id="cb1-30">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> sol, ws, target</span></code></pre></div>
</div>
<p>Below is a version of the algorithm similar to the one implemented in <code>sklearn</code> (yet in pure Python here). Moreover, it can be made an inplace method (as in <code>sklearn</code>), which is more memory efficient.</p>
<div id="f96a8df6" class="cell" data-execution_count="4">
<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="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">def</span> isotonic_regression(z, w):</span>
<span id="cb2-2">    y <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> z.copy()</span>
<span id="cb2-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>(y)</span>
<span id="cb2-4">    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>
<span id="cb2-5">    target <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>(y))</span>
<span id="cb2-6">    targets <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [target.copy()]</span>
<span id="cb2-7">    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="cb2-8">    <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> n:</span>
<span id="cb2-9">        k <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> target[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>
<span id="cb2-10">        <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> k <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> n:</span>
<span id="cb2-11">            <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">break</span></span>
<span id="cb2-12">        <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> y[i] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> y[k]:</span>
<span id="cb2-13">            <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># We are in an increasing subsequence.</span></span>
<span id="cb2-14">            i <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> k</span>
<span id="cb2-15">            targets.append(target.copy())</span>
<span id="cb2-16">            idx.append(k)</span>
<span id="cb2-17">            <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">continue</span></span>
<span id="cb2-18">        sum_wy <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> w[i] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> y[i]</span>
<span id="cb2-19">        sum_w <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> w[i]</span>
<span id="cb2-20">        <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">while</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>:</span>
<span id="cb2-21">            <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># We are within a decreasing subsequence.</span></span>
<span id="cb2-22">            prev_y <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> y[k]</span>
<span id="cb2-23">            sum_wy <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+=</span> w[k] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> y[k]</span>
<span id="cb2-24">            sum_w <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+=</span> w[k]</span>
<span id="cb2-25">            k <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> target[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>
<span id="cb2-26">            <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> k <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> n <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">or</span> prev_y <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> y[k]:</span>
<span id="cb2-27">                targets.append(target.copy())</span>
<span id="cb2-28">                idx.append(k)</span>
<span id="cb2-29"></span>
<span id="cb2-30">                <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Non-singleton decreasing subsequence is finished,</span></span>
<span id="cb2-31">                <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># update first entry.</span></span>
<span id="cb2-32">                y[i] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> sum_wy <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> sum_w</span>
<span id="cb2-33">                w[i] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> sum_w</span>
<span id="cb2-34"></span>
<span id="cb2-35">                target[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;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span></span>
<span id="cb2-36">                target[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="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> i</span>
<span id="cb2-37"></span>
<span id="cb2-38">                <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> i <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>
<span id="cb2-39">                    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Backtrack if we can.  This makes the algorithm</span></span>
<span id="cb2-40">                    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># single-pass and ensures O(n) complexity.</span></span>
<span id="cb2-41">                    i <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> target[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>
<span id="cb2-42">                <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Otherwise, restart from the same point.</span></span>
<span id="cb2-43">                <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">break</span></span>
<span id="cb2-44"></span>
<span id="cb2-45">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Reconstruct the solution.</span></span>
<span id="cb2-46">    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>
<span id="cb2-47">    <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> n:</span>
<span id="cb2-48">        k <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> target[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>
<span id="cb2-49">        y[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> : k] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> y[i]</span>
<span id="cb2-50">        i <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> k</span>
<span id="cb2-51">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> y, targets, idx</span></code></pre></div>
</div>
</section>
<section id="convergence" class="level2">
<h2 class="anchored" data-anchor-id="convergence">Convergence</h2>
<div id="thm-convergence" class="theorem">
<p><span class="theorem-title"><strong>Theorem 3 (Convergence of the PAVA algorithm)</strong></span> The PAVA algorithm converges in a finite number of iterations and output the primal solution of the isotonic regression problem.</p>
</div>
<div class="proof-container">
<div class="proof-header" onclick="toggleProof('thm-convergence')">
<p><span id="proof-arrow-thm-convergence" class="proof-arrow">▶</span> <span class="proof-title">Proof</span></p>
</div>
<div id="proof-content-thm-convergence" class="proof-content">
<p>To show the convergence we will create a dual variable <img src="https://latex.codecogs.com/png.latex?%5Calpha">, show that it is dual feasible, and that at the end of the algorithm it satisfies KKT along with the output of the PAVA algorithm.</p>
<p>For that let us first prove the following result:</p>
<p><strong>Fact 1</strong>. Let <img src="https://latex.codecogs.com/png.latex?B%20%5Cin%20J"> be a block at some stage of the algorithm. Then, <img src="https://latex.codecogs.com/png.latex?%5Cforall%20i%20%5Cin%20B,%20%5Coverline%7By%7D_%7BB%20%5Ccap%20%5Cllbracket%201,%20i%20%5Crrbracket%7D%20%5Cgeq%20%5Coverline%7By%7D_%7BB%7D%20%5Censpace.%0A"></p>
<p>To show this result, we will use induction and show that the merging process does maintain this condition. First, at initialization, the condition is true as the blocks have all size 1. Now, assume that the condition is true, and check what happen when we merge two consecutive groups <img src="https://latex.codecogs.com/png.latex?J_i"> and <img src="https://latex.codecogs.com/png.latex?J_%7Bi-1%7D"> into <img src="https://latex.codecogs.com/png.latex?B=J_%7Bi-1%7D%20%5Ccup%20J_%7Bi%7D">. First the condition is true for <img src="https://latex.codecogs.com/png.latex?J_i"> and <img src="https://latex.codecogs.com/png.latex?J_%7Bi-1%7D">, so <img src="https://latex.codecogs.com/png.latex?%5Coverline%7By%7D_%7BJ_i%20%5Ccap%20%5Cllbracket%201,%20k%20%5Crrbracket%7D%20%5Cgeq%20%5Coverline%7By%7D_%7BJ_i%7D"> and <img src="https://latex.codecogs.com/png.latex?%5Coverline%7By%7D_%7BJ_%7Bi-1%7D%20%5Ccap%20%5Cllbracket%201,%20k'%20%5Crrbracket%7D%20%5Cgeq%20%5Coverline%7By%7D_%7BJ_%7Bi-1%7D%7D"> for any <img src="https://latex.codecogs.com/png.latex?k%20%5Cin%20J_i"> and <img src="https://latex.codecogs.com/png.latex?k'%20%5Cin%20J_%7Bi-1%7D">. Then, the test <img src="https://latex.codecogs.com/png.latex?r_i%20%3C%20r_%7Bi-1%7D"> is equivalent to <img src="https://latex.codecogs.com/png.latex?%5Coverline%7By%7D_%7BJ_i%7D%20%3C%20%5Coverline%7By%7D_%7BJ_%7Bi-1%7D%7D">. So for any <img src="https://latex.codecogs.com/png.latex?k%20%5Cin%20J_%7Bi-1%7D">, we have <img src="https://latex.codecogs.com/png.latex?%5Coverline%7By%7D_%7BJ_i%20%5Ccap%20%5Cllbracket%20k,%20n%20%5Crrbracket%7D%20%5Cgeq%20%5Coverline%7By%7D_%7BJ_i%7D"> using the induction hypothesis. For <img src="https://latex.codecogs.com/png.latex?k'%5Cin%20J_%7Bi%7D">, <img src="https://latex.codecogs.com/png.latex?%5Coverline%7By%7D_%7BB%20%5Ccap%20%5Cllbracket%201,%20k%20%5Crrbracket%7D%20=%20%5Coverline%7By%7D_%7BJ_%7Bi-1%7D%20%5Ccap%20%5Cllbracket%201,%20k%20%5Crrbracket%7D%20%5Cgeq%20%5Coverline%7By%7D_%7BJ_%7Bi-1%7D%7D%20%5Cgeq%20%5Coverline%7By%7D_%7BB%7D"> (where the last inequality is due to the test <img src="https://latex.codecogs.com/png.latex?r_i%20%3C%20r_%7Bi-1%7D">). For the case <img src="https://latex.codecogs.com/png.latex?k'%20%5Cin%20J_i">, we have</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign*%7D%0A%5Coverline%7By%7D_%7BB%20%5Ccap%20%5Cllbracket%201,%20k'%20%5Crrbracket%7D%0A&amp;%20=%20%5Coverline%7By%7D_%7B%20J_%7Bi-1%7D%20%5Ccup%20(J_%7Bi%7D%20%5Ccap%20%5Cllbracket%201,%20k'%20%5Crrbracket)%7D%20%5C%5C%0A&amp;%20%5Cgeq%20%5Cfrac%7B%5CBig(%5Csum_%7B%5Cell%20%5Cin%20J_%7Bi-1%7D%7D%20w_%7B%5Cell%7D%20%5CBig)%20%5Ccdot%20%5Coverline%7By%7D_%7BJ_%7Bi-1%7D%7D%20+%20%5CBig(%5Csum_%7B%5Cell%20%5Cin%20J_%7Bi%7D%20%5Ccap%20%5Cllbracket%201,%20k'%20%5Crrbracket%7D%20w_%7B%5Cell%7D%20%5CBig)%20%5Ccdot%20%5Coverline%7By%7D_%7BJ_%7Bi%7D%20%5Ccap%20%5Cllbracket%201,%20k'%20%5Crrbracket%7D%7D%7B%5Csum_%7BJ_%7Bi-1%7D%7D%20w_i%20+%20%5Csum_%7BJ_%7Bi%7D%20%5Ccap%20%5Cllbracket%201,%20k'%20%5Crrbracket%7D%20w_i%7D%5C%5C%0A&amp;%20%5Cgeq%20%5Cfrac%7B%5CBig(%5Csum_%7B%5Cell%20%5Cin%20J_%7Bi-1%7D%7D%20w_%7B%5Cell%7D%20%5CBig)%20%5Ccdot%20%5Coverline%7By%7D_%7BJ_%7Bi-1%7D%7D%20+%20%5CBig(%5Csum_%7B%5Cell%20%5Cin%20J_%7Bi%7D%20%5Ccap%20%5Cllbracket%201,%20k'%20%5Crrbracket%7D%20w_%7B%5Cell%7D%20%5CBig)%20%5Ccdot%20%5Coverline%7By%7D_%7BJ_%7Bi%7D%7D%7D%7B%5Csum_%7BJ_%7Bi-1%7D%7D%20w_i%20+%20%5Csum_%7BJ_%7Bi%7D%20%5Ccap%20%5Cllbracket%201,%20k'%20%5Crrbracket%7D%20w_i%7D%20%5Cquad%20(%5Ctext%7Binduction%7D)%5C%5C%0A&amp;%20%5Cgeq%20%5Cfrac%7B%5CBig(%5Csum_%7B%5Cell%20%5Cin%20J_%7Bi-1%7D%7D%20w_%7B%5Cell%7D%20%5CBig)%20%5Ccdot%20%5Coverline%7By%7D_%7BJ_%7Bi-1%7D%7D%20+%20%5CBig(%5Csum_%7B%5Cell%20%5Cin%20J_%7Bi%7D%20%5Ccap%20%5Cllbracket%201,%20k'%20%5Crrbracket%7D%20w_%7B%5Cell%7D%20%5CBig)%20%5Ccdot%20%5Coverline%7By%7D_%7BJ_%7Bi%7D%7D%7D%7B%5Csum_%7BJ_%7Bi-1%7D%7D%20w_i%20+%20%5Csum_%7BJ_%7Bi%7D%20%5Ccap%20%5Cllbracket%201,%20k'%20%5Crrbracket%7D%20w_i%7D%20%5Cquad%20(%5Ctext%7BPAVA%7D)%5C%5C%0A%5Cend%7Balign*%7D%0A"> Now, remember that <img src="https://latex.codecogs.com/png.latex?%5Coverline%7By%7D_%7BB%7D%20=%20%5Cfrac%7B%5CBig(%5Csum_%7B%5Cell%20%5Cin%20J_%7Bi-1%7D%7D%20w_%7B%5Cell%7D%20%5CBig)%20%5Ccdot%20%5Coverline%7By%7D_%7BJ_%7Bi-1%7D%7D%20+%20%5CBig(%5Csum_%7B%5Cell%20%5Cin%20J_%7Bi%7D%20%7D%20w_%7B%5Cell%7D%20%5CBig)%20%5Ccdot%20%5Coverline%7By%7D_%7BJ_%7Bi%7D%7D%7D%7B%5Csum_%7BJ_%7Bi-1%7D%7D%20w_i%20+%20%5Csum_%7BJ_%7Bi%7D%7D%20w_i%7D"> and that <img src="https://latex.codecogs.com/png.latex?%5Coverline%7By%7D_%7BJ_%7Bi-1%7D%7D%20%5Cgeq%20%20%5Coverline%7By%7D_%7BB%7D%20%5Cgeq%20%5Coverline%7By%7D_%7BJ_%7Bi%7D%7D"> (since <img src="https://latex.codecogs.com/png.latex?%5Coverline%7By%7D_%7BB%7D"> is a convex combination of <img src="https://latex.codecogs.com/png.latex?%5Coverline%7By%7D_%7BJ_%7Bi-1%7D%7D"> and <img src="https://latex.codecogs.com/png.latex?%5Coverline%7By%7D_%7BJ_i%7D">), so the last inequality is true. One can check that the weight of <img src="https://latex.codecogs.com/png.latex?J_%7Bi%7D"> is larger in the definition of <img src="https://latex.codecogs.com/png.latex?%5Coverline%7By%7D_%7BB%7D"> than in the last inequality above, and so among the two convex combinations, the larger is the former. Hence, the fact is proved by induction.</p>
<p><strong>Fact 2.</strong> If you update <img src="https://latex.codecogs.com/png.latex?%5Calpha"> recursively, starting from <img src="https://latex.codecogs.com/png.latex?%5Calpha%20=%20%5Cmathbf%7B0%7D_%7Bn-1%7D"> and for if for each updated block <img src="https://latex.codecogs.com/png.latex?B%20%5Cin%20J"> you update <img src="https://latex.codecogs.com/png.latex?%5Calpha"> (as in Lemma&nbsp;3) by</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign*%7D%0A%5Cforall%20i%20%5Cin%20B,%20%5Calpha_i%20&amp;%20=%20%5CBig(%5Csum_%7Bj%20%5Cin%20B%20%5Ccap%20%5Cllbracket%201,%20i%20%5Crrbracket%7D%20w_j%20%5CBig)%5Cleft(%20%5Cbar%7By%7D_%7BB%20%5Ccap%20%5Cllbracket%201,%20i%20%5Crrbracket%7D%20-%20%5Cbar%7By%7D_%7BB%7D%5Cright)%20%5Censpace,%0A%5Cend%7Balign*%7D%0A"> then <img src="https://latex.codecogs.com/png.latex?%5Calpha"> is dual feasible for all steps of the algorithm</p>
<p>The proof is a direct consequence of Fact 1 and the fact that the weights <img src="https://latex.codecogs.com/png.latex?w_i"> are non-negative.</p>
<p><strong>Fact 3.</strong> <img src="https://latex.codecogs.com/png.latex?%5Cforall%20i%20%5Cin%20B,%20%5Calpha_i=%5Calpha_%7Bi-1%7D%20+w_i(x_i%20-%20y_i)"> (where we assume that <img src="https://latex.codecogs.com/png.latex?x_i%20=%20%5Coverline%7By%7D_B">), which means that <img src="https://latex.codecogs.com/png.latex?%5Calpha"> and <img src="https://latex.codecogs.com/png.latex?x"> hence created satsfies.</p>
<p>Again this result is simple to prove, by following the exact same line encountered in the proof of Lemma&nbsp;3.</p>
<p><strong>Fact 4.</strong> When you exit the while loop, the output of the PAVA algorithm is a primal feasible point.</p>
<p>Indeed, the only way to exist is to have all blocks mean values ordered. Hence, when the algorithm stops the primal point create (after the block averaging step) is primal feasible.</p>
<p>Leveraging Fact 1. to 4. ensures that the KKT conditions are satisfied with the primal and dual points created. Hence, at the end of the algorithm, and the optimal solution is found.</p>
</div>
</div>
</section>
<section id="duality-gap" class="level2">
<h2 class="anchored" data-anchor-id="duality-gap">Duality Gap</h2>
<p>Given a primal feasible point <img src="https://latex.codecogs.com/png.latex?x%20%5Cin%20%5Cmathcal%7BK%7D"> and a dual feasible point <img src="https://latex.codecogs.com/png.latex?%5Calpha%20%5Cin%20%5Cmathbb%7BR%7D_+%5E%7Bn-1%7D">, we can obtain upper and lower bounds on the optimal value of the primal problem .</p>
<p>Note that at optimality <img src="https://latex.codecogs.com/png.latex?W%20x%5E%5Cstar%20=%20W%20y%20-%20A%5E%5Ctop%20%5Calpha%5E%5Cstar"> Hence, using a value of <img src="https://latex.codecogs.com/png.latex?x"> at some stage of the algorithm (corresponding to a feasible <img src="https://latex.codecogs.com/png.latex?%5Calpha">), the dual reads <img src="https://latex.codecogs.com/png.latex?%5Cfrac%7B1%7D%7B2%7D%20y%5E%5Ctop%20W%20y%20-%20%5Cfrac%7B1%7D%7B2%7D%20x%5E%5Ctop%20W%20x">. For creating a primal feasible point, one can simply take the ordered version of the output, making the last element constant to create a non-decreasing vector. The later is coded in Python with the following function:</p>
<div id="a38c0d4d" class="cell" data-execution_count="5">
<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> replace_after_first_non_increasing(x, w<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>w):</span>
<span id="cb3-2">    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-3">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> i <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;">1</span>, n):</span>
<span id="cb3-4">        <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> x[i] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> x[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>
<span id="cb3-5">            mean_value <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">sum</span>(x[i:] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> w[i:]) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> np.<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">sum</span>(w[i:])</span>
<span id="cb3-6">            x[i:] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> mean_value</span>
<span id="cb3-7">            <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">break</span></span>
<span id="cb3-8">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> x</span></code></pre></div>
</div>
<p>As can be seen in the preliminary animation, the primal and dual objectives converge to the same value, which is the optimal value of the primal problem.</p>
</section>
<section id="further-reading" class="level2">
<h2 class="anchored" data-anchor-id="further-reading">Further reading</h2>
<p>For readers interested in generalization of isotonic regression (to partial orders in particular), one can check the book by <span class="citation" data-cites="robertson1988order">Robertson, Wright, and Dykstra (1988)</span>.</p>
</section>
</section>
<section id="acknowledgement" class="level1">
<h1>Acknowledgement</h1>
<p>I am grateful to Hugo Negrel for his kind help, catching a few typos in the first version of the post.</p>
</section>
<section id="references" class="level1">
<h1><i class="fa-solid fa-link" title="link" aria-label="link"></i> References</h1>
<div id="refs" class="references csl-bib-body hanging-indent" data-entry-spacing="0">
<div id="ref-Bellec_Salmon_Vaiter17" class="csl-entry">
Bellec, P. C., J. Salmon, and S. Vaiter. 2017. <span>“A Sharp Oracle Inequality for <span>Graph-Slope</span>.”</span> <em>Electron. J. Statist.</em> 11 (2): 4851–70. <a href="https://arxiv.org/pdf/1706.06977.pdf">https://arxiv.org/pdf/1706.06977.pdf</a>.
</div>
<div id="ref-Best_Chakravarti90" class="csl-entry">
Best, M. J., and N. Chakravarti. 1990. <span>“Active Set Algorithms for Isotonic Regression; a Unifying Framework.”</span> <em>Math. Programming</em> 47 (3): 425–39.
</div>
<div id="ref-Bogdan_vandenBerg_Sabatti_Su_Candes15" class="csl-entry">
Bogdan, M., E. van den Berg, C. Sabatti, W. Su, and E. J. Candès. 2015. <span>“<span class="nocase">SLOPE-adaptive</span> Variable Selection via Convex Optimization.”</span> <em>Ann. Appl. Stat.</em> 9 (3): 1103.
</div>
<div id="ref-Boyd_Vandenberghe04" class="csl-entry">
Boyd, S., and L. Vandenberghe. 2004. <em>Convex Optimization</em>. Cambridge University Press.
</div>
<div id="ref-Pedregosa13" class="csl-entry">
Pedregosa, F. 2013. <span>“Isotonic Regression.”</span> <a href="https://fa.bianp.net/blog/2013/isotonic-regression/" class="uri">https://fa.bianp.net/blog/2013/isotonic-regression/</a>.
</div>
<div id="ref-robertson1988order" class="csl-entry">
Robertson, Tim, F. T. Wright, and R. L. Dykstra. 1988. <span>“Order Restricted Statistical Inference,”</span> Wiley series in probability and mathematical statistics: Probability and mathematical statistics, xx+521.
</div>
<div id="ref-Zeng_Figueiredo14" class="csl-entry">
Zeng, X., and M. A. T. Figueiredo. 2014. <span>“<span class="nocase">The Ordered Weighted <img src="https://latex.codecogs.com/png.latex?%5Cell_1"> Norm: Atomic Formulation, Projections, and Algorithms</span>.”</span> <em>ArXiv e-Prints</em>.
</div>
</div>


<!-- -->

</section>

<div id="quarto-appendix" class="default"><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><pre class="sourceCode code-with-copy quarto-appendix-bibtex"><code class="sourceCode bibtex">@online{salmon2024,
  author = {Salmon, Joseph},
  title = {Isotonic Regression},
  date = {2024-11-10},
  url = {https://josephsalmon.eu/blog/isotonic/},
  langid = {en}
}
</code></pre></div></section></div> ]]></description>
  <category>Quadratic programming</category>
  <category>Calibration</category>
  <category>PAVA</category>
  <category>Optimization</category>
  <guid>https://josephsalmon.eu/blog/isotonic/</guid>
  <pubDate>Sat, 09 Nov 2024 23:00:00 GMT</pubDate>
  <media:content url="https://josephsalmon.eu/blog/isotonic/isotonic.png" medium="image" type="image/png" height="114" width="144"/>
</item>
<item>
  <title>LaTeX for scientific writing?</title>
  <dc:creator>Joseph Salmon</dc:creator>
  <link>https://josephsalmon.eu/blog/latex/</link>
  <description><![CDATA[ 
<div class="no-row-height column-margin column-container">
  <div class="">
    <img src="https://josephsalmon.eu/blog/latex/Tsybakov2009.svg" style="width:100%">
  </div>
</div>





<section id="history-of-latex" class="level2">
<h2 class="anchored" data-anchor-id="history-of-latex"><i class="fa-solid fa-book-open" title="an open box" aria-label="book-open"></i> History of <img src="https://latex.codecogs.com/png.latex?%5CLaTeX"></h2>
<p>First a bit of history on <img src="https://latex.codecogs.com/png.latex?%5CLaTeX"> (pronounced “Lay-tech” or “Lah-tech”). is a typesetting system that was created by Leslie Lamport in 1984. It is based on Donald Knuth’s <img src="https://latex.codecogs.com/png.latex?%5CTeX"> typesetting system. LaTeX is widely used in academia for the communication and publication of scientific documents in many fields, including mathematics, computer science, engineering, physics, chemistry, biology, and economics. LaTeX is also used in the humanities and social sciences. LaTeX is free and open-source software. It was the prototype of the modern scientific writing, and it is still the standard in many fields, especially in mathematics and computer science as it’s a good way to write equations, and to go towards <a href="https://en.wikipedia.org/wiki/Literate_programming" target="_blank">literate programming</a>.</p>
<p>As a short motivation, I will show you two books from the same author, one written before using <img src="https://latex.codecogs.com/png.latex?%5CLaTeX"> and one after. Compare the two following images (you can click on them to enlarge):</p>
<div>

</div>
<div class="quarto-layout-panel" data-layout-ncol="2">
<div class="quarto-layout-row">
<div class="quarto-layout-cell" style="flex-basis: 50.0%;justify-content: flex-start;">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><a href="Korostelev_Tsybakov93.svg" class="lightbox" data-gallery="my-gallery" title="[@Korostelev_Tsybakov93]: scientific writing before using \LaTeX"><img src="https://josephsalmon.eu/blog/latex/Korostelev_Tsybakov93.svg" class="img-fluid figure-img" width="350" alt="(Korostelëv and Tsybakov 1993): scientific writing before using \LaTeX"></a></p>
<figcaption><span class="citation" data-cites="Korostelev_Tsybakov93">(Korostelëv and Tsybakov 1993)</span>: scientific writing before using <img src="https://latex.codecogs.com/png.latex?%5CLaTeX"></figcaption>
</figure>
</div>
</div>
<div class="quarto-layout-cell" style="flex-basis: 50.0%;justify-content: flex-start;">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><a href="Tsybakov2009.svg" class="lightbox" data-gallery="my-gallery" title="[@Tsybakov09]: scientific writing after using \LaTeX"><img src="https://josephsalmon.eu/blog/latex/Tsybakov2009.svg" class="img-fluid figure-img" width="350" alt="(Tsybakov 2009): scientific writing after using \LaTeX"></a></p>
<figcaption><span class="citation" data-cites="Tsybakov09">(Tsybakov 2009)</span>: scientific writing after using <img src="https://latex.codecogs.com/png.latex?%5CLaTeX"></figcaption>
</figure>
</div>
</div>
</div>
</div>
<p>Conclusion: two books, same author, but very different scientific rendering.</p>
</section>
<section id="pros-for-latex" class="level2">
<h2 class="anchored" data-anchor-id="pros-for-latex"><i class="fa-solid fa-thumbs-up" title="a thumb up" aria-label="thumbs-up"></i> Pros for <img src="https://latex.codecogs.com/png.latex?%5CLaTeX"></h2>
<p>Below I list some of the important points that make LaTeX the standard tool for scientific writing.</p>
<section id="stability-and-reusability" class="level3">
<h3 class="anchored" data-anchor-id="stability-and-reusability">Stability and reusability</h3>
<p>First, <img src="https://latex.codecogs.com/png.latex?%5CLaTeX"> guarantees stability in time. You can re-use your files from 20 years ago without any problem (and I did!). You can extract some code you used in a draft or an article, and then use it in a presentation (<code>beamer</code>), a poster, etc., by just copy pasting.</p>
<p>Moreover for large files (<em>e.g.</em>, books), when it compiles fine, it stays fine. Ok, you might suffer to reach this point though, but that’s another story.</p>
</section>
<section id="open-source-software-and-cross-platform" class="level3">
<h3 class="anchored" data-anchor-id="open-source-software-and-cross-platform">Open-source software and cross-platform</h3>
<p><img src="https://latex.codecogs.com/png.latex?%5CLaTeX"> works fine on most operating systems (OS), for instance on</p>
<ul>
<li>Linux</li>
<li>Windows</li>
<li>MacOS</li>
</ul>
<div id="fig-os" class="quarto-layout-panel">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-os-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<div class="quarto-layout-row">
<div class="quarto-layout-cell" style="flex-basis: 33.3%;justify-content: flex-start;">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://josephsalmon.eu/blog/latex/Linux_logo.svg" class="img-fluid figure-img" width="150"></p>
<figcaption>Linux</figcaption>
</figure>
</div>
</div>
<div class="quarto-layout-cell" style="flex-basis: 33.3%;justify-content: flex-start;">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://josephsalmon.eu/blog/latex/Windows_logo.svg" class="img-fluid figure-img" width="150"></p>
<figcaption>Windows</figcaption>
</figure>
</div>
</div>
<div class="quarto-layout-cell" style="flex-basis: 33.3%;justify-content: flex-start;">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://josephsalmon.eu/blog/latex/MacOS_logo.svg" class="img-fluid figure-img" width="150"></p>
<figcaption>Mac OS</figcaption>
</figure>
</div>
</div>
</div>
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-os-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;1: <img src="https://latex.codecogs.com/png.latex?%5CLaTeX"> is friendly for multiple OS!
</figcaption>
</figure>
</div>
<p>Hence, you do not face the problem you might have met while opening a file from Word in Linux (it could be a nightmare, and you could loose information).</p>
</section>
<section id="default-language-in-scientific-writing" class="level3">
<h3 class="anchored" data-anchor-id="default-language-in-scientific-writing">Default language in scientific writing</h3>
<p><img src="https://latex.codecogs.com/png.latex?%5CLaTeX"> is widely used academia, so you will find a lot of resources and support, including templates, packages, and tutorials (see for instance <a href="https://www.overleaf.com/learn/latex/Tutorials#Overleaf_LaTeX_tutorials" target="_blank">Overleaf tutorials</a>).</p>
<p>If you don’t know a command, you can try to find it with <a href="https://detexify.kirelabs.org/classify.html" target="_blank">detexify</a>: just draw the symbol you target and look for the closest output.</p>
</section>
<section id="quality-of-the-output" class="level3">
<h3 class="anchored" data-anchor-id="quality-of-the-output">Quality of the output</h3>
<p>The quality of the output produced by <img src="https://latex.codecogs.com/png.latex?%5CLaTeX"> is very high. The typesetting is very professional, and the documents look great. This is especially important for scientific writing, where you want your work to be taken seriously. Hence, publishers often ask for <img src="https://latex.codecogs.com/png.latex?%5CLaTeX"> files for the final version of the manuscript. Hence, you will produce <code>pdf</code> files thanks to <img src="https://latex.codecogs.com/png.latex?%5CLaTeX">. Alternatives formats exist but are now mostly outdated, like <code>dvi</code> files or <code>ps</code> files.</p>
</section>
<section id="collaborative-work-git-compatibility" class="level3">
<h3 class="anchored" data-anchor-id="collaborative-work-git-compatibility">Collaborative work: git compatibility</h3>
<p>For collaborating <img src="https://latex.codecogs.com/png.latex?%5CLaTeX"> is simple to use with <code>git</code>. This is not the case if you version a <code>pdf</code> or a <code>docx</code> file for instance, as they are binary files. Hence, you can use <code>git</code> to version your work, and to collaborate with others. This is especially useful if you are working on a large document with multiple authors, as it allows you to track changes, resolve conflicts, and keep everyone on the same page. Another popular alternative is to use <a href="https://www.overleaf.com/" target="_blank">Overleaf</a>, which is an online collaborative writing and publishing tool that makes it easy to work with others on a <img src="https://latex.codecogs.com/png.latex?%5CLaTeX"> document. I do not recommend this solution much as this is proprietary, and requires a good internet connection.</p>
</section>
<section id="hyperlinks-cross-references-citations-and-bibliographies" class="level3">
<h3 class="anchored" data-anchor-id="hyperlinks-cross-references-citations-and-bibliographies">Hyperlinks, cross-references, citations, and bibliographies</h3>
<p><img src="https://latex.codecogs.com/png.latex?%5CLaTeX"> can handle hyperlinks, cross-references, citations, and bibliographies in a very efficient way. For cross-references, I recommend using the package <code>cleveref</code>, as it will simplify your life if you write a lot of equations, figures, tables, theorems, etc. Typically, this is what you will need in your Ph.D.&nbsp;or M.Sc. manuscript.</p>
<p>For bibliographies I recommend using the more modern <code>biblatex</code>, instead of <code>bibtex</code>. This prove useful if you have several bibliographies, or if you need customize a lot the way you cite your references. The Overleaf website provide a simple introduction to <a href="https://www.overleaf.com/learn/latex/Bibliography_management_with_biblatex" target="_blank">biblatex</a>.</p>
</section>
</section>
<section id="cons-for-latex" class="level2">
<h2 class="anchored" data-anchor-id="cons-for-latex"><i class="fa-solid fa-thumbs-down" title="a thumb down" aria-label="thumbs-down"></i> Cons for <img src="https://latex.codecogs.com/png.latex?%5CLaTeX"></h2>
<p>As you have understood, <img src="https://latex.codecogs.com/png.latex?%5CLaTeX"> is a great tool for scientific writing, but it is not perfect. Here are some of the cons of using <img src="https://latex.codecogs.com/png.latex?%5CLaTeX">:</p>
<section id="steep-learning-curve" class="level3">
<h3 class="anchored" data-anchor-id="steep-learning-curve">Steep learning curve</h3>
<p>The learning curve for <img src="https://latex.codecogs.com/png.latex?%5CLaTeX"> can be steep, especially if you are not familiar with programming or markup languages. However, there are many resources available online to help you learn <img src="https://latex.codecogs.com/png.latex?%5CLaTeX">, including tutorials, forums, and books.</p>
</section>
<section id="not-wysiwyg" class="level3">
<h3 class="anchored" data-anchor-id="not-wysiwyg">Not WYSIWYG</h3>
<p><img src="https://latex.codecogs.com/png.latex?%5CLaTeX"> is not a WYSIWYG (<strong>What You See Is What You Get</strong>) editor, which means that you have to write the code for your document and then compile it to see the final output. This can be frustrating for some people who are used to working with WYSIWYG editors like Microsoft Word. This is particularly annoying for very graphical documents, like posters, or presentations, where you might want to see the final rendering as you write. Hence for presentations, I would rather recommend using using <a href="https://quarto.org/" target="_blank">Quarto</a>, which is a markdown-based tool, that is lighter than <img src="https://latex.codecogs.com/png.latex?%5CLaTeX"> (though can use <img src="https://latex.codecogs.com/png.latex?%5CLaTeX"> for equations).</p>
<p>Such a drawback is also appearing with large documents. For instance, if you have a large document, you might have to compile it several times to get the references right, or to get the table of contents right. This can be time-consuming, especially if you have a slow computer. For instance, for a Ph.D.&nbsp;manuscript, a book or a very large <code>beamer</code> presentations, it can takes minutes to visualize the final output. It calls for compiling only a few chapters or a few slides at a time.</p>
</section>
<section id="debugging-is-hard-in-latex" class="level3">
<h3 class="anchored" data-anchor-id="debugging-is-hard-in-latex">Debugging is hard in <img src="https://latex.codecogs.com/png.latex?%5CLaTeX"></h3>
<p>Debugging in <img src="https://latex.codecogs.com/png.latex?%5CLaTeX"> can be difficult, especially if you are not familiar with the language. Errors can be cryptic and hard to understand, and it can take some time to figure out what went wrong (enjoy the logs!). Some tools can help you debug your <img src="https://latex.codecogs.com/png.latex?%5CLaTeX"> code, including editors with built-in error checking, or <a href="https://www.charles-deledalle.fr/pages/moosetex.php" target="_blank">MooseTeX</a>.</p>
</section>
<section id="really-many-packages" class="level3">
<h3 class="anchored" data-anchor-id="really-many-packages">(Really) Many packages</h3>
<p>There are many packages available for <img src="https://latex.codecogs.com/png.latex?%5CLaTeX">. On one hand, packages can extend the functionality of <img src="https://latex.codecogs.com/png.latex?%5CLaTeX"> and make it more powerful and versatile. On the other hand, it can be difficult to find the right package for your needs, and some packages can be incompatible with others (which can be extremely hard to diagnose). Moreover, some packages are not maintained anymore, and might not work with the latest version of <img src="https://latex.codecogs.com/png.latex?%5CLaTeX">.</p>
</section>
<section id="tables-and-figures-are-not-easy-to-handle" class="level3">
<h3 class="anchored" data-anchor-id="tables-and-figures-are-not-easy-to-handle">Tables and figures are not easy to handle</h3>
<p>For tables, consider <a href="https://www.tablesgenerator.com/" target="_blank">Tables generator</a>, as modifying a <img src="https://latex.codecogs.com/png.latex?%5CLaTeX"> table could lead to horrible results. For instance, the following code will include a table in your document:</p>
<div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb1-1">\begin{tabular}{lllll}</span>
<span id="cb1-2">    Col1  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> Col2  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span>  ...   <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> Col4 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> Col5   \<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\</span></span>
<span id="cb1-3">    oih   <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> oih   <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> oih    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span>      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> oih    \<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\</span></span>
<span id="cb1-4">    oh    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> oih   <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> oi     <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> o    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> o</span>
<span id="cb1-5">\end{tabular}</span></code></pre></div>
<p>as follows:</p>
<div id="tbl-table" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-tbl figure">
<figcaption class="quarto-float-caption-top quarto-float-caption quarto-float-tbl" id="tbl-table-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Table&nbsp;1: My first table
</figcaption>
<div aria-describedby="tbl-table-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<table class="caption-top table">
<thead>
<tr class="header">
<th>Col1</th>
<th>Col2</th>
<th>…</th>
<th>Col4</th>
<th>Col5</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>oih</td>
<td>oih</td>
<td>oih</td>
<td></td>
<td>oih</td>
</tr>
<tr class="even">
<td>oh</td>
<td>oih</td>
<td>oi</td>
<td>o</td>
<td>o</td>
</tr>
<tr class="odd">
<td>ooh</td>
<td>oh</td>
<td>oh</td>
<td>oho</td>
<td>oho</td>
</tr>
</tbody>
</table>
</div>
</figure>
</div>
<p>Note that in Markdown (the language used to write this document), you can use the following code to include a table:</p>
<div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode markdown code-with-copy"><code class="sourceCode markdown"><span id="cb2-1">| Col1  | Col2  |  ...   | Col4 | Col5    |</span>
<span id="cb2-2">|-----|-----|-----|-----|-----|</span>
<span id="cb2-3">| oih | oih | oih |     | oih |</span>
<span id="cb2-4">| oh  | oih | oi  | o   | o   |</span>
<span id="cb2-5">| ooh | oh  | oh  | oho | oho |</span></code></pre></div>
<style>
  figure {
    float: right; /* Align the figure to the right of the text. Use 'left' to align it to the left */
    margin: 0 0 1em 1em; /* Add some space around the figure */
  }
    figcaption {
    text-align: center; /* Center-align the text of the figcaption */
  }
</style>
<figure class="figure">
<a href="https://inkscape.org/"> <img id="myimage" src="https://josephsalmon.eu/blog/latex/Inkscape_logo.svg" width="150" alt="Inkscape Logo" class="figure-img"> </a>
<figcaption>
Inkscape
</figcaption>
</figure>
<p>For images, that’s a long story. See for instance <a href="https://www.overleaf.com/learn/latex/Inserting_Images" target="_blank">this post</a>. Some authors recommend using <code>tikz</code> for simple figures, and <code>pgfplots</code> for plots:I don’t. You could instead use Inkscape to draw your figures, and then export as <code>pdf</code> files, and include the outputs in your <img src="https://latex.codecogs.com/png.latex?%5CLaTeX"> document. That’s what I do, and I am happy with the result. This is WYSIWYG (when you draw), and you can easily modify your figure afterwards, and version it ( <code>svg</code> is fine for versioning, while <code>pdf</code> is not). Alternative tools could be using R or Python to generate your plots, and then include them in your <img src="https://latex.codecogs.com/png.latex?%5CLaTeX"> document.</p>
</section>
</section>
<section id="whats-next" class="level2">
<h2 class="anchored" data-anchor-id="whats-next"><i class="fa-solid fa-magnifying-glass-arrow-right" title="magnifying glass over arrow right" aria-label="magnifying-glass-arrow-right"></i> What’s next?</h2>
<p>In the last few years, some alternatives to <img src="https://latex.codecogs.com/png.latex?%5CLaTeX"> have emerged, like <a href="https://en.wikipedia.org/wiki/Markdown" target="_blank">Markdown</a>, <a href="https://quarto.org/" target="_blank">Quarto</a>, or <a href="https://rmarkdown.rstudio.com/" target="_blank">RMarkdown</a>. These tools are simpler to use than <img src="https://latex.codecogs.com/png.latex?%5CLaTeX">, and they are more WYSIWYG. using I would recommend using Markdown, RMarkdown or Quarto for writing blog posts, reports, presentations or light documents with scientific content.</p>
<p>Moreover, a recent alternative to <img src="https://latex.codecogs.com/png.latex?%5CLaTeX"> is <a href="https://typst.app/" target="_blank">Typst</a>, which is a new typesetting system that is designed to be more user-friendly and easier to use than <img src="https://latex.codecogs.com/png.latex?%5CLaTeX">. Typst is still in development, but it shows promise as a modern alternative to <img src="https://latex.codecogs.com/png.latex?%5CLaTeX">.</p>
</section>
<section id="additional-resources" class="level2">
<h2 class="anchored" data-anchor-id="additional-resources"><i class="fa-solid fa-folder-open" title="open folder" aria-label="folder-open"></i> Additional resources</h2>
<ul>
<li><a href="https://guides.nyu.edu/LaTeX/bibtex" target="_blank">Getting Started with LaTeX</a> by M. Frenkel.</li>
<li><a href="https://github.com/josephsalmon/OrganizationFiles/tree/master/tex" target="_blank">Templates, tips and tools</a> by J. Salmon.</li>
</ul>
</section>
<section id="references" class="level2">
<h2 class="anchored" data-anchor-id="references"><i class="fa-solid fa-link" title="link" aria-label="link"></i> References</h2>
<div id="refs" class="references csl-bib-body hanging-indent" data-entry-spacing="0">
<div id="ref-Korostelev_Tsybakov93" class="csl-entry">
Korostelëv, A. P., and A. B. Tsybakov. 1993. <em>Minimax Theory of Image Reconstruction</em>. Vol. 82. Lecture Notes in Statistics. New York: Springer-Verlag.
</div>
<div id="ref-Tsybakov09" class="csl-entry">
Tsybakov, A. B. 2009. <em>Introduction to Nonparametric Estimation</em>. Springer Series in Statistics. New York: Springer.
</div>
</div>


<!-- -->

</section>

<div id="quarto-appendix" class="default"><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><pre class="sourceCode code-with-copy quarto-appendix-bibtex"><code class="sourceCode bibtex">@online{salmon2024,
  author = {Salmon, Joseph},
  title = {LaTeX for Scientific Writing?},
  date = {2024-09-05},
  url = {https://josephsalmon.eu/blog/latex/},
  langid = {en}
}
</code></pre></div></section></div> ]]></description>
  <category>Latex</category>
  <category>writing</category>
  <guid>https://josephsalmon.eu/blog/latex/</guid>
  <pubDate>Wed, 04 Sep 2024 22:00:00 GMT</pubDate>
  <media:content url="https://josephsalmon.eu/blog/latex/Tsybakov2009.svg" medium="image" type="image/svg+xml"/>
</item>
<item>
  <title>Soft-max and Soft-argmax</title>
  <dc:creator>Joseph Salmon</dc:creator>
  <dc:creator>François-David Collin</dc:creator>
  <link>https://josephsalmon.eu/blog/softmax/</link>
  <description><![CDATA[ 
<div class="no-row-height column-margin column-container">
  <div class="">
    <img src="https://josephsalmon.eu/blog/softmax/softmax.png" style="width:100%">
  </div>
</div>





<p>The softmax function is a smooth approximation of the max function, and is used in many machine learning models. Similarly we can define the soft-argmax function, which is a smooth approximation of the argmax function.</p>
<section id="definition-and-notation" class="level2">
<h2 class="anchored" data-anchor-id="definition-and-notation"><i class="fa-solid fa-pencil-alt" title="pencil" aria-label="pencil-alt"></i> Definition and notation</h2>
<p>First, let us define <img src="https://latex.codecogs.com/png.latex?%5CDelta_%7BK%7D%20=%20%5C%7Bp%20%5Cin%20%5Cmathbb%7BR%7D%5EK%20%5Cgeq%200:%20%5Csum_%7Bk%7D%20p_k%20=%201%5C%7D"> the probability simplex in <img src="https://latex.codecogs.com/png.latex?%5Cmathbb%7BR%7D%5EK">, and <img src="https://latex.codecogs.com/png.latex?u_K%20=%20(1/K,%20%5Cdots,%201/K)%5E%5Ctop"> the uniform distribution in <img src="https://latex.codecogs.com/png.latex?%5CDelta_%7BK%7D">, and the standard basis vectors <img src="https://latex.codecogs.com/png.latex?(%5Cdelta_k)_%7Bk=1,%5Cdots,K%7D">, where <img src="https://latex.codecogs.com/png.latex?%5Cdelta_k%20=%20(0,%5Cdots,%5Cunderbrace%7B1%7D_%7Bk-%5Crm%7Bth%7D%7D,%5Cdots,0)%5E%5Ctop%20%5Cin%20%5Cmathbb%7BR%7D%5EK">.</p>
<p>Formally, the standard <strong>soft-argmax</strong> function <img src="https://latex.codecogs.com/png.latex?%5Csigma%20%5Ccolon%20%5Cmathbb%7BR%7D%5E%7BK%7D%20%5Cto%20(0,%201)%5E%7BK%7D">, where <img src="https://latex.codecogs.com/png.latex?K%20%5Cgeq%201">, takes a vector <img src="https://latex.codecogs.com/png.latex?z%20=%20(z_%7B1%7D,%20%5Cdots,%20z_%7BK%7D)%5E%5Ctop%20%5Cin%20%5Cmathbb%7BR%7D%5E%7BK%7D"> and computes each component of the vector <img src="https://latex.codecogs.com/png.latex?%5Csigma(z)%20%5Cin%20%5B0,%201%5D%5E%7BK%7D"> by <img src="https://latex.codecogs.com/png.latex?%0A%5Cleft(%5Csigma(z)%5Cright)_k%20=%20%5Cfrac%7B%5Cexp(z_k)%7D%7B%5Csum_%7Bk'=1%7D%5E%7BK%7D%20%5Cexp(z_%7Bk'%7D)%7D%5Censpace,%20%5Cquad%20%5Ctext%7Bfor%20%7D%20k%20=%201,%20%5Cdots,%20K.%0A"></p>
<p>Note in particular that <img src="https://latex.codecogs.com/png.latex?%5Csigma(z)=%5Csigma_%7Bu_K,%201%7D(z)"> for any <img src="https://latex.codecogs.com/png.latex?z%20%5Cin%20%5Cmathbb%7BR%7D%5EK">.</p>
<p>We also define for any <img src="https://latex.codecogs.com/png.latex?q%20%5Cin%20%5CDelta_%7BK%7D"> with positive coordinates<sup>1</sup>, <em>i.e.</em>, <img src="https://latex.codecogs.com/png.latex?q_k%3E0">, for all <img src="https://latex.codecogs.com/png.latex?k%5Cin%20%5BK%5D">, the function <img src="https://latex.codecogs.com/png.latex?%5Csigma_%7Bq,%5Cbeta%7D%20%5Ccolon%20%5Cmathbb%7BR%7D%5E%7BK%7D%20%5Cto%20%5Cmathbb%7BR%7D%5EK"> as</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cleft(%5Csigma_%7Bq,%5Cbeta%7D(z)%5Cright)_k%20=%20%5Cfrac%7Bq_k%5Cexp(z_k/%5Cbeta)%7D%7B%5Csum_%7Bk'=1%7D%5E%7BK%7D%20q_%7Bk'%7D%5Cexp(z_%7Bk'%7D/%5Cbeta)%7D%20%5Censpace,%20%5Cquad%20%5Ctext%7Bfor%20%7D%20k%20=%201,%20%5Cdots,%20K.%0A"></p>
<p>Last but not least, we introduce the real valued log-sum-exp function (or weighted <strong>softmax</strong>), defined for any vector <img src="https://latex.codecogs.com/png.latex?z%20%5Cin%20%5Cmathbb%7BR%7D%5EK"> by</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Ctext%7Blogsumexp%7D_%7Bq,%5Cbeta%7D(z)%20=%20%5Cbeta%20%5Ccdot%20%5Clog%5Cleft(%5Csum_%7Bk=1%7D%5E%7BK%7D%20q_k%20%5Ccdot%20%5Cexp(z_k/%5Cbeta)%5Cright).%0A"></p>
</section>
<section id="variational-formulation" class="level2">
<h2 class="anchored" data-anchor-id="variational-formulation"><i class="fa-solid fa-wave-square" aria-label="wave-square"></i> Variational formulation</h2>
<p>In this note we show that the soft-argmax function can be written as the conjugate of the log-sum-exp function.</p>
<div id="thm-lfgn" class="theorem">
<p><span class="theorem-title"><strong>Theorem 1</strong></span> Let <img src="https://latex.codecogs.com/png.latex?q%20%5Cin%20%5CDelta_%7BK%7D"> be with positive coordinates, <em>i.e.</em>, <img src="https://latex.codecogs.com/png.latex?q_k%3E0">, for all <img src="https://latex.codecogs.com/png.latex?k%5Cin%20%5BK%5D">, <img src="https://latex.codecogs.com/png.latex?%5Cbeta%3E0"> and let <img src="https://latex.codecogs.com/png.latex?z%20%5Cin%20%5Cmathbb%7BR%7D%5EK">. Then,</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign*%7D%0A%5Ctext%7Blogsumexp%7D_%7Bq,%5Cbeta%7D(z)%0A&amp;%20=%0A%5Cmax_%7B%20p%20%5Cin%20%5CDelta_K%7D%20%5Clangle%20z,%20p%20%5Crangle%20-%20%5Cbeta%5Csum_%7Bk=1%7D%5E%7BK%7D%20p_k%20%5Clog(p_k%20/%20q_k)%20%5C%5C%0A%5Csigma_%7Bq,%5Cbeta%7D(z)%0A&amp;%20=%0A%5Cargmax_%7B%20p%20%5Cin%20%5CDelta_K%7D%20%5Clangle%20z,%20p%20%5Crangle%20-%20%5Cbeta%5Csum_%7Bk=1%7D%5E%7BK%7D%20p_k%20%5Clog(p_k%20/%20q_k)%5Censpace.%0A%5Cend%7Balign*%7D%0A"></p>
</div>
<div class="proof-container">
<div class="proof-header" onclick="toggleProof('thm-lfgn')">
<p><span id="proof-arrow-thm-lfgn" class="proof-arrow">▶</span> <span class="proof-title">Proof</span></p>
</div>
<div id="proof-content-thm-lfgn" class="proof-content">
<p>Using Lagrange multipliers <span class="citation" data-cites="Boyd_Vandenberghe04">(see for instance Ch. 5, Boyd and Vandenberghe 2004)</span> you get for <img src="https://latex.codecogs.com/png.latex?%5CLambda=(%5Clambda_1,%5Cdots,%5Clambda_K)%5E%5Ctop">, <img src="https://latex.codecogs.com/png.latex?%5Cmu%20%5Cin%20%5Cmathbb%7BR%7D"> and <img src="https://latex.codecogs.com/png.latex?p%20%5Cin%20%5CDelta_K"> the Lagrangian function:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cmathcal%7BL%7D(p,%5Cmu,%5CLambda)%20=%20%5Clangle%20z,%20p%20%5Crangle%20-%20%5Cbeta%5Csum_%7Bk=1%7D%5E%7BK%7D%20p_k%20%5Clog(p_k%20/%20q_k)%20+%20%5Cmu%5Cleft(%5Csum_%7Bk=1%7D%5E%7BK%7D%20p_k%20-%201%5Cright)%20-%20%5Csum_%7Bk=1%7D%5E%7BK%7D%20%5Clambda_k%20p_k.%0A"></p>
<p>The Slater condition is satisfied, so the KKT conditions are necessary and sufficient for optimality. The KKT conditions are <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign*%7D%0A%5Cfrac%7B%5Cpartial%20%5Cmathcal%7BL%7D%7D%7B%5Cpartial%20p_k%7D%20&amp;=%20z_k%20-%20%5Cbeta%5Clog(p_k%20/%20q_k)%20-%20%5Cbeta%20-%20%5Cmu%20-%20%5Clambda_k%20=%200,%20%5Cquad%20k%20=%201,%20%5Cdots,%20K,%5C%5C%0A%5Cmu%5Cleft(%5Csum_%7Bk=1%7D%5E%7BK%7D%20p_k%20-%201%5Cright)%20&amp;=%200,%5C%5C%0A%5Clambda_k%20p_k%20&amp;=%200,%20%5Cquad%20k%20=%201,%20%5Cdots,%20K,%5C%5C%0Ap_k%20&amp;%5Cgeq%200,%20%5Cquad%20k%20=%201,%20%5Cdots,%20K.%0A%5Cend%7Balign*%7D%0A"> From the first KKT condition we get <img src="https://latex.codecogs.com/png.latex?%0Ap_k%20=%20q_k%5Cexp%5Cleft(%5Cfrac%7Bz_k-%5Cbeta-%5Cmu-%5Clambda_k%7D%7B%5Cbeta%7D%5Cright),%20%5Cquad%20k%20=%201,%20%5Cdots,%20K.%0A"> Now, since <img src="https://latex.codecogs.com/png.latex?%5Clambda_k%20p_k%20=%200"> and that <img src="https://latex.codecogs.com/png.latex?q_k%3E0"> for all <img src="https://latex.codecogs.com/png.latex?k">, we have that <img src="https://latex.codecogs.com/png.latex?%5Clambda_k%20=%200"> for all <img src="https://latex.codecogs.com/png.latex?k">. Thus, we get after normalisation that <img src="https://latex.codecogs.com/png.latex?%0Ap_k%20=%20%5Cfrac%7Bq_k%5Cexp(z_k/%5Cbeta)%7D%7B%5Csum_%7Bk'=1%7D%5E%7BK%7D%20q_%7Bk'%7D%5Cexp(z_%7Bk'%7D/%5Cbeta)%7D,%20%5Cquad%20k%20=%201,%20%5Cdots,%20K.%0A"> Note that <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign*%7D%0A&amp;%20p_k%20=%20%5Cfrac%7Bq_k%5Cexp(z_k/%5Cbeta)%7D%7B%5Csum_%7Bk'=1%7D%5E%7BK%7D%20q_%7Bk'%7D%5Cexp(z_%7Bk'%7D/%5Cbeta)%7D%5C%5C%0A%5Ciff%20&amp;%20%5Clog(%20p_k)%20=%20%5Clog(q_k)%20+%20%5Cfrac%7Bz_k%7D%7B%5Cbeta%7D%20-%20%5Cfrac%7B1%7D%7B%5Cbeta%7D%20%5Ccdot%20%20%5Ctext%7Blogsumexp%7D_%7Bq,%5Cbeta%7D(z).%0A%5Cend%7Balign*%7D%0A"> Finally, we have that <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign*%7D%0A%5Cbeta%5Csum_%7Bk=1%7D%5E%7BK%7D%20p_k%20%5Clog(p_k%20/%20q_k)%20&amp;=%20%5Cbeta%5Csum_%7Bk=1%7D%5E%7BK%7D%20p_k%20%5Cleft(%5Cfrac%7Bz_k%7D%7B%5Cbeta%7D%20-%20%5Cfrac%7B1%7D%7B%5Cbeta%7D%20%5Ccdot%20%5Ctext%7Blogsumexp%7D_%7Bq,%5Cbeta%7D(z)%5Cright)%5C%5C%0A&amp;=%20%5Csum_%7Bk=1%7D%5E%7BK%7D%20p_k%20z_k%20-%20%5Ctext%7Blogsumexp%7D_%7Bq,%5Cbeta%7D(z),%0A%5Cend%7Balign*%7D%0A"> Hence, <img src="https://latex.codecogs.com/png.latex?%5Csum_%7Bk=1%7D%5E%7BK%7D%20p_k%20z_k%20-%20%5Cbeta%20%5Csum_%7Bk=1%7D%5E%7BK%7D%20p_k%20%5Clog(p_k%20/%20q_k)%20=%20%5Ctext%7Blogsumexp%7D_%7Bq,%5Cbeta%7D(z)">.</p>
</div>
</div>
<p>The following limit properties for infinitesimal <img src="https://latex.codecogs.com/png.latex?%5Cbeta"> explain the naming and the regularizing property of the (temperature) parameter <img src="https://latex.codecogs.com/png.latex?%5Cbeta">:</p>
<div id="prp-soft" class="theorem proposition">
<p><span class="theorem-title"><strong>Proposition 1</strong></span> Reminding that <img src="https://latex.codecogs.com/png.latex?u_K=(1/K,%5Cdots,1/K)%5E%5Ctop"> and <img src="https://latex.codecogs.com/png.latex?%5Cdelta_%7Bk%7D"> is the <img src="https://latex.codecogs.com/png.latex?k">-th standard basis vector, for any <img src="https://latex.codecogs.com/png.latex?z%20%5Cin%20%5Cmathbb%7BR%7D%5EK">, we have that</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign*%7D%0A%5Csigma_%7Bu_K,%5Cbeta%7D(z)%20&amp;%20%5Cxrightarrow%5B%5Cbeta%20%5Cto%200%5D%7B%7D%20%20%5Cdelta_%7Bk_0%7D,%20%5Ctext%7B%20where%20%7D%20k_0=%5Cargmax_%7Bk%5Cin%20%5BK%5D%7D%20z_k%20%5C%5C%0A%5Ctext%7Blogsumexp%7D_%7Bu_K,%5Cbeta%7D(z)%20&amp;%20%5Cxrightarrow%5B%5Cbeta%20%5Cto%200%5D%7B%7D%20%5Cmax_%7Bk%5Cin%20%5BK%5D%7D%20z_k%20%5Censpace.%0A%5Cend%7Balign*%7D%0A"></p>
</div>
<p>The first limit show that the soft-argmax function is a kind of smooth approximation of the argmax function, while the log-sum-exp function is a smooth approximation of the max function.</p>
</section>
<section id="invariance-properties" class="level2">
<h2 class="anchored" data-anchor-id="invariance-properties"><i class="fa-solid fa-sync-alt" aria-label="sync-alt"></i> Invariance properties</h2>
<p>The softmax function is invariant to the addition of a constant to each component of the input vector. More precisely, we have the following result:</p>
<div id="thm-invariance" class="theorem">
<p><span class="theorem-title"><strong>Theorem 2</strong></span> Let <img src="https://latex.codecogs.com/png.latex?q%20%5Cin%20%5CDelta_%7BK%7D"> be with positive coordinates, <em>i.e.</em>, <img src="https://latex.codecogs.com/png.latex?q_k%3E0">, for all <img src="https://latex.codecogs.com/png.latex?k%5Cin%20%5BK%5D">, <img src="https://latex.codecogs.com/png.latex?%5Cbeta%3E0"> and let <img src="https://latex.codecogs.com/png.latex?z%20%5Cin%20%5Cmathbb%7BR%7D%5EK">. Then, for any <img src="https://latex.codecogs.com/png.latex?c%20%5Cin%20%5Cmathbb%7BR%7D">, we have that <img src="https://latex.codecogs.com/png.latex?%0A%5Csigma_%7Bq,%5Cbeta%7D(z)%20=%20%5Csigma_%7Bq,%5Cbeta%7D(z+c).%0A"></p>
</div>
<div class="proof-container">
<div class="proof-header" onclick="toggleProof('thm-invariance')">
<p><span id="proof-arrow-thm-invariance" class="proof-arrow">▶</span> <span class="proof-title">Proof</span></p>
</div>
<div id="proof-content-thm-invariance" class="proof-content">
<p>We have that <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign*%7D%0A%5Csigma_%7Bq,%5Cbeta%7D(z+c)_k%20&amp;=%20%5Cfrac%7Bq_k%5Cexp((z_k+c)/%5Cbeta)%7D%7B%5Csum_%7Bk'=1%7D%5E%7BK%7D%20q_%7Bk'%7D%5Cexp((z_%7Bk'%7D+c)/%5Cbeta)%7D%5C%5C%0A&amp;=%20%5Cfrac%7Bq_k%5Cexp(z_k/%5Cbeta)%5Cexp(c/%5Cbeta)%7D%7B%5Csum_%7Bk'=1%7D%5E%7BK%7D%20q_%7Bk'%7D%5Cexp(z_%7Bk'%7D/%5Cbeta)%5Cexp(c/%5Cbeta)%7D%5C%5C%0A&amp;=%20%5Cfrac%7Bq_k%5Cexp(z_k/%5Cbeta)%7D%7B%5Csum_%7Bk'=1%7D%5E%7BK%7D%20q_%7Bk'%7D%5Cexp(z_%7Bk'%7D/%5Cbeta)%7D%5C%5C%0A&amp;=%20%5Csigma_%7Bq,%5Cbeta%7D(z)_k.%0A%5Cend%7Balign*%7D%0A"></p>
</div>
</div>
<p>Let us consider also the effect of rescaling the input vector by a positive constant. We have the following result:</p>
<div id="thm-rescaling" class="theorem">
<p><span class="theorem-title"><strong>Theorem 3</strong></span> Let <img src="https://latex.codecogs.com/png.latex?q%20%5Cin%20%5CDelta_%7BK%7D"> be with positive coordinates, <em>i.e.</em>, <img src="https://latex.codecogs.com/png.latex?q_k%3E0">, for all <img src="https://latex.codecogs.com/png.latex?k%5Cin%20%5BK%5D">, <img src="https://latex.codecogs.com/png.latex?%5Cbeta%3E0"> and let <img src="https://latex.codecogs.com/png.latex?z%20%5Cin%20%5Cmathbb%7BR%7D%5EK">. Then, for any <img src="https://latex.codecogs.com/png.latex?%5Calpha%20%3E0">, we have that <img src="https://latex.codecogs.com/png.latex?%0A%5Csigma_%7Bq,%5Cbeta%7D(%5Calpha%20z)%20=%20%5Csigma_%7Bq,%5Ctfrac%7B%5Cbeta%7D%7B%5Calpha%7D%7D(z).%0A"></p>
</div>
<div class="proof-container">
<div class="proof-header" onclick="toggleProof('thm-rescaling')">
<p><span id="proof-arrow-thm-rescaling" class="proof-arrow">▶</span> <span class="proof-title">Proof</span></p>
</div>
<div id="proof-content-thm-rescaling" class="proof-content">
<p>We have that <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign*%7D%0A%5Cleft(%5Csigma_%7Bq,%5Cbeta%7D(%5Calpha%20z)%5Cright)_k%20&amp;=%20%5Cfrac%7Bq_k%5Cexp(%5Calpha%20z_k/%5Cbeta)%7D%7B%5Csum_%7Bk'=1%7D%5E%7BK%7D%20q_%7Bk'%7D%5Cexp(%5Calpha%20z_%7Bk'%7D/%5Cbeta)%7D%5C%5C%0A&amp;=%20%5Cfrac%7Bq_k%5Cexp(z_k/%5Cfrac%7B%5Cbeta%7D%7B%5Calpha%7D)%7D%7B%5Csum_%7Bk'=1%7D%5E%7BK%7D%20q_%7Bk'%7D%5Cexp(z_%7Bk'%7D/%5Cfrac%7B%5Cbeta%7D%7B%5Calpha%7D)%7D%5C%5C%0A&amp;=%20%5Cleft(%5Csigma_%7Bq,%5Ctfrac%7B%5Cbeta%7D%7B%5Calpha%7D%7D(z)%5Cright)_k.%0A%5Cend%7Balign*%7D%0A"></p>
</div>
</div>
</section>
<section id="visualization" class="level2">
<h2 class="anchored" data-anchor-id="visualization"><i class="fa-solid fa-sliders" aria-label="sliders"></i> Visualization</h2>
<p>We consider the case <img src="https://latex.codecogs.com/png.latex?K=3"> for visualization. <!-- color a word in purple with html in the following sentence--></p>
<p>You can click on the plot to move <img src="https://latex.codecogs.com/png.latex?z"> <span style="color: purple;">(the purple dot)</span>, and see the corresponding soft-argmax <img src="https://latex.codecogs.com/png.latex?%5Csigma_%7Bq,%5Cbeta%7D"> <span style="color: red;">(the red dot)</span>. You can modify <img src="https://latex.codecogs.com/png.latex?q"> (the black dot) and <img src="https://latex.codecogs.com/png.latex?%5Cbeta"> with the slider. The level sets displayed are for the function after the max in the log-sum-exp definition, <em>i.e.</em>, for a fixed <img src="https://latex.codecogs.com/png.latex?z%5Cin%20%5Cmathbb%7BR%7D%5E3">, <img src="https://latex.codecogs.com/png.latex?q%5Cin%20%5CDelta_K"> and <img src="https://latex.codecogs.com/png.latex?%5Cbeta%3E0">, the level set is the set of points <img src="https://latex.codecogs.com/png.latex?p%5Cin%20%5CDelta_K"> such that <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign*%7D%0A%5CDelta_K%20&amp;%5Cto%20%5Cmathbb%7BR%7D%20%5C%5C%0Ap%20&amp;%20%5Cmapsto%20%5Clangle%20z,%20p%20%5Crangle%20-%20%5Cbeta%5Csum_%7Bk=1%7D%5E%7BK%7D%20p_k%20%5Clog(p_k%20/%20q_k)%0A%5Cend%7Balign*%7D%0A"></p>
<details class="code-fold">
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb1" data-startfrom="243" data-source-offset="-1" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 242;"><span id="cb1-243">d3 <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;">require</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"d3@v6"</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;">"d3-hexbin@0.2"</span>)</span>
<span id="cb1-244">math <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;">require</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mathjs"</span>)</span>
<span id="cb1-245">digamma <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;">require</span>( <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-digamma@umd/browser.js'</span> )</span>
<span id="cb1-246"></span>
<span id="cb1-247"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> {legend} <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;">"@d3/color-legend"</span></span>
<span id="cb1-248"></span>
<span id="cb1-249"></span>
<span id="cb1-250">densityResolution <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>
<span id="cb1-251">margin <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;">left</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;">30</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;">top</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;">30</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;">right</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;">30</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;">bottom</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;">30</span> })</span>
<span id="cb1-252">height <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;">400</span></span>
<span id="cb1-253"></span>
<span id="cb1-254"></span>
<span id="cb1-255"></span>
<span id="cb1-256">beta <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="at" style="color: #657422;
background-color: null;
font-style: inherit;">beta</span>]</span>
<span id="cb1-257"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// lbd = [0.3,0.3,0.4]</span></span>
<span id="cb1-258"></span>
<span id="cb1-259">viewof q1 <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="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</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;">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="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="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="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tex</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`q_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="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span>})</span>
<span id="cb1-260">viewof q2 <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="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</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;">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="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="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="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tex</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`q_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;">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.01</span>})</span>
<span id="cb1-261">viewof q3 <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="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</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;">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="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="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="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tex</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`q_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;">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.01</span>})</span>
<span id="cb1-262">viewof z1 <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="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;">10</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="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;">label</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;">tex</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`z_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="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span>})</span>
<span id="cb1-263">viewof z2 <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="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;">10</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="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.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;">label</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;">tex</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`z_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;">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.01</span>})</span>
<span id="cb1-264">viewof z3 <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="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;">10</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="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.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;">label</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;">tex</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`z_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;">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.01</span>})</span>
<span id="cb1-265"></span>
<span id="cb1-266"></span>
<span id="cb1-267">viewof inputs <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;">form</span>({</span>
<span id="cb1-268">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">z1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> viewof z1<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb1-269">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">z2</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> viewof z2<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb1-270">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">z3</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> viewof z3<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb1-271">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">beta</span><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="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</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="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;">label</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;">tex</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;">\b</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">eta`</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="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span>})<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb1-272">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">q1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> viewof q1<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb1-273">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">q2</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> viewof q2<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb1-274">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">q3</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> viewof q3<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb1-275">})</span>
<span id="cb1-276"></span>
<span id="cb1-277">q <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [q1<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> q2<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> q3]</span>
<span id="cb1-278">z <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [z1<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> z2<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> z3]</span>
<span id="cb1-279"></span>
<span id="cb1-280">logsumexp <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (x<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> alpha<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> beta) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb1-281">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> result <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="cb1-282">  <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;">0</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> x<span 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>) result <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+=</span> alpha[i] <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;">exp</span>(x[i] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> beta)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-283">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> beta <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;">log</span>(result)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-284">}</span>
<span id="cb1-285"></span>
<span id="cb1-286"></span>
<span id="cb1-287">objective <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (x<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> z<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> alpha<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> beta) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb1-288">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> result <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="cb1-289">  <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;">0</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> x<span 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>) result <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-=</span> beta <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> x[i] <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;">log</span>(x[i] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> alpha[i])<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-290">  <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;">0</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> x<span 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>) result <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+=</span> x[i] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> z[i]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-291">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> result<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-292">}</span>
<span id="cb1-293"></span>
<span id="cb1-294"></span>
<span id="cb1-295">kull_leibler <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (x<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> alpha<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> beta) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb1-296">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> result <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="cb1-297">  <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;">0</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> x<span 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>) result <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-=</span> x[i] <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;">log</span>(x[i] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> alpha[i])<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-298">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> beta <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> result<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-299">}</span>
<span id="cb1-300"></span>
<span id="cb1-301"></span>
<span id="cb1-302">softmax <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (x<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> alpha<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> beta) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb1-303">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> result <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="cb1-304">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> sum <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="cb1-305">  <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;">0</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> x<span 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="cb1-306">    result<span 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>(alpha[i] <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;">exp</span>(x[i] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> beta))<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-307">    sum <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+=</span> result[i]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-308">  }</span>
<span id="cb1-309">  <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;">0</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> x<span 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>) result[i] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/=</span> sum<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-310">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> result<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-311">}</span>
<span id="cb1-312"></span>
<span id="cb1-313"><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;">cartesianToBarycentric</span>(x<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> y<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> corners) {</span>
<span id="cb1-314">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> A <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> corners[<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="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> corners[<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> C <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> corners[<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-315">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> v0 <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> 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;">x</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</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;">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> 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;">y</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</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;">y</span> }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-316">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> v1 <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> 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;">x</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</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;">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> 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;">y</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</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;">y</span> }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-317">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> v2 <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> x <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</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;">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> y <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</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;">y</span> }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-318"></span>
<span id="cb1-319">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> d00 <span 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>(v0<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> v0)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-320">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> d01 <span 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>(v0<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> v1)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-321">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> d11 <span 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>(v1<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> v1)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-322">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> d20 <span 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>(v2<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> v0)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-323">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> d21 <span 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>(v2<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> v1)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-324">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> denom <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> d00 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> d11 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> d01 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> d01<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-325"></span>
<span id="cb1-326">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> lambda1 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (d11 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> d20 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> d01 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> d21) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> denom<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-327">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> lambda2 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (d00 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> d21 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> d01 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> d20) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> denom<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-328">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> lambda3 <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="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> lambda1 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> lambda2<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-329"></span>
<span id="cb1-330">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> [lambda1<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> lambda2<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> lambda3]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-331">}</span>
<span id="cb1-332"></span>
<span id="cb1-333"><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;">barycentricToCartesian</span>(q<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> corners) {</span>
<span id="cb1-334">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> [</span>
<span id="cb1-335">    corners[<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="at" style="color: #657422;
background-color: null;
font-style: inherit;">x</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> q[<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> corners[<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;">x</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> q[<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> corners[<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="at" style="color: #657422;
background-color: null;
font-style: inherit;">x</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> q[<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-336">    corners[<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="at" style="color: #657422;
background-color: null;
font-style: inherit;">y</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> q[<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> corners[<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;">y</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> q[<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> corners[<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="at" style="color: #657422;
background-color: null;
font-style: inherit;">y</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> q[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>]</span>
<span id="cb1-337">  ]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-338">}</span>
<span id="cb1-339"></span>
<span id="cb1-340"><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;">dot</span>(v1<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> v2) {</span>
<span id="cb1-341">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> v1<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> v2<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> v1<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> v2<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-342">}</span>
<span id="cb1-343"></span>
<span id="cb1-344">ternaryDensity <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (density<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> resolution<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> options<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> lbd) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb1-345">  options <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>
<span id="cb1-346">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">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;">400</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb1-347">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">margin</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;">left</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;">30</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;">top</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;">30</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;">right</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;">30</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;">bottom</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;">30</span> }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb1-348">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">colorScheme</span><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="at" style="color: #657422;
background-color: null;
font-style: inherit;">interpolateBlues</span></span>
<span id="cb1-349">  }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> options)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-350"></span>
<span id="cb1-351"></span>
<span id="cb1-352">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> fillScale <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;">scaleSequential</span>(options<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colorScheme</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;">domain</span>([<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span></span>
<span id="cb1-353">  <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;">log</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;">max</span>(q[<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>q[<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>q[<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-354">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// const fillScale = d3.scaleSequential(options.colorScheme).domain(d3.extent(density.map(d =&gt; d.density)))</span></span>
<span id="cb1-355"></span>
<span id="cb1-356">  <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="cb1-357">    <span 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> options<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size</span>)</span>
<span id="cb1-358">    <span 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> options<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-359"></span>
<span id="cb1-360">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> x <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;">scaleLinear</span>()</span>
<span id="cb1-361">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">domain</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="cb1-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;">range</span>([options<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">margin</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> options<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> options<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">margin</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;">right</span>])</span>
<span id="cb1-363"></span>
<span id="cb1-364">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> y <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;">scaleLinear</span>()</span>
<span id="cb1-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;">domain</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="cb1-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;">range</span>([options<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> options<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">margin</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;">bottom</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> options<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">margin</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></span>
<span id="cb1-367"></span>
<span id="cb1-368"></span>
<span id="cb1-369">  <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;">inverseScaleX</span>(value) {</span>
<span id="cb1-370">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// Constants from the original scale</span></span>
<span id="cb1-371">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> domainMin <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="cb1-372">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> domainMax <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="cb1-373">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> rangeMin <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> options<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">margin</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></span>
<span id="cb1-374">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> rangeMax <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> options<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> options<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">margin</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;">right</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-375"></span>
<span id="cb1-376">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// Calculate the proportion of the input value within the range</span></span>
<span id="cb1-377">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> proportion <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (value <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> rangeMin) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> (rangeMax <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> rangeMin)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-378"></span>
<span id="cb1-379">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// Apply the proportion to the domain</span></span>
<span id="cb1-380">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> proportion <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> (domainMax <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> domainMin) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> domainMin<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-381">  }</span>
<span id="cb1-382"></span>
<span id="cb1-383">  <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;">inverseInverseScaleX</span>(value) {</span>
<span id="cb1-384">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// Constants from the original scale</span></span>
<span id="cb1-385">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> domainMin <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="cb1-386">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> domainMax <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="cb1-387">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> rangeMin <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> options<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> options<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">margin</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;">right</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-388">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> rangeMax <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> options<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">margin</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></span>
<span id="cb1-389"></span>
<span id="cb1-390">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// Calculate the proportion of the input value within the range</span></span>
<span id="cb1-391">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> proportion <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (rangeMax <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> rangeMin)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-392"></span>
<span id="cb1-393">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// Apply the proportion to the domain</span></span>
<span id="cb1-394">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> rangeMax <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> proportion <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> value <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-395">  }</span>
<span id="cb1-396"></span>
<span id="cb1-397">  <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;">inverseScaleY</span>(value) {</span>
<span id="cb1-398">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// Constants from the original scale</span></span>
<span id="cb1-399">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> domainMin <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="cb1-400">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> domainMax <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="cb1-401">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> rangeMin <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> options<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> options<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">margin</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;">bottom</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-402">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> rangeMax <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> options<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">margin</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></span>
<span id="cb1-403"></span>
<span id="cb1-404">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// Calculate the proportion of the input value within the range</span></span>
<span id="cb1-405">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> proportion <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (value <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> rangeMin) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> (rangeMax <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> rangeMin)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-406"></span>
<span id="cb1-407"></span>
<span id="cb1-408">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// Apply the proportion to the domain</span></span>
<span id="cb1-409">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> proportion <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> (domainMax <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> domainMin) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> domainMin<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-410">  }</span>
<span id="cb1-411"></span>
<span id="cb1-412">  <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;">inverseInverseScaleY</span>(value) {</span>
<span id="cb1-413">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// Constants from the original scale</span></span>
<span id="cb1-414">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> domainMin <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="cb1-415">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> domainMax <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="cb1-416">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> rangeMin <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> options<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> options<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">margin</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;">bottom</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-417">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> rangeMax <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> options<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">margin</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></span>
<span id="cb1-418"></span>
<span id="cb1-419">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// Calculate the proportion of the input value within the range</span></span>
<span id="cb1-420">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> proportion <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (rangeMax <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> rangeMin)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-421"></span>
<span id="cb1-422">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// Apply the proportion to the domain</span></span>
<span id="cb1-423">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> proportion <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> value <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> rangeMin<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-424">  }</span>
<span id="cb1-425"></span>
<span id="cb1-426"></span>
<span id="cb1-427"></span>
<span id="cb1-428">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> axisBottom <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> g <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;">call</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;">axisBottom</span>(x)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ticks</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>))</span>
<span id="cb1-429">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> axisTop <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> g <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;">call</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;">axisTop</span>(x)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ticks</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="cb1-430"></span>
<span id="cb1-431">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> hexagonSize <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ((<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">x</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> resolution)) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">x</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="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;">cos</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 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>) <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="cb1-432"></span>
<span id="cb1-433">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> corners <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="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 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="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;">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;">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;">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;">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;">y</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;">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> <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="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="cb1-434">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> corners_expanded <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="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 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="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;">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;">2</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 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="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 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="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</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="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="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.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;">y</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="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>
<span id="cb1-435"></span>
<span id="cb1-436">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> line <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;">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;">x</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;">x</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;">x</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;">y</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;">y</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;">y</span>))<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-437"></span>
<span id="cb1-438">  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;">'defs'</span>)</span>
<span id="cb1-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;">append</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'clipPath'</span>)</span>
<span id="cb1-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;">attr</span>(<span class="st" style="color: #20794D;
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;">'triangle'</span>)</span>
<span id="cb1-441">    <span 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;">'path'</span>)</span>
<span id="cb1-442">    <span 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> options<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">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;">2</span>)</span>
<span id="cb1-443">    <span 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> options<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">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;">2</span>)</span>
<span id="cb1-444">    <span 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;">'d'</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;">line</span>(corners))</span>
<span id="cb1-445"></span>
<span id="cb1-446">  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;">selectAll</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'.border'</span>)</span>
<span id="cb1-447">    <span 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>([[corners[<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> corners[<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="cb1-448">           [corners[<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> corners[<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-449">           [corners[<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> corners[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>]]])</span>
<span id="cb1-450">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">enter</span>()</span>
<span id="cb1-451">    <span 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>
<span id="cb1-452">    <span 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> (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;">x</span>(d[<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="at" style="color: #657422;
background-color: null;
font-style: inherit;">x</span>))</span>
<span id="cb1-453">    <span 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> (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;">x</span>(d[<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;">x</span>))</span>
<span id="cb1-454">    <span 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> (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;">y</span>(d[<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="at" style="color: #657422;
background-color: null;
font-style: inherit;">y</span>))</span>
<span id="cb1-455">    <span 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> (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;">y</span>(d[<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;">y</span>))</span>
<span id="cb1-456">    <span 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;">'border'</span>)</span>
<span id="cb1-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;">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> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'black'</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-458"></span>
<span id="cb1-459">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> hexbin <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;">hexbin</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-460"></span>
<span id="cb1-461">  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>
<span id="cb1-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;">'clip-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;">'url(#triangle)'</span>)</span>
<span id="cb1-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;">selectAll</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".point"</span>)</span>
<span id="cb1-464">    <span 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>(density)</span>
<span id="cb1-465">    <span 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;">'path'</span>)</span>
<span id="cb1-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;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'transform'</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="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`translate(</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;">x</span>(corners[<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="at" style="color: #657422;
background-color: null;
font-style: inherit;">x</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;">x</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> corners[<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;">x</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;">x</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> corners[<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="at" style="color: #657422;
background-color: null;
font-style: inherit;">x</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;">x</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><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">y</span>(corners[<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="at" style="color: #657422;
background-color: null;
font-style: inherit;">y</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;">x</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> corners[<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;">y</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;">x</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> corners[<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="at" style="color: #657422;
background-color: null;
font-style: inherit;">y</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;">x</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>
<span id="cb1-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;">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;">fillScale</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;">density</span>))</span>
<span id="cb1-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;">'d'</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> hexbin<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">hexagon</span>(hexagonSize))<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-469"></span>
<span id="cb1-470">  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;">selectAll</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'text'</span>)</span>
<span id="cb1-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;">data</span>([[corners_expanded[<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> corners_expanded[<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="cb1-472">           [corners_expanded[<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> corners_expanded[<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-473">           [corners_expanded[<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> corners_expanded[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>]]])</span>
<span id="cb1-474">    <span 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="cb1-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;">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="cb1-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;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"alignment-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;">"middle"</span>)</span>
<span id="cb1-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;">"font-style"</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;">"italic"</span>)</span>
<span id="cb1-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;">"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> (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">x</span>(d[<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="at" style="color: #657422;
background-color: null;
font-style: inherit;">x</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;">x</span>(d[<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;">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;">2</span>)</span>
<span id="cb1-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;">"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> (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">y</span>(d[<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="at" style="color: #657422;
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;">y</span>(d[<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;">y</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="cb1-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;">text</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="cb1-481">      <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</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="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</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="cb1-482">      <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</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="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</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="cb1-483">      <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</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;">2</span>) <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</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="cb1-484">    })</span>
<span id="cb1-485"></span>
<span id="cb1-486">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> xy <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">barycentricToCartesian</span>(z<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> corners)</span>
<span id="cb1-487">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> xyr <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">inverseInverseScaleX</span>(xy[<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;">inverseInverseScaleY</span>(xy[<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="cb1-488"></span>
<span id="cb1-489">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> xy_q <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">barycentricToCartesian</span>(q<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> corners)</span>
<span id="cb1-490">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> xyr_q <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">inverseInverseScaleX</span>(xy_q[<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;">inverseInverseScaleY</span>(xy_q[<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="cb1-491"></span>
<span id="cb1-492">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> sftmax <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">softmax</span>([z1<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> z2<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> z3]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> q<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> beta)</span>
<span id="cb1-493">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> xy_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;">barycentricToCartesian</span>(sftmax<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> corners)</span>
<span id="cb1-494">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> xyr_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;">inverseInverseScaleX</span>(xy_s[<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;">inverseInverseScaleY</span>(xy_s[<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="cb1-495"></span>
<span id="cb1-496">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// If it does not exist, append a new red circle</span></span>
<span id="cb1-497">    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;">"circle"</span>)</span>
<span id="cb1-498">      <span 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;">"red-circle"</span>) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// Add a class for easy selection</span></span>
<span id="cb1-499">      <span 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;">"cx"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> xyr_s[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>])</span>
<span id="cb1-500">      <span 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;">"cy"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> xyr_s[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>])</span>
<span id="cb1-501">      <span 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;">"z-index"</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;">1000</span>)</span>
<span id="cb1-502">      <span 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;">"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="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// Radius of the circle</span></span>
<span id="cb1-503">      <span 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> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"red"</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;">// Fill color of the circle</span></span>
<span id="cb1-504"></span>
<span id="cb1-505">    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;">"circle"</span>)</span>
<span id="cb1-506">      <span 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;">"purple-circle"</span>) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// Add a class for easy selection</span></span>
<span id="cb1-507">      <span 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;">"cx"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> xyr[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>])</span>
<span id="cb1-508">      <span 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;">"cy"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> xyr[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>])</span>
<span id="cb1-509">      <span 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;">"z-index"</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;">1000</span>)</span>
<span id="cb1-510">      <span 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;">"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="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// Radius of the circle</span></span>
<span id="cb1-511">      <span 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> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"purple"</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;">// Fill color of the circle</span></span>
<span id="cb1-512"></span>
<span id="cb1-513"></span>
<span id="cb1-514">    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;">"circle"</span>)</span>
<span id="cb1-515">      <span 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;">"black-circle"</span>) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// Add a class for easy selection</span></span>
<span id="cb1-516">      <span 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;">"cx"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> xyr_q[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>])</span>
<span id="cb1-517">      <span 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;">"cy"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> xyr_q[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>])</span>
<span id="cb1-518">      <span 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;">"z-index"</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;">1000</span>)</span>
<span id="cb1-519">      <span 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;">"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="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// Radius of the circle</span></span>
<span id="cb1-520">      <span 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> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"black"</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;">// Fill color of the circle</span></span>
<span id="cb1-521"></span>
<span id="cb1-522"></span>
<span id="cb1-523">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// Append text for the coordinates</span></span>
<span id="cb1-524">    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;">"text"</span>)</span>
<span id="cb1-525">      <span 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;">"coord-text"</span>) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// Add a class for easy selection</span></span>
<span id="cb1-526">      <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// .attr("x", xyr[0] + 10) // Position the text right next to the circle</span></span>
<span id="cb1-527">      <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// .attr("y", xyr[1])</span></span>
<span id="cb1-528">      <span 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> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">300</span>) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// Position the text right next to the circle</span></span>
<span id="cb1-529">      <span 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> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">80</span>)</span>
<span id="cb1-530">      <span 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> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"black"</span>) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// Text color</span></span>
<span id="cb1-531">      <span 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;">"font-size"</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;">"10px"</span>)</span>
<span id="cb1-532">      <span 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 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>q[<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;">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>q[<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;">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>q[<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;">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 class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// Display coordinates</span></span>
<span id="cb1-533">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// Append color legend for purple-circle and red-circle:</span></span>
<span id="cb1-534"></span>
<span id="cb1-535"></span>
<span id="cb1-536">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// Append text for the coordinates</span></span>
<span id="cb1-537">    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;">"text"</span>)</span>
<span id="cb1-538">      <span 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;">"coord-text"</span>) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// Add a class for easy selection</span></span>
<span id="cb1-539">      <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// .attr("x", xyr[0] + 10) // Position the text right next to the circle</span></span>
<span id="cb1-540">      <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// .attr("y", xyr[1])</span></span>
<span id="cb1-541">      <span 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> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">300</span>) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// Position the text right next to the circle</span></span>
<span id="cb1-542">      <span 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> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>)</span>
<span id="cb1-543">      <span 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> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"red"</span>) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// Text color</span></span>
<span id="cb1-544">      <span 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;">"font-size"</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;">"10px"</span>)</span>
<span id="cb1-545">      <span 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 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>sftmax[<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;">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>sftmax[<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;">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>sftmax[<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;">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 class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// Display coordinates</span></span>
<span id="cb1-546">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// Append color legend for purple-circle and red-circle:</span></span>
<span id="cb1-547"></span>
<span id="cb1-548">    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;">"text"</span>)</span>
<span id="cb1-549">      <span 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;">"coord-text"</span>) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// Add a class for easy selection</span></span>
<span id="cb1-550">      <span 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> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">300</span>) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// Position the text right next to the circle</span></span>
<span id="cb1-551">      <span 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> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">120</span>)</span>
<span id="cb1-552">      <span 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> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"purple"</span>) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// Text color</span></span>
<span id="cb1-553">      <span 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;">"font-size"</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;">"10px"</span>)</span>
<span id="cb1-554">      <span 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 class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`z=(</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>z1<span 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>z2<span 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>z3<span 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 class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// Display coordinates</span></span>
<span id="cb1-555"></span>
<span id="cb1-556"></span>
<span id="cb1-557">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> removeLine <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> g <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;">select</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".domain"</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="cb1-558"></span>
<span id="cb1-559"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">set</span>(input<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> value) {</span>
<span id="cb1-560">  input<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">value</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> value<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-561">  input<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dispatchEvent</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;">Event</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;">bubbles</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="cb1-562">}</span>
<span id="cb1-563"></span>
<span id="cb1-564"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// Attach a click event listener to the SVG</span></span>
<span id="cb1-565">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;">"click"</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>(<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">event</span>) {</span>
<span id="cb1-566">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// Extract the click coordinates</span></span>
<span id="cb1-567">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> [clickX<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> clickY] <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;">pointer</span>(<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">event</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-568">  lbd <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cartesianToBarycentric</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">inverseScaleX</span>(clickX)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">inverseScaleY</span>(clickY)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> corners)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-569"></span>
<span id="cb1-570">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">set</span>(viewof z1<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> lbd[<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-571">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">set</span>(viewof z2<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> lbd[<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="cb1-572">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">set</span>(viewof z3<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> lbd[<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="cb1-573">})<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-574"></span>
<span id="cb1-575"> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// display axis values</span></span>
<span id="cb1-576">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>
<span id="cb1-577">    <span 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;">"transform"</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;">`translate(0, </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>options<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> options<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">margin</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;">bottom</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="cb1-578">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">call</span>(axisBottom)</span>
<span id="cb1-579">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">call</span>(removeLine)</span>
<span id="cb1-580"></span>
<span id="cb1-581">  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>
<span id="cb1-582">    <span 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;">"transform"</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;">`translate(</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;">x</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> options<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">margin</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;">right</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="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><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">y</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;">26</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;">) rotate(-120)`</span>)</span>
<span id="cb1-583">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">call</span>(axisBottom)</span>
<span id="cb1-584">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">call</span>(removeLine)</span>
<span id="cb1-585">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">call</span>(g <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;">selectAll</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;">"transform"</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;">"translate(11, 22) rotate(120)"</span>))<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-586"></span>
<span id="cb1-587">  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>
<span id="cb1-588">    <span 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;">"transform"</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;">`translate(</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;">x</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> options<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">margin</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> <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><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">y</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;">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;">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;">26</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;">) rotate(120)`</span>)</span>
<span id="cb1-589">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">call</span>(axisBottom)</span>
<span id="cb1-590">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">call</span>(removeLine)</span>
<span id="cb1-591">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">call</span>(g <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;">selectAll</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;">"transform"</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;">"translate(-11, 22) rotate(-120)"</span>))<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-592"></span>
<span id="cb1-593">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</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="cb1-594">}</span>
<span id="cb1-595"></span>
<span id="cb1-596"></span>
<span id="cb1-597">levelLogsumexp <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> {</span>
<span id="cb1-598">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> density <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="cb1-599">  <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> densityResolution<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="cb1-600">    <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> 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> j <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> densityResolution <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>
<span id="cb1-601">      <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> x1 <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> densityResolution <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-602">      <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> x2 <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> densityResolution<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-603">      <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> x3 <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;">max</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> x1 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> x2)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-604">      <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> x <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [ x1<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> x2<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> x3 ]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-605"></span>
<span id="cb1-606">      density<span 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>({ x<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;">density</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;">logsumexp</span>(x<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> q<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> beta) })<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-607">    }</span>
<span id="cb1-608">  }</span>
<span id="cb1-609">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> density<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-610">}</span>
<span id="cb1-611"></span>
<span id="cb1-612">levelKL <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> {</span>
<span id="cb1-613">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> density <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="cb1-614">  <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> densityResolution<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="cb1-615">    <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> 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> j <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> densityResolution <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>
<span id="cb1-616">      <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> x1 <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> densityResolution <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-617">      <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> x2 <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> densityResolution<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-618">      <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> x3 <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;">max</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> x1 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> x2)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-619">      <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> x <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [ x1<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> x2<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> x3 ]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-620"></span>
<span id="cb1-621">      <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// density.push({ x, density: logsumexp(x, q, beta) / Math.log(Math.max(q[0],q[1], q[2]) * Math.exp(1/beta)) });</span></span>
<span id="cb1-622">      density<span 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>({ x<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;">density</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;">kull_leibler</span>(x<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> q<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> beta) })<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-623">    }</span>
<span id="cb1-624">  }</span>
<span id="cb1-625">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> density<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-626">}</span>
<span id="cb1-627"></span>
<span id="cb1-628"></span>
<span id="cb1-629">levelKL_full <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> {</span>
<span id="cb1-630">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> density <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="cb1-631">  <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> densityResolution<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="cb1-632">    <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> 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> j <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> densityResolution <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>
<span id="cb1-633">      <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> x1 <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> densityResolution <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-634">      <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> x2 <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> densityResolution<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-635">      <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> x3 <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;">max</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> x1 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> x2)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-636">      <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> x <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [ x1<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> x2<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> x3 ]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-637"></span>
<span id="cb1-638">      <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// density.push({ x, density: logsumexp(x, q, beta) / Math.log(Math.max(q[0],q[1], q[2]) * Math.exp(1/beta)) });</span></span>
<span id="cb1-639">      density<span 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>({ x<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;">density</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;">objective</span>(x<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> z<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> q<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> beta) })<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-640">    }</span>
<span id="cb1-641">  }</span>
<span id="cb1-642">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> density<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-643">}</span>
<span id="cb1-644"></span>
<span id="cb1-645"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ternaryDensity</span>(levelKL_full<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> densityResolution<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;">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;">500</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;">colorScheme</span><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="at" style="color: #657422;
background-color: null;
font-style: inherit;">interpolateBlues</span>})</span>
<span id="cb1-646">logsumexpColorScale <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">legend</span>({<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> 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;">scaleSequential</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;">extent</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;">logsumexp</span>(z<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> q<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> beta)])<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="at" style="color: #657422;
background-color: null;
font-style: inherit;">interpolateBlues</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;">title</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;">"Intensity"</span>})</span></code></pre></div>
</details>
<div class="cell quarto-layout-panel" data-layout-ncol="1" data-layout-align="left">
<div class="quarto-layout-row">
<div class="quarto-layout-cell" style="flex-basis: 100.0%;justify-content: flex-start;">
<div id="ojs-cell-1-1" data-nodetype="declaration">

</div>
</div>
</div>
<div class="quarto-layout-row">
<div class="quarto-layout-cell" style="flex-basis: 100.0%;justify-content: flex-start;">
<div id="ojs-cell-1-2" data-nodetype="declaration">

</div>
</div>
</div>
<div class="quarto-layout-row">
<div class="quarto-layout-cell" style="flex-basis: 100.0%;justify-content: flex-start;">
<div id="ojs-cell-1-3" data-nodetype="declaration">

</div>
</div>
</div>
<div class="quarto-layout-row">
<div class="quarto-layout-cell" style="flex-basis: 100.0%;justify-content: flex-start;">
<div id="ojs-cell-1-4" data-nodetype="declaration">

</div>
</div>
</div>
<div class="quarto-layout-row">
<div class="quarto-layout-cell" style="flex-basis: 100.0%;justify-content: flex-start;">
<div id="ojs-cell-1-5" data-nodetype="declaration">

</div>
</div>
</div>
<div class="quarto-layout-row">
<div class="quarto-layout-cell" style="flex-basis: 100.0%;justify-content: flex-start;">
<div id="ojs-cell-1-6" data-nodetype="declaration">

</div>
</div>
</div>
<div class="quarto-layout-row">
<div class="quarto-layout-cell" style="flex-basis: 100.0%;justify-content: flex-start;">
<div id="ojs-cell-1-7" data-nodetype="declaration">

</div>
</div>
</div>
<div class="quarto-layout-row">
<div class="quarto-layout-cell" style="flex-basis: 100.0%;justify-content: flex-start;">
<div id="ojs-cell-1-8" data-nodetype="declaration">

</div>
</div>
</div>
<div class="quarto-layout-row">
<div class="quarto-layout-cell" style="flex-basis: 100.0%;justify-content: flex-start;">
<div id="ojs-cell-1-9" data-nodetype="declaration">

</div>
</div>
</div>
<div class="quarto-layout-row">
<div class="quarto-layout-cell" style="flex-basis: 100.0%;justify-content: flex-start;">
<div id="ojs-cell-1-10" data-nodetype="declaration">

</div>
</div>
</div>
<div class="quarto-layout-row">
<div class="quarto-layout-cell" style="flex-basis: 100.0%;justify-content: flex-start;">
<div id="ojs-cell-1-11" data-nodetype="declaration">

</div>
</div>
</div>
<div class="quarto-layout-row">
<div class="quarto-layout-cell" style="flex-basis: 100.0%;justify-content: flex-start;">
<div id="ojs-cell-1-12" data-nodetype="declaration">

</div>
</div>
</div>
<div class="quarto-layout-row">
<div class="quarto-layout-cell" style="flex-basis: 100.0%;justify-content: flex-start;">
<div id="ojs-cell-1-13" data-nodetype="declaration">

</div>
</div>
</div>
<div class="quarto-layout-row">
<div class="quarto-layout-cell" style="flex-basis: 100.0%;justify-content: flex-start;">
<div id="ojs-cell-1-14" data-nodetype="declaration">

</div>
</div>
</div>
<div class="quarto-layout-row">
<div class="quarto-layout-cell" style="flex-basis: 100.0%;justify-content: flex-start;">
<div id="ojs-cell-1-15" data-nodetype="declaration">

</div>
</div>
</div>
<div class="quarto-layout-row">
<div class="quarto-layout-cell" style="flex-basis: 100.0%;justify-content: flex-start;">
<div id="ojs-cell-1-16" data-nodetype="declaration">

</div>
</div>
</div>
<div class="quarto-layout-row">
<div class="quarto-layout-cell" style="flex-basis: 100.0%;justify-content: flex-start;">
<div id="ojs-cell-1-17" data-nodetype="declaration">

</div>
</div>
</div>
<div class="quarto-layout-row">
<div class="quarto-layout-cell" style="flex-basis: 100.0%;justify-content: flex-start;">
<div id="ojs-cell-1-18" data-nodetype="declaration">

</div>
</div>
</div>
<div class="quarto-layout-row">
<div class="quarto-layout-cell" style="flex-basis: 100.0%;justify-content: flex-start;">
<div id="ojs-cell-1-19" data-nodetype="declaration">

</div>
</div>
</div>
<div class="quarto-layout-row">
<div class="quarto-layout-cell" style="flex-basis: 100.0%;justify-content: flex-start;">
<div id="ojs-cell-1-20" data-nodetype="declaration">

</div>
</div>
</div>
<div class="quarto-layout-row">
<div class="quarto-layout-cell" style="flex-basis: 100.0%;justify-content: flex-start;">
<div id="ojs-cell-1-21" data-nodetype="declaration">

</div>
</div>
</div>
<div class="quarto-layout-row">
<div class="quarto-layout-cell" style="flex-basis: 100.0%;justify-content: flex-start;">
<div id="ojs-cell-1-22" data-nodetype="declaration">

</div>
</div>
</div>
<div class="quarto-layout-row">
<div class="quarto-layout-cell" style="flex-basis: 100.0%;justify-content: flex-start;">
<div id="ojs-cell-1-23" data-nodetype="declaration">

</div>
</div>
</div>
<div class="quarto-layout-row">
<div class="quarto-layout-cell" style="flex-basis: 100.0%;justify-content: flex-start;">
<div id="ojs-cell-1-24" data-nodetype="declaration">

</div>
</div>
</div>
<div class="quarto-layout-row">
<div class="quarto-layout-cell" style="flex-basis: 100.0%;justify-content: flex-start;">
<div id="ojs-cell-1-25" data-nodetype="declaration">

</div>
</div>
</div>
<div class="quarto-layout-row">
<div class="quarto-layout-cell" style="flex-basis: 100.0%;justify-content: flex-start;">
<div id="ojs-cell-1-26" data-nodetype="declaration">

</div>
</div>
</div>
<div class="quarto-layout-row">
<div class="quarto-layout-cell" style="flex-basis: 100.0%;justify-content: flex-start;">
<div id="ojs-cell-1-27" data-nodetype="declaration">

</div>
</div>
</div>
<div class="quarto-layout-row">
<div class="quarto-layout-cell" style="flex-basis: 100.0%;justify-content: flex-start;">
<div id="ojs-cell-1-28" data-nodetype="declaration">

</div>
</div>
</div>
<div class="quarto-layout-row">
<div class="quarto-layout-cell" style="flex-basis: 100.0%;justify-content: flex-start;">
<div id="ojs-cell-1-29" data-nodetype="expression">

</div>
</div>
</div>
<div class="quarto-layout-row">
<div class="quarto-layout-cell" style="flex-basis: 100.0%;justify-content: flex-start;">
<div id="ojs-cell-1-30" data-nodetype="declaration">

</div>
</div>
</div>
</div>
</section>
<section id="credit" class="level2">
<h2 class="anchored" data-anchor-id="credit"><i class="fa-solid fa-handshake" title="handshakes" aria-label="handshake"></i> Credit</h2>
<ul>
<li><p>The observable code was made with the help of <a href="https://github.com/fradav" target="_blank">François-David Collin</a></p></li>
<li><p>The plot is freely inspired from <a href="http://herbsusmann.com/" target="_blank">Herb Susmann</a>’s code on <a href="https://observablehq.com/@herbps10/dirichlet-distribution" target="_blank">Dirichlet Distribution</a></p></li>
<li><p>The terminology is inspired by posts from Gabriel Peyré: <a href="https://x.com/gabrielpeyre/status/1830470713041354968" target="_blank">https://x.com/gabrielpeyre/status/1830470713041354968</a>, <a href="https://x.com/gabrielpeyre/status/1680804520862056448" target="_blank">https://x.com/gabrielpeyre/status/1680804520862056448</a></p></li>
</ul>
</section>
<section id="references" class="level2">
<h2 class="anchored" data-anchor-id="references"><i class="fa-solid fa-link" title="link" aria-label="link"></i> References</h2>
<div id="refs" class="references csl-bib-body hanging-indent" data-entry-spacing="0">
<div id="ref-Boyd_Vandenberghe04" class="csl-entry">
Boyd, S., and L. Vandenberghe. 2004. <em>Convex Optimization</em>. Cambridge University Press.
</div>
</div>


<!-- -->

</section>


<div id="quarto-appendix" class="default"><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>

<ol>
<li id="fn1"><p>the case with <img src="https://latex.codecogs.com/png.latex?q_k=0"> for some <img src="https://latex.codecogs.com/png.latex?k"> can be reduced to a case with fewer coordinates↩︎</p></li>
</ol>
</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><pre class="sourceCode code-with-copy quarto-appendix-bibtex"><code class="sourceCode bibtex">@online{salmon2024,
  author = {Salmon, Joseph and Collin, François-David},
  title = {Soft-Max and {Soft-argmax}},
  date = {2024-09-03},
  url = {https://josephsalmon.eu/blog/softmax/},
  langid = {en}
}
</code></pre></div></section></div> ]]></description>
  <category>statistics</category>
  <category>optimization</category>
  <category>machine learning</category>
  <guid>https://josephsalmon.eu/blog/softmax/</guid>
  <pubDate>Mon, 02 Sep 2024 22:00:00 GMT</pubDate>
  <media:content url="https://josephsalmon.eu/blog/softmax/softmax.png" medium="image" type="image/png" height="120" width="144"/>
</item>
<item>
  <title>Public civil servant salaries and inflation</title>
  <dc:creator>Joseph Salmon</dc:creator>
  <link>https://josephsalmon.eu/blog/inflation/</link>
  <description><![CDATA[ 
<div class="no-row-height column-margin column-container">
  <div class="">
    <img src="https://josephsalmon.eu/blog/inflation/point_indice.png" style="width:100%">
  </div>
</div>





<p>This is a post with executable code. It actually loads an old post from another website, that updates with a GitHub action; see <a href="https://josephsalmon.github.io/Tweets/economics/index.html" target="_blank">https://josephsalmon.github.io/Tweets/economics/index.html</a></p>
<br> <br> <br> <br>
<div style="transform: scale(0.5); transform-origin: top left; width: 200%; height: 200%;">
<iframe src="https://josephsalmon.github.io/Tweets/economics/index.html" width="105%" height="280%">
</iframe>
</div>
<p><br> <br> <br></p>


<!-- -->


 ]]></description>
  <category>news</category>
  <category>code</category>
  <category>data science</category>
  <category>economics</category>
  <guid>https://josephsalmon.eu/blog/inflation/</guid>
  <pubDate>Sun, 01 Sep 2024 22:00:00 GMT</pubDate>
  <media:content url="https://josephsalmon.eu/blog/inflation/point_indice.png" medium="image" type="image/png" height="107" width="144"/>
</item>
<item>
  <title>Welcome to Donadas Brutas!</title>
  <dc:creator>Joseph Salmon</dc:creator>
  <link>https://josephsalmon.eu/blog/hello-world/</link>
  <description><![CDATA[ 
<div class="no-row-height column-margin column-container">
  <div class="">
    <img src="https://josephsalmon.eu/blog/hello-world/Bezier_good.gif" style="width:100%">
  </div>
</div>





<p>In this blog, I intend to talk about things I like, powered by Quarto, Python, and a bit of Observable for some visualizations. You can expect math, stats, machine learning, biking and whatever I feel like sharing. And sometimes, I will also share things just because I find them nice…</p>
<p>I shall also mention</p>
<ul>
<li><a href="https://emilhvitfeldt.com/blog" target="_blank">Emil Hvitfeldt’s blog</a></li>
<li><a href="freakonometrics.hypotheses.org" target="_blank">Freakonometrics</a></li>
<li><a href="ploum.net" target="_blank">ploum.net</a></li>
</ul>
<p>who are all great sources of inspiration. <!-- 
<div style="text-align: center">
<a href="https://github.com/josephsalmon/Tweets/tree/master/Spline-ish">
  <img src="Bezier_good.gif" width=95% loop=infinite>
</a>
</div> --></p>


<!-- -->


<div id="quarto-appendix" class="default"><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><pre class="sourceCode code-with-copy quarto-appendix-bibtex"><code class="sourceCode bibtex">@online{salmon2024,
  author = {Salmon, Joseph},
  title = {Welcome to {Donadas} {Brutas!}},
  date = {2024-09-01},
  url = {https://josephsalmon.eu/blog/hello-world/},
  langid = {en}
}
</code></pre></div></section></div> ]]></description>
  <category>news</category>
  <guid>https://josephsalmon.eu/blog/hello-world/</guid>
  <pubDate>Sat, 31 Aug 2024 22:00:00 GMT</pubDate>
  <media:content url="https://josephsalmon.eu/blog/hello-world/Bezier_good.gif" medium="image" type="image/gif"/>
</item>
</channel>
</rss>
