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

Degree centrality implementation #1306

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

Conversation

Gohlub
Copy link

@Gohlub Gohlub commented Nov 3, 2024

Proposed a solution for #1129. The implementation is straightforward, though I wonder whether I should add a flag to support in-degree and out-degree centrality, and support for weighted graphs (since the current implementation assumes an unweighted graph). Let me know what you think!

@CLAassistant
Copy link

CLAassistant commented Nov 3, 2024

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
2 out of 3 committers have signed the CLA.

✅ Gohlub
✅ onsali
❌ ons


ons seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
0 out of 3 committers have signed the CLA.

❌ Gohlub
❌ onsali
❌ ons


ons seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

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.

Thanks for making your first contribution. I left some comments, but some things to note:

Also, I noticed from the CLA bot that this PR has two authors. This is quite unusual for a first contribution so please let me know if you are:

  1. Working on a college assignment together
  2. One of the users flagged by the bot is an AI Assistant

There is nothing wrong with either, but it can help me review the PR accordingly.

.gitignore Show resolved Hide resolved
degree_centrality_implementation_rustworkx.md Outdated Show resolved Hide resolved
rustworkx-core/src/centrality.rs Show resolved Hide resolved
rustworkx/__init__.pyi Outdated Show resolved Hide resolved
src/centrality.rs Outdated Show resolved Hide resolved
tests/graph/test_centrality.py Outdated Show resolved Hide resolved
@@ -230,3 +230,46 @@ def test_custom_graph_unnormalized(self):
expected = {0: 9, 1: 9, 2: 12, 3: 15, 4: 11, 5: 14, 6: 10, 7: 13, 8: 9, 9: 9}
for k, v in centrality.items():
self.assertAlmostEqual(v, expected[k])


class TestDegreeCentrality(unittest.TestCase):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The existing test coverage is good, but remember to add a test with the multigraph case to check that we cover it properly

@IvanIsCoding
Copy link
Collaborator

Also, we can handle in_degree and out_degree in a separate PR. These methods would only be for PyDiGraph. They probably would reuse most of the existing code as I pointed out in the comment, but it requires more tests and all that.

@Gohlub
Copy link
Author

Gohlub commented Nov 3, 2024

Hi, thank you for the swift feedback! I just wanted to note that this was in fact a college assignment, with the other contributor being my classmate. However we are now moving on to individual work, so I will be responsible for the next steps. I will be begin addressing your suggestions shortly.

@IvanIsCoding
Copy link
Collaborator

Hi, thank you for the swift feedback! I just wanted to note that this was in fact a college assignment, with the other contributor being my classmate. However we are now moving on to individual work, so I will be responsible for the next steps. I will be begin addressing your suggestions shortly.

Sounds good to me, just remember to ask your classmate(s) to sign the CLA otherwise the bot will not let it get merged

/// }
/// ```

pub fn graph_degree_centrality<G>(graph: G) -> Vec<f64>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For rustworkx-core, use a generic method that takes both kind of graphs.

pub fn eigenvector_centrality<G, F, E>(
is a good example

}
self.assertEqual(expected, centrality)

def test_digraph_degree_centrality_with_direction(self):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor organization detail. This should put the digraph tests in tests/digraph/test_centrality.py with the other directed graph tests

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.

4 participants