necromant2005/tt-math

此包已被废弃且不再维护。作者建议使用https://github.com/truesocialmetrics/math 包。

PHP标准数学算法:移动平均,线性插值,导数,局部极值

1.2.0 2018-12-28 11:35 UTC

This package is auto-updated.

Last update: 2022-02-01 12:33:10 UTC


README

Build Status

介绍

标准数学算法:移动平均,线性插值

特性/目标

  • 简单的函数式API
  • 实现自定义窗口大小的移动平均
  • 实现自定义窗口大小和边缘绑定的移动平均
  • 实现线性插值
  • 实现导数
  • 实现局部极值

安装

主要设置

使用composer

  1. 将其添加到您的composer.json中
"require": {
    "necromant2005/tt-math": "1.*",
}
  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)