-
-
Notifications
You must be signed in to change notification settings - Fork 46.9k
Initial commit of conjugate gradient method #2486
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
Initial commit of conjugate gradient method #2486
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.
This looks really great. I am not a numpy guy so I can not comment on the usage of numpy. In Python, UPPERCASE variable names are reserved for constants that never change during the runtime of the script. Function parameters should never be uppercase. Also, please use more self-documenting variable names. Single-letter variable names look so old school. Instead of A
, use matrix
or spd_matrix
or some other name that is even more self-documenting of the data that the variable contains. It is OK to have a comment that links the Python variable name back to the formula name: spd_matrix is often called A in discussions of the conjugate gradient algorithm.
Returns a symmetric positive definite matrix given a dimension. | ||
|
||
Input: | ||
N is an integer. |
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 line is redundant now that we have type hints so let's instead give N
a more self-documenting variable name so that this comment is no longer required or make this comment document the what & why, not the datatype.
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.
Yes good point. I changed this.
@@ -0,0 +1,172 @@ | |||
import numpy as np |
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 add a URL that can help the reader learn about the problems that your algorithm is trying to solve...
https://en.wikipedia.org/wiki/Conjugate_gradient_method
https://en.wikipedia.org/wiki/Definite_symmetric_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.
Added :)
Co-authored-by: Christian Clauss <[email protected]>
Co-authored-by: Christian Clauss <[email protected]>
…ore descriptive naming, added check for symmetry in _is_matrix_spd
Totally agree. I changed many namings to be more meaningful. Thanks! |
return np.all(eigen_values > 0) | ||
|
||
|
||
def _create_spd_matrix(N: np.int64) -> np.array: |
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.
N? A more self-documenting name please with no uppercase in variable names.
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.
Changed this :)
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Co-authored-by: Christian Clauss <[email protected]>
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.
@dhruvmanila, check this
@algorithms-keeper review |
* Initial commit of the conjugate gradient method * Update linear_algebra/src/conjugate_gradient.py * Added documentation links, changed variable names to lower case and more descriptive naming, added check for symmetry in _is_matrix_spd * Made changes to some variable naming to be more clear * Update conjugate_gradient.py Co-authored-by: Zeyad Zaky <[email protected]> Co-authored-by: Christian Clauss <[email protected]> Co-authored-by: Dhruv Manilawala <[email protected]>
* Initial commit of the conjugate gradient method * Update linear_algebra/src/conjugate_gradient.py * Added documentation links, changed variable names to lower case and more descriptive naming, added check for symmetry in _is_matrix_spd * Made changes to some variable naming to be more clear * Update conjugate_gradient.py Co-authored-by: Zeyad Zaky <[email protected]> Co-authored-by: Christian Clauss <[email protected]> Co-authored-by: Dhruv Manilawala <[email protected]>
* Initial commit of the conjugate gradient method * Update linear_algebra/src/conjugate_gradient.py * Added documentation links, changed variable names to lower case and more descriptive naming, added check for symmetry in _is_matrix_spd * Made changes to some variable naming to be more clear * Update conjugate_gradient.py Co-authored-by: Zeyad Zaky <[email protected]> Co-authored-by: Christian Clauss <[email protected]> Co-authored-by: Dhruv Manilawala <[email protected]>
* Initial commit of the conjugate gradient method * Update linear_algebra/src/conjugate_gradient.py * Added documentation links, changed variable names to lower case and more descriptive naming, added check for symmetry in _is_matrix_spd * Made changes to some variable naming to be more clear * Update conjugate_gradient.py Co-authored-by: Zeyad Zaky <[email protected]> Co-authored-by: Christian Clauss <[email protected]> Co-authored-by: Dhruv Manilawala <[email protected]>
Describe your change:
This is an implementation of the conjugate gradient method for solving a linear system given an SPD matrix A.
Checklist:
Fixes: #{$ISSUE_NO}
.