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
ENH : Provide non-normalized and normalized directed laplacian matrix calculation #7199
ENH : Provide non-normalized and normalized directed laplacian matrix calculation #7199
Conversation
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.
Nicely done and with good tests.
And thanks for that reference.
For the docs, can you add the reference as part of that?
Maybe use the same example as is done for the undirected case so people can compare. If you have other better ideas please use them instead of my suggestions. :)
I don't think the current example should have the print
statement. But the printing of numpy arrays in examples has been problematic in the past, so if removing that print function call makes it fail, leave it in obviously.
Thanks very much!!
…al_laplacian_matrix` in docstring of `laplacian_matrix`
…etric output to `directed_combinatorial_laplacian_matrix` and `directed_laplacian_matrix`.
… along with associated references Also removed `print` statement from example in `laplacian_matrix`
@dschult I believe I've done everything you suggested in the Issue and your comments above. I want to confirm that I understand your suggestion below:
Is something like this, this, and this what you had in mind? |
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 like the tests, the addition of normalized_laplacian_matrix handling of DiGraph and the content of the doc_strings. The only things left as far as I can see involve formatting of doc_strings and making the examples differ from the test graphs. If this is too much trouble let me know as it's more formatting than coding and I know the NX formatting.
- It looks like removing the "print" from the doc_string test did cause one test failure. Looks like the
repr
can vary from system to system, whilestr
is consistent. So could we try putting the print back in?print(nx.laplacian_matrix(G).toarray())
- The doc_strings should be wrapped to ~85 chars like the code. This can be a pain so if it doesn't fit, go over the limit, but if it is easy make a line break. Thsi doesn't change the html docs, but it does make it more uniform when reading the docs in the code.
- Could we make the directed example one node smaller than the test graph (which comes fro the article)? For example, remove node 6. Or if you prefer 2 and 6? My goal is to make it easier to read the example, even if the resulting graph is not as good of a test of the algorithm.
- Could we put the
set_printoptions
and comment on a separate line from the import of numpy?
I like the moving of the 1/2 in the math expressions. I like the tests. I like the expansion to the normalized_laplacian_matrix case. It's kind of amazing that we already had two normalized directed functions and we still didn't cover the basic extension of the undirected normalized definition. It just shows that there are many more possibilities in directed graphs than undirected graphs.
Thanks for this!
Also -- the dev
tests might not pass due to new releases of pytest. We're working on that. After it is fixed on main
we can merge this PR with main and they should pass.
Done!
Done!
Done!
Done! All the tests pass now. Ready for review an merge! |
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.
Generally LGTM, thanks @smokestacklightnin . There's an issue with line length that should automatically be corrected by the linter, but which is currently not being handled correctly for whatever reason.
That issue should be handled separately though - for this PR, I think we can just go in and manually fix it prior to merging.
networkx/linalg/laplacianmatrix.py
Outdated
|
||
All calculations here are done using the out-degree. For Laplacians using in-degree, us `G.reverse(copy=False)` instead of `G`. | ||
|
||
The `laplacian_matrix` function provides an unnormalized matrix, while `normalized_laplacian_matrix`, `directed_laplacian_matrix`, and `directed_combinatorial_laplacian_matrix` are all normalized. |
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.
Did our linting rules change? These lines are clearly greater than 100 chars so I would've expected CI to complain about it. @MridulS any ideas?
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.
Should I go ahead and just fix the line lengths manually now?
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 think our lint checks line lengths for comments. But I could be wrong.
Yes, @smokestacklightnin it would help to wrap the comment lines to about 80 chars (less than 88 for sure). There are others below...
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.
Done
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.
Thanks very much for this.
It looks good to me... :)
Excellent, thanks again @smokestacklightnin ! |
… calculation (networkx#7199) Adds functionality for directed laplacian matrices * Remove the `not_implemented_for("directed")` decorator on `laplacian_matrix` * Add tests for 'laplacian_matrix` as applied to directed graphs * Add pointers to `directed_laplacian_matrix` and `directed_combinatorial_laplacian_matrix` in docstring of `laplacian_matrix` * Allow DiGraphs in `normalized_laplacian_matrix`
This pull request addresses Issue #7148
Here, I provide both normalized and non-normalized graph Laplacian as well as improve the documentation for them.
I welcome any comments or questions