truesocialmetrics / math
PHP标准数学算法:运行平均数、线性插值、导数、局部极值
1.2.0
2018-12-28 11:35 UTC
Requires
- php: >=7.1
README
简介
标准数学算法:运行平均数,线性插值
特性/目标
- 简单的函数式API
- 自定义窗口大小的运行平均数实现
- 自定义窗口大小和边界的运行平均数实现
- 线性插值实现
- 导数实现
- 局部极值实现
安装
主要设置
使用composer
- 将以下内容添加到您的composer.json中
"require": { "necromant2005/tt-math": "1.*", }
- 现在运行命令让composer下载TweeMath PHP SDK
$ php composer.phar update
用法
使用窗口大小=2的运行平均数
use TweeMath\Algorithm; Algorithm\RunningAverage(array(0 => 0, 1 => 2, 3 => 3, 4 => 5, 5 => 3, 6 => 1), 2); // array(1 => 1, 4 => 4, 6 => 2)
使用窗口大小=2和边界绑定的运行平均数
use TweeMath\Algorithm; Algorithm\RunningAverageEdge(array(0 => 0, 1 => 2, 3 => 3, 4 => 5, 5 => 3), 2); // array(0 => 0, 1 => 1, 4 => 4, 5 => 3)
线性插值用于下一个点x=2
use TweeMath\Algorithm; Algorithm\LinearInterpolation(array(0 => 0, 1 => 1), 2); // 2
用于大数的线性插值用于下一个点max + 2
use TweeMath\Algorithm; $max = (PHP_MAX_INT >> 1) + 1000; Algorithm\LinearInterpolationGracefull(array(time() => $max, time() + 1 => $max + 1), time() + 2); // $max + 2
使用epsilon = 1的导数
use TweeMath\Algorithm; Algorithm\Derivative(array(0 => 0, 1 => 2, 4 => 5, 6 => 1), 1); // array(0 => 2, 1 => 3, 4 => -5)
使用epsilon = 1的局部极值
use TweeMath\Algorithm; Algorithm\LocalExtremum(array(0 => 0, 1 => 2, 2 => 4, 3 => 3, 4 => 5, 5 => 3, 6 => 1), 1); // array(2 => -1, 3 => 2, 4 => -2)