Skip to content

Commit 286a719

Browse files
Generalizing Closeness centrality to weighted networks using Newman method (#1385)
* Add `Closeness` centrality to weighted networks using newman method Signed-off-by: FedericoBruzzone <[email protected]> * Test by using `assert_almost_equal!` Signed-off-by: FedericoBruzzone <[email protected]> * Make available `weighted_closeness` for python users Signed-off-by: FedericoBruzzone <[email protected]> * Fix typo in some files Signed-off-by: FedericoBruzzone <[email protected]> * Add docs and update `pyi` files Signed-off-by: FedericoBruzzone <[email protected]> * Minor fix Signed-off-by: FedericoBruzzone <[email protected]> * Add `releasenote` Signed-off-by: FedericoBruzzone <[email protected]> * Update rustworkx-core/src/centrality.rs --------- Signed-off-by: FedericoBruzzone <[email protected]> Co-authored-by: Ivan Carvalho <[email protected]>
1 parent a9460dc commit 286a719

File tree

14 files changed

+652
-19
lines changed

14 files changed

+652
-19
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ retworkx/*pyd
2323
**/*.so
2424
retworkx-core/Cargo.lock
2525
**/.DS_Store
26+
venv/

docs/source/api/algorithm_functions/centrality.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ Centrality
1212
rustworkx.eigenvector_centrality
1313
rustworkx.katz_centrality
1414
rustworkx.closeness_centrality
15+
rustworkx.newman_weighted_closeness_centrality
1516
rustworkx.in_degree_centrality
16-
rustworkx.out_degree_centrality
17+
rustworkx.out_degree_centrality

docs/source/api/pydigraph_api_functions.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ the functions from the explicitly typed based on the data type.
5151
rustworkx.digraph_betweenness_centrality
5252
rustworkx.digraph_edge_betweenness_centrality
5353
rustworkx.digraph_closeness_centrality
54+
rustworkx.digraph_newman_weighted_closeness_centrality
5455
rustworkx.digraph_eigenvector_centrality
5556
rustworkx.digraph_katz_centrality
5657
rustworkx.digraph_unweighted_average_shortest_path_length

docs/source/api/pygraph_api_functions.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ typed API based on the data type.
5252
rustworkx.graph_betweenness_centrality
5353
rustworkx.graph_edge_betweenness_centrality
5454
rustworkx.graph_closeness_centrality
55+
rustworkx.graph_newman_weighted_closeness_centrality
5556
rustworkx.graph_eigenvector_centrality
5657
rustworkx.graph_katz_centrality
5758
rustworkx.graph_unweighted_average_shortest_path_length
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
features:
3+
- |
4+
Added a new function, :func:`~.newman_weighted_closeness_centrality` to compute the
5+
closeness centrality of all nodes in a weighted :class:`~.PyGraph` or
6+
:class:`~.PyDiGraph` object.
7+
8+
The weighted closeness centrality is an extension of the standard closeness
9+
centrality measure where edge weights represent connection strength rather
10+
than distance. To properly compute shortest paths, weights are inverted
11+
so that stronger connections correspond to shorter effective distances.
12+
The algorithm follows the method described by Newman (2001) in analyzing
13+
weighted graphs.
14+
15+
The edges originally represent connection strength between nodes.
16+
The idea is that if two nodes have a strong connection, the computed
17+
distance between them should be small (shorter), and vice versa.
18+
Note that this assume that the graph is modelling a measure of
19+
connection strength (e.g. trust, collaboration, or similarity).

0 commit comments

Comments
 (0)