## necromant2005/tt-math

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

4 103

2

1

1

1.1.0 2016-03-17 05:48 UTC

## 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

```"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)```