truesocialmetrics / math
php standard math algorithms: running average, linear interpolation, derivative, local extremum
Installs: 6 703
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 2
Forks: 2
Open Issues: 0
Requires
- php: >=7.1
README
Introduction
Standard Math Algorithms: Running Average, Linear Interpolation
Features / Goals
- Simple functional API
- Implementation Running Average with custom window size
- Implementation Running Average with custom window size and Edge binding
- Implementation Linear interpolation
- Implementation Derivative
- Implementation Local Extremum
Installation
Main Setup
With composer
- Add this to your composer.json:
"require": { "necromant2005/tt-math": "1.*", }
- Now tell composer to download TweeMath PHP SDK by running the command:
$ php composer.phar update
Usage
Running average using with window size = 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)
Running average using with window size = 2 and edges binding
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)
Linear interpolation for the next point x=2
use TweeMath\Algorithm; Algorithm\LinearInterpolation(array(0 => 0, 1 => 1), 2); // 2
Linear interpolation for large numbers for the next point max + 2
use TweeMath\Algorithm; $max = (PHP_MAX_INT >> 1) + 1000; Algorithm\LinearInterpolationGracefull(array(time() => $max, time() + 1 => $max + 1), time() + 2); // $max + 2
Derivative for input with epsilon = 1
use TweeMath\Algorithm; Algorithm\Derivative(array(0 => 0, 1 => 2, 4 => 5, 6 => 1), 1); // array(0 => 2, 1 => 3, 4 => -5)
Local Extremum's for input with 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)