2017-03-05 08:43:19 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
2018-01-06 12:09:33 +00:00
|
|
|
namespace Phpml\Tests\Math\Statistic;
|
2017-03-05 08:43:19 +00:00
|
|
|
|
|
|
|
use Phpml\Math\Statistic\Gaussian;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
|
|
|
|
class GaussianTest extends TestCase
|
|
|
|
{
|
2017-11-14 20:21:23 +00:00
|
|
|
public function testPdf(): void
|
2017-03-05 08:43:19 +00:00
|
|
|
{
|
|
|
|
$std = 1.0;
|
2017-08-17 06:50:37 +00:00
|
|
|
$mean = 0.0;
|
2017-03-05 08:43:19 +00:00
|
|
|
$g = new Gaussian($mean, $std);
|
|
|
|
|
|
|
|
// Allowable error
|
|
|
|
$delta = 0.001;
|
2017-08-17 06:50:37 +00:00
|
|
|
$x = [0, 0.1, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0];
|
2017-03-05 08:43:19 +00:00
|
|
|
$pdf = [0.3989, 0.3969, 0.3520, 0.2419, 0.1295, 0.0539, 0.0175, 0.0044];
|
|
|
|
foreach ($x as $i => $v) {
|
|
|
|
$this->assertEquals($pdf[$i], $g->pdf($v), '', $delta);
|
|
|
|
|
|
|
|
$this->assertEquals($pdf[$i], Gaussian::distributionPdf($mean, $std, $v), '', $delta);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|