/** * It should return the standard deviation. */ public function testStdev() { $this->assertEquals(1.4142, round(Statistics::stdev(array(1, 2, 3, 4, 5)), 4)); $this->assertEquals(17.2116, round(Statistics::stdev(array(13, 23, 12, 44, 55)), 4)); $this->assertEquals(0, round(Statistics::stdev(array(1)), 4)); $this->assertEquals(0, round(Statistics::stdev(array(1, 1, 1)), 4)); $this->assertEquals(2.47, round(Statistics::stdev(array(2, 6, 4, 1, 7, 3, 6, 1, 7, 1, 6, 5, 1, 1), true), 2)); }
/** * It should return the standard deviation. */ public function testStdev() { $this->assertEquals(1.4142, round(Statistics::stdev([1, 2, 3, 4, 5]), 4)); $this->assertEquals(17.2116, round(Statistics::stdev([13, 23, 12, 44, 55]), 4)); $this->assertEquals(0, round(Statistics::stdev([1]), 4)); $this->assertEquals(0, round(Statistics::stdev([1, 1, 1]), 4)); $this->assertEquals(2.47, round(Statistics::stdev([2, 6, 4, 1, 7, 3, 6, 1, 7, 1, 6, 5, 1, 1], true), 2)); }
/** * Calculate and set the deviation from the mean time for each iteration. If * the deviation is greater than the rejection threshold, then mark the iteration as * rejected. */ public function computeStats() { $this->rejects = array(); if (0 === count($this->iterations)) { return; } $times = array(); foreach ($this->iterations as $iteration) { $times[] = $iteration->getResult()->getTime() / $iteration->getRevolutions(); } // standard deviation for T Distribution $this->stats['stdev'] = Statistics::stdev($times); // mean of the times $this->stats['mean'] = Statistics::mean($times); // standard error $this->stats['rstdev'] = $this->stats['stdev'] / $this->stats['mean'] * 100; // variance $this->stats['variance'] = Statistics::variance($times); // min and max $this->stats['min'] = min($times); $this->stats['max'] = max($times); foreach ($this->iterations as $iteration) { // deviation is the percentage different of the value from the mean of the set. $deviation = 100 / $this->stats['mean'] * ($iteration->getResult()->getTime() / $iteration->getRevolutions() - $this->stats['mean']); $iteration->setDeviation($deviation); // the Z-Value repreents the number of standard deviations this // value is away from the mean. $revTime = $iteration->getResult()->getTime() / $iteration->getRevolutions(); $zValue = $this->stats['stdev'] ? ($revTime - $this->stats['mean']) / $this->stats['stdev'] : 0; $iteration->setZValue($zValue); if (null !== $this->rejectionThreshold) { if (abs($deviation) >= $this->rejectionThreshold) { $this->rejects[] = $iteration; } } } $this->computed = true; }
public function benchStDev() { Statistics::stdev([10, 100, 42, 84, 11, 12, 9, 6]); }