-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Branchings.py - Removed graphs and branchings structures in favor of an unique for unrolling the circuits #2117
base: main
Are you sure you want to change the base?
Conversation
…levels and inserted an unique structure, called unroll, that stores the edges involved in a circuits for all levels, in order to rebuild the graph at every level.
On a quick first look, it seems that you are basing this off an older version of NetworkX. The reason I say this is that |
Current version is here: https://github.com/networkx/networkx/blob/master/networkx/algorithms/tree/branchings.py |
Thank you for giving it a look! I can confirm your synopsis. I am going to fix it. |
OK looks much more how I expected. This is really nice to see, and something we needed but never had time to do. A couple quick questions for you:
|
I need to give this a better look when I get off work today. Look for a merge later tonight. |
if self.store: | ||
self.graphs.append(G.copy()) | ||
self.branchings.append(B.copy()) | ||
def getFinalGraphAndBranch(nodes): |
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.
Python functions should be underscore_separated not CamelCase.
I am glad for you words @chebee7i. To answer your questions:
I want to thank @jfinkels about the comments. I am going to follow them. |
…Removed print comments and fixed other part of code as directed me.
# (b) every node of G^i is in D^i and E^i is a branching | ||
# Construction guarantees that it's a branching. | ||
if len(G) != len(B): | ||
raise Exception('Graph and branching must be of the same lenght.') |
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.
Small typo 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.
Where is it?
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.
Opps: must be of the same lenght
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.
I don't really see the problem! :)
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 word is "length". However, a better message would be "graph and branching must have the same number of nodes", since a graph doesn't really have a "length".
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.
How could I have been so blind! I am going to change the message.
This looks good to me. As to point 1) above, the memory usage is a definite improvement, so we need to keep that. It might make sense to refactor the find_optimium() method a bit more. For example, should the stuff from
onward be moved into its own method? This would separate the first phase from the second phase of the algorithm. Then, as you suggested, the first part of the algorithm could take an extra parameter that instructs whether or not we should keep the information to build the intermediate structures. I'll leave it up to you whether this should be implemented at all, and if so, precisely how to implement it. At this point, you are much closer to the code than I am now. There's more than a bit of effort involved in getting one's state of mind back into Edmond's. Reading the paper, seeing how the algorithm progresses, and comparing to the pictures in the paper was my main motivation for keeping the intermediate structures. My goal was to imagine how easy/difficult it would be for someone to come back to this code many years from now after not having touched/read it...which is my current situation :). So factor that into your decision. Either decision is fine, since the original code will always be available in git anyway. Honestly, this code/algorithm is a bit esoteric in the sense that very few people have needed it...certainly the two of us, and probably only a handful of other people. Let us know what you decide. |
I totally agree on you considerations! In the same way of the find_optimium() method, the methods that invoke it (maximum_spanning_arborescence, etc.) should have the same parameter to indicate whether or not we should keep the information to build the intermediate structures. |
Everything going well on this? No prob if things are busy. |
I am sorry, I am very busy recently. However I was thinking about how to implement it, and doing it as we said, we will spend cpu time to rebuild the structures in the second phase and more memory usage due the necessary structures for this purpose . So I am thinking to mix the two versions and making them coexist using the parameter. What do you think about it? |
Yeah that sounds good. The k-best spanning arborescences sounds neat---definitely a separate pull request. |
Ok, I am going to push the code for this pull request soon. |
…2883) Removed not_implemented_for decorator from line_graph function. See networkx#2814 and networkx#2880.
…#2871) * Add greedy modularity maximization community detection. * Adds modularity_max module to networkx.algorithms.community package * Adds greedy_modularity_communities() function * Adds test using Zachary karate club network. * Add Clauset-Newman-Moore community detection. * Replace greedy_modularity_communities() with CNM implementation. * Add networkx.utils.mapped_queue used by the above implementation. * Add tests for networkx.utils.mapped_queue. * Add tests for naive modularity maximization. * Add TestNaive class. * Remove redundant modularity calculation. * Removes call to modularity() left over from debugging. Results in a significant speed-up. * Comply with pep8. * Update modularity_max module and tests for pep8. * Update mapped_queue module and tests for pep8. * Fix import of MappedQueue. * Add documentation for modularity_max module.
* reconstruct_path source code * minor update to examples * test_reconstruct_path * updated example * fixed tests and __all__ declaration * updated docstring example * typo
* Updated release notes. Updated release notes for topological sort changes * Updated migration guide. Updated migration guide for changes to topological sort. Changed "iterator" to "iterable" where appropriate. * Update migration_guide_from_1.x_to_2.0.rst Reverted iterator -> iterable. * Update migration_guide_from_1.x_to_2.0.rst Fixed missing parentheses. * Update migration_guide_from_1.x_to_2.0.rst
…levels and inserted an unique structure, called unroll, that stores the edges involved in a circuits for all levels, in order to rebuild the graph at every level.
…Removed print comments and fixed other part of code as directed me.
…f intermediate results.
Removed the structures that contain the graphs and branchings of all levels and inserted an unique structure, called unroll, that stores the edges involved in a circuits for all levels, in order to rebuild the graph at every level in the second phase of the algorithm.