[med-svn] [Git][med-team/python-leidenalg][upstream] New upstream version 0.8.9

Andreas Tille (@tille) gitlab at salsa.debian.org
Mon Mar 14 19:24:17 GMT 2022



Andreas Tille pushed to branch upstream at Debian Med / python-leidenalg


Commits:
f523de0f by Andreas Tille at 2022-03-14T17:28:20+01:00
New upstream version 0.8.9
- - - - -


7 changed files:

- .gitignore
- CHANGELOG
- doc/source/intro.rst
- setup.py
- src/leidenalg/VertexPartition.py
- src/leidenalg/functions.py
- src/leidenalg/python_partition_interface.cpp


Changes:

=====================================
.gitignore
=====================================
@@ -36,3 +36,4 @@ vendor/install
 src/leidenalg/version.py
 pip-wheel-metadata
 .eggs/
+doc/source/_build


=====================================
CHANGELOG
=====================================
@@ -1,3 +1,8 @@
+0.8.9
+- Fixed bug with renaming of python-igraph to igraph (issue #93)
+- Removed irrelevant node_sizes argument for RBConfigurationVertexPartition and ModularityVertexPartition
+- Improved documentation
+
 0.8.8
 - Corrected relabeling bug (PR #82)
 - Improved error handling, avoiding some crashses (issue #81)


=====================================
doc/source/intro.rst
=====================================
@@ -20,6 +20,12 @@ detect communities given a graph ``G`` using modularity, you simply use
 
 That's it.
 
+The result ``partition`` is in this case a
+:class:`~leidenalg.ModularityVertexPartition` which is derived from the
+:mod:`igraph` type :class:`ig.VertexClustering`, see the `documentation
+<https://igraph.org/python/api/latest/igraph.clustering.VertexClustering.html>`_
+for more details.
+
 Why then should you use this package rather than for example the Louvain
 algorithm :func:`community_multilevel` built into :mod:`igraph`? If you want to
 use modularity, and you work with a simple undirected, unweighted graph, then


=====================================
setup.py
=====================================
@@ -780,7 +780,7 @@ options =  dict(
   package_dir = {'leidenalg': os.path.join('src', 'leidenalg')},
   packages = ['leidenalg'],
   ext_modules = [leiden_ext],
-  install_requires = ['python-igraph >= 0.9.0'],
+  install_requires = ['igraph >= 0.9.0,< 0.10'],
   platforms="ALL",
   keywords=[
     'graph',


=====================================
src/leidenalg/VertexPartition.py
=====================================
@@ -3,7 +3,10 @@ from . import _c_leiden
 from .functions import _get_py_capsule
 
 class MutableVertexPartition(_ig.VertexClustering):
-  """ Contains a partition of graph, derives from :class:`ig.VertexClustering`.
+  """ Contains a partition of a graph, derives from
+  :class:`ig.VertexClustering`. Please see the `documentation
+  <https://igraph.org/python/api/latest/igraph.clustering.VertexClustering.html>`_
+  of :class:`ig.VertexClustering` for more details about its functionality.
 
   This class contains the basic implementation for optimising a partition.
   Specifically, it implements all the administration necessary to keep track of
@@ -38,12 +41,12 @@ class MutableVertexPartition(_ig.VertexClustering):
     Parameters
     ----------
     graph
-      The `ig.Graph` on which this partition is defined.
+      The :class:`ig.Graph` on which this partition is defined.
 
     membership
-      The membership vector of this partition. Membership[i] = c implies that
-      node i is in community c. If None, it is initialised with a singleton
-      partition community, i.e. membership[i] = i.
+      The membership vector of this partition. ``Membership[i] = c`` implies that
+      node ``i`` is in community ``c``. If ``None``, it is initialised with a singleton
+      partition community, i.e. ``membership[i] = i``.
     """
     if initial_membership is not None:
       initial_membership = list(initial_membership)
@@ -423,7 +426,7 @@ class ModularityVertexPartition(MutableVertexPartition):
          in Directed Networks. Physical Review Letters, 100(11), 118703.
          `10.1103/PhysRevLett.100.118703 <https://doi.org/10.1103/PhysRevLett.100.118703>`_
    """
-  def __init__(self, graph, initial_membership=None, weights=None, node_sizes=None):
+  def __init__(self, graph, initial_membership=None, weights=None):
     """
     Parameters
     ----------
@@ -436,11 +439,6 @@ class ModularityVertexPartition(MutableVertexPartition):
 
     weights : list of double, or edge attribute
       Weights of edges. Can be either an iterable or an edge attribute.
-
-    node_sizes : list of int, or vertex attribute
-      Sizes of nodes are necessary to know the size of communities in aggregate
-      graphs. Usually this is set to 1 for all nodes, but in specific cases
-      this could be changed.
     """
     if initial_membership is not None:
       initial_membership = list(initial_membership)
@@ -455,20 +453,13 @@ class ModularityVertexPartition(MutableVertexPartition):
         # Make sure it is a list
         weights = list(weights)
 
-    if node_sizes is not None:
-      if isinstance(node_sizes, str):
-        node_sizes = graph.vs[node_sizes]
-      else:
-        # Make sure it is a list
-        node_sizes = list(node_sizes)
-
     self._partition = _c_leiden._new_ModularityVertexPartition(pygraph_t,
-        initial_membership, weights, node_sizes)
+        initial_membership, weights)
     self._update_internal_membership()
 
   def __deepcopy__(self, memo):
     n, directed, edges, weights, node_sizes = _c_leiden._MutableVertexPartition_get_py_igraph(self._partition)
-    new_partition = ModularityVertexPartition(self.graph, self.membership, weights, node_sizes)
+    new_partition = ModularityVertexPartition(self.graph, self.membership, weights)
     return new_partition
 
 class SurpriseVertexPartition(MutableVertexPartition):
@@ -523,9 +514,11 @@ class SurpriseVertexPartition(MutableVertexPartition):
       Weights of edges. Can be either an iterable or an edge attribute.
 
     node_sizes : list of int, or vertex attribute
-      Sizes of nodes are necessary to know the size of communities in aggregate
-      graphs. Usually this is set to 1 for all nodes, but in specific cases
-      this could be changed.
+      The quality function takes into account the size of a community, which
+      is defined as the sum over the sizes of each individual node. By default, 
+      the node sizes are set to 1, meaning that the size of a community equals 
+      the number of nodes of a community. If a node already represents an 
+      aggregation, this could be reflect in its node size.
     """
     if initial_membership is not None:
       initial_membership = list(initial_membership)
@@ -603,9 +596,11 @@ class SignificanceVertexPartition(MutableVertexPartition):
       singleton partition.
 
     node_sizes : list of int, or vertex attribute
-      Sizes of nodes are necessary to know the size of communities in aggregate
-      graphs. Usually this is set to 1 for all nodes, but in specific cases
-      this could be changed.
+      The quality function takes into account the size of a community, which
+      is defined as the sum over the sizes of each individual node. By default, 
+      the node sizes are set to 1, meaning that the size of a community equals 
+      the number of nodes of a community. If a node already represents an 
+      aggregation, this could be reflect in its node size.
     """
     if initial_membership is not None:
       initial_membership = list(initial_membership)
@@ -723,9 +718,11 @@ class RBERVertexPartition(LinearResolutionParameterVertexPartition):
       Weights of edges. Can be either an iterable or an edge attribute.
 
     node_sizes : list of int, or vertex attribute
-      Sizes of nodes are necessary to know the size of communities in aggregate
-      graphs. Usually this is set to 1 for all nodes, but in specific cases
-      this could be changed.
+      The quality function takes into account the size of a community, which
+      is defined as the sum over the sizes of each individual node. By default, 
+      the node sizes are set to 1, meaning that the size of a community equals 
+      the number of nodes of a community. If a node already represents an 
+      aggregation, this could be reflect in its node size.
 
     resolution_parameter : double
       Resolution parameter.
@@ -809,7 +806,7 @@ class RBConfigurationVertexPartition(LinearResolutionParameterVertexPartition):
          `10.1103/PhysRevLett.100.118703 <https://doi.org/10.1103/PhysRevLett.100.118703>`_
 
    """
-  def __init__(self, graph, initial_membership=None, weights=None, node_sizes=None, resolution_parameter=1.0):
+  def __init__(self, graph, initial_membership=None, weights=None, resolution_parameter=1.0):
     """
     Parameters
     ----------
@@ -823,11 +820,6 @@ class RBConfigurationVertexPartition(LinearResolutionParameterVertexPartition):
     weights : list of double, or edge attribute
       Weights of edges. Can be either an iterable or an edge attribute.
 
-    node_sizes : list of int, or vertex attribute
-      Sizes of nodes are necessary to know the size of communities in aggregate
-      graphs. Usually this is set to 1 for all nodes, but in specific cases
-      this could be changed.
-
     resolution_parameter : double
       Resolution parameter.
     """
@@ -845,20 +837,13 @@ class RBConfigurationVertexPartition(LinearResolutionParameterVertexPartition):
         # Make sure it is a list
         weights = list(weights)
 
-    if node_sizes is not None:
-      if isinstance(node_sizes, str):
-        node_sizes = graph.vs[node_sizes]
-      else:
-        # Make sure it is a list
-        node_sizes = list(node_sizes)
-
     self._partition = _c_leiden._new_RBConfigurationVertexPartition(pygraph_t,
-        initial_membership, weights, node_sizes, resolution_parameter)
+        initial_membership, weights, resolution_parameter)
     self._update_internal_membership()
 
   def __deepcopy__(self, memo):
     n, directed, edges, weights, node_sizes = _c_leiden._MutableVertexPartition_get_py_igraph(self._partition)
-    new_partition = RBConfigurationVertexPartition(self.graph, self.membership, weights, node_sizes, self.resolution_parameter)
+    new_partition = RBConfigurationVertexPartition(self.graph, self.membership, weights, self.resolution_parameter)
     return new_partition
 
 class CPMVertexPartition(LinearResolutionParameterVertexPartition):
@@ -920,9 +905,11 @@ class CPMVertexPartition(LinearResolutionParameterVertexPartition):
       Weights of edges. Can be either an iterable or an edge attribute.
 
     node_sizes : list of int, or vertex attribute
-      Sizes of nodes are necessary to know the size of communities in aggregate
-      graphs. Usually this is set to 1 for all nodes, but in specific cases
-      this could be changed.
+      The quality function takes into account the size of a community, which
+      is defined as the sum over the sizes of each individual node. By default, 
+      the node sizes are set to 1, meaning that the size of a community equals 
+      the number of nodes of a community. If a node already represents an 
+      aggregation, this could be reflect in its node size.
 
     resolution_parameter : double
       Resolution parameter.


=====================================
src/leidenalg/functions.py
=====================================
@@ -365,7 +365,9 @@ def slices_to_layers(G_coupling,
   """ Convert a coupling graph of slices to layers of graphs.
 
   This function converts a graph of slices to layers so that they can be used
-  with this package. This function assumes that the slices are represented by
+  with this package. 
+  
+  This function assumes that the slices are represented by
   nodes in ``G_coupling``, and stored in the attribute ``slice_attr``. In other
   words, ``G_coupling.vs[slice_attr]`` should contain :class:`ig.Graph` s . The
   slices will be converted to layers, and nodes in different slices will be
@@ -373,7 +375,11 @@ def slices_to_layers(G_coupling,
   connected slices are identified on the basis of the ``vertex_id_attr``, i.e.
   if two nodes in two connected slices have an identical value of the
   ``vertex_id_attr`` they will be coupled. The ``vertex_id_attr`` should hence
-  be unique in each slice.  The weight of the coupling is determined by the
+  be unique in each slice.  Each node in the resulting layer graphs will contain
+  two vertex attributes with the name of ``slice_attr`` and ``vertex_id_attr``
+  that refer respectively to the slice and id of the node.
+  
+  The weight of the coupling is determined by the
   weight of this link in ``G_coupling``, as determined by the ``weight_attr``.
 
   Parameters


=====================================
src/leidenalg/python_partition_interface.cpp
=====================================
@@ -172,18 +172,17 @@ extern "C"
     PyObject* py_obj_graph = NULL;
     PyObject* py_initial_membership = NULL;
     PyObject* py_weights = NULL;
-    PyObject* py_node_sizes = NULL;
 
-    static const char* kwlist[] = {"graph", "initial_membership", "weights", "node_sizes", NULL};
+    static const char* kwlist[] = {"graph", "initial_membership", "weights", NULL};
 
-    if (!PyArg_ParseTupleAndKeywords(args, keywds, "O|OOO", (char**) kwlist,
-                                     &py_obj_graph, &py_initial_membership, &py_weights, &py_node_sizes))
+    if (!PyArg_ParseTupleAndKeywords(args, keywds, "O|OO", (char**) kwlist,
+                                     &py_obj_graph, &py_initial_membership, &py_weights))
         return NULL;
 
     try
     {
 
-      Graph* graph = create_graph_from_py(py_obj_graph, py_node_sizes, py_weights);
+      Graph* graph = create_graph_from_py(py_obj_graph, NULL, py_weights);
 
       ModularityVertexPartition* partition = NULL;
 
@@ -414,19 +413,18 @@ extern "C"
     PyObject* py_obj_graph = NULL;
     PyObject* py_initial_membership = NULL;
     PyObject* py_weights = NULL;
-    PyObject* py_node_sizes = NULL;
     double resolution_parameter = 1.0;
 
-    static const char* kwlist[] = {"graph", "initial_membership", "weights", "node_sizes", "resolution_parameter", NULL};
+    static const char* kwlist[] = {"graph", "initial_membership", "weights", "resolution_parameter", NULL};
 
-    if (!PyArg_ParseTupleAndKeywords(args, keywds, "O|OOOd", (char**) kwlist,
-                                     &py_obj_graph, &py_initial_membership, &py_weights, &py_node_sizes, &resolution_parameter))
+    if (!PyArg_ParseTupleAndKeywords(args, keywds, "O|OOd", (char**) kwlist,
+                                     &py_obj_graph, &py_initial_membership, &py_weights, &resolution_parameter))
         return NULL;
 
     try
     {
 
-      Graph* graph = create_graph_from_py(py_obj_graph, py_node_sizes, py_weights);
+      Graph* graph = create_graph_from_py(py_obj_graph, NULL, py_weights);
 
       RBConfigurationVertexPartition* partition = NULL;
 



View it on GitLab: https://salsa.debian.org/med-team/python-leidenalg/-/commit/f523de0f7fc25c71d3d18268699856c42a72e810

-- 
View it on GitLab: https://salsa.debian.org/med-team/python-leidenalg/-/commit/f523de0f7fc25c71d3d18268699856c42a72e810
You're receiving this email because of your account on salsa.debian.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/debian-med-commit/attachments/20220314/6d488372/attachment-0001.htm>


More information about the debian-med-commit mailing list