<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
  <meta charset="utf-8" /><meta name="generator" content="Docutils 0.18.1: http://docutils.sourceforge.net/" />

  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>Introduction to Structify_Net &mdash; structify_net 2 documentation</title>
      <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
      <link rel="stylesheet" href="../_static/css/theme.css" type="text/css" />
      <link rel="stylesheet" href="../_static/custom.css" type="text/css" />
  <!--[if lt IE 9]>
    <script src="../_static/js/html5shiv.min.js"></script>
  <![endif]-->
  
        <script src="../_static/jquery.js"></script>
        <script src="../_static/_sphinx_javascript_frameworks_compat.js"></script>
        <script data-url_root="../" id="documentation_options" src="../_static/documentation_options.js"></script>
        <script src="../_static/doctools.js"></script>
        <script src="../_static/sphinx_highlight.js"></script>
        <script async="async" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
    <script src="../_static/js/theme.js"></script>
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="next" title="Classes" href="../Classes.html" />
    <link rel="prev" title="Welcome to Structify_net’s documentation!" href="../index.html" /> 
</head>

<body class="wy-body-for-nav"> 
  <div class="wy-grid-for-nav">
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >

          
          
          <a href="../index.html" class="icon icon-home">
            structify_net
          </a>
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" aria-label="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>
        </div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu">
              <ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../index.html">Welcome to Structify_net’s documentation!</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">Introduction to Structify_Net</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#step-1-graph-properties-definition">Step 1: Graph properties definition</a></li>
<li class="toctree-l2"><a class="reference internal" href="#step-2-structure-definion">Step 2: Structure definion</a></li>
<li class="toctree-l2"><a class="reference internal" href="#step-3-edge-probability-definition">Step 3: Edge probability definition</a></li>
<li class="toctree-l2"><a class="reference internal" href="#step-4-generate-a-graph-from-edge-probabilities">Step 4: Generate a graph from edge probabilities</a></li>
<li class="toctree-l2"><a class="reference internal" href="#whole-process-in-a-function">Whole process in a function</a></li>
<li class="toctree-l2"><a class="reference internal" href="#structure-zoo">Structure Zoo</a></li>
<li class="toctree-l2"><a class="reference internal" href="#graph-description">Graph description</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#getting-started-replicating-watts-strogatz-small-world-experiment">Getting Started: replicating Watts-Strogatz Small World experiment</a></li>
<li class="toctree-l3"><a class="reference internal" href="#plotting-the-results">Plotting the results</a></li>
<li class="toctree-l3"><a class="reference internal" href="#small-world-regime-for-other-structures">Small World regime for other structures</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="#models-profiling">Models Profiling</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#we-can-also-compare-properties-of-a-set-of-models">We can also compare properties of a set of models</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="#comparing-with-an-observed-network">Comparing with an observed network</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#generate-graphs-of-the-same-size">Generate graphs of the same size</a><ul>
<li class="toctree-l4"><a class="reference internal" href="#comparing">Comparing</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="#details-of-models-matching">Details of models matching</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../Classes.html">Classes</a></li>
<li class="toctree-l1"><a class="reference internal" href="../Zoo.html">Structure Zoo</a></li>
<li class="toctree-l1"><a class="reference internal" href="../Visualization.html">Visualization</a></li>
<li class="toctree-l1"><a class="reference internal" href="../Scoring.html">Scoring</a></li>
</ul>

        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" >
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../index.html">structify_net</a>
      </nav>

      <div class="wy-nav-content">
        <div class="rst-content">
          <div role="navigation" aria-label="Page navigation">
  <ul class="wy-breadcrumbs">
      <li><a href="../index.html" class="icon icon-home" aria-label="Home"></a></li>
      <li class="breadcrumb-item active">Introduction to Structify_Net</li>
      <li class="wy-breadcrumbs-aside">
            <a href="../_sources/Tutorial/Tutorial.rst.txt" rel="nofollow"> View page source</a>
      </li>
  </ul>
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
             
  <div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="o">%</span><span class="k">load_ext</span> autoreload
<span class="o">%</span><span class="k">autoreload</span> 2
<span class="kn">import</span> <span class="nn">networkx</span> <span class="k">as</span> <span class="nn">nx</span>
<span class="kn">import</span> <span class="nn">itertools</span>
<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="kn">import</span> <span class="nn">pandas</span> <span class="k">as</span> <span class="nn">pd</span>
<span class="kn">import</span> <span class="nn">matplotlib.pyplot</span> <span class="k">as</span> <span class="nn">plt</span>
<span class="kn">from</span> <span class="nn">matplotlib.pyplot</span> <span class="kn">import</span> <span class="n">figure</span>
<span class="kn">import</span> <span class="nn">netwulf</span>
<span class="kn">import</span> <span class="nn">seaborn</span> <span class="k">as</span> <span class="nn">sns</span>

<span class="kn">import</span> <span class="nn">structify_net</span> <span class="k">as</span> <span class="nn">stn</span>
<span class="kn">import</span> <span class="nn">structify_net.viz</span> <span class="k">as</span> <span class="nn">viz</span>
<span class="kn">import</span> <span class="nn">structify_net.zoo</span> <span class="k">as</span> <span class="nn">zoo</span>
<span class="kn">import</span> <span class="nn">structify_net.scoring</span> <span class="k">as</span> <span class="nn">scoring</span>
</pre></div>
</div>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">The</span> <span class="n">autoreload</span> <span class="n">extension</span> <span class="ow">is</span> <span class="n">already</span> <span class="n">loaded</span><span class="o">.</span> <span class="n">To</span> <span class="n">reload</span> <span class="n">it</span><span class="p">,</span> <span class="n">use</span><span class="p">:</span>
  <span class="o">%</span><span class="n">reload_ext</span> <span class="n">autoreload</span>
