Skip to content

add (alpha, beta)-core computation for bipartite graphs - #7728

Closed
ShunyangLi wants to merge 4 commits into
networkx:mainfrom
ShunyangLi:abcore
Closed

ShunyangLi wants to merge 4 commits into
networkx:mainfrom
ShunyangLi:abcore

Conversation

@ShunyangLi

Copy link
Copy Markdown
Contributor

The (alpha, beta)-core of a bipartite graph is a maximal subgraph where each vertex in the upper set has at least alpha neighbors and each vertex in the lower set has at least beta neighbors.

The idea is mentioned in the paper:
Efficient (alpha, beta)-core computation: An index-based approach
B. Liu, L. Yuan, X. Lin, L. Qin, W. Zhang, & J. Zhou
The World Wide Web Conference, 2019, pp. 1130-1141.
https://doi.org/10.1145/3308558.3313682

@rossbar rossbar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I will start by saying that I'm certainly no expert in bipartite network analysis, so my opinions are only weakly informed.

That said, this is a simple enough operation that I'm hesitant to expand the API surface for it. I think it essentially boils down to a one-or-two liner (see inline comments) which is straightforward to formulate. Furthermore, it's easy to see how the pattern could be generalized to multipartite graphs - and in that case I don't think we'd want to have functions for each level of partitioning (e.g. an alpha_beta_gamma_core, alpha_beta_gamma_delta_core... etc.)

Given these considerations, unless this is very common operation in bipartite analysis, I'd be more inclined to include it as a gallery example than adding to the API. Just my two cents - can't wait to hear what others think!

Comment on lines +88 to +103
while True:
remove_nodes = set()

for u in U:
if u in G_tmp and G_tmp.degree(u) < alpha:
remove_nodes.add(u)

for v in V:
if v in G_tmp and G_tmp.degree(v) < beta:
remove_nodes.add(v)

if not remove_nodes:
break

G_tmp.remove_nodes_from(remove_nodes)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ultimately I think this is a one-liner (almost):

Suggested change
while True:
remove_nodes = set()
for u in U:
if u in G_tmp and G_tmp.degree(u) < alpha:
remove_nodes.add(u)
for v in V:
if v in G_tmp and G_tmp.degree(v) < beta:
remove_nodes.add(v)
if not remove_nodes:
break
G_tmp.remove_nodes_from(remove_nodes)
while (remove_nodes := [
n for n, d in G_tmp.degree() if ((n in U and d < alpha) or (n in V and d < beta))
]):
G_tmp.remove_nodes_from(remove_nodes)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thank you for your insightful feedback! I agree that since the (alpha, beta)-core is simple to implement in a few lines of code, it would be more appropriate to include it as a gallery example rather than expanding the API.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Additionally, there are other potentially useful bipartite graph APIs, such as butterfly counting (Sanei-Mehri et al., 2018), which I can propose in future PRs to enhance the functionality for bipartite network analysis.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

it would be more appropriate to include it as a gallery example rather than expanding the API.

👍 - are you planning to do so in this PR? Please feel free; otherwise let's go ahead and close this!

Additionally, there are other potentially useful bipartite graph APIs, such as butterfly counting (Sanei-Mehri et al., 2018), which I can propose in future PRs to enhance the functionality for bipartite network analysis.

I'd recommend taking a look at the contributor guide - there is no hard-and-fast policy for inclusion, but one thing to consider is the tradeoff between the complexity of the implementation, and how "central" or widely-used the operation is in network analysis.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Currently this algorithm is not used much, the butterfly counting may also be more suitable as an example to add to the document.
Thank you for your feedback and suggestions.
Meanwhile, I would like to ask if we have considered using the GPU to accelerate graph algorithms, because I am currently doing research on gpu-accelerated graph computation.

BTW, the PR can be closed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Meanwhile, I would like to ask if we have considered using the GPU to accelerate graph algorithms, because I am currently doing research on gpu-accelerated graph computation.

NetworkX itself does not support GPUs, though there is a dispatching mechanism in place to allow for different computational backends (including GPU support via cugraph) to "plug-in" to networkx functions. I'd suggest reading up on backends to learn more!

@rossbar

rossbar commented Dec 5, 2024

Copy link
Copy Markdown
Contributor

Thanks @ShunyangLi - I'll go ahead and close this then. Generally I think the idea is really cool, so I went ahead and opened a PR converting this to a gallery example in #7757 (and listed you as a co-author, since this is your idea!).

If you're interested in adding other bipartite motifs, please feel free to use #7757 as a template/example for doing so!

@rossbar rossbar closed this Dec 5, 2024
@ShunyangLi

Copy link
Copy Markdown
Contributor Author

Hi rossbar,

Thanks so much, I will add the motif counting algorithms later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

2 participants