Currently, only Gaussian kernels are implemented. Original Python version by: Robert Kern Date: 2004-08-09 Modified: 2005-02-10 by Robert Kern. Contributed to Scipy 2005-10-07 by Robert Kern. Some fixes to match the new scipy_core Copyright 2004-2005 by Enthought, Inc. Copyright 2003-2013 SciPy Developers. All rights reserved.
예제 #1
0
파일: KdeTest.php 프로젝트: Remo/phpbench
 /**
  * It should evaluate a kernel distribution estimate over a given space.
  *
  * @dataProvider provideEvaluate
  */
 public function testEvaluate($dataSet, $space, $bwMethod, $expected)
 {
     $kde = new Kde($dataSet, $bwMethod);
     $result = $kde->evaluate($space);
     // round result
     $result = array_map(function ($v) {
         return round($v, 8);
     }, $result);
     $this->assertEquals($expected, $result);
 }
예제 #2
0
    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;
    }
예제 #3
0
 public function benchKde()
 {
     $kde = new Kde([50, 40, 55, 52, 60, 55, 43, 45, 34, 22]);
     $kde->evaluate($this->points);
 }