-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add edge betweenness centrality (#799)
* Add edge betweenness centrality * Fix MSRV * Update pyfunction signatures * Add tests * Add test with stable graph * Remove unnecessary import from doc test * Address review comments --------- Co-authored-by: Ivan Carvalho <8753214+IvanIsCoding@users.noreply.github.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
- Loading branch information
1 parent
8cfc849
commit 004dc16
Showing
11 changed files
with
694 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
releasenotes/notes/add-edge-betweenness-centrality-8de06bf716caece0.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
--- | ||
features: | ||
- | | ||
Added a new function, :func:`~rustworkx.edge_betweenness_centrality` to compute | ||
edge betweenness centrality of all edges in a :class:`~rustworkx.PyGraph` or | ||
:class:`~rustworkx.PyDiGraph` object. The algorithm used in this function is | ||
based on: | ||
Ulrik Brandes, On Variants of Shortest-Path Betweenness Centrality | ||
and their Generic Computation. Social Networks 30(2):136-145, 2008. | ||
Edge betweenness centrality of an edge :math:`e` is the sum of the | ||
fraction of all-pairs shortest paths that pass through :math`e` | ||
.. math:: | ||
c_B(e) =\sum_{s,t \in V} \frac{\sigma(s, t|e)}{\sigma(s, t)} | ||
where :math:`V` is the set of nodes, :math:`\sigma(s, t)` is the | ||
number of shortest :math:`(s, t)`-paths, and :math:`\sigma(s, t|e)` is | ||
the number of those paths passing through edge :math:`e`. | ||
For example, the following computes the edge betweenness centrality for all | ||
edges in a 5x5 grid graph and uses the result to color the edges in a graph | ||
visualization: | ||
.. jupyter-execute:: | ||
import rustworkx | ||
from rustworkx.visualization import mpl_draw | ||
graph = rustworkx.generators.grid_graph(5, 5) | ||
btw = rustworkx.edge_betweenness_centrality(graph) | ||
# Color edges in graph visualization with edge betweenness centrality | ||
colors = [] | ||
for i in graph.edge_indices(): | ||
colors.append(btw[i]) | ||
mpl_draw(graph, edge_color=colors) | ||
- | | ||
Added a new function to rustworkx-core ``edge_betweenness_centrality`` to | ||
the ``rustworkx_core:centrality`` module which computes the edge betweenness | ||
centrality of all edges in a given graph. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.