</pre></div>
</div>
<section id="introduction-to-structify-net">
<h1>Introduction to Structify_Net<a class="headerlink" href="#introduction-to-structify-net" title="Permalink to this heading"></a></h1>
<p>Structify_Net is a network generator provided as a python library.</p>
<p>It allows to generate networks with: * A chosen number of nodes and
edges * A chosen structure * A constrolled amount of randomness</p>
<section id="step-1-graph-properties-definition">
<h2>Step 1: Graph properties definition<a class="headerlink" href="#step-1-graph-properties-definition" title="Permalink to this heading"></a></h2>
<p>We start by defining the number of nodes and edges that we want</p>
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">n</span><span class="o">=</span><span class="mi">128</span>
<span class="n">m</span><span class="o">=</span><span class="mi">512</span>
</pre></div>
</div>
</section>
<section id="step-2-structure-definion">
<h2>Step 2: Structure definion<a class="headerlink" href="#step-2-structure-definion" title="Permalink to this heading"></a></h2>
<p>We start by defining a structure, by ordering the pairs of nodes in the
graph from the most likely to appear to the less likely to appear. For
instance, if we assume that our network is a spatial network, and that
each node has a position in an euclidean space, we can define that the
pairs of nodes are ranked according to their distance in this space.</p>
<p>Many classic structures are already implemented in Structify-Net. For
the sake of example, here we define a very simple organisation, which
actually correspond to a nested structure, by defining a sorting
function. This simple function only requires the nodes ids. we could
provide node attributes in the third parameter.</p>
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">R_nestedness</span><span class="p">(</span><span class="n">u</span><span class="p">,</span><span class="n">v</span><span class="p">,</span><span class="n">_</span><span class="p">):</span>
    <span class="k">return</span> <span class="n">u</span><span class="o">+</span><span class="n">v</span>
</pre></div>
</div>
<p>We then generate a Rank_model object using Structify-net</p>
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">rank_nested</span> <span class="o">=</span> <span class="n">stn</span><span class="o">.</span><span class="n">Rank_model</span><span class="p">(</span><span class="n">n</span><span class="p">,</span><span class="n">R_nestedness</span><span class="p">)</span>
</pre></div>
</div>
<p>A way to visualize the resulting structure is to plot the node pairs
order as a matrix</p>
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">figure</span><span class="p">(</span><span class="n">figsize</span><span class="o">=</span><span class="p">(</span><span class="mi">4</span><span class="p">,</span> <span class="mi">4</span><span class="p">),</span> <span class="n">dpi</span><span class="o">=</span><span class="mi">80</span><span class="p">)</span>

<span class="n">rank_nested</span><span class="o">.</span><span class="n">plot_matrix</span><span class="p">()</span>
</pre></div>
</div>
<img alt="../_images/output_10_0.png" src="../_images/output_10_0.png" />
</section>
<section id="step-3-edge-probability-definition">
<h2>Step 3: Edge probability definition<a class="headerlink" href="#step-3-edge-probability-definition" title="Permalink to this heading"></a></h2>
<p>Now that we know which node pairs are the most likely to appear, we need
to define a function <span class="math notranslate nohighlight">\(f\)</span> that assign edge probabilities on each
node pair, by respecting some constraints: * The expected number of
edges must be equal to the chosen parameter <code class="docutils literal notranslate"><span class="pre">m</span></code>,
i.e. <span class="math notranslate nohighlight">\(\sum_{u,v\in G}f(rank(u,v))=m\)</span> * For any two node pairs
<span class="math notranslate nohighlight">\(e_1\)</span> and <span class="math notranslate nohighlight">\(e_2\)</span>, if <span class="math notranslate nohighlight">\(rank(e_1)&gt;rank(e_2)\)</span>, then
<span class="math notranslate nohighlight">\(f(e_1)\geq f(e_2)\)</span></p>
<p>Although any such function can be provided, Structify-net provides a
convenient function generator, using a constraint parameter
<span class="math notranslate nohighlight">\(\epsilon \in [0,1]\)</span>, such as 0 corresponds to a deterministic
structure, the m pairs of highest rank being connected by an edge, while
1 corresponds to a fully random network.</p>
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">probas</span> <span class="o">=</span> <span class="n">rank_nested</span><span class="o">.</span><span class="n">get_generator</span><span class="p">(</span><span class="n">epsilon</span><span class="o">=</span><span class="mf">0.5</span><span class="p">,</span><span class="n">m</span><span class="o">=</span><span class="n">m</span><span class="p">)</span>
</pre></div>
</div>
<p>We can plot the probability as a function of rank for various values of
<code class="docutils literal notranslate"><span class="pre">epsilon</span></code></p>
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">fig</span><span class="p">,</span> <span class="n">ax</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplots</span><span class="p">()</span>
<span class="k">for</span> <span class="n">epsilon</span> <span class="ow">in</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mf">1.1</span><span class="p">,</span><span class="mi">1</span><span class="o">/</span><span class="mi">6</span><span class="p">):</span>
    <span class="n">probas</span> <span class="o">=</span> <span class="n">rank_nested</span><span class="o">.</span><span class="n">get_generator</span><span class="p">(</span><span class="n">epsilon</span><span class="o">=</span><span class="n">epsilon</span><span class="p">,</span><span class="n">m</span><span class="o">=</span><span class="n">m</span><span class="p">)</span>
    <span class="n">elt</span> <span class="o">=</span> <span class="n">probas</span><span class="o">.</span><span class="n">plot_proba_function</span><span class="p">(</span><span class="n">ax</span><span class="o">=</span><span class="n">ax</span><span class="p">)</span>
    <span class="c1">#elt=viz.plot_proba_function(probas,ax=ax)</span>
    <span class="n">elt</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">set_label</span><span class="p">(</span><span class="nb">format</span><span class="p">(</span><span class="n">epsilon</span><span class="p">,</span> <span class="s1">&#39;.2f&#39;</span><span class="p">))</span>
    <span class="c1">#fig_tem.plot(label=&quot;pouet&quot;+str(epsilon))</span>
