Visitar URL original
Add the type of norm as an input for Power Iteration by smturro2 · Pull Request #5309 · TheAlgorithms/Python · GitHub
The Wayback Machine - https://web.archive.org/web/20260530040639/https://github.com/TheAlgorithms/Python/pull/5309
Skip to content

Add the type of norm as an input for Power Iteration#5309

Closed
smturro2 wants to merge 4 commits into
TheAlgorithms:masterfrom
smturro2:master
Closed

Add the type of norm as an input for Power Iteration#5309
smturro2 wants to merge 4 commits into
TheAlgorithms:masterfrom
smturro2:master

Conversation

@smturro2
Copy link
Copy Markdown
Contributor

@smturro2 smturro2 commented Oct 14, 2021 •

Describe your change:

Power iteration has better convergence if you normalize the output vector after every iteration. This can be seen in the current code. In some case it is better to normalize by the infinity-norm than the 2-norm. I will add an extra parameter to the function so the user can change the type of norm used. The default value would be 2, so existing external implementations of the code will not be altered and would not require changes.

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Documentation change?

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation.
  • If this pull request resolves one or more open issues then the commit message contains Fixes: Add the type of norm as an input for Power Iteration #5301 .

@ghost ghost added awaiting reviews This PR is ready to be reviewed enhancement This PR modified some existing files labels Oct 14, 2021
@smturro2 smturro2 changed the title Add the type of norm as an input for Power Iteration. Fixes: #5301 Add the type of norm as an input for Power Iteration Oct 14, 2021
@smturro2
Copy link
Copy Markdown
Contributor Author

Should I check off checkboxes which are not applicable such as "All filenames are in all lowercase characters with no spaces or dashes."?

Comment thread linear_algebra/src/power_iteration.py Outdated
vector: random initial vector in same space as matrix.
Numpy array. np.shape(vector) == (N,) or (N,1)
ord: The order of the norm used in normalization. Optional.
{non-zero int, np.inf, -1*np.inf, ‘fro’, ‘nuc’}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

np.inf is a float
fro is a str

Copy link
Copy Markdown
Contributor Author

@smturro2 smturro2 Oct 14, 2021 •

Choose a reason for hiding this comment

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

There are several valid inputs that you can put in. You can put in an non zero int, np.inf, -1*np.inf as well as these two strings. All are valid inputs for the numpy.linalg norm function. What would be the best way to clarify this in the documentation?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Look at the type hints for numpy.linalg and see how they do it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Numpy uses the same set to denote the possible inputs. I saved some space by putting in np.inf instead of clarifying later in the comment which numpy does. Something else to note is they do not use type hints.
Reference
ord : {non-zero int, inf, -inf, 'fro', 'nuc'}, optional
Order of the norm (see table under Notes). 'inf' means numpy's inf object. The default is None.
There is also a large table with details on each input. I think providing the set, explanation, and link to the numpy documentation will be sufficient for our documentation

@ghost ghost added the tests are failing Do not merge until tests pass label Oct 14, 2021
@smturro2 smturro2 marked this pull request as draft October 14, 2021 17:48
@smturro2 smturro2 marked this pull request as ready for review October 14, 2021 18:53
@ghost ghost removed the tests are failing Do not merge until tests pass label Oct 14, 2021
@smturro2 smturro2 closed this Dec 23, 2021
@smturro2
Copy link
Copy Markdown
Contributor Author

This request was closed due to the original branch being deleted. The new branch is requested to merge at #6111

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting reviews This PR is ready to be reviewed enhancement This PR modified some existing files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add the type of norm as an input for Power Iteration

2 participants