-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
BUG: add check for isolated nodes in degree_sequence_tree
#8235
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
Conversation
dschult
left a comment
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.
This is great -- the addition of a missing useful utility for the tree suite of functions.
Thanks!
(I have one minor suggestion, but only if you prefer it -- and feel free to change the name choices to something else. :)
Co-authored-by: Dan Schult <dschult@colgate.edu>
|
Thanks Dan, your suggestion improves readability. This PR still needs a label by the way! :) |
| t(nx.random_powerlaw_tree, 5, seed=seed, tries=5000) | ||
| t(nx.random_powerlaw_tree_sequence, 5, seed=seed, tries=5000) |
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.
Any particular reason for changing the n here?
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.
These tests exceed the maximum number of tries with the old values now that invalid sequences are filtered more thoroughly.
Fixes #8227.
This PR adds the check suggested in the linked issue for zero-degree nodes, which cannot appear in a valid degree sequence.
To do so, a utility function
is_valid_tree_degree_sequencehas been added, which returns whether a degree sequence follows two basic rules: the number of nodes must be equal to one more than the number of edges, and there cannot be any negative degrees in the degree sequence unless the degree sequence represents the trivial graph. It also gives a string representing which of the two checks was failed, to simplify error reporting downstream; I wasn't sure whether returning the string was worth doing; perhaps downstream functions using this utility function should just raise with a generic"invalid degree sequence for tree"message.This change affects
random_powerlaw_tree_sequencein that it now becomes (significantly?) less likely to yield a "valid" sequence in the given number oftries.