-
Notifications
You must be signed in to change notification settings - Fork 259
feat: expose voronoi to python #833
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
02e74a2
178bde6
b7669cc
4fa9667
9141205
2540511
239fe5b
6bd5cc7
4e125fd
8662811
3e1f4ac
505f25a
06fca73
7a79c5c
1d7e7ff
2f87237
ec92492
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -327,6 +327,69 @@ def _community_spinglass(graph, *args, **kwds): | |
return VertexClustering(graph, membership, modularity_params=modularity_params) | ||
|
||
|
||
def _community_voronoi(graph, lengths=None, weights=None, mode="out", radius=None): | ||
"""Finds communities using Voronoi partitioning. | ||
|
||
This function finds communities using a Voronoi partitioning of vertices based | ||
on the given edge lengths divided by the edge clustering coefficient | ||
(L{igraph.Graph.ecc}). The generator vertices are chosen to be those with the | ||
largest local relative density within a radius, with the local relative | ||
density of a vertex defined as C{s * m / (m + k)}, where C{s} is the strength | ||
of the vertex, C{m} is the number of edges within the vertex's first order | ||
neighborhood, while C{k} is the number of edges with only one endpoint within | ||
this neighborhood. | ||
Comment on lines
+333
to
+340
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use Please also wrap the formulas in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should I use \cdot or something else? Since it looks strange in the built documentation There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alright, let's keep it as-is for now. Can you please add the |
||
|
||
B{References} | ||
|
||
- Deritei et al., Community detection by graph Voronoi diagrams, | ||
I{New Journal of Physics} 16, 063007 (2014). | ||
U{https://doi.org/10.1088/1367-2630/16/6/063007}. | ||
- Molnár et al., Community Detection in Directed Weighted Networks using | ||
Voronoi Partitioning, I{Scientific Reports} 14, 8124 (2024). | ||
U{https://doi.org/10.1038/s41598-024-58624-4}. | ||
|
||
@param lengths: edge lengths, or C{None} to consider all edges as having | ||
unit length. Voronoi partitioning will use edge lengths equal to | ||
lengths / ECC where ECC is the edge clustering coefficient. | ||
@param weights: edge weights, or C{None} to consider all edges as having | ||
unit weight. Weights are used when selecting generator points, as well | ||
as for computing modularity. | ||
@param mode: specifies how to use the direction of edges when computing | ||
distances from generator points. If C{"out"} (the default), distances | ||
from generator points to all other nodes are considered following the | ||
direction of edges. If C{"in"}, distances are computed in the reverse | ||
direction (i.e., from all nodes to generator points). If C{"all"}, | ||
edge directions are ignored and the graph is treated as undirected. | ||
This parameter is ignored for undirected graphs. | ||
@param radius: the radius/resolution to use when selecting generator points. | ||
The larger this value, the fewer partitions there will be. Pass C{None} | ||
to automatically select the radius that maximizes modularity. | ||
@return: an appropriate L{VertexClustering} object with extra attributes | ||
called C{generators} (the generator vertices). | ||
""" | ||
# Convert mode string to proper enum value to avoid deprecation warning | ||
if isinstance(mode, str): | ||
mode_map = {"out": "out", "in": "in", "all": "all", "total": "all"} # alias | ||
if mode.lower() in mode_map: | ||
mode = mode_map[mode.lower()] | ||
else: | ||
raise ValueError(f"Invalid mode '{mode}'. Must be one of: out, in, all") | ||
|
||
membership, generators, modularity = GraphBase.community_voronoi(graph, lengths, weights, mode, radius) | ||
|
||
params = {"generators": generators} | ||
modularity_params = {} | ||
if weights is not None: | ||
modularity_params["weights"] = weights | ||
|
||
clustering = VertexClustering( | ||
graph, membership, modularity=modularity, params=params, modularity_params=modularity_params | ||
) | ||
|
||
clustering.generators = generators | ||
return clustering | ||
|
||
|
||
def _community_walktrap(graph, weights=None, steps=4): | ||
"""Community detection algorithm of Latapy & Pons, based on random | ||
walks. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ecc()
is not currently exposed. Please check if the links that were added are valid. You can build docs from the terminal usingscripts/mkdoc.sh -c
. There will be warnings if a link is invalid.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hi, I can help, sure, however until now I wasn't able to find the issue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's just remove the link for now. We can do cross-linking once the ECC function is exposed.