aboks/power-iteration
Composer 安装命令:
composer require aboks/power-iteration
包简介
Implementation of the Power Iteration method for finding eigenvalues of a matrix, using math-php
README 文档
README
PowerIteration
Implementation of the Power Iteration method for finding (dominant) eigenvalues and the corresponding eigenvectors of a matrix, using the excellent math-php library.
Installation
Install using composer:
$ composer require aboks/power-iteration
Basic usage
<?php use Aboks\PowerIteration\PowerIteration; use MathPHP\LinearAlgebra\MatrixFactory; $power_iteration = new PowerIteration(); $dominant_eigenpair = $power_iteration->getDominantEigenpair(MatrixFactory::create([ [2, 1], [0, 1] ])); var_dump($dominant_eigenpair->getEigenvalue()); // 2 var_dump($dominant_eigenpair->getEigenvector()); // Vector([1, 0]), or a scalar multiple
Advanced usage
Calculating the least dominant eigenpair
In most situations, one is interested in the dominant eigenvalue and its corresponding eigenvector. It is also possible to calculate the least dominant eigenpair however:
<?php use Aboks\PowerIteration\PowerIteration; use MathPHP\LinearAlgebra\Matrix; $power_iteration = new PowerIteration(); $dominant_eigenpair = $power_iteration->getLeastDominantEigenpair(MatrixFactory::create([ [2, 1], [0, 1] ])); var_dump($dominant_eigenpair->getEigenvalue()); // 1 var_dump($dominant_eigenpair->getEigenvector()); // Vector([√2, -√2]), or a scalar multiple
Customizations
Stopping criterion
By 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:
<?php use Aboks\PowerIteration\PowerIteration; use Aboks\PowerIteration\StoppingCriterion\MaxIterations; use Aboks\PowerIteration\StoppingCriterion\EigenvectorTolerance; new PowerIteration(new MaxIterations(10)); // will stop after 10 iterations new PowerIteration(new EigenvectorTolerance(0.01)); // will stop when ‖Av - λv‖ < 0.01
Scaling method
To 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:
<?php use Aboks\PowerIteration\PowerIteration; use Aboks\PowerIteration\ScalingMethod\NormBased; use Aboks\PowerIteration\Norm\MaxNorm; new PowerIteration(null, new NormBased(new MaxNorm())); // will scale to a unit vector based on the max-norm
Running tests
After installing dependencies (including development dependencies) using Composer, run
$ ./vendor/bin/phpunit
from the project root dir.
Contributing
Contributions to this library are very welcome! Please make sure that your changes have sufficient test coverage, and that the code follows PSR-2.
Versioning
This project adheres to Semantic Versioning.
License
The code is released under the MIT license.
aboks/power-iteration 适用场景与选型建议
aboks/power-iteration 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 32 次下载、GitHub Stars 达 3, 最近一次更新时间为 2018 年 02 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「math」 「mathematics」 「linear-algebra」 「eigenvalue」 「eigenvector」 「math-php」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 aboks/power-iteration 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 aboks/power-iteration 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 aboks/power-iteration 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Matrix math for PHP.
LaTeX formula to PNG
Mathematical functions with strict typing and predictable error handling
PHP library for scientific computing.
Geo calculations library
Partition problem for balanced arrays splitting made easy.
统计信息
- 总下载量: 32
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 10
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-02-19