variance() public static method

Return the variance for a given population.
public static variance ( array $values, boolean $sample = false ) : float
$values array
$sample boolean
return float
Exemplo n.º 1
0
 /**
  * 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;
 }
Exemplo n.º 2
0
 public function benchVariance()
 {
     Statistics::variance([10, 100, 42, 84, 11, 12, 9, 6]);
 }