-
Notifications
You must be signed in to change notification settings - Fork 165
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
Generalizing Closeness
centrality to weighted networks using Newman method
#1385
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: FedericoBruzzone <[email protected]>
Closeness
centrality to weighted networks using newman methodCloseness
centrality to weighted networks using Newman method
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.
THe implemenation LGTM for rustworkx-core, do you intend to make the method available for Pytohn users though?
I left a comment about the tests. It applies to all of our centrality metrics, we need to be careful with floats
rustworkx-core/src/centrality.rs
Outdated
assert_eq!( | ||
[ | ||
Some(0.0), | ||
Some(0.14285714285714285), |
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.
You probably want to compare the results using something like
rustworkx/rustworkx-core/src/centrality.rs
Line 538 in df38b0a
macro_rules! assert_almost_equal { |
We should aim to have the most precision we can, but in practice minor changes to the algorithm can fudge non-significant digits of the float. Define an epsilon and check if |a - b| <= eps
.
You might want a macro that loops over the arrays as well with zip
as well.
Thanks for the review. I do not actually need the python implementation, but I can understand that this could improve usability for Python users. So, I will work on exposing the method to Python as well. Regarding the tests, I appreciate the feedback. I'll make sure to add checks that account for floating-point precision issues across all centrality metrics. |
Signed-off-by: FedericoBruzzone <[email protected]>
#[test] | ||
fn test_weighted_closeness_many_to_one_not_connected_2_digraph() { | ||
let g = petgraph::graph::DiGraph::<u32, f64>::from_edges([ | ||
(1, 0, 0.1), | ||
(2, 0, 0.1), | ||
(3, 0, 0.1), | ||
(4, 0, 0.1), | ||
(5, 0, 0.1), | ||
(6, 0, 0.1), | ||
(7, 0, 0.1), | ||
(1, 7, 1.0), | ||
]); | ||
let c = newman_weighted_closeness_centrality(&g, false, |x| *x.weight()); | ||
let result = [ | ||
Some(0.1), | ||
Some(0.0), | ||
Some(0.0), | ||
Some(0.0), | ||
Some(0.0), | ||
Some(0.0), | ||
Some(0.0), | ||
Some(1.0), | ||
]; | ||
|
||
assert_eq!(result, *c); | ||
} |
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.
IMO this test should keep assert_eq!
predicate but let me know :D
1fb850f
to
b364913
Compare
@IvanIsCoding Make sure that the following commit is in line with the rest, but most importantly, make sure it is correct. Make available weighted_closeness for python users Why is CI not starting? 🤔 |
Signed-off-by: FedericoBruzzone <[email protected]>
Signed-off-by: FedericoBruzzone <[email protected]>
81813f3
to
7de1312
Compare
I need to manually approve CI. Also, I asked about Python just to confirm. Someone else can work on the Python bindings. |
There was no problem to implement it. It was a pleasure, I look forward to your review :D |
Signed-off-by: FedericoBruzzone <[email protected]>
0bc11f9
to
95c0166
Compare
Close #1384