mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-11 17:58:41 +00:00
97 lines
2.2 KiB
PHP
97 lines
2.2 KiB
PHP
<?php
|
|
/**
|
|
* Orange Management
|
|
*
|
|
* PHP Version 7.4
|
|
*
|
|
* @package tests
|
|
* @copyright Dennis Eichhorn
|
|
* @license OMS License 1.0
|
|
* @version 1.0.0
|
|
* @link https://orange-management.org
|
|
*/
|
|
declare(strict_types=1);
|
|
|
|
namespace phpOMS\tests\Math\Stochastic\Distribution;
|
|
|
|
use phpOMS\Math\Stochastic\Distribution\GeometricDistribution;
|
|
|
|
/**
|
|
* @internal
|
|
*/
|
|
class GeometricDistributionTest extends \PHPUnit\Framework\TestCase
|
|
{
|
|
public function testPmf() : void
|
|
{
|
|
$p = 0.2;
|
|
$k = 4;
|
|
|
|
self::assertEqualsWithDelta(0.1024, GeometricDistribution::getPmf($p, $k), 0.01);
|
|
}
|
|
|
|
public function testCdf() : void
|
|
{
|
|
$p = 0.2;
|
|
$k = 6;
|
|
|
|
// P(X > 6) = P(X <= 6) => 1 - CDF
|
|
self::assertEqualsWithDelta(0.262, 1 - GeometricDistribution::getCdf($p, $k), 0.01);
|
|
}
|
|
|
|
public function testMode() : void
|
|
{
|
|
self::assertEquals(1, GeometricDistribution::getMode());
|
|
}
|
|
|
|
public function testMean() : void
|
|
{
|
|
$p = 0.3;
|
|
self::assertEquals(1 / $p, GeometricDistribution::getMean($p));
|
|
}
|
|
|
|
public function testVariance() : void
|
|
{
|
|
$p = 0.3;
|
|
|
|
self::assertEquals((1 - $p) / $p ** 2, GeometricDistribution::getVariance($p));
|
|
}
|
|
|
|
public function testgetStandardDeviation() : void
|
|
{
|
|
$p = 0.3;
|
|
|
|
self::assertEquals(\sqrt((1 - $p) / $p ** 2), GeometricDistribution::getStandardDeviation($p));
|
|
}
|
|
|
|
public function testSkewness() : void
|
|
{
|
|
$p = 0.3;
|
|
|
|
self::assertEquals((2 - $p) / \sqrt(1 - $p), GeometricDistribution::getSkewness($p));
|
|
}
|
|
|
|
public function testExKurtosis() : void
|
|
{
|
|
$p = 0.3;
|
|
|
|
self::assertEquals(6 + ($p ** 2) / (1 - $p), GeometricDistribution::getExKurtosis($p));
|
|
}
|
|
|
|
public function testMedian() : void
|
|
{
|
|
$p = 0.3;
|
|
|
|
self::assertEquals(\ceil(-1 / \log(1 - $p, 2)), GeometricDistribution::getMedian($p));
|
|
}
|
|
|
|
public function testMgf() : void
|
|
{
|
|
$p = 0.3;
|
|
$t1 = 2;
|
|
$t2 = -\log(1 - $p) * 0.8;
|
|
|
|
self::assertEquals($p / (1 - (1 - $p) * \exp($t1)), GeometricDistribution::getMgf($p, $t1));
|
|
self::assertEquals($p * \exp($t2) / (1 - (1 - $p) * \exp($t2)), GeometricDistribution::getMgf($p, $t2));
|
|
}
|
|
}
|