Skip to content
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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

FedericoBruzzone
Copy link

@FedericoBruzzone FedericoBruzzone commented Feb 11, 2025

Close #1384

  • I ran rustfmt locally
  • I have added the tests to cover my changes.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.

@CLAassistant
Copy link

CLAassistant commented Feb 11, 2025

CLA assistant check
All committers have signed the CLA.

@FedericoBruzzone FedericoBruzzone changed the title Generalizing Closeness centrality to weighted networks using newman method Generalizing Closeness centrality to weighted networks using Newman method Feb 11, 2025
Copy link
Collaborator

@IvanIsCoding IvanIsCoding left a 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

assert_eq!(
[
Some(0.0),
Some(0.14285714285714285),
Copy link
Collaborator

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

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.

@FedericoBruzzone
Copy link
Author

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

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]>
Comment on lines +1495 to +1520
#[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);
}
Copy link
Author

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

@FedericoBruzzone
Copy link
Author

FedericoBruzzone commented Feb 12, 2025

@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? 🤔

@IvanIsCoding
Copy link
Collaborator

I need to manually approve CI.

Also, I asked about Python just to confirm. Someone else can work on the Python bindings.

@FedericoBruzzone
Copy link
Author

FedericoBruzzone commented Feb 12, 2025

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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Generalizing Closeness centrality to weighted networks
3 participants