<span class="n">ax</span><span class="o">.</span><span class="n">legend</span><span class="p">(</span><span class="n">title</span><span class="o">=</span><span class="s2">&quot;$\epsilon$&quot;</span><span class="p">)</span>
</pre></div>
</div>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">&lt;</span><span class="n">matplotlib</span><span class="o">.</span><span class="n">legend</span><span class="o">.</span><span class="n">Legend</span> <span class="n">at</span> <span class="mh">0x2e8157d10</span><span class="o">&gt;</span>
</pre></div>
</div>
<img alt="../_images/output_14_1.png" src="../_images/output_14_1.png" />
</section>
<section id="step-4-generate-a-graph-from-edge-probabilities">
<h2>Step 4: Generate a graph from edge probabilities<a class="headerlink" href="#step-4-generate-a-graph-from-edge-probabilities" title="Permalink to this heading"></a></h2>
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">generator</span> <span class="o">=</span> <span class="n">rank_nested</span><span class="o">.</span><span class="n">get_generator</span><span class="p">(</span><span class="n">epsilon</span><span class="o">=</span><span class="mf">0.5</span><span class="p">,</span><span class="n">m</span><span class="o">=</span><span class="n">m</span><span class="p">)</span>
<span class="n">g_generated</span> <span class="o">=</span> <span class="n">generator</span><span class="o">.</span><span class="n">generate</span><span class="p">()</span>
</pre></div>
</div>
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">figure</span><span class="p">(</span><span class="n">figsize</span><span class="o">=</span><span class="p">(</span><span class="mi">4</span><span class="p">,</span> <span class="mi">4</span><span class="p">),</span> <span class="n">dpi</span><span class="o">=</span><span class="mi">80</span><span class="p">)</span>
<span class="n">viz</span><span class="o">.</span><span class="n">plot_adjacency_matrix</span><span class="p">(</span><span class="n">g_generated</span><span class="p">)</span>
</pre></div>
</div>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">&lt;</span><span class="n">AxesSubplot</span><span class="p">:</span> <span class="o">&gt;</span>
</pre></div>
</div>
<img alt="../_images/output_17_1.png" src="../_images/output_17_1.png" />
</section>
<section id="whole-process-in-a-function">
<h2>Whole process in a function<a class="headerlink" href="#whole-process-in-a-function" title="Permalink to this heading"></a></h2>
<p>The whole process of graph generation from a desired number of nodes and
edges can be done in a single function</p>
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">g_example</span> <span class="o">=</span> <span class="n">rank_nested</span><span class="o">.</span><span class="n">generate_graph</span><span class="p">(</span><span class="n">epsilon</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span><span class="n">m</span><span class="o">=</span><span class="mi">500</span><span class="p">)</span>
</pre></div>
</div>
</section>
<section id="structure-zoo">
<h2>Structure Zoo<a class="headerlink" href="#structure-zoo" title="Permalink to this heading"></a></h2>
<p>StructifyNet already implement various graph structure. They are
exemplified below</p>
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">n</span><span class="o">=</span><span class="mi">128</span>
<span class="n">m</span><span class="o">=</span><span class="mi">512</span>
<span class="n">figure</span><span class="p">(</span><span class="n">figsize</span><span class="o">=</span><span class="p">(</span><span class="mi">12</span><span class="p">,</span> <span class="mi">12</span><span class="p">),</span> <span class="n">dpi</span><span class="o">=</span><span class="mi">80</span><span class="p">)</span>
<span class="k">for</span> <span class="n">i</span><span class="p">,(</span><span class="n">name</span><span class="p">,</span><span class="n">rank_model</span><span class="p">)</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">zoo</span><span class="o">.</span><span class="n">get_all_rank_models</span><span class="p">(</span><span class="n">n</span><span class="o">=</span><span class="mi">128</span><span class="p">,</span><span class="n">m</span><span class="o">=</span><span class="n">m</span><span class="p">)</span><span class="o">.</span><span class="n">items</span><span class="p">()):</span>
    <span class="n">ax</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplot</span><span class="p">(</span><span class="mi">4</span><span class="p">,</span><span class="mi">4</span><span class="p">,</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span> <span class="p">)</span>

    <span class="n">rank_model</span><span class="o">.</span><span class="n">plot_matrix</span><span class="p">()</span>

    <span class="n">ax</span><span class="o">.</span><span class="n">set_title</span><span class="p">(</span><span class="n">name</span><span class="p">)</span>
</pre></div>
</div>
<img alt="../_images/output_21_0.png" src="../_images/output_21_0.png" />
</section>
<section id="graph-description">
<h2>Graph description<a class="headerlink" href="#graph-description" title="Permalink to this heading"></a></h2>
<p>Models generate graphs having specific properties. Structify-Net
includes various scores that can be used to characterize networks –and
the model generating them.</p>
<section id="getting-started-replicating-watts-strogatz-small-world-experiment">
<h3>Getting Started: replicating Watts-Strogatz Small World experiment<a class="headerlink" href="#getting-started-replicating-watts-strogatz-small-world-experiment" title="Permalink to this heading"></a></h3>
<p>The famous small world experiments consisted in generating networks with
a locally clustered structure (nodes are located on a ring and connected
to their neighbors), and then introducing progressively random noise,
until reaching a random network. The <em>small world regime</em> corresponds to
the level of noise for which the clustering coefficient is still high
-as in the locally clustered network- but the average shortest path is
already low -as in a random network.</p>
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">n</span><span class="o">=</span><span class="mi">1000</span>
<span class="n">m</span><span class="o">=</span><span class="n">n</span><span class="o">*</span><span class="mi">5</span>
<span class="n">WS_model</span> <span class="o">=</span> <span class="n">zoo</span><span class="o">.</span><span class="n">sort_spatial_WS</span><span class="p">(</span><span class="n">n</span><span class="p">,</span><span class="n">k</span><span class="o">=</span><span class="mi">10</span><span class="p">)</span> <span class="c1">#k is the nodes degree</span>
<span class="n">df_scores</span> <span class="o">=</span> <span class="n">WS_model</span><span class="o">.</span><span class="n">scores</span><span class="p">(</span><span class="n">m</span><span class="o">=</span><span class="n">m</span><span class="p">,</span>
                <span class="n">scores</span><span class="o">=</span><span class="p">{</span><span class="s2">&quot;clustering&quot;</span><span class="p">:</span><span class="n">scoring</span><span class="o">.</span><span class="n">average_clustering</span><span class="p">,</span>
                        <span class="s2">&quot;short paths&quot;</span><span class="p">:</span><span class="n">scoring</span><span class="o">.</span><span class="n">average_shortest_path_length</span><span class="p">},</span>
                <span class="n">epsilons</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">logspace</span><span class="p">(</span><span class="o">-</span><span class="mi">4</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">10</span><span class="p">),</span><span class="n">latex_names</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="n">df_scores</span><span class="o">.</span><span class="n">head</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span>
