mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-07-05 09:21:13 +08:00
[pre-commit.ci] pre-commit autoupdate (#6629)
* [pre-commit.ci] pre-commit autoupdate updates: - [github.com/psf/black: 22.6.0 → 22.8.0](https://github.com/psf/black/compare/22.6.0...22.8.0) - [github.com/asottile/pyupgrade: v2.37.0 → v2.38.2](https://github.com/asottile/pyupgrade/compare/v2.37.0...v2.38.2) - https://gitlab.com/pycqa/flake8 → https://github.com/PyCQA/flake8 - [github.com/PyCQA/flake8: 3.9.2 → 5.0.4](https://github.com/PyCQA/flake8/compare/3.9.2...5.0.4) - [github.com/pre-commit/mirrors-mypy: v0.961 → v0.981](https://github.com/pre-commit/mirrors-mypy/compare/v0.961...v0.981) - [github.com/codespell-project/codespell: v2.1.0 → v2.2.1](https://github.com/codespell-project/codespell/compare/v2.1.0...v2.2.1) * Fix a long line * Update sol1.py * Update sol1.py * lambda_ * Update multi_level_feedback_queue.py * Update double_ended_queue.py * Update sequential_minimum_optimization.py * Update .pre-commit-config.yaml Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Christian Clauss <cclauss@me.com>
This commit is contained in:
![66853113+pre-commit-ci[bot]@users.noreply.github.com](/assets/img/avatar_default.png)
committed by
GitHub

parent
e9862adafc
commit
756bb268eb
@ -52,7 +52,7 @@ def power_iteration(
|
||||
# or when we have small changes from one iteration to next.
|
||||
|
||||
convergence = False
|
||||
lamda_previous = 0
|
||||
lambda_previous = 0
|
||||
iterations = 0
|
||||
error = 1e12
|
||||
|
||||
@ -64,21 +64,21 @@ def power_iteration(
|
||||
# Find rayleigh quotient
|
||||
# (faster than usual b/c we know vector is normalized already)
|
||||
vectorH = vector.conj().T if is_complex else vector.T
|
||||
lamda = np.dot(vectorH, np.dot(input_matrix, vector))
|
||||
lambda_ = np.dot(vectorH, np.dot(input_matrix, vector))
|
||||
|
||||
# Check convergence.
|
||||
error = np.abs(lamda - lamda_previous) / lamda
|
||||
error = np.abs(lambda_ - lambda_previous) / lambda_
|
||||
iterations += 1
|
||||
|
||||
if error <= error_tol or iterations >= max_iterations:
|
||||
convergence = True
|
||||
|
||||
lamda_previous = lamda
|
||||
lambda_previous = lambda_
|
||||
|
||||
if is_complex:
|
||||
lamda = np.real(lamda)
|
||||
lambda_ = np.real(lambda_)
|
||||
|
||||
return lamda, vector
|
||||
return lambda_, vector
|
||||
|
||||
|
||||
def test_power_iteration() -> None:
|
||||
|
Reference in New Issue
Block a user