{"id":22846255,"url":"https://github.com/aboks/power-iteration","last_synced_at":"2025-07-18T10:09:44.513Z","repository":{"id":29577279,"uuid":"122109325","full_name":"aboks/power-iteration","owner":"aboks","description":"Implementation of the Power Iteration method for finding eigenvalues of a matrix, using math-php","archived":false,"fork":false,"pushed_at":"2022-06-27T19:07:51.000Z","size":42,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-30T11:41:35.445Z","etag":null,"topics":["eigenvalues","eigenvectors","linear-algebra","mathematics","php"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aboks.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-02-19T19:21:07.000Z","updated_at":"2022-09-27T10:01:25.000Z","dependencies_parsed_at":"2022-09-07T19:01:43.816Z","dependency_job_id":null,"html_url":"https://github.com/aboks/power-iteration","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aboks%2Fpower-iteration","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aboks%2Fpower-iteration/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aboks%2Fpower-iteration/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aboks%2Fpower-iteration/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aboks","download_url":"https://codeload.github.com/aboks/power-iteration/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251357455,"owners_count":21576710,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["eigenvalues","eigenvectors","linear-algebra","mathematics","php"],"created_at":"2024-12-13T03:26:52.180Z","updated_at":"2025-04-28T17:41:19.261Z","avatar_url":"https://github.com/aboks.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Continuous Integration](https://github.com/aboks/power-iteration/workflows/Continuous%20Integration/badge.svg)\n[![Latest Stable Version](https://poser.pugx.org/aboks/power-iteration/v/stable)](https://packagist.org/packages/aboks/power-iteration)\n\nPowerIteration\n==============\nImplementation of the Power Iteration method for finding (dominant) eigenvalues and the corresponding eigenvectors of a matrix, using the excellent [math-php](https://github.com/markrogoyski/math-php) library.\n \nInstallation\n------------\nInstall using composer:\n```\n$ composer require aboks/power-iteration\n```\n\nBasic usage\n-----------\n```php\n\u003c?php\nuse Aboks\\PowerIteration\\PowerIteration;\nuse MathPHP\\LinearAlgebra\\MatrixFactory;\n\n$power_iteration = new PowerIteration();\n$dominant_eigenpair = $power_iteration-\u003egetDominantEigenpair(MatrixFactory::create([\n    [2, 1],\n    [0, 1]\n ]));\nvar_dump($dominant_eigenpair-\u003egetEigenvalue()); // 2\nvar_dump($dominant_eigenpair-\u003egetEigenvector()); // Vector([1, 0]), or a scalar multiple\n```\n\nAdvanced usage\n--------------\n\n### Calculating the least dominant eigenpair\n\nIn most situations, one is interested in the dominant eigenvalue and its corresponding eigenvector. It is also possible to calculate the least dominant eigenpair however: \n```php\n\u003c?php\nuse Aboks\\PowerIteration\\PowerIteration;\nuse MathPHP\\LinearAlgebra\\Matrix;\n\n$power_iteration = new PowerIteration();\n$dominant_eigenpair = $power_iteration-\u003egetLeastDominantEigenpair(MatrixFactory::create([\n    [2, 1],\n    [0, 1]\n ]));\nvar_dump($dominant_eigenpair-\u003egetEigenvalue()); // 1\nvar_dump($dominant_eigenpair-\u003egetEigenvector()); // Vector([√2, -√2]), or a scalar multiple\n```\n\n\nCustomizations\n--------------\n\n### Stopping criterion\n\nBy default, the power iteration runs for 1000 iterations. The stopping criterion can be altered by passing an instance of `StoppingCriterion` as the first argument to `PowerIteration`:\n```php\n\u003c?php\nuse Aboks\\PowerIteration\\PowerIteration;\nuse Aboks\\PowerIteration\\StoppingCriterion\\MaxIterations;\nuse Aboks\\PowerIteration\\StoppingCriterion\\EigenvectorTolerance;\n\nnew PowerIteration(new MaxIterations(10));           // will stop after 10 iterations\nnew PowerIteration(new EigenvectorTolerance(0.01));  // will stop when ‖Av - λv‖ \u003c 0.01\n```\n\n### Scaling method\n\nTo prevent overflow in case of very large eigenvalues (or underflow in case of small eigenvalues), the eigenvector estimates are scaled/normalized after each iteration. The final eigenvector estimate is also scaled using the same method. By default, the estimates are scaled to a unit vector based on the L2-norm. To use a different method, provide an instance of `ScalingMethod` as a second argument to `PowerIteration`:\n```php\n\u003c?php\nuse Aboks\\PowerIteration\\PowerIteration;\nuse Aboks\\PowerIteration\\ScalingMethod\\NormBased;\nuse Aboks\\PowerIteration\\Norm\\MaxNorm;\n\nnew PowerIteration(null, new NormBased(new MaxNorm()));  // will scale to a unit vector based on the max-norm\n``` \n\nRunning tests\n-------------\nAfter installing dependencies (including development dependencies) using Composer, run\n```\n$ ./vendor/bin/phpunit\n```\nfrom the project root dir.\n\nContributing\n------------\nContributions to this library are very welcome! Please make sure that your changes have sufficient test coverage, and that the code follows [PSR-2](https://www.php-fig.org/psr/psr-2/).\n\nVersioning\n----------\nThis project adheres to [Semantic Versioning](http://semver.org/).\n\nLicense\n-------\nThe code is released under the MIT license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faboks%2Fpower-iteration","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faboks%2Fpower-iteration","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faboks%2Fpower-iteration/lists"}