</pre></div>
</div>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>Epsilon:   0%|          | 0/10 [00:00&lt;?, ?it/s]
</pre></div>
</div>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>Run:   0%|          | 0/1 [00:00&lt;?, ?it/s]
</pre></div>
</div>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>Run:   0%|          | 0/1 [00:00&lt;?, ?it/s]
</pre></div>
</div>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>Run:   0%|          | 0/1 [00:00&lt;?, ?it/s]
</pre></div>
</div>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>Run:   0%|          | 0/1 [00:00&lt;?, ?it/s]
</pre></div>
</div>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>Run:   0%|          | 0/1 [00:00&lt;?, ?it/s]
</pre></div>
</div>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>Run:   0%|          | 0/1 [00:00&lt;?, ?it/s]
</pre></div>
</div>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>Run:   0%|          | 0/1 [00:00&lt;?, ?it/s]
</pre></div>
</div>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>Run:   0%|          | 0/1 [00:00&lt;?, ?it/s]
</pre></div>
</div>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>Run:   0%|          | 0/1 [00:00&lt;?, ?it/s]
</pre></div>
</div>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>Run:   0%|          | 0/1 [00:00&lt;?, ?it/s]
</pre></div>
</div>
<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>name</th>
      <th>clustering</th>
      <th>short paths</th>
      <th>epsilon</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>model</td>
      <td>0.664838</td>
      <td>0.043552</td>
      <td>0.000100</td>
    </tr>
    <tr>
      <th>1</th>
      <td>model</td>
      <td>0.663089</td>
      <td>0.055966</td>
      <td>0.000278</td>
    </tr>
    <tr>
      <th>2</th>
      <td>model</td>
      <td>0.657589</td>
      <td>0.092717</td>
      <td>0.000774</td>
    </tr>
  </tbody>
</table>
</div></section>
<section id="plotting-the-results">
<h3>Plotting the results<a class="headerlink" href="#plotting-the-results" title="Permalink to this heading"></a></h3>
<p>We can observe the small world regime by plotting the evolution of both
values as a function of <code class="docutils literal notranslate"><span class="pre">epsilon</span></code>. Note that the <code class="docutils literal notranslate"><span class="pre">short</span> <span class="pre">paths</span></code> is
defined in a different way than in the original article, to be more
generic. It corresponds to the inverse of the average distance,
normalized such as <code class="docutils literal notranslate"><span class="pre">short</span> <span class="pre">paths</span></code>=1 for a network with a complete
star, such as each node is at distance 2 from all other node.</p>
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">df_scores</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">x</span><span class="o">=</span><span class="s2">&quot;epsilon&quot;</span><span class="p">,</span><span class="n">logx</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span><span class="n">figsize</span><span class="o">=</span><span class="p">(</span><span class="mi">8</span><span class="p">,</span> <span class="mi">3</span><span class="p">))</span>
</pre></div>
</div>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">&lt;</span><span class="n">AxesSubplot</span><span class="p">:</span> <span class="n">xlabel</span><span class="o">=</span><span class="s1">&#39;epsilon&#39;</span><span class="o">&gt;</span>
</pre></div>
</div>
<img alt="../_images/output_26_1.png" src="../_images/output_26_1.png" />
</section>
<section id="small-world-regime-for-other-structures">
<h3>Small World regime for other structures<a class="headerlink" href="#small-world-regime-for-other-structures" title="Permalink to this heading"></a></h3>
<p>We can replicate this experiment for all structures in our structure zoo</p>
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">df_scores</span> <span class="o">=</span> <span class="n">scoring</span><span class="o">.</span><span class="n">scores_for_rank_models</span><span class="p">(</span><span class="n">zoo</span><span class="o">.</span><span class="n">get_all_rank_models</span><span class="p">(</span><span class="n">n</span><span class="p">,</span><span class="n">m</span><span class="p">),</span><span class="n">m</span><span class="o">=</span><span class="n">m</span><span class="p">,</span>
                       <span class="n">scores</span><span class="o">=</span><span class="p">{</span><span class="s2">&quot;clustering&quot;</span><span class="p">:</span><span class="n">scoring</span><span class="o">.</span><span class="n">average_clustering</span><span class="p">,</span>
                               <span class="s2">&quot;short paths&quot;</span><span class="p">:</span><span class="n">scoring</span><span class="o">.</span><span class="n">average_shortest_path_length</span><span class="p">},</span>
                       <span class="n">epsilons</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">logspace</span><span class="p">(</span><span class="o">-</span><span class="mi">4</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">10</span><span class="p">),</span><span class="n">latex_names</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
