php standard math algorithms: running average, linear interpolation, derivative, local extremum

1.2.0 2018-12-28 11:35 UTC

This package is not auto-updated.

Last update: 2024-12-22 20:42:25 UTC


README

Build Status

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

  1. Add this to your composer.json:
"require": {
    "necromant2005/tt-math": "1.*",
}
  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)