1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265
|
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Community detection for NetworkX’s documentation — Community detection for NetworkX 2 documentation</title>
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="_static/classic.css" type="text/css" />
<script id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
<script src="_static/jquery.js"></script>
<script src="_static/underscore.js"></script>
<script src="_static/doctools.js"></script>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="community API" href="api.html" />
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try{
var pageTracker = _gat._getTracker("UA-7251741-1");
pageTracker._trackPageview();
} catch(err) {}
</script>
</head><body>
<div style="background-color: white; text-align: left; padding: 10px 10px 15px 15px">
<a href="#">Community detection</a>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="api.html" title="community API"
accesskey="N">next</a> |</li>
<li><a href="#">home</a>| </li>
<li><a href="search.html">search</a>| </li>
<li><a href="api.html">documentation </a> »</li>
<li class="nav-item nav-item-this"><a href="">Community detection for NetworkX’s documentation</a></li>
</ul>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<h3><a href="#">Table of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">Community detection for NetworkX’s documentation</a></li>
<li><a class="reference internal" href="#example">Example :</a><ul>
<li><a class="reference internal" href="#as-a-command-line-utility">As a command line utility :</a></li>
<li><a class="reference internal" href="#as-python-module">As python module :</a></li>
</ul>
</li>
<li><a class="reference internal" href="#changelog">Changelog :</a></li>
<li><a class="reference internal" href="#license">License :</a></li>
<li><a class="reference internal" href="#indices-and-tables">Indices and tables</a></li>
</ul>
<h4>Next topic</h4>
<p class="topless"><a href="api.html"
title="next chapter">community API</a></p>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/index.rst.txt"
rel="nofollow">Show Source</a></li>
</ul>
</div>
<div id="searchbox" style="display: none" role="search">
<h3 id="searchlabel">Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" />
<input type="submit" value="Go" />
</form>
</div>
</div>
<script>$('#searchbox').show(0);</script>
</div>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<div class="toctree-wrapper compound">
<ul>
<li class="toctree-l1"><a class="reference internal" href="api.html">community API</a><ul class="simple">
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="api.html#indices-and-tables">Indices and tables</a></li>
</ul>
</div>
<div class="section" id="community-detection-for-networkx-s-documentation">
<h1>Community detection for NetworkX’s documentation<a class="headerlink" href="#community-detection-for-networkx-s-documentation" title="Permalink to this headline">¶</a></h1>
<p>This module implements community detection.</p>
<p>It uses the louvain method described in
Fast unfolding of communities in large networks,
Vincent D Blondel, Jean-Loup Guillaume, Renaud Lambiotte, Renaud Lefebvre,
Journal of Statistical Mechanics: Theory and Experiment 2008(10), P10008 (12pp)</p>
<p>It depends on Networkx to handle graph operations :
<a class="reference external" href="http://networkx.lanl.gov/">http://networkx.lanl.gov/</a></p>
<p>The program can be found in a repository where you can also report bugs :</p>
<a href="https://github.com/taynaud/python-louvain">https://github.com/taynaud/python-louvain</a></div>
<div class="section" id="example">
<h1>Example :<a class="headerlink" href="#example" title="Permalink to this headline">¶</a></h1>
<div class="section" id="as-a-command-line-utility">
<h2>As a command line utility :<a class="headerlink" href="#as-a-command-line-utility" title="Permalink to this headline">¶</a></h2>
<p>You should consider using the cpp version at
<a class="reference external" href="http://findcommunities.googlepages.com/">http://findcommunities.googlepages.com/</a> !</p>
<p>./community.py file.bin > tree</p>
<p>where file.bin is a binary graph as generated by the convert utility of the cpp
version.</p>
<p>The generated file can then be used with the hierarchy utility of the cpp version.
Note that the program does not make many verifications about the arguments,
and is expecting a friendly use.</p>
</div>
<div class="section" id="as-python-module">
<h2>As python module :<a class="headerlink" href="#as-python-module" title="Permalink to this headline">¶</a></h2>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">community</span> <span class="k">as</span> <span class="nn">community_louvain</span>
<span class="kn">import</span> <span class="nn">matplotlib.cm</span> <span class="k">as</span> <span class="nn">cm</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">import</span> <span class="nn">networkx</span> <span class="k">as</span> <span class="nn">nx</span>
<span class="c1"># load the karate club graph</span>
<span class="n">G</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="c1">#first compute the best partition</span>
<span class="n">partition</span> <span class="o">=</span> <span class="n">community_louvain</span><span class="o">.</span><span class="n">best_partition</span><span class="p">(</span><span class="n">G</span><span class="p">)</span>
<span class="c1"># compute the best partition</span>
<span class="n">partition</span> <span class="o">=</span> <span class="n">community_louvain</span><span class="o">.</span><span class="n">best_partition</span><span class="p">(</span><span class="n">G</span><span class="p">)</span>
<span class="c1"># draw the graph</span>
<span class="n">pos</span> <span class="o">=</span> <span class="n">nx</span><span class="o">.</span><span class="n">spring_layout</span><span class="p">(</span><span class="n">G</span><span class="p">)</span>
<span class="c1"># color the nodes according to their partition</span>
<span class="n">cmap</span> <span class="o">=</span> <span class="n">cm</span><span class="o">.</span><span class="n">get_cmap</span><span class="p">(</span><span class="s1">'viridis'</span><span class="p">,</span> <span class="nb">max</span><span class="p">(</span><span class="n">partition</span><span class="o">.</span><span class="n">values</span><span class="p">())</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span>
<span class="n">nx</span><span class="o">.</span><span class="n">draw_networkx_nodes</span><span class="p">(</span><span class="n">G</span><span class="p">,</span> <span class="n">pos</span><span class="p">,</span> <span class="n">partition</span><span class="o">.</span><span class="n">keys</span><span class="p">(),</span> <span class="n">node_size</span><span class="o">=</span><span class="mi">40</span><span class="p">,</span>
<span class="n">cmap</span><span class="o">=</span><span class="n">cmap</span><span class="p">,</span> <span class="n">node_color</span><span class="o">=</span><span class="nb">list</span><span class="p">(</span><span class="n">partition</span><span class="o">.</span><span class="n">values</span><span class="p">()))</span>
<span class="n">nx</span><span class="o">.</span><span class="n">draw_networkx_edges</span><span class="p">(</span><span class="n">G</span><span class="p">,</span> <span class="n">pos</span><span class="p">,</span> <span class="n">alpha</span><span class="o">=</span><span class="mf">0.5</span><span class="p">)</span>
<span class="n">plt</span><span class="o">.</span><span class="n">show</span><span class="p">()</span>
</pre></div>
</div>
</div>
</div>
<div class="section" id="changelog">
<h1>Changelog :<a class="headerlink" href="#changelog" title="Permalink to this headline">¶</a></h1>
<ul class="simple">
<li><p>2020-12-27 : 0.15, Stop relabelling stable partitions, tests on power, doc fixes</p></li>
<li><p>2020-04-06 : 0.14, bugfixes (on resolution parameter), optimization on random state</p></li>
<li><p>2018-12-21 : 0.13, better random state, some files missing included, communities always in 0..N-1</p></li>
<li><p>2018-05-22 : 0.11, stop forcing networkx<2.0 and expose module __version__</p></li>
<li><p>2018-01-02 : 0.10, bug fix: taking into account the node removal cost</p></li>
<li><p>2017-09-21 : 0.9, support networkx 2.0</p></li>
<li><p>2017-06-03 : 0.8, add randomization and bugfixes</p></li>
<li><p>2017-05-21 : 0.7, migrate to github, readthedocs and travis. Add resolution parameter to control community size, bugfixes</p></li>
<li><p>04/21/2011 : modifications to use networkx like documentation and use of test.</p></li>
<li><p>02/22/2011 : correction of a bug regarding edge weights</p></li>
<li><p>01/14/2010 : modification to use networkx 1.01 graph api and adding the possibility to start the algorithm with a given partition</p></li>
<li><p>04/10/2009 : increase of the speed of the detection by caching node degrees</p></li>
</ul>
</div>
<div class="section" id="license">
<h1>License :<a class="headerlink" href="#license" title="Permalink to this headline">¶</a></h1>
Copyright (c) 2009, Thomas Aynaud <<a href="mailto:thomas.aynaud@lip6.fr">thomas.aynaud@lip6.fr</a>><br>
All rights reserved.<br><br>
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:<br><br>
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.<br><br>
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.<br><br>
* Neither the name of the python-louvain Developers nor the names of its
contributors may be used to endorse or promote products derived from this
software without specific prior written permission.<br><br><br>
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</div>
<div class="section" id="indices-and-tables">
<h1>Indices and tables<a class="headerlink" href="#indices-and-tables" title="Permalink to this headline">¶</a></h1>
<ul class="simple">
<li><p><a class="reference internal" href="genindex.html"><span class="std std-ref">Index</span></a></p></li>
<li><p><a class="reference internal" href="py-modindex.html"><span class="std std-ref">Module Index</span></a></p></li>
<li><p><a class="reference internal" href="search.html"><span class="std std-ref">Search Page</span></a></p></li>
</ul>
</div>
<div class="clearer"></div>
</div>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="api.html" title="community API"
>next</a> |</li>
<li><a href="#">home</a>| </li>
<li><a href="search.html">search</a>| </li>
<li><a href="api.html">documentation </a> »</li>
<li class="nav-item nav-item-this"><a href="">Community detection for NetworkX’s documentation</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
© Copyright 2010, Thomas Aynaud.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.4.1.
</div>
<div class="footer">This page uses <a href="http://analytics.google.com/">
Google Analytics</a> to collect statistics. You can disable it by blocking
the JavaScript coming from www.google-analytics.com.
<script type="text/javascript">
(function() {
var ga = document.createElement('script');
ga.src = ('https:' == document.location.protocol ?
'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
ga.setAttribute('async', 'true');
document.documentElement.firstChild.appendChild(ga);
})();
</script>
</div>
</body>
</html>
|