805 lines
No EOL
46 KiB
HTML
805 lines
No EOL
46 KiB
HTML
<!DOCTYPE html>
|
||
<html xmlns="http://www.w3.org/1999/xhtml" lang="fr" xml:lang="fr"><head>
|
||
|
||
<meta charset="utf-8">
|
||
<meta name="generator" content="quarto-1.7.22">
|
||
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
|
||
|
||
<meta name="author" content="Louis Lacoste">
|
||
|
||
<title>Idées autour de l’inclusion de la phylogénie – Suivi de la thèse</title>
|
||
<style>
|
||
code{white-space: pre-wrap;}
|
||
span.smallcaps{font-variant: small-caps;}
|
||
div.columns{display: flex; gap: min(4vw, 1.5em);}
|
||
div.column{flex: auto; overflow-x: auto;}
|
||
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
|
||
ul.task-list{list-style: none;}
|
||
ul.task-list li input[type="checkbox"] {
|
||
width: 0.8em;
|
||
margin: 0 0.8em 0.2em -1em; /* quarto-specific, see https://github.com/quarto-dev/quarto-cli/issues/4556 */
|
||
vertical-align: middle;
|
||
}
|
||
</style>
|
||
|
||
|
||
<script src="../site_libs/quarto-nav/quarto-nav.js"></script>
|
||
<script src="../site_libs/quarto-nav/headroom.min.js"></script>
|
||
<script src="../site_libs/clipboard/clipboard.min.js"></script>
|
||
<script src="../site_libs/quarto-search/autocomplete.umd.js"></script>
|
||
<script src="../site_libs/quarto-search/fuse.min.js"></script>
|
||
<script src="../site_libs/quarto-search/quarto-search.js"></script>
|
||
<meta name="quarto:offset" content="../">
|
||
<script src="../site_libs/quarto-html/quarto.js" type="module"></script>
|
||
<script src="../site_libs/quarto-html/tabsets/tabsets.js" type="module"></script>
|
||
<script src="../site_libs/quarto-html/popper.min.js"></script>
|
||
<script src="../site_libs/quarto-html/tippy.umd.min.js"></script>
|
||
<script src="../site_libs/quarto-html/anchor.min.js"></script>
|
||
<link href="../site_libs/quarto-html/tippy.css" rel="stylesheet">
|
||
<link href="../site_libs/quarto-html/quarto-syntax-highlighting-7b4406b7675125bc2ba204020e191172.css" rel="stylesheet" id="quarto-text-highlighting-styles">
|
||
<script src="../site_libs/bootstrap/bootstrap.min.js"></script>
|
||
<link href="../site_libs/bootstrap/bootstrap-icons.css" rel="stylesheet">
|
||
<link href="../site_libs/bootstrap/bootstrap-c3e95e02e727cc1eb63534e29640e14d.min.css" rel="stylesheet" append-hash="true" id="quarto-bootstrap" data-mode="light">
|
||
<script id="quarto-search-options" type="application/json">{
|
||
"location": "navbar",
|
||
"copy-button": false,
|
||
"collapse-after": 3,
|
||
"panel-placement": "end",
|
||
"type": "overlay",
|
||
"limit": 50,
|
||
"keyboard-shortcut": [
|
||
"f",
|
||
"/",
|
||
"s"
|
||
],
|
||
"show-item-context": false,
|
||
"language": {
|
||
"search-no-results-text": "Pas de résultats",
|
||
"search-matching-documents-text": "documents trouvés",
|
||
"search-copy-link-title": "Copier le lien vers la recherche",
|
||
"search-hide-matches-text": "Cacher les correspondances additionnelles",
|
||
"search-more-match-text": "correspondance de plus dans ce document",
|
||
"search-more-matches-text": "correspondances de plus dans ce document",
|
||
"search-clear-button-title": "Effacer",
|
||
"search-text-placeholder": "",
|
||
"search-detached-cancel-button-title": "Annuler",
|
||
"search-submit-button-title": "Envoyer",
|
||
"search-label": "Recherche"
|
||
}
|
||
}</script>
|
||
|
||
<script>window.backupDefine = window.define; window.define = undefined;</script><script src="https://cdn.jsdelivr.net/npm/katex@latest/dist/katex.min.js"></script>
|
||
<script>document.addEventListener("DOMContentLoaded", function () {
|
||
var mathElements = document.getElementsByClassName("math");
|
||
var macros = [];
|
||
for (var i = 0; i < mathElements.length; i++) {
|
||
var texText = mathElements[i].firstChild;
|
||
if (mathElements[i].tagName == "SPAN") {
|
||
katex.render(texText.data, mathElements[i], {
|
||
displayMode: mathElements[i].classList.contains('display'),
|
||
throwOnError: false,
|
||
macros: macros,
|
||
fleqn: false
|
||
});
|
||
}}});
|
||
</script>
|
||
<script>window.define = window.backupDefine; window.backupDefine = undefined;</script><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@latest/dist/katex.min.css">
|
||
|
||
<script type="text/javascript">
|
||
const typesetMath = (el) => {
|
||
if (window.MathJax) {
|
||
// MathJax Typeset
|
||
window.MathJax.typeset([el]);
|
||
} else if (window.katex) {
|
||
// KaTeX Render
|
||
var mathElements = el.getElementsByClassName("math");
|
||
var macros = [];
|
||
for (var i = 0; i < mathElements.length; i++) {
|
||
var texText = mathElements[i].firstChild;
|
||
if (mathElements[i].tagName == "SPAN") {
|
||
window.katex.render(texText.data, mathElements[i], {
|
||
displayMode: mathElements[i].classList.contains('display'),
|
||
throwOnError: false,
|
||
macros: macros,
|
||
fleqn: false
|
||
});
|
||
}
|
||
}
|
||
}
|
||
}
|
||
window.Quarto = {
|
||
typesetMath
|
||
};
|
||
</script>
|
||
|
||
</head>
|
||
|
||
<body class="nav-fixed quarto-light">
|
||
|
||
<div id="quarto-search-results"></div>
|
||
<header id="quarto-header" class="headroom fixed-top">
|
||
<nav class="navbar navbar-expand-lg " data-bs-theme="dark">
|
||
<div class="navbar-container container-fluid">
|
||
<div class="navbar-brand-container mx-auto">
|
||
<a class="navbar-brand" href="../index.html">
|
||
<span class="navbar-title">Suivi de la thèse</span>
|
||
</a>
|
||
</div>
|
||
<div id="quarto-search" class="" title="Recherche"></div>
|
||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarCollapse" aria-controls="navbarCollapse" role="menu" aria-expanded="false" aria-label="Basculer la navigation" onclick="if (window.quartoToggleHeadroom) { window.quartoToggleHeadroom(); }">
|
||
<span class="navbar-toggler-icon"></span>
|
||
</button>
|
||
<div class="collapse navbar-collapse" id="navbarCollapse">
|
||
<ul class="navbar-nav navbar-nav-scroll me-auto">
|
||
<li class="nav-item">
|
||
<a class="nav-link" href="../index.html"> <i class="bi bi-journals" role="img">
|
||
</i>
|
||
<span class="menu-text">Liste des semaines</span></a>
|
||
</li>
|
||
</ul>
|
||
<ul class="navbar-nav navbar-nav-scroll ms-auto">
|
||
<li class="nav-item compact">
|
||
<a class="nav-link" href="https://git.polarolouis.fr/polarolouis/these-recap-hebdo"> <i class="bi bi-git" role="img" aria-label="Dépôt Git du journal">
|
||
</i>
|
||
<span class="menu-text"></span></a>
|
||
</li>
|
||
</ul>
|
||
</div> <!-- /navcollapse -->
|
||
<div class="quarto-navbar-tools">
|
||
</div>
|
||
</div> <!-- /container-fluid -->
|
||
</nav>
|
||
</header>
|
||
<!-- content -->
|
||
<div id="quarto-content" class="quarto-container page-columns page-rows-contents page-layout-article page-navbar">
|
||
<!-- sidebar -->
|
||
<!-- margin-sidebar -->
|
||
<div id="quarto-margin-sidebar" class="sidebar margin-sidebar">
|
||
<nav id="TOC" role="doc-toc" class="toc-active">
|
||
<h2 id="toc-title">Sur cette page</h2>
|
||
|
||
<ul>
|
||
<li><a href="#contexte-de-linclusion-de-la-phylogénie-dans-lestimation-de-la-structure-des-interactions" id="toc-contexte-de-linclusion-de-la-phylogénie-dans-lestimation-de-la-structure-des-interactions" class="nav-link active" data-scroll-target="#contexte-de-linclusion-de-la-phylogénie-dans-lestimation-de-la-structure-des-interactions"><span class="header-section-number">1</span> Contexte de l’inclusion de la phylogénie dans l’estimation de la structure des interactions</a>
|
||
<ul class="collapse">
|
||
<li><a href="#formalisme-commun" id="toc-formalisme-commun" class="nav-link" data-scroll-target="#formalisme-commun"><span class="header-section-number">1.1</span> Formalisme commun</a></li>
|
||
</ul></li>
|
||
<li><a href="#sbm-ou-lbm-séquentiel" id="toc-sbm-ou-lbm-séquentiel" class="nav-link" data-scroll-target="#sbm-ou-lbm-séquentiel"><span class="header-section-number">2</span> SBM (ou LBM) Séquentiel</a>
|
||
<ul class="collapse">
|
||
<li><a href="#formalisation-de-lidée" id="toc-formalisation-de-lidée" class="nav-link" data-scroll-target="#formalisation-de-lidée"><span class="header-section-number">2.1</span> Formalisation de l’idée</a></li>
|
||
<li><a href="#limites-de-lapproche" id="toc-limites-de-lapproche" class="nav-link" data-scroll-target="#limites-de-lapproche"><span class="header-section-number">2.2</span> Limites de l’approche</a></li>
|
||
</ul></li>
|
||
<li><a href="#sbm-et-lbm-avec-covariables-sur-les-noeuds" id="toc-sbm-et-lbm-avec-covariables-sur-les-noeuds" class="nav-link" data-scroll-target="#sbm-et-lbm-avec-covariables-sur-les-noeuds"><span class="header-section-number">3</span> SBM et LBM avec covariables sur les noeuds</a>
|
||
<ul class="collapse">
|
||
<li><a href="#formalisation-du-modèle" id="toc-formalisation-du-modèle" class="nav-link" data-scroll-target="#formalisation-du-modèle"><span class="header-section-number">3.1</span> Formalisation du modèle</a></li>
|
||
<li><a href="#preuve-de-lidentifiabilité" id="toc-preuve-de-lidentifiabilité" class="nav-link" data-scroll-target="#preuve-de-lidentifiabilité"><span class="header-section-number">3.2</span> Preuve de l’identifiabilité</a></li>
|
||
<li><a href="#inférence" id="toc-inférence" class="nav-link" data-scroll-target="#inférence"><span class="header-section-number">3.3</span> Inférence</a></li>
|
||
<li><a href="#implémentation" id="toc-implémentation" class="nav-link" data-scroll-target="#implémentation"><span class="header-section-number">3.4</span> Implémentation</a></li>
|
||
<li><a href="#la-suite" id="toc-la-suite" class="nav-link" data-scroll-target="#la-suite"><span class="header-section-number">3.5</span> La suite</a></li>
|
||
</ul></li>
|
||
<li><a href="#lbm-avec-dépendance-latente-entre-les-probabilités-a-priori" id="toc-lbm-avec-dépendance-latente-entre-les-probabilités-a-priori" class="nav-link" data-scroll-target="#lbm-avec-dépendance-latente-entre-les-probabilités-a-priori"><span class="header-section-number">4</span> LBM avec dépendance latente entre les probabilités <em>a priori</em></a>
|
||
<ul class="collapse">
|
||
<li><a href="#formalisation-du-modèle-1" id="toc-formalisation-du-modèle-1" class="nav-link" data-scroll-target="#formalisation-du-modèle-1"><span class="header-section-number">4.1</span> Formalisation du modèle</a></li>
|
||
</ul></li>
|
||
<li><a href="#échantillonnage-selon-larbre" id="toc-échantillonnage-selon-larbre" class="nav-link" data-scroll-target="#échantillonnage-selon-larbre"><span class="header-section-number">5</span> Échantillonnage selon l’arbre</a></li>
|
||
<li><a href="#latent-position-model-lpm-avec-phylogénie-des-représentations-latentes-selon-la-phylogénie" id="toc-latent-position-model-lpm-avec-phylogénie-des-représentations-latentes-selon-la-phylogénie" class="nav-link" data-scroll-target="#latent-position-model-lpm-avec-phylogénie-des-représentations-latentes-selon-la-phylogénie"><span class="header-section-number">6</span> <em>Latent Position Model</em> (LPM) avec phylogénie des représentations latentes selon la phylogénie</a></li>
|
||
</ul>
|
||
</nav>
|
||
</div>
|
||
<!-- main -->
|
||
<main class="content" id="quarto-document-content">
|
||
|
||
<header id="title-block-header" class="quarto-title-block default">
|
||
<div class="quarto-title">
|
||
<h1 class="title">Idées autour de l’inclusion de la phylogénie</h1>
|
||
<div class="quarto-categories">
|
||
<div class="quarto-category">phylogénie</div>
|
||
<div class="quarto-category">graphes</div>
|
||
<div class="quarto-category">lbm</div>
|
||
<div class="quarto-category">sbm</div>
|
||
</div>
|
||
</div>
|
||
|
||
|
||
<div class="quarto-title-meta-author">
|
||
<div class="quarto-title-meta-heading">Auteur·rice</div>
|
||
<div class="quarto-title-meta-heading">Affiliation</div>
|
||
|
||
<div class="quarto-title-meta-contents">
|
||
<p class="author">Louis Lacoste <a href="mailto:louis.lacoste@agroparistech.fr" class="quarto-title-author-email"><i class="bi bi-envelope"></i></a> <a href="https://orcid.org/0009-0004-0178-9821" class="quarto-title-author-orcid"> <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAA2ZpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wTU09Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9tbS8iIHhtbG5zOnN0UmVmPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvc1R5cGUvUmVzb3VyY2VSZWYjIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iIHhtcE1NOk9yaWdpbmFsRG9jdW1lbnRJRD0ieG1wLmRpZDo1N0NEMjA4MDI1MjA2ODExOTk0QzkzNTEzRjZEQTg1NyIgeG1wTU06RG9jdW1lbnRJRD0ieG1wLmRpZDozM0NDOEJGNEZGNTcxMUUxODdBOEVCODg2RjdCQ0QwOSIgeG1wTU06SW5zdGFuY2VJRD0ieG1wLmlpZDozM0NDOEJGM0ZGNTcxMUUxODdBOEVCODg2RjdCQ0QwOSIgeG1wOkNyZWF0b3JUb29sPSJBZG9iZSBQaG90b3Nob3AgQ1M1IE1hY2ludG9zaCI+IDx4bXBNTTpEZXJpdmVkRnJvbSBzdFJlZjppbnN0YW5jZUlEPSJ4bXAuaWlkOkZDN0YxMTc0MDcyMDY4MTE5NUZFRDc5MUM2MUUwNEREIiBzdFJlZjpkb2N1bWVudElEPSJ4bXAuZGlkOjU3Q0QyMDgwMjUyMDY4MTE5OTRDOTM1MTNGNkRBODU3Ii8+IDwvcmRmOkRlc2NyaXB0aW9uPiA8L3JkZjpSREY+IDwveDp4bXBtZXRhPiA8P3hwYWNrZXQgZW5kPSJyIj8+84NovQAAAR1JREFUeNpiZEADy85ZJgCpeCB2QJM6AMQLo4yOL0AWZETSqACk1gOxAQN+cAGIA4EGPQBxmJA0nwdpjjQ8xqArmczw5tMHXAaALDgP1QMxAGqzAAPxQACqh4ER6uf5MBlkm0X4EGayMfMw/Pr7Bd2gRBZogMFBrv01hisv5jLsv9nLAPIOMnjy8RDDyYctyAbFM2EJbRQw+aAWw/LzVgx7b+cwCHKqMhjJFCBLOzAR6+lXX84xnHjYyqAo5IUizkRCwIENQQckGSDGY4TVgAPEaraQr2a4/24bSuoExcJCfAEJihXkWDj3ZAKy9EJGaEo8T0QSxkjSwORsCAuDQCD+QILmD1A9kECEZgxDaEZhICIzGcIyEyOl2RkgwAAhkmC+eAm0TAAAAABJRU5ErkJggg=="></a></p>
|
||
</div>
|
||
<div class="quarto-title-meta-contents">
|
||
<p class="affiliation">
|
||
MIA Paris-Saclay, INRAE, AgroParisTech, Université Paris-Saclay
|
||
</p>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="quarto-title-meta">
|
||
|
||
|
||
<div>
|
||
<div class="quarto-title-meta-heading">Date de publication</div>
|
||
<div class="quarto-title-meta-contents">
|
||
<p class="date">7 mai 2026</p>
|
||
</div>
|
||
</div>
|
||
|
||
<div>
|
||
<div class="quarto-title-meta-heading">Modifié</div>
|
||
<div class="quarto-title-meta-contents">
|
||
<p class="date-modified">7 mai 2026</p>
|
||
</div>
|
||
</div>
|
||
|
||
</div>
|
||
|
||
|
||
|
||
</header>
|
||
|
||
|
||
<section id="contexte-de-linclusion-de-la-phylogénie-dans-lestimation-de-la-structure-des-interactions" class="level1" data-number="1">
|
||
<h1 data-number="1"><span class="header-section-number">1</span> Contexte de l’inclusion de la phylogénie dans l’estimation de la structure des interactions</h1>
|
||
<p>Dans le 3e axe de ma thèse nous souhaitons inclure de l’information phylogénétique dans l’estimation de la structure des réseaux d’interaction microbiens.</p>
|
||
<ol type="1">
|
||
<li><p>Ces réseaux se présentent sous la forme de matrice des comptages hautement rectangulaire, c’est-à-dire avec un grand nombre de microorganismes et, en comparaison, peu d’échantillons (de sols, d’aliments, de patients…). Cette haute dimensionnalité met en échec les méthodes classiques non concues pour gérer autant de noeuds (SBM). Il s’agit donc d’un <strong>premier enjeu</strong></p></li>
|
||
<li><p>Les données de comptages de ces matrices sont compositionnelles : la profondeur de séquençage (le nombre de séquences lues) étant finie, cela implique une dépendance entre les comptages observés. Si une séquence est surexprimée par rapport aux autres, alors que l’abondance réelle des autres n’a pas changée, les comptages observés des autres séquences vont diminuer. Voir <a href="#note-donnees-compo">la note sur les données compositionnelles</a>.</p></li>
|
||
</ol>
|
||
<div id="note-donnees-compo" class="callout callout-style-default callout-note callout-titled" title="Données compositionelles">
|
||
<div class="callout-header d-flex align-content-center">
|
||
<div class="callout-icon-container">
|
||
<i class="callout-icon"></i>
|
||
</div>
|
||
<div class="callout-title-container flex-fill">
|
||
Données compositionelles
|
||
</div>
|
||
</div>
|
||
<div class="callout-body-container callout-body">
|
||
<p>Soit <span class="math inline">N</span> la profondeur de séquençage, <span class="math inline">\forall s \in \{1,\dots,s\}, n_s</span> le nombre réel de fois où la séquence <span class="math inline">s</span> est présente, <span class="math inline">t = \sum_s n_s</span> la somme des séquences totale. Les comptages observés <span class="math inline">o_s</span> pour la séquence <span class="math inline">s</span> sont <span class="math inline">o_s = \dfrac{n_s}{N}</span>, et on a <span class="math inline">\sum_{s} o_s = \dfrac{1}{N} \sum_{s} n_s</span> par construction.</p>
|
||
<p>Et donc à pour un <span class="math inline">S</span> quelconque on a <span class="math inline">o_S = \dfrac{t}{N} - \sum_{s, s\neq S} o_s</span> et donc une contrainte sur les <span class="math inline">o_s</span>.</p>
|
||
</div>
|
||
</div>
|
||
<p>Diverses autres enjeux se posent quand on considère ce type de données. Par exemple, l’arbre phylogénétique peut ne pas être directement accessible, ou bien être dominé par un certain clade. Il peut aussi exploser en nombre d’individu à chaque niveau (à relier au point 1).</p>
|
||
<section id="formalisme-commun" class="level2" data-number="1.1">
|
||
<h2 data-number="1.1" class="anchored" data-anchor-id="formalisme-commun"><span class="header-section-number">1.1</span> Formalisme commun</h2>
|
||
<p>Dans la suite, nous considèrerons <span class="math inline">\mathcal{T}</span> l’arbre ayant <span class="math inline">L</span> niveaux, indexés de <span class="math inline">l = 0,\dots,L</span> avec <span class="math inline">0</span> la racine commune et <span class="math inline">L</span> les feuilles de l’arbre.</p>
|
||
<p><span class="math inline">Y</span> la matrice de bi-adjacence encodant le graphe et modélisant les interactions, de taille <span class="math inline">n_1\times n_2</span>.</p>
|
||
<p><span class="math inline">V, X</span> les matrices de covariable sur les noeuds en ligne et en colonnes de <span class="math inline">Y</span>. <span class="math inline">V</span> est de taille <span class="math inline">n_1 \times d</span> et <span class="math inline">X</span> est de taille <span class="math inline">n_2 \times p</span></p>
|
||
</section>
|
||
</section>
|
||
<section id="sbm-ou-lbm-séquentiel" class="level1" data-number="2">
|
||
<h1 data-number="2"><span class="header-section-number">2</span> SBM (ou LBM) Séquentiel</h1>
|
||
<section id="formalisation-de-lidée" class="level2" data-number="2.1">
|
||
<h2 data-number="2.1" class="anchored" data-anchor-id="formalisation-de-lidée"><span class="header-section-number">2.1</span> Formalisation de l’idée</h2>
|
||
<p>Ici on utilise l’arbre phylogénétique afin d’initialiser l’EM variationnel du niveau suivant.</p>
|
||
<p>Concrètement, on ajuste un LBM au niveau <span class="math inline">l</span>, sur la matrice de comptage aggrégées à ce niveau <span class="math inline">Y^l</span>, ce qui donne des probabilités variationnelles <span class="math inline">\pmb{\tau}^{1,l},\pmb{\tau}^{2,l}</span> qui sont de tailles respectives <span class="math inline">n_{1,l} \times Q_{l}</span> et <span class="math inline">n_{2,l} \times R_{l}</span>.</p>
|
||
<p>Puis pour tout individu <span class="math inline">u\in \text{Child}(i)</span>, on initialise ses probas <span class="math inline">\widetilde{\tau}^{1,l+1}_u = \tau^{1,l}_u + \varepsilon_{u}</span>, avec <span class="math inline">\varepsilon_u \sim \mathcal{N}_{Q_l}(0,\sigma^2)</span> et on renormalise <span class="math inline">\tau^{1,l+1}_{u} = \dfrac{\widetilde{\tau}^{1,l+1}_u}{\sum_q \widetilde{\tau}^{1,l+1}_{u,q}}</span>. On ajoute une perturbation afin de ne pas rester bloqué sur le point fixe précédent et de pouvoir donc obtenir les <span class="math inline">\tau^{1,l+1}</span> à l’issue de l’optimisation.</p>
|
||
</section>
|
||
<section id="limites-de-lapproche" class="level2" data-number="2.2">
|
||
<h2 data-number="2.2" class="anchored" data-anchor-id="limites-de-lapproche"><span class="header-section-number">2.2</span> Limites de l’approche</h2>
|
||
<p>Le passage d’information selon l’arbre nous semble intuitivement être une bonne approche et les résultats que nous avons obtenues indique qu’un peu d’information semble passer mais il faut aller profondément dans l’arbre et alors on rencontre le problème du coût computationnel. En effet cette méthode ne diminue pas le coût en calcul puisqu’elle calcule un LBM à chacun des <span class="math inline">L</span> niveaux, au mieux elle donne un point d’initialisation intelligent mais cela semble difficilement applicable à des données réelles.</p>
|
||
</section>
|
||
</section>
|
||
<section id="sbm-et-lbm-avec-covariables-sur-les-noeuds" class="level1" data-number="3">
|
||
<h1 data-number="3"><span class="header-section-number">3</span> SBM et LBM avec covariables sur les noeuds</h1>
|
||
<p>Ce modèle visent à intégrer des covariables de noeuds comme modificateurs des probabilités <em>a priori</em> d’appartenance aux groupes. Pour la phylogénie, en passant par une MDS ou une autre méthode permettant à partir des distances phylogénétique d’obtenir des “positions” ou des covariables, cela permettrait d’injecter l’a priori phylogénétique dans l’estimation de la structure du réseau.</p>
|
||
<section id="formalisation-du-modèle" class="level2" data-number="3.1">
|
||
<h2 data-number="3.1" class="anchored" data-anchor-id="formalisation-du-modèle"><span class="header-section-number">3.1</span> Formalisation du modèle</h2>
|
||
<p>Toujours modèle LBM mais avec probas d’appartenance pour les colonnes variables:</p>
|
||
<p><span class="math display">\begin{align*}
|
||
Z_i &\sim \mathcal{M}(1; \pi_1, \dots, \pi_Q), \sum_{q=1}^{Q} \pi_q = 1\\
|
||
W_j &\sim \mathcal{M}(1; \rho_1^j, \dots, \rho_R^j), \sum_{r=1}^{R} \rho_r^j = 1\\
|
||
Y_{i,j}&\mid Z_i = q, W_j = r \sim \mathcal{F}(\alpha_{qr})
|
||
\end{align*}</span></p>
|
||
<p>Voici pour les probas pour les individus en colonne de la matrice d’adjacence : <span class="math display">\begin{align*}
|
||
\pmb{\beta}_{r}& = \begin{pmatrix}
|
||
\beta_{r,0}\\
|
||
\vdots\\
|
||
\beta_{r,p}
|
||
\end{pmatrix}, & X_{j,\bullet} = \begin{pmatrix}
|
||
1 = x_{0,j} & x_{1,j} & \dots & x_{p,j}
|
||
\end{pmatrix}\\
|
||
X_{j,\bullet} \pmb{\beta}_r& = \beta_{r,0} x_{0,j} + \beta_{r,1} x_{1,j} + \dots + \beta_{r,p} x_{p,j} & \approx \log(\rho_r^j) \\
|
||
B & = \begin{pmatrix}
|
||
\pmb{\beta}_1 \dots \pmb{\beta}_r \dots \pmb{\beta}_R
|
||
\end{pmatrix} & X_{j,\bullet}B \approx \log(\pmb{\rho}^j) \\
|
||
X B & \approx \log((\pmb{\rho}^j)_{j=1,\dots,n_2}) = \log(\pmb{\Rho})\\
|
||
\end{align*}</span> avec les <span class="math inline">\beta, B</span> qui désigne donc les coefficient de la combinaison linéaire et <span class="math inline">X</span> les covariables des individus (taille <span class="math inline">n_2\times p</span>, <span class="math inline">p</span> covariables).</p>
|
||
<p>Et pour les probas en lignes du LBM : <span class="math display">\begin{align*}
|
||
\pmb{\gamma}_{q}& = \begin{pmatrix}
|
||
\gamma_{q,0}\\
|
||
\vdots\\
|
||
\gamma_{q,d}
|
||
\end{pmatrix}, & V_{i,\bullet} = \begin{pmatrix}
|
||
1 = v_{0,i} & v_{1,i} & \dots & v_{d,i}
|
||
\end{pmatrix}\\
|
||
V_{i,\bullet} \pmb{\gamma}_q & = \gamma_{q,0} v_{0,i} + \gamma_{q,1} v_{1,i} + \dots + \gamma_{q,d} v_{d,i} & \approx \log(\pi_q^i) \\
|
||
\Gamma & = \begin{pmatrix}
|
||
\gamma_1 \dots \pmb{\gamma}_q \dots \pmb{\gamma}_Q
|
||
\end{pmatrix} & V_{i,\bullet} \Gamma \approx \log(\pmb{\pi}^i) \\
|
||
V \Gamma & \approx \log((\pmb{\pi}^i)_{i=1,\dots,n_1}) = \log(\pmb{\Pi})
|
||
\end{align*}</span> avec les <span class="math inline">\gamma, G</span> qui désigne donc les coefficient de la combinaison linéaire et <span class="math inline">V</span> les covariables des individus (taille <span class="math inline">n_1\times d</span>, <span class="math inline">d</span> covariables).</p>
|
||
</section>
|
||
<section id="preuve-de-lidentifiabilité" class="level2" data-number="3.2">
|
||
<h2 data-number="3.2" class="anchored" data-anchor-id="preuve-de-lidentifiabilité"><span class="header-section-number">3.2</span> Preuve de l’identifiabilité</h2>
|
||
<p>Soient <span class="math inline">B,B^{\prime}</span> avec <span class="math inline">B_{\bullet,R} = B^{\prime}_{\bullet,R} = \vec{0}_{p+1}</span> et <span class="math inline">X</span> de rang plein tel que <span class="math inline">X^{\top}X</span> soit inversible.</p>
|
||
<p><span class="math display">\begin{align*}
|
||
&\sigma(XB) = \sigma(XB^{\prime})\\
|
||
&\implies \exists C = \begin{pmatrix}c_1 \\ \vdots \\ c_j \\ \vdots \\ c_{n_2}\end{pmatrix} \in \mathbb{R}^{n_2}, X B = X B^{\prime} + C \pmb{1}_{R}^{\top} \\
|
||
&\implies \exists C \in \mathbb{R}^{n_2}, (X B)_{j,r} = (X B^{\prime})_{j,r} + (C \pmb{1}_{R}^{\top})_{j,r} \\
|
||
&\implies \exists C \in \mathbb{R}^{n_2}, \forall r\in\{1\dots,R\}, \forall j\in\{1,\dots,n_2\}, \sum_{k=1}^{p+1} x_{j,k} \beta_{k,r} = \sum_{k=1}^{p+1} x_{j,k} \beta^{\prime}_{k,r} + c_j\\
|
||
&\implies \exists C \in \mathbb{R}^{n_2}, \forall j\in\{1,\dots,n_2\}, \sum_{k=1}^{p+1} x_{j,k} \beta_{k,R} = \sum_{k=1}^{p+1} x_{j,k} \beta^{\prime}_{k,R} + c_j \\
|
||
&\implies \exists C \in \mathbb{R}^{n_2}, \forall j\in\{1,\dots,n_2\}, \sum_{k=1}^{p+1} x_{j,k} \times 0 = \sum_{k=1}^{p+1} x_{j,k} \times 0 + c_j \\
|
||
&\implies \exists C \in \mathbb{R}^{n_2}, \forall j\in\{1,\dots,n_2\}, 0 = 0 + c_j \implies c_j = 0 \\
|
||
&\implies C = \begin{pmatrix} 0 \\ \vdots \\ 0 \end{pmatrix} \text{and thus}, XB = XB^{\prime} \\
|
||
& \implies (X^{\top} X)^{-1}X^{\top} X B = (X^{\top} X)^{-1}X^{\top} X B^{\prime} \implies B=B^{\prime}
|
||
\end{align*}</span></p>
|
||
</section>
|
||
<section id="inférence" class="level2" data-number="3.3">
|
||
<h2 data-number="3.3" class="anchored" data-anchor-id="inférence"><span class="header-section-number">3.3</span> Inférence</h2>
|
||
<p>Inférence variationnelle donc <span class="math inline">\ell(Y;\pmb{\theta}) \geq \mathcal{J}(\mathcal{R},\pmb{\theta})</span> avec</p>
|
||
<p><span class="math display">
|
||
\mathcal{J}(\mathcal{R},\pmb{\theta})= \sum_{i = 1}^{n_1}\sum_{j=1}^{n_2}\sum_{q \in \mathcal{Q}_1} \sum_{r \in \mathcal{Q}_2} \tau_{iq}^{1} \tau_{jr}^{2} \log f(Y_{ij}; \alpha_{qr})
|
||
+ \sum_{i=1}^{n_1} \sum_{q \in \mathcal{Q}_1} \tau_{iq}^{1} \log \pi_{\color{black}q} + \sum_{j=1}^{n_2} \sum_{r \in \mathcal{Q}_2} \tau_{jr}^{2} \log \rho_{\color{black}r} \\
|
||
- \sum_{i=1}^{n_1} \tau_{iq}^{1} \log \tau_{iq}^{1} - \sum_{j=1}^{n_2} \tau_{jr}^{2} \log \tau_{jr}^{2}
|
||
</span></p>
|
||
<p>Avec <span class="math inline">\rho_r^j = \frac{\exp{\beta_r X_j}}{\sum_{s=1}^{R} \exp{\beta_s X_j}} = \sigma(\pmb{\beta} \pmb{X})_{r,j}</span>, où <span class="math inline">\sigma</span> désigne le softmax. Et sous la contrainte d’<a href="#preuve-de-lidentifiabilité">identifiabilité</a> que l’un des <span class="math inline">(\beta_r)_{r=1,\dots,R}</span> soit nul, ici <span class="math inline">\beta_R = 0</span>.</p>
|
||
<p>La partie pertinente de l’ELBO devient: <span id="eq-modele-covar-prop"><span class="math display">
|
||
P((\beta_r)_{r=1,\dots,R}, (X_j)_{j=1,\dots,n_2}, (\tau_{jr})_{\substack{j=1,\dots,n_2\\r=1,\dots,R}} ) = \sum_{j=1}^{n_2} \sum_{r=1}^{R} [\tau_{jr} (\beta_r X_j - \log (\sum_{s=1}^{R} \exp{\beta_s X_j}))]
|
||
\tag{1}</span></span></p>
|
||
<p>Et on obtient la dérivée partielle par rapport à <span class="math inline">\beta_t</span> comme: <span class="math display">\begin{align*}
|
||
\dfrac{\partial P}{\partial \beta_t}&((\beta_r)_{r=1,\dots,R}, (X_j)_{j=1,\dots,n_2}, (\tau_{jr})_{\substack{j=1,\dots,n_2\\r=1,\dots,R}} ) = \sum_{j=1}^{n_2} \biggl[ \tau_{jt} X_j - \frac{X_j \exp{\beta_t X_j}}{\sum_{s=1}^{R} \exp{\beta_s X_j}} \biggr]\\
|
||
& = \sum_{j=1}^{n_2} \biggl[\bigl(\tau_{jt} - \sigma(\pmb{\beta} \pmb{X})_{t,j}\bigr) X_j\biggr] = \sum_{j=1}^{n_2} \biggl[\bigl(\tau_{jt} - \rho_t^j \bigr) X_j\biggr]
|
||
\end{align*}</span></p>
|
||
</section>
|
||
<section id="implémentation" class="level2" data-number="3.4">
|
||
<h2 data-number="3.4" class="anchored" data-anchor-id="implémentation"><span class="header-section-number">3.4</span> Implémentation</h2>
|
||
<p>J’ai implémenté tout ça dans un <em>fork</em> de <a href="https://github.com/GrossSBM/blockmodels">blockmodels</a>. Ce fork est disponible <a href="https://github.com/Polarolouis/blockmodels">ici</a> et <strong>en cours de relecture par JBL</strong>.</p>
|
||
<p>Pour les détails techniques, j’ai ré-écrit la gestion des <em>memberships</em> en R pour passer les covariables et coefficients nécessaires aux calculs. J’ai implémenté une descente de gradient en utilisant un algorithme de type BFGS pour l’optimisation des coefficients de la combinaison linéaire. Et enfin j’ai intégré plusieurs choses dans le package R <a href="https://github.com/GrossSBM/sbm">sbm</a>:</p>
|
||
<ol type="1">
|
||
<li><a href="https://github.com/GrossSBM/sbm/tree/nodescovariates">La gestion des covariables de noeuds</a></li>
|
||
<li>Le support des <a href="https://github.com/GrossSBM/sbm/tree/feat/NAsupport">valeurs manquantes</a></li>
|
||
</ol>
|
||
</section>
|
||
<section id="la-suite" class="level2" data-number="3.5">
|
||
<h2 data-number="3.5" class="anchored" data-anchor-id="la-suite"><span class="header-section-number">3.5</span> La suite</h2>
|
||
<p>Maintenant, Sophie et Pierre gèrent la rédaction de vignettes et de simulations autour de ces fonctionnalités.</p>
|
||
<p>Nous attendons de voir si l’on trouve un jeu de données adaptées pour cette méthode.</p>
|
||
<p><strong>Limites</strong> : Ce modèle ne permet pas le passage à l’échelle pour les gros réseaux que représentent les matrices de comptage.</p>
|
||
</section>
|
||
</section>
|
||
<section id="lbm-avec-dépendance-latente-entre-les-probabilités-a-priori" class="level1" data-number="4">
|
||
<h1 data-number="4"><span class="header-section-number">4</span> LBM avec dépendance latente entre les probabilités <em>a priori</em></h1>
|
||
<section id="formalisation-du-modèle-1" class="level2" data-number="4.1">
|
||
<h2 data-number="4.1" class="anchored" data-anchor-id="formalisation-du-modèle-1"><span class="header-section-number">4.1</span> Formalisation du modèle</h2>
|
||
<p>Pierre a proposé que l’on pose une structure latente sur les <span class="math inline">\pmb{Z}</span>. C’est à dire <span class="math display">\begin{align*}
|
||
& P \sim \mathcal{N}_{n_1, K-1} (O_{n_1, K-1}, \Sigma, \sigma^2 Id_{K-1}), \\
|
||
\forall i \in \{1,\dots,n_1\}, & Z_i \mid P_i \overset{ind}{\sim} \mathop{\mathrm{Cat}}_{K} ({\mathop{\mathrm{ilr}}}^{-1}(P_i) = \pi_{1:K}^{(i)}), \\
|
||
\forall j \in \{1,\dots,n_2\}, & W_j \overset{iid}{\sim} \mathop{\mathrm{Cat}}_R (\rho_{1:R}),\\
|
||
\forall i,j \in \{1,\dots,n_1\}\times\{1,\dots,n_2\}, & Y_{ij} \mid Z_i = k, W_j = r \overset{ind}{\sim} \mathcal{F}(\alpha_{qr}),
|
||
\end{align*}</span> avec <span class="math inline">\Sigma</span>, la matrice de variance-covariance déterminée en fonction de l’apparentement (phylogénétique) des noeuds.</p>
|
||
<div class="quarto-figure quarto-figure-center">
|
||
<figure class="figure">
|
||
<p><embed src="figs/projets-phylo/dag-simple.pdf" class="img-fluid"></p>
|
||
<figcaption>Le DAG simplifié du modèle</figcaption>
|
||
</figure>
|
||
</div>
|
||
</section>
|
||
</section>
|
||
<section id="échantillonnage-selon-larbre" class="level1" data-number="5">
|
||
<h1 data-number="5"><span class="header-section-number">5</span> Échantillonnage selon l’arbre</h1>
|
||
<p>Afin d’affronter le coût computationnel que représente l’ajustement</p>
|
||
</section>
|
||
<section id="latent-position-model-lpm-avec-phylogénie-des-représentations-latentes-selon-la-phylogénie" class="level1" data-number="6">
|
||
<h1 data-number="6"><span class="header-section-number">6</span> <em>Latent Position Model</em> (LPM) avec phylogénie des représentations latentes selon la phylogénie</h1>
|
||
|
||
|
||
</section>
|
||
|
||
</main> <!-- /main -->
|
||
<script id="quarto-html-after-body" type="application/javascript">
|
||
window.document.addEventListener("DOMContentLoaded", function (event) {
|
||
const icon = "";
|
||
const anchorJS = new window.AnchorJS();
|
||
anchorJS.options = {
|
||
placement: 'right',
|
||
icon: icon
|
||
};
|
||
anchorJS.add('.anchored');
|
||
const isCodeAnnotation = (el) => {
|
||
for (const clz of el.classList) {
|
||
if (clz.startsWith('code-annotation-')) {
|
||
return true;
|
||
}
|
||
}
|
||
return false;
|
||
}
|
||
const onCopySuccess = function(e) {
|
||
// button target
|
||
const button = e.trigger;
|
||
// don't keep focus
|
||
button.blur();
|
||
// flash "checked"
|
||
button.classList.add('code-copy-button-checked');
|
||
var currentTitle = button.getAttribute("title");
|
||
button.setAttribute("title", "Copié");
|
||
let tooltip;
|
||
if (window.bootstrap) {
|
||
button.setAttribute("data-bs-toggle", "tooltip");
|
||
button.setAttribute("data-bs-placement", "left");
|
||
button.setAttribute("data-bs-title", "Copié");
|
||
tooltip = new bootstrap.Tooltip(button,
|
||
{ trigger: "manual",
|
||
customClass: "code-copy-button-tooltip",
|
||
offset: [0, -8]});
|
||
tooltip.show();
|
||
}
|
||
setTimeout(function() {
|
||
if (tooltip) {
|
||
tooltip.hide();
|
||
button.removeAttribute("data-bs-title");
|
||
button.removeAttribute("data-bs-toggle");
|
||
button.removeAttribute("data-bs-placement");
|
||
}
|
||
button.setAttribute("title", currentTitle);
|
||
button.classList.remove('code-copy-button-checked');
|
||
}, 1000);
|
||
// clear code selection
|
||
e.clearSelection();
|
||
}
|
||
const getTextToCopy = function(trigger) {
|
||
const codeEl = trigger.previousElementSibling.cloneNode(true);
|
||
for (const childEl of codeEl.children) {
|
||
if (isCodeAnnotation(childEl)) {
|
||
childEl.remove();
|
||
}
|
||
}
|
||
return codeEl.innerText;
|
||
}
|
||
const clipboard = new window.ClipboardJS('.code-copy-button:not([data-in-quarto-modal])', {
|
||
text: getTextToCopy
|
||
});
|
||
clipboard.on('success', onCopySuccess);
|
||
if (window.document.getElementById('quarto-embedded-source-code-modal')) {
|
||
const clipboardModal = new window.ClipboardJS('.code-copy-button[data-in-quarto-modal]', {
|
||
text: getTextToCopy,
|
||
container: window.document.getElementById('quarto-embedded-source-code-modal')
|
||
});
|
||
clipboardModal.on('success', onCopySuccess);
|
||
}
|
||
var localhostRegex = new RegExp(/^(?:http|https):\/\/localhost\:?[0-9]*\//);
|
||
var mailtoRegex = new RegExp(/^mailto:/);
|
||
var filterRegex = new RegExp('/' + window.location.host + '/');
|
||
var isInternal = (href) => {
|
||
return filterRegex.test(href) || localhostRegex.test(href) || mailtoRegex.test(href);
|
||
}
|
||
// Inspect non-navigation links and adorn them if external
|
||
var links = window.document.querySelectorAll('a[href]:not(.nav-link):not(.navbar-brand):not(.toc-action):not(.sidebar-link):not(.sidebar-item-toggle):not(.pagination-link):not(.no-external):not([aria-hidden]):not(.dropdown-item):not(.quarto-navigation-tool):not(.about-link)');
|
||
for (var i=0; i<links.length; i++) {
|
||
const link = links[i];
|
||
if (!isInternal(link.href)) {
|
||
// undo the damage that might have been done by quarto-nav.js in the case of
|
||
// links that we want to consider external
|
||
if (link.dataset.originalHref !== undefined) {
|
||
link.href = link.dataset.originalHref;
|
||
}
|
||
}
|
||
}
|
||
function tippyHover(el, contentFn, onTriggerFn, onUntriggerFn) {
|
||
const config = {
|
||
allowHTML: true,
|
||
maxWidth: 500,
|
||
delay: 100,
|
||
arrow: false,
|
||
appendTo: function(el) {
|
||
return el.parentElement;
|
||
},
|
||
interactive: true,
|
||
interactiveBorder: 10,
|
||
theme: 'quarto',
|
||
placement: 'bottom-start',
|
||
};
|
||
if (contentFn) {
|
||
config.content = contentFn;
|
||
}
|
||
if (onTriggerFn) {
|
||
config.onTrigger = onTriggerFn;
|
||
}
|
||
if (onUntriggerFn) {
|
||
config.onUntrigger = onUntriggerFn;
|
||
}
|
||
window.tippy(el, config);
|
||
}
|
||
const noterefs = window.document.querySelectorAll('a[role="doc-noteref"]');
|
||
for (var i=0; i<noterefs.length; i++) {
|
||
const ref = noterefs[i];
|
||
tippyHover(ref, function() {
|
||
// use id or data attribute instead here
|
||
let href = ref.getAttribute('data-footnote-href') || ref.getAttribute('href');
|
||
try { href = new URL(href).hash; } catch {}
|
||
const id = href.replace(/^#\/?/, "");
|
||
const note = window.document.getElementById(id);
|
||
if (note) {
|
||
return note.innerHTML;
|
||
} else {
|
||
return "";
|
||
}
|
||
});
|
||
}
|
||
const xrefs = window.document.querySelectorAll('a.quarto-xref');
|
||
const processXRef = (id, note) => {
|
||
// Strip column container classes
|
||
const stripColumnClz = (el) => {
|
||
el.classList.remove("page-full", "page-columns");
|
||
if (el.children) {
|
||
for (const child of el.children) {
|
||
stripColumnClz(child);
|
||
}
|
||
}
|
||
}
|
||
stripColumnClz(note)
|
||
if (id === null || id.startsWith('sec-')) {
|
||
// Special case sections, only their first couple elements
|
||
const container = document.createElement("div");
|
||
if (note.children && note.children.length > 2) {
|
||
container.appendChild(note.children[0].cloneNode(true));
|
||
for (let i = 1; i < note.children.length; i++) {
|
||
const child = note.children[i];
|
||
if (child.tagName === "P" && child.innerText === "") {
|
||
continue;
|
||
} else {
|
||
container.appendChild(child.cloneNode(true));
|
||
break;
|
||
}
|
||
}
|
||
if (window.Quarto?.typesetMath) {
|
||
window.Quarto.typesetMath(container);
|
||
}
|
||
return container.innerHTML
|
||
} else {
|
||
if (window.Quarto?.typesetMath) {
|
||
window.Quarto.typesetMath(note);
|
||
}
|
||
return note.innerHTML;
|
||
}
|
||
} else {
|
||
// Remove any anchor links if they are present
|
||
const anchorLink = note.querySelector('a.anchorjs-link');
|
||
if (anchorLink) {
|
||
anchorLink.remove();
|
||
}
|
||
if (window.Quarto?.typesetMath) {
|
||
window.Quarto.typesetMath(note);
|
||
}
|
||
if (note.classList.contains("callout")) {
|
||
return note.outerHTML;
|
||
} else {
|
||
return note.innerHTML;
|
||
}
|
||
}
|
||
}
|
||
for (var i=0; i<xrefs.length; i++) {
|
||
const xref = xrefs[i];
|
||
tippyHover(xref, undefined, function(instance) {
|
||
instance.disable();
|
||
let url = xref.getAttribute('href');
|
||
let hash = undefined;
|
||
if (url.startsWith('#')) {
|
||
hash = url;
|
||
} else {
|
||
try { hash = new URL(url).hash; } catch {}
|
||
}
|
||
if (hash) {
|
||
const id = hash.replace(/^#\/?/, "");
|
||
const note = window.document.getElementById(id);
|
||
if (note !== null) {
|
||
try {
|
||
const html = processXRef(id, note.cloneNode(true));
|
||
instance.setContent(html);
|
||
} finally {
|
||
instance.enable();
|
||
instance.show();
|
||
}
|
||
} else {
|
||
// See if we can fetch this
|
||
fetch(url.split('#')[0])
|
||
.then(res => res.text())
|
||
.then(html => {
|
||
const parser = new DOMParser();
|
||
const htmlDoc = parser.parseFromString(html, "text/html");
|
||
const note = htmlDoc.getElementById(id);
|
||
if (note !== null) {
|
||
const html = processXRef(id, note);
|
||
instance.setContent(html);
|
||
}
|
||
}).finally(() => {
|
||
instance.enable();
|
||
instance.show();
|
||
});
|
||
}
|
||
} else {
|
||
// See if we can fetch a full url (with no hash to target)
|
||
// This is a special case and we should probably do some content thinning / targeting
|
||
fetch(url)
|
||
.then(res => res.text())
|
||
.then(html => {
|
||
const parser = new DOMParser();
|
||
const htmlDoc = parser.parseFromString(html, "text/html");
|
||
const note = htmlDoc.querySelector('main.content');
|
||
if (note !== null) {
|
||
// This should only happen for chapter cross references
|
||
// (since there is no id in the URL)
|
||
// remove the first header
|
||
if (note.children.length > 0 && note.children[0].tagName === "HEADER") {
|
||
note.children[0].remove();
|
||
}
|
||
const html = processXRef(null, note);
|
||
instance.setContent(html);
|
||
}
|
||
}).finally(() => {
|
||
instance.enable();
|
||
instance.show();
|
||
});
|
||
}
|
||
}, function(instance) {
|
||
});
|
||
}
|
||
let selectedAnnoteEl;
|
||
const selectorForAnnotation = ( cell, annotation) => {
|
||
let cellAttr = 'data-code-cell="' + cell + '"';
|
||
let lineAttr = 'data-code-annotation="' + annotation + '"';
|
||
const selector = 'span[' + cellAttr + '][' + lineAttr + ']';
|
||
return selector;
|
||
}
|
||
const selectCodeLines = (annoteEl) => {
|
||
const doc = window.document;
|
||
const targetCell = annoteEl.getAttribute("data-target-cell");
|
||
const targetAnnotation = annoteEl.getAttribute("data-target-annotation");
|
||
const annoteSpan = window.document.querySelector(selectorForAnnotation(targetCell, targetAnnotation));
|
||
const lines = annoteSpan.getAttribute("data-code-lines").split(",");
|
||
const lineIds = lines.map((line) => {
|
||
return targetCell + "-" + line;
|
||
})
|
||
let top = null;
|
||
let height = null;
|
||
let parent = null;
|
||
if (lineIds.length > 0) {
|
||
//compute the position of the single el (top and bottom and make a div)
|
||
const el = window.document.getElementById(lineIds[0]);
|
||
top = el.offsetTop;
|
||
height = el.offsetHeight;
|
||
parent = el.parentElement.parentElement;
|
||
if (lineIds.length > 1) {
|
||
const lastEl = window.document.getElementById(lineIds[lineIds.length - 1]);
|
||
const bottom = lastEl.offsetTop + lastEl.offsetHeight;
|
||
height = bottom - top;
|
||
}
|
||
if (top !== null && height !== null && parent !== null) {
|
||
// cook up a div (if necessary) and position it
|
||
let div = window.document.getElementById("code-annotation-line-highlight");
|
||
if (div === null) {
|
||
div = window.document.createElement("div");
|
||
div.setAttribute("id", "code-annotation-line-highlight");
|
||
div.style.position = 'absolute';
|
||
parent.appendChild(div);
|
||
}
|
||
div.style.top = top - 2 + "px";
|
||
div.style.height = height + 4 + "px";
|
||
div.style.left = 0;
|
||
let gutterDiv = window.document.getElementById("code-annotation-line-highlight-gutter");
|
||
if (gutterDiv === null) {
|
||
gutterDiv = window.document.createElement("div");
|
||
gutterDiv.setAttribute("id", "code-annotation-line-highlight-gutter");
|
||
gutterDiv.style.position = 'absolute';
|
||
const codeCell = window.document.getElementById(targetCell);
|
||
const gutter = codeCell.querySelector('.code-annotation-gutter');
|
||
gutter.appendChild(gutterDiv);
|
||
}
|
||
gutterDiv.style.top = top - 2 + "px";
|
||
gutterDiv.style.height = height + 4 + "px";
|
||
}
|
||
selectedAnnoteEl = annoteEl;
|
||
}
|
||
};
|
||
const unselectCodeLines = () => {
|
||
const elementsIds = ["code-annotation-line-highlight", "code-annotation-line-highlight-gutter"];
|
||
elementsIds.forEach((elId) => {
|
||
const div = window.document.getElementById(elId);
|
||
if (div) {
|
||
div.remove();
|
||
}
|
||
});
|
||
selectedAnnoteEl = undefined;
|
||
};
|
||
// Handle positioning of the toggle
|
||
window.addEventListener(
|
||
"resize",
|
||
throttle(() => {
|
||
elRect = undefined;
|
||
if (selectedAnnoteEl) {
|
||
selectCodeLines(selectedAnnoteEl);
|
||
}
|
||
}, 10)
|
||
);
|
||
function throttle(fn, ms) {
|
||
let throttle = false;
|
||
let timer;
|
||
return (...args) => {
|
||
if(!throttle) { // first call gets through
|
||
fn.apply(this, args);
|
||
throttle = true;
|
||
} else { // all the others get throttled
|
||
if(timer) clearTimeout(timer); // cancel #2
|
||
timer = setTimeout(() => {
|
||
fn.apply(this, args);
|
||
timer = throttle = false;
|
||
}, ms);
|
||
}
|
||
};
|
||
}
|
||
// Attach click handler to the DT
|
||
const annoteDls = window.document.querySelectorAll('dt[data-target-cell]');
|
||
for (const annoteDlNode of annoteDls) {
|
||
annoteDlNode.addEventListener('click', (event) => {
|
||
const clickedEl = event.target;
|
||
if (clickedEl !== selectedAnnoteEl) {
|
||
unselectCodeLines();
|
||
const activeEl = window.document.querySelector('dt[data-target-cell].code-annotation-active');
|
||
if (activeEl) {
|
||
activeEl.classList.remove('code-annotation-active');
|
||
}
|
||
selectCodeLines(clickedEl);
|
||
clickedEl.classList.add('code-annotation-active');
|
||
} else {
|
||
// Unselect the line
|
||
unselectCodeLines();
|
||
clickedEl.classList.remove('code-annotation-active');
|
||
}
|
||
});
|
||
}
|
||
const findCites = (el) => {
|
||
const parentEl = el.parentElement;
|
||
if (parentEl) {
|
||
const cites = parentEl.dataset.cites;
|
||
if (cites) {
|
||
return {
|
||
el,
|
||
cites: cites.split(' ')
|
||
};
|
||
} else {
|
||
return findCites(el.parentElement)
|
||
}
|
||
} else {
|
||
return undefined;
|
||
}
|
||
};
|
||
var bibliorefs = window.document.querySelectorAll('a[role="doc-biblioref"]');
|
||
for (var i=0; i<bibliorefs.length; i++) {
|
||
const ref = bibliorefs[i];
|
||
const citeInfo = findCites(ref);
|
||
if (citeInfo) {
|
||
tippyHover(citeInfo.el, function() {
|
||
var popup = window.document.createElement('div');
|
||
citeInfo.cites.forEach(function(cite) {
|
||
var citeDiv = window.document.createElement('div');
|
||
citeDiv.classList.add('hanging-indent');
|
||
citeDiv.classList.add('csl-entry');
|
||
var biblioDiv = window.document.getElementById('ref-' + cite);
|
||
if (biblioDiv) {
|
||
citeDiv.innerHTML = biblioDiv.innerHTML;
|
||
}
|
||
popup.appendChild(citeDiv);
|
||
});
|
||
return popup.innerHTML;
|
||
});
|
||
}
|
||
}
|
||
});
|
||
</script>
|
||
</div> <!-- /content -->
|
||
|
||
|
||
|
||
|
||
</body></html> |