Skip to content

Created Sherman Morrison method #1162

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

Merged
merged 4 commits into from
Sep 3, 2019
Merged

Created Sherman Morrison method #1162

merged 4 commits into from
Sep 3, 2019

Conversation

McDic
Copy link
Contributor

@McDic McDic commented Aug 31, 2019

I created method to apply Sherman-Morrison formula to Matrix.

Sherman-Morrison formula is important to reduce time complexity on calculating inverse matrix on some special cases. This formula is also used to improve BFGS update performance. For deeper stuffs please look into this documents:

https://en.wikipedia.org/wiki/Sherman%E2%80%93Morrison_formula
https://en.wikipedia.org/wiki/Broyden%E2%80%93Fletcher%E2%80%93Goldfarb%E2%80%93Shanno_algorithm
https://en.wikipedia.org/wiki/Quasi-Newton_method

@McDic McDic changed the title Created Sherman Morrison Created Sherman Morrison method Aug 31, 2019
Copy link
Member

@cclauss cclauss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really slick! I like the type hints and assertions to guard against bad data. Nice contribution.

A couple of optional things that I would be interested to see added are doctests and list comprehensions.

1. Added docstring tests
2. Tweaked __str__() using join
3. Added __repr__()
4. Changed index validation to be independent method
@McDic
Copy link
Contributor Author

McDic commented Aug 31, 2019

@cclauss I added doctests.

By the way, I'm sorry, what do you mean for list comprehension? Do you want some method to iterate over all elements in matrix as single 1x1 element or row/column vector?

s += "["
s += ", ".join(string_format_identifier % (obj,) for obj in row_vector)
s += "]\n"
s += "\n".join("[" + ", ".join(string_format_identifier % (obj,) for obj in row_vector) + "]" for row_vector in self.array)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line can not be read on GitHub without left-right scrolling. Please wrap it so this is no longer the case.

assert(isinstance(another, Matrix))
assert(self.row == another.row and self.column == another.column)
Copy link
Member

@cclauss cclauss Aug 31, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assert(0)

assert(False)

Lose the parens ()... it is not a function.

1. Reduced line length for __str__()
2. Removed parens for assert
@McDic
Copy link
Contributor Author

McDic commented Aug 31, 2019

If you need more things to fix then please write comments. Thank you.

@McDic
Copy link
Contributor Author

McDic commented Sep 3, 2019

@cclauss Is there anything needed to change?

@cclauss cclauss merged commit 9492e7a into TheAlgorithms:master Sep 3, 2019
stokhos pushed a commit to stokhos/Python that referenced this pull request Jan 3, 2021
* Created Sherman Morrison

* Added docstring for class

* Updated Sherman morrison

1. Added docstring tests
2. Tweaked __str__() using join
3. Added __repr__()
4. Changed index validation to be independent method

* Applied cclauss's point

1. Reduced line length for __str__()
2. Removed parens for assert
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants