-
Notifications
You must be signed in to change notification settings - Fork 36
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
normalization added #176
normalization added #176
Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #176 +/- ##
===========================================
+ Coverage 76.09% 96.87% +20.77%
===========================================
Files 22 32 +10
Lines 2460 3518 +1058
===========================================
+ Hits 1872 3408 +1536
+ Misses 588 110 -478 ☔ View full report in Codecov by Sentry. |
toponetx/utils/normalization.py
Outdated
return out | ||
|
||
|
||
def kipf_adjacency_matrix_normalization( |
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 think we should use descriptive names for these functions (in that the names should indicate what the function does).
Something like:
normalized_symmetric_adjacency_matrix
is what is computed here. It is true (and perhaps) interesting that this is used in Kipf's work, but it is not an invention of that paper as well..
The information where this normalization is used could be provided in the function description with a reference. Examples: Kipf... [REF]
Second, it would be good to have all names consistent, atm we have things like
normalize_x_laplacian (verb first), and ..._adjacency_matrix_normalization.
We should decide for one style and apply consistently, Perhaps something like:
compute_xy_normalized_zmatrix ??
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 agree.
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.
@michaelschaub do you know a better reference for the above normalization ?
Also, do you have a ref for D^{-1}A normalization?
please let me know if you like the current naming convection-I can change it again if you have something better in mind.
toponetx/__init__.py
Outdated
_compute_D1, | ||
_compute_D2, | ||
_compute_D3, | ||
_compute_D5, |
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 are internal functions (starting with an underscore) and should not be imported into the toponetx
namespace.
test/utils/test_normalization.py
Outdated
_compute_D1, | ||
_compute_D2, | ||
_compute_D3, | ||
_compute_D5, |
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.
As far as I see these internal functions are not called directly here and should not be imported.
test/utils/test_normalization.py
Outdated
|
||
L = csr_matrix(L).asfptype() | ||
normalized_L = compute_laplacian_normalized_matrix(L) | ||
expected_result = csr_matrix( |
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.
No need to construct a csr_matrix
here when you convert it to dense arrays below again. Just use np.array
.
test/utils/test_normalization.py
Outdated
L = csr_matrix([[2.0, -1.0, 0.0], [-1.0, 3.0, -1.0], [0.0, -1.0, 2.0]]) | ||
Lx = csr_matrix([[1.0, 0.0, 0.0], [0.0, 0.0, 1.0], [0.0, 1.0, 0.0]]) | ||
normalized_Lx = compute_x_laplacian_normalized_matrix(L, Lx) | ||
expected_result = csr_matrix([[0.25, 0.0, 0.0], [0.0, 0.0, 0.25], [0.0, 0.25, 0.0]]) |
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.
See above.
test/utils/test_normalization.py
Outdated
L = csr_matrix([[4.0, 0], [0.0, 4.0]]) | ||
Lx = csr_matrix([[0.0, 1.0], [1.0, 0.0]]) | ||
normalized_Lx = compute_x_laplacian_normalized_matrix(L, Lx) | ||
expected_result = csr_matrix([[0.0, 0.25], [0.25, 0.0]]) |
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.
See above.
toponetx/utils/normalization.py
Outdated
---------- | ||
A_opt : numpy.ndarray | ||
The adjacency matrix. | ||
add_identity : bool, optional |
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.
add_identity : bool, optional | |
add_identity : bool, default=False |
In general optional boolean flags feel weird, there is nothing optional about them. They default to true or to false, that's it.
Notes | ||
----- | ||
This normalization is based on Kipf's formulation, which computes the row-sums, | ||
constructs a diagonal matrix D^(-0.5), and applies the normalization as D^(-0.5) * A_opt * D^(-0.5). |
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.
Maybe format this a proper LaTeX formulas? This would render better on the documentation website. See https://numpydoc.readthedocs.io/en/latest/format.html#notes and their rendered example.
B : numpy.ndarray or scipy.sparse.csr_matrix | ||
The asymmetric matrix. | ||
is_sparse : bool, optional | ||
If True, treat B as a sparse matrix. |
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 wonder whether that parameter is actually useful? Just test whether B
is sparse (scipy.sparse.issparse
) should be sufficient, right? Or is there ever a case where B
is of sparse type but you want to set is_sparse=False
?
toponetx/utils/normalization.py
Outdated
|
||
Parameters | ||
---------- | ||
B1 : numpy array or scipy csr_matrix |
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.
numpy array
and scipy csr_matrix
should be replaced by np.ndarray
and scipy.sparse.csr_matrix
, respectively, throughout the document
toponetx/utils/normalization.py
Outdated
|
||
Returns | ||
------- | ||
_ : numpy array or scipy csr_matrix |
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.
Please remove the _ :
here and below. If a function returns just one value (as opposed to a tuple of values), just state the type.
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.
Requesting some changes.
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.
References need to be reformatted.
toponetx/utils/normalization.py
Outdated
[1] Schaub, M. T., Benson, A. R., Horn, P., Lippner, G., & Jadbabaie, A. | ||
"Random walks on simplicial complexes and the normalized hodge 1-laplacian." | ||
|
||
[2] Bunch, E., You, Q., Fung, G., & Singh, V. | ||
"Simplicial 2-Complex Convolutional Neural Networks." | ||
""" |
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 references section is still not in the required format. See https://github.com/pyt-team/TopoModelX/blob/main/topomodelx/nn/simplicial/dist2cycle_layer.py for an example or here https://bashtage.github.io/sphinx-material/rst-cheatsheet/rst-cheatsheet.html
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.
LGTM.
often in DL computations normalization must be added to matrices for computations. This file is a collection of popular methods typically used in a DL setting.