</pre></div>
</div>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>Epsilon:   0%|          | 0/10 [00:00&lt;?, ?it/s]
</pre></div>
</div>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>Run:   0%|          | 0/1 [00:00&lt;?, ?it/s]
</pre></div>
</div>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>Run:   0%|          | 0/1 [00:00&lt;?, ?it/s]
</pre></div>
</div>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>Run:   0%|          | 0/1 [00:00&lt;?, ?it/s]
</pre></div>
</div>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>Run:   0%|          | 0/1 [00:00&lt;?, ?it/s]
</pre></div>
</div>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>Run:   0%|          | 0/1 [00:00&lt;?, ?it/s]
</pre></div>
</div>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>Run:   0%|          | 0/1 [00:00&lt;?, ?it/s]
</pre></div>
</div>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>Run:   0%|          | 0/1 [00:00&lt;?, ?it/s]
</pre></div>
</div>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>Run:   0%|          | 0/1 [00:00&lt;?, ?it/s]
</pre></div>
</div>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>Run:   0%|          | 0/1 [00:00&lt;?, ?it/s]
</pre></div>
</div>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>Run:   0%|          | 0/1 [00:00&lt;?, ?it/s]
</pre></div>
</div>
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">df_scores</span><span class="o">.</span><span class="n">head</span><span class="p">()</span>
</pre></div>
</div>
<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>name</th>
      <th>clustering</th>
      <th>short paths</th>
      <th>epsilon</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>ER</td>
      <td>0.009857</td>
      <td>0.444096</td>
      <td>0.0001</td>
    </tr>
    <tr>
      <th>1</th>
      <td>blocks_assortative</td>
      <td>0.329946</td>
      <td>0.000000</td>
      <td>0.0001</td>
    </tr>
    <tr>
      <th>2</th>
      <td>core_distance</td>
      <td>0.112838</td>
      <td>0.000000</td>
      <td>0.0001</td>
    </tr>
    <tr>
      <th>3</th>
      <td>disconnected_cliques</td>
      <td>0.978983</td>
      <td>0.000000</td>
      <td>0.0001</td>
    </tr>
    <tr>
      <th>4</th>
      <td>fractal_hierarchy</td>
      <td>0.829898</td>
      <td>0.971546</td>
      <td>0.0001</td>
    </tr>
  </tbody>
</table>
</div><div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">g</span> <span class="o">=</span> <span class="n">df_scores</span><span class="o">.</span><span class="n">groupby</span><span class="p">(</span><span class="s1">&#39;name&#39;</span><span class="p">)</span>

<span class="n">fig</span><span class="p">,</span> <span class="n">axes</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplots</span><span class="p">(</span><span class="mi">4</span><span class="p">,</span><span class="mi">4</span><span class="p">,</span> <span class="n">sharex</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="n">all_axes</span> <span class="o">=</span> <span class="n">axes</span><span class="o">.</span><span class="n">flatten</span><span class="p">()</span>
<span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">d</span><span class="p">)</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">g</span><span class="p">):</span>
    <span class="n">ax</span> <span class="o">=</span> <span class="n">d</span><span class="o">.</span><span class="n">plot</span><span class="o">.</span><span class="n">line</span><span class="p">(</span><span class="n">x</span><span class="o">=</span><span class="s1">&#39;epsilon&#39;</span><span class="p">,</span> <span class="n">ax</span><span class="o">=</span><span class="n">all_axes</span><span class="p">[</span><span class="n">i</span><span class="p">],</span> <span class="n">title</span><span class="o">=</span><span class="n">name</span><span class="p">,</span><span class="n">logx</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span><span class="n">figsize</span><span class="o">=</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span> <span class="mi">8</span><span class="p">))</span>
    <span class="n">ax</span><span class="o">.</span><span class="n">set_ylim</span><span class="p">(</span><span class="o">-</span><span class="mf">0.05</span><span class="p">,</span><span class="mf">1.05</span><span class="p">)</span>
    <span class="n">ax</span><span class="o">.</span><span class="n">legend</span><span class="p">()</span><span class="o">.</span><span class="n">remove</span><span class="p">()</span>
</pre></div>
</div>
<img alt="../_images/output_30_0.png" src="../_images/output_30_0.png" />
</section>
</section>
<section id="models-profiling">
<h2>Models Profiling<a class="headerlink" href="#models-profiling" title="Permalink to this heading"></a></h2>
<p>Average distance and Average clustering are only two examples of graph
structure descriptors. Structify-Net contains several other descriptors.
We can use them to show more details of the evolution from the regular
grid to the random network</p>
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">detail_evolution</span> <span class="o">=</span> <span class="n">zoo</span><span class="o">.</span><span class="n">sort_spatial_WS</span><span class="p">(</span><span class="mi">500</span><span class="p">)</span><span class="o">.</span><span class="n">scores</span><span class="p">(</span><span class="n">m</span><span class="o">=</span><span class="mi">500</span><span class="o">*</span><span class="mi">5</span><span class="p">,</span><span class="n">epsilons</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">logspace</span><span class="p">(</span><span class="o">-</span><span class="mi">4</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">6</span><span class="p">),</span><span class="n">scores</span><span class="o">=</span><span class="n">scoring</span><span class="o">.</span><span class="n">get_default_scores</span><span class="p">(),</span><span class="n">latex_names</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="c1">#detail_evolution = toolBox.scores_for_rank_functions({&quot;spatialWS&quot;:zoo.sort_spatial_WS},500,500*5,epsilons=np.logspace(-4,0,6),scores=toolBox.get_all_scores())</span>
</pre></div>
</div>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>Epsilon:   0%|          | 0/6 [00:00&lt;?, ?it/s]
</pre></div>
</div>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>Run:   0%|          | 0/1 [00:00&lt;?, ?it/s]
</pre></div>
</div>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>Run:   0%|          | 0/1 [00:00&lt;?, ?it/s]
</pre></div>
</div>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>Run:   0%|          | 0/1 [00:00&lt;?, ?it/s]
</pre></div>
</div>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>Run:   0%|          | 0/1 [00:00&lt;?, ?it/s]
</pre></div>
</div>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>Run:   0%|          | 0/1 [00:00&lt;?, ?it/s]
</pre></div>
</div>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>Run:   0%|          | 0/1 [00:00&lt;?, ?it/s]
</pre></div>
</div>
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">detail_evolution</span>
</pre></div>
</div>
<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>name</th>
      <th>$CC(G)$</th>
      <th>$\overline{CC(u)}$</th>
      <th>Core</th>
      <th>$\overline{d}$</th>
      <th>Rob</th>
      <th>I</th>
      <th>$Q$</th>
      <th>$Q_{bound}$</th>
      <th>$\sigma(k)$</th>
      <th>$$-(k \propto k)$$</th>
      <th>$${k \propto CC}$$</th>
      <th>$\epsilon$</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>model</td>
      <td>0.666075</td>
      <td>0.666182</td>
      <td>0.200000</td>
      <td>0.046832</td>
      <td>1.00</td>
      <td>1.0</td>
      <td>0.777533</td>
      <td>0.260278</td>
      <td>0.000398</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.000100</td>
    </tr>
    <tr>
      <th>1</th>
      <td>model</td>
      <td>0.656600</td>
      <td>0.657631</td>
      <td>0.183673</td>
      <td>0.108350</td>
      <td>0.98</td>
      <td>1.0</td>
      <td>0.773530</td>
      <td>0.224972</td>
      <td>0.008416</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.000631</td>
    </tr>
    <tr>
      <th>2</th>
      <td>model</td>
      <td>0.626598</td>
      <td>0.631821</td>
      <td>0.163265</td>
      <td>0.206054</td>
      <td>0.98</td>
      <td>1.0</td>
      <td>0.764524</td>
      <td>0.238881</td>
      <td>0.030597</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.003981</td>
    </tr>
    <tr>
      <th>3</th>
      <td>model</td>
      <td>0.447929</td>
      <td>0.466216</td>
      <td>0.142857</td>
      <td>0.355655</td>
      <td>0.98</td>
      <td>1.0</td>
      <td>0.654202</td>
      <td>0.217358</td>
      <td>0.077708</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.025119</td>
    </tr>
    <tr>
      <th>4</th>
      <td>model</td>
      <td>0.105552</td>
      <td>0.113990</td>
      <td>0.142857</td>
      <td>0.481359</td>
      <td>1.00</td>
      <td>1.0</td>
      <td>0.268974</td>
      <td>0.172912</td>
      <td>0.141030</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.158489</td>
    </tr>
    <tr>
      <th>5</th>
      <td>model</td>
      <td>0.017456</td>
      <td>0.016949</td>
      <td>0.140000</td>
      <td>0.518599</td>
      <td>0.98</td>
      <td>1.0</td>
      <td>0.021596</td>
      <td>0.070055</td>
      <td>0.163151</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>1.000000</td>
    </tr>
  </tbody>
</table>
</div><div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">viz</span><span class="o">.</span><span class="n">spider_plot</span><span class="p">(</span><span class="n">detail_evolution</span><span class="p">,</span><span class="n">reference</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
</pre></div>
</div>
<img alt="../_images/output_34_0.png" src="../_images/output_34_0.png" />
<section id="we-can-also-compare-properties-of-a-set-of-models">
<h3>We can also compare properties of a set of models<a class="headerlink" href="#we-can-also-compare-properties-of-a-set-of-models" title="Permalink to this heading"></a></h3>
<p>In this case, we plot all models in Structify’s Zoo, with
<code class="docutils literal notranslate"><span class="pre">epsilon</span></code>=0</p>
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">n</span><span class="p">,</span><span class="n">m</span><span class="o">=</span><span class="mi">128</span><span class="p">,</span><span class="mi">128</span><span class="o">*</span><span class="mi">8</span>
<span class="n">detail_evolution</span> <span class="o">=</span> <span class="n">scoring</span><span class="o">.</span><span class="n">scores_for_rank_models</span><span class="p">(</span><span class="n">zoo</span><span class="o">.</span><span class="n">get_all_rank_models</span><span class="p">(</span><span class="n">n</span><span class="p">,</span><span class="n">m</span><span class="p">),</span><span class="n">m</span><span class="p">,</span><span class="n">epsilons</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span><span class="n">latex_names</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
</pre></div>
</div>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>Epsilon:   0%|          | 0/1 [00:00&lt;?, ?it/s]
</pre></div>
</div>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>Run:   0%|          | 0/1 [00:00&lt;?, ?it/s]
</pre></div>
</div>
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">viz</span><span class="o">.</span><span class="n">spider_plot</span><span class="p">(</span><span class="n">detail_evolution</span><span class="p">,</span><span class="n">reference</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
</pre></div>
</div>
<img alt="../_images/output_37_0.png" src="../_images/output_37_0.png" />
</section>
</section>
<section id="comparing-with-an-observed-network">
<h2>Comparing with an observed network<a class="headerlink" href="#comparing-with-an-observed-network" title="Permalink to this heading"></a></h2>
<p>If we are interested in a particular network, we can compare the
structure of that network with the strucuture of some candidate models
in our strucuture zoo. For instance, let us check the structure of the
Zackary karate club graph</p>
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">karate_scores</span> <span class="o">=</span> <span class="n">scoring</span><span class="o">.</span><span class="n">scores_for_graphs</span><span class="p">({</span><span class="s2">&quot;karate club&quot;</span><span class="p">:</span><span class="n">nx</span><span class="o">.</span><span class="n">karate_club_graph</span><span class="p">()},</span><span class="n">latex_names</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="n">viz</span><span class="o">.</span><span class="n">spider_plot</span><span class="p">(</span><span class="n">karate_scores</span><span class="p">)</span>
</pre></div>
</div>
<img alt="../_images/output_39_0.png" src="../_images/output_39_0.png" />
<section id="generate-graphs-of-the-same-size">
<h3>Generate graphs of the same size<a class="headerlink" href="#generate-graphs-of-the-same-size" title="Permalink to this heading"></a></h3>
<p>We generate graphs using the structures in the zoo, varying the epsilon
parameter, but keeping the same number of nodes and (expected) edges
than in the target graph. To get more reliable results, we take the
average values over multiple runs.</p>
<p>Since the karate club graph is often interpreted in term of communities,
we include two additional versions of the structures, that can be
parameterized with the number of blocks.</p>
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">n</span><span class="o">=</span><span class="n">nx</span><span class="o">.</span><span class="n">karate_club_graph</span><span class="p">()</span><span class="o">.</span><span class="n">number_of_nodes</span><span class="p">()</span>
<span class="n">m</span><span class="o">=</span><span class="n">nx</span><span class="o">.</span><span class="n">karate_club_graph</span><span class="p">()</span><span class="o">.</span><span class="n">number_of_edges</span><span class="p">()</span>
<span class="n">models_to_compare</span><span class="o">=</span><span class="n">zoo</span><span class="o">.</span><span class="n">get_all_rank_models</span><span class="p">(</span><span class="n">n</span><span class="p">,</span><span class="n">m</span><span class="p">)</span>

<span class="n">louvain_communities</span><span class="o">=</span><span class="n">nx</span><span class="o">.</span><span class="n">community</span><span class="o">.</span><span class="n">louvain_communities</span><span class="p">(</span><span class="n">nx</span><span class="o">.</span><span class="n">karate_club_graph</span><span class="p">())</span>
<span class="n">models_to_compare</span><span class="p">[</span><span class="s2">&quot;louvain&quot;</span><span class="p">]</span><span class="o">=</span><span class="n">zoo</span><span class="o">.</span><span class="n">sort_blocks_assortative</span><span class="p">(</span><span class="n">n</span><span class="p">,</span><span class="n">blocks</span><span class="o">=</span><span class="n">louvain_communities</span><span class="p">)</span>
<span class="n">models_to_compare</span><span class="p">[</span><span class="s2">&quot;com=2&quot;</span><span class="p">]</span><span class="o">=</span><span class="n">zoo</span><span class="o">.</span><span class="n">sort_blocks_assortative</span><span class="p">(</span><span class="n">n</span><span class="p">,</span><span class="n">blocks</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span>
<span class="n">epsilons</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">logspace</span><span class="p">(</span><span class="o">-</span><span class="mi">3</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">10</span><span class="p">)</span>
</pre></div>
</div>
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">compare_scores</span> <span class="o">=</span> <span class="n">scoring</span><span class="o">.</span><span class="n">scores_for_rank_models</span><span class="p">(</span><span class="n">models_to_compare</span><span class="p">,</span><span class="n">m</span><span class="p">,</span><span class="n">epsilons</span><span class="o">=</span><span class="n">epsilons</span><span class="p">,</span><span class="n">runs</span><span class="o">=</span><span class="mi">20</span><span class="p">)</span>
</pre></div>
</div>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>Epsilon:   0%|          | 0/10 [00:00&lt;?, ?it/s]
</pre></div>
</div>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>Run:   0%|          | 0/20 [00:00&lt;?, ?it/s]
</pre></div>
</div>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>Run:   0%|          | 0/20 [00:00&lt;?, ?it/s]
</pre></div>
</div>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>Run:   0%|          | 0/20 [00:00&lt;?, ?it/s]
</pre></div>
</div>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>Run:   0%|          | 0/20 [00:00&lt;?, ?it/s]
</pre></div>
</div>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>Run:   0%|          | 0/20 [00:00&lt;?, ?it/s]
</pre></div>
</div>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>Run:   0%|          | 0/20 [00:00&lt;?, ?it/s]
</pre></div>
</div>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>Run:   0%|          | 0/20 [00:00&lt;?, ?it/s]
</pre></div>
</div>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>Run:   0%|          | 0/20 [00:00&lt;?, ?it/s]
</pre></div>
</div>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>Run:   0%|          | 0/20 [00:00&lt;?, ?it/s]
</pre></div>
</div>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>Run:   0%|          | 0/20 [00:00&lt;?, ?it/s]
</pre></div>
</div>
<section id="comparing">
<h4>Comparing<a class="headerlink" href="#comparing" title="Permalink to this heading"></a></h4>
<p>We compute the <span class="math notranslate nohighlight">\(L_1\)</span> distance (sum of differences in each score)
between the observed graph and the models. We can explore how the
models’ similarity evolve as a function of the random parameter</p>
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">compare</span> <span class="o">=</span> <span class="n">scoring</span><span class="o">.</span><span class="n">compare_graphs</span><span class="p">(</span><span class="n">karate_scores</span><span class="p">,</span><span class="n">compare_scores</span><span class="p">,</span><span class="n">best_by_name</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span><span class="n">score_difference</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
</pre></div>
</div>
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">ax</span> <span class="o">=</span> <span class="n">sns</span><span class="o">.</span><span class="n">lineplot</span><span class="p">(</span><span class="n">data</span><span class="o">=</span><span class="n">compare</span><span class="p">,</span><span class="n">x</span><span class="o">=</span><span class="s2">&quot;$\epsilon$&quot;</span><span class="p">,</span><span class="n">y</span><span class="o">=</span><span class="s2">&quot;distance&quot;</span><span class="p">,</span><span class="n">hue</span><span class="o">=</span><span class="s2">&quot;name&quot;</span><span class="p">,</span><span class="n">style</span><span class="o">=</span><span class="s2">&quot;name&quot;</span><span class="p">,</span><span class="n">palette</span><span class="o">=</span><span class="n">sns</span><span class="o">.</span><span class="n">color_palette</span><span class="p">(</span><span class="s2">&quot;husl&quot;</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">models_to_compare</span><span class="p">)))</span>
<span class="n">sns</span><span class="o">.</span><span class="n">move_legend</span><span class="p">(</span><span class="n">ax</span><span class="p">,</span> <span class="s2">&quot;upper left&quot;</span><span class="p">,</span> <span class="n">bbox_to_anchor</span><span class="o">=</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span>
<span class="n">plt</span><span class="o">.</span><span class="n">xscale</span><span class="p">(</span><span class="s1">&#39;log&#39;</span><span class="p">)</span>
</pre></div>
</div>
<img alt="../_images/output_45_0.png" src="../_images/output_45_0.png" />
</section>
</section>
</section>
<section id="details-of-models-matching">
<h2>Details of models matching<a class="headerlink" href="#details-of-models-matching" title="Permalink to this heading"></a></h2>
<p>We can study in more details what properties does each model captures or
not. We select for each model the value of epsilon giving the best
match. Models are also sorted according the distance, so that the first
models returned are the most similar, and then we plot the properties of
those selected models, with the properties of our graph for comparison</p>
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">compare</span> <span class="o">=</span> <span class="n">scoring</span><span class="o">.</span><span class="n">compare_graphs</span><span class="p">(</span><span class="n">karate_scores</span><span class="p">,</span><span class="n">compare_scores</span><span class="p">,</span><span class="n">best_by_name</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span><span class="n">score_difference</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
</pre></div>
</div>
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">compare</span><span class="o">.</span><span class="n">head</span><span class="p">()</span>
</pre></div>
</div>
<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>name</th>
      <th>$CC(G)$</th>
      <th>$\overline{CC(u)}$</th>
      <th>Core</th>
      <th>$\overline{d}$</th>
      <th>Rob</th>
      <th>I</th>
      <th>$Q$</th>
      <th>$Q_{bound}$</th>
      <th>$\sigma(k)$</th>
      <th>$$-(k \propto k)$$</th>
      <th>$${k \propto CC}$$</th>
      <th>$\epsilon$</th>
      <th>distance</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>fractal_hierarchy</td>
      <td>0.280471</td>
      <td>0.564375</td>
      <td>0.461806</td>
      <td>0.869461</td>
      <td>0.254</td>
      <td>0.992647</td>
      <td>0.132835</td>
      <td>0.414314</td>
      <td>0.319198</td>
      <td>0.000000</td>
      <td>0.159376</td>
      <td>0.100000</td>
      <td>0.898688</td>
    </tr>
    <tr>
      <th>1</th>
      <td>fractal_root</td>
      <td>0.440271</td>
      <td>0.622941</td>
      <td>0.425000</td>
      <td>0.557126</td>
      <td>0.418</td>
      <td>0.998529</td>
      <td>0.302972</td>
      <td>0.476464</td>
      <td>0.279551</td>
      <td>0.043807</td>
      <td>0.681881</td>
      <td>0.100000</td>
      <td>1.023490</td>
    </tr>
    <tr>
      <th>2</th>
      <td>maximal_stars</td>
      <td>0.226890</td>
      <td>0.423235</td>
      <td>0.449306</td>
      <td>0.882993</td>
      <td>0.400</td>
      <td>0.970588</td>
      <td>0.000000</td>
      <td>0.285450</td>
      <td>0.439384</td>
      <td>0.000000</td>
      <td>0.070655</td>
      <td>0.464159</td>
      <td>1.198892</td>
    </tr>
    <tr>
      <th>3</th>
      <td>core_distance</td>
      <td>0.280774</td>
      <td>0.240385</td>
      <td>0.527778</td>
      <td>0.606878</td>
      <td>0.600</td>
      <td>0.957353</td>
      <td>0.007563</td>
      <td>0.369889</td>
      <td>0.362630</td>
      <td>0.039165</td>
      <td>0.004190</td>
      <td>0.464159</td>
      <td>1.481096</td>
    </tr>
    <tr>
      <th>4</th>
      <td>spatialWS</td>
      <td>0.314400</td>
      <td>0.282437</td>
      <td>0.500000</td>
      <td>0.547238</td>
      <td>0.600</td>
      <td>1.000000</td>
      <td>0.198066</td>
      <td>0.412887</td>
      <td>0.195659</td>
      <td>0.000000</td>
      <td>0.000000</td>
      <td>0.001000</td>
      <td>1.498977</td>
    </tr>
  </tbody>
</table>
</div><div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">compare_plot</span><span class="o">=</span><span class="n">compare</span><span class="o">.</span><span class="n">drop</span><span class="p">(</span><span class="n">columns</span><span class="o">=</span><span class="p">[</span><span class="s2">&quot;distance&quot;</span><span class="p">])</span>
<span class="n">compare_plot</span><span class="o">.</span><span class="n">loc</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="p">:]</span> <span class="o">=</span> <span class="n">karate_scores</span><span class="o">.</span><span class="n">iloc</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
<span class="n">compare_plot</span><span class="o">.</span><span class="n">sort_index</span><span class="p">(</span><span class="n">inplace</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
</pre></div>
</div>
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">viz</span><span class="o">.</span><span class="n">spider_plot</span><span class="p">(</span><span class="n">compare_plot</span><span class="p">,</span><span class="n">reference</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
</pre></div>
</div>
<img alt="../_images/output_50_0.png" src="../_images/output_50_0.png" />
</section>
</section>


           </div>
          </div>
          <footer><div class="rst-footer-buttons" role="navigation" aria-label="Footer">
        <a href="../index.html" class="btn btn-neutral float-left" title="Welcome to Structify_net’s documentation!" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
        <a href="../Classes.html" class="btn btn-neutral float-right" title="Classes" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
    </div>

  <hr/>

  <div role="contentinfo">
    <p>&#169; Copyright 2023, Rémy Cazabet.</p>
  </div>

  Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a
    <a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a>
    provided by <a href="https://readthedocs.org">Read the Docs</a>.
   

</footer>
        </div>
      </div>
    </section>
  </div>
  <script>
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script> 

</body>
</html>