Skip to content

Commit f24f0be

Browse files
committed
doc: Corrected some problem in Bipartite description.
1 parent 7d747aa commit f24f0be

File tree

2 files changed

+35
-18
lines changed

2 files changed

+35
-18
lines changed

doc/source/multiplex.rst

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -147,19 +147,19 @@ like to be able to set three different resolution parameters: one for within
147147
each class :math:`\gamma_0, \gamma_1`, and one for the links between classes,
148148
:math:`\gamma_{01}`. Then the formulation would be
149149

150-
.. math:: Q = \sum_{ij}
150+
.. math:: Q = \sum_{ij}
151151
[A_{ij}
152-
- (\gamma_0\delta(s_i,0) + \gamma_1\delta(s_i,1)) \delta(s_i,s_j)
153-
- \gamma_{01}(1 - \delta(s_i, s_j))
152+
- (\gamma_0\delta(s_i,0) + \gamma_1\delta(s_i,1)) \delta(s_i,s_j)
153+
- \gamma_{01}(1 - \delta(s_i, s_j))
154154
]\delta(\sigma_i, \sigma_j)
155155

156156
where :math:`s_i` denotes the bipartite class of a node and :math:`\sigma_i`
157157
the community of the node as elsewhere in the documentation. Rewriting as a sum
158158
over communities gives a bit more insight
159159

160-
.. math:: Q = \sum_c (e_c
160+
.. math:: Q = \sum_c (e_c
161161
- \gamma_{01} 2 n_c(0) n_c(1)
162-
- \gamma_0 n^2_c(0)
162+
- \gamma_0 n^2_c(0)
163163
- \gamma_1 n^2_c(1))
164164

165165
where :math:`n_c(0)` is the number of nodes in community :math:`c` of class 0
@@ -188,7 +188,7 @@ layer has layer weight 1, we obtain the following:
188188
+ ( \gamma_{01} - \gamma_1) n_c(1)^2
189189
] \\
190190
&= \sum_c (e_c - \gamma_{01} 2 n_c(0) n_c(1)
191-
- \gamma_{0} n_c(0)^2
191+
- \gamma_{0} n_c(0)^2
192192
- \gamma_{1} n_c(1)^2) \\
193193

194194
Hence detecting communities with these three layers corresponds to detecting
@@ -199,15 +199,17 @@ corresponds to the CPM method. However, using a little additional trick, we can
199199
also make this work for modularity. Essentially, modularity is nothing else
200200
than CPM with the ``node_size`` set to the degree, and the resolution parameter
201201
set to :math:`\gamma = \frac{1}{2m}`. In particular, in general (i.e. not
202-
specifically for bipartite graph) if ``node_sizes=G.degree()`` we then obtain
202+
specifically for bipartite graph) if ``node_sizes=G.degree()`` we then obtain
203203

204204
.. math:: Q = \sum_{ij} A_{ij} - \gamma k_i k_j
205205

206206
In the case of bipartite graphs something similar is obtained, but then
207207
correctly adapted (as long as the resolution parameter is also appropriately
208208
rescaled). Note that this is only possible for modularity for undirected
209209
graphs. Hence, we can also detect communities in bipartite networks using
210-
modularity by using this little trick.
210+
modularity by using this little trick. The definition of modularity for
211+
bipartite graphs is identical to the formulation of bipartite modularity
212+
provided in [3]_.
211213

212214
All of this has been implemented in the constructor
213215
:func:`~leidenalg.CPMVertexPartition.Bipartite`. You can simply pass in a
@@ -225,7 +227,7 @@ An explicit example of this:
225227

226228
>>> p_01, p_0, p_1 = la.CPMVertexPartition.Bipartite(G,
227229
... resolution_parameter_01=0.1);
228-
>>> diff = optimiser.optimise_partition_multiplex([p_01, p_0, p_1],
230+
>>> diff = optimiser.optimise_partition_multiplex([p_01, p_0, p_1],
229231
... layer_weights=[1, -1, -1]);
230232

231233
Slices to layers
@@ -309,13 +311,13 @@ types for different layers.
309311
:class:`~leidenalg.SignificanceVertexPartition`.
310312

311313
.. testsetup::
312-
314+
313315
gamma = 0.5;
314316

315-
>>> partitions = [la.CPMVertexPartition(H, node_sizes='node_size',
316-
... weights='weight', resolution_parameter=gamma)
317+
>>> partitions = [la.CPMVertexPartition(H, node_sizes='node_size',
318+
... weights='weight', resolution_parameter=gamma)
317319
... for H in layers];
318-
>>> interslice_partition = la.CPMVertexPartition(interslice_layer, resolution_parameter=0,
320+
>>> interslice_partition = la.CPMVertexPartition(interslice_layer, resolution_parameter=0,
319321
... node_sizes='node_size', weights='weight');
320322

321323
You can then simply optimise these partitions as before using
@@ -349,12 +351,12 @@ partitions in a slightly more convenient way using
349351
>>> layers, interslice_layer, G_full = \
350352
... la.time_slices_to_layers([G_1, G_2, G_3],
351353
... interslice_weight=0.1);
352-
>>> partitions = [la.CPMVertexPartition(H, node_sizes='node_size',
353-
... weights='weight',
354-
... resolution_parameter=gamma)
354+
>>> partitions = [la.CPMVertexPartition(H, node_sizes='node_size',
355+
... weights='weight',
356+
... resolution_parameter=gamma)
355357
... for H in layers];
356358
>>> interslice_partition = \
357-
... la.CPMVertexPartition(interslice_layer, resolution_parameter=0,
359+
... la.CPMVertexPartition(interslice_layer, resolution_parameter=0,
358360
... node_sizes='node_size', weights='weight');
359361
>>> diff = optimiser.optimise_partition_multiplex(partitions + [interslice_partition]);
360362

@@ -371,3 +373,6 @@ References
371373
.. [2] Traag, V. A., & Bruggeman, J. (2009). Community detection in networks
372374
with positive and negative links. Physical Review E, 80(3), 036115.
373375
`10.1103/PhysRevE.80.036115 <http://doi.org/10.1103/PhysRevE.80.036115>`_
376+
.. [3] Barber, M. J. (2007). Modularity and community detection in bipartite
377+
networks. Physical Review E, 76(6), 066102. `10.1103/PhysRevE.76.066102
378+
<https://doi.org/10.1103/PhysRevE.76.066102>`_

src/VertexPartition.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -931,7 +931,7 @@ def Bipartite(cls, graph, resolution_parameter_01,
931931
This creates three layers for bipartite partition necessary for detecting
932932
communities in bipartite networks. These three layers should be passed to
933933
:func:`Optimiser.optimise_partition_multiplex` with
934-
``layer_weights=[1,-1,-1]``.
934+
``layer_weights=[1,-1,-1]``. See `Notes <#notes-bipartite>`_ for more details.
935935
936936
Parameters
937937
----------
@@ -959,6 +959,18 @@ def Bipartite(cls, graph, resolution_parameter_01,
959959
Additional arguments passed on to default constructor of
960960
:class:`CPMVertexPartition`.
961961
962+
Returns
963+
-------
964+
:class:`ig.CPMVertexPartition`
965+
partition containing the bipartite graph and correct node sizes.
966+
967+
:class:`ig.CPMVertexPartition`
968+
partition for type 0, containing the correct node sizes for type 0.
969+
970+
:class:`ig.CPMVertexPartition`
971+
partition for type 1, containing the correct node sizes for type 1.
972+
973+
962974
.. _notes-bipartite:
963975
964976
Notes

0 commit comments

Comments
 (0)