linspace() public static method

Return an array populated with $num numbers from $min to $max.
public static linspace ( float $min, float $max, integer $num = 50, boolean $endpoint = true ) : float[]
$min float
$max float
$num integer
$endpoint boolean
return float[]
    public function generate(SuiteDocument $results, Config $config)
    {
        $document = new Document();
        $reportEl = $document->createRoot('reports');
        $reportEl->setAttribute('name', $config->getName());
        $reportEl = $reportEl->appendElement('report');
        $descriptionEl = $reportEl->appendElement('description');
        $descriptionEl->nodeValue = <<<EOT
Warning: The histogram report is experimental, it may change or be removed without warning in
future versions of PHPBench.
EOT;
        $tableEl = $reportEl->appendElement('table');
        foreach ($results->query('//subject') as $subjectEl) {
            foreach ($subjectEl->query('.//variant') as $variantEl) {
                $times = array();
                foreach ($variantEl->query('.//iteration') as $iterationEl) {
                    $times[] = $iterationEl->getAttribute('rev-time');
                }
                if (count($times) > 1) {
                    $histogram = Statistics::histogram($times, $config['bins']);
                    $kde = new Kde($times);
                    $kdeX = Statistics::linspace(min($times), max($times), $config['bins'] + 1);
                    $kdeY = $kde->evaluate($kdeX);
                } else {
                    $histogram = array((string) current($times) => 1);
                    $kdeY = array(null);
                }
                $counter = 0;
                foreach ($histogram as $xValue => $frequency) {
                    $kdeVal = $kdeY[$counter++];
                    $rowEl = $tableEl->appendElement('row');
                    $cellEl = $rowEl->appendElement('cell');
                    $cellEl->setAttribute('name', 'benchmark');
                    $cellEl->nodeValue = functions\class_name($subjectEl->evaluate('string(ancestor::benchmark/@class)'));
                    $cellEl = $rowEl->appendElement('cell');
                    $cellEl->setAttribute('name', 'subject');
                    $cellEl->nodeValue = $subjectEl->evaluate('string(./@name)');
                    $cellEl = $rowEl->appendElement('cell');
                    $cellEl->setAttribute('name', 'index');
                    $cellEl->nodeValue = $counter;
                    $cellEl = $rowEl->appendElement('cell');
                    $cellEl->setAttribute('name', 'time');
                    $cellEl->nodeValue = $xValue;
                    $cellEl = $rowEl->appendElement('cell');
                    $cellEl->setAttribute('name', 'freq');
                    $cellEl->nodeValue = $frequency;
                    $cellEl = $rowEl->appendElement('cell');
                    $cellEl->setAttribute('name', 'kde');
                    $cellEl->nodeValue = $kdeVal;
                }
            }
        }
        return $document;
    }
Example #2
0
 /**
  * It should throw an exception if the linspace min and max are the same number.
  *
  * @expectedException InvalidArgumentException
  * @expectedExceptionMessage Min and max cannot be the same number: 4
  */
 public function testLinspaceMinMaxSame()
 {
     Statistics::linspace(4, 4, 10);
 }
Example #3
0
 public function provideEvaluate()
 {
     return array(array(array(10, 20, 15, 5), Statistics::linspace(0, 9, 10), 'silverman', array(0.01537595, 0.0190706, 0.02299592, 0.02700068, 0.03092369, 0.0346125, 0.03794007, 0.0408159, 0.04318983, 0.04504829)), array(array(10, 20, 15, 5), Statistics::linspace(0, 3, 4), 'scott', array(0.01480612, 0.01869787, 0.02286675, 0.02713209)), array(array(10, 20, 15, 5), Statistics::linspace(0, 3, 4), 'silverman', array(0.01537595, 0.0190706, 0.02299592, 0.02700068)));
 }
Example #4
0
 public function generatePoints($params)
 {
     $this->points = Statistics::linspace(1, 10, $params['points']);
 }