mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-11 17:58:41 +00:00
Documentation and distribution additions
This commit is contained in:
parent
c23d515173
commit
4e510ea10e
|
|
@ -1,24 +1,78 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.0
|
||||
*
|
||||
* @category TBD
|
||||
* @package TBD
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @copyright 2013 Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link http://orange-management.com
|
||||
*/
|
||||
|
||||
namespace phpOMS\Math\Statistic;
|
||||
|
||||
/**
|
||||
* Average class.
|
||||
*
|
||||
* @category Framework
|
||||
* @package phpOMS\DataStorage\Database
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @license OMS License 1.0
|
||||
* @link http://orange-management.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Average
|
||||
{
|
||||
|
||||
public static function weightedAverage(array $value, array $weight)
|
||||
/**
|
||||
* Calculate weighted average.
|
||||
*
|
||||
* Example: ([1, 2, 3, 4], [0.25, 0.5, 0.125, 0.125])
|
||||
*
|
||||
* @param array $values Values
|
||||
* @param array $weight Weight for values
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @throws
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function weightedAverage(array $values, array $weight) : \float
|
||||
{
|
||||
if (($count = count($value)) !== count($weight)) {
|
||||
if (($count = count($values)) !== count($weight)) {
|
||||
throw new \Exception('Dimension');
|
||||
}
|
||||
|
||||
$avg = 0.0;
|
||||
|
||||
for ($i = 0; $i < $count; $i++) {
|
||||
$avg += $value[$i] * $weight[$i];
|
||||
$avg += $values[$i] * $weight[$i];
|
||||
}
|
||||
|
||||
return $avg;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Calculate the mode.
|
||||
*
|
||||
* Example: ([1, 2, 2, 3, 4, 4, 2])
|
||||
*
|
||||
* @param array $values Values
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function mode($values)
|
||||
{
|
||||
$count = array_count_values($values);
|
||||
|
|
@ -27,7 +81,19 @@ class Average
|
|||
return array_keys($count, $best);
|
||||
}
|
||||
|
||||
public static function median(array $values)
|
||||
/**
|
||||
* Calculate the median.
|
||||
*
|
||||
* Example: ([1, 2, 2, 3, 4, 4, 2])
|
||||
*
|
||||
* @param array $values Values
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function median(array $values) : \float
|
||||
{
|
||||
sort($values);
|
||||
$count = count($values);
|
||||
|
|
@ -44,6 +110,21 @@ class Average
|
|||
return $median;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the arithmetic mean.
|
||||
*
|
||||
* Example: ([1, 2, 2, 3, 4, 4, 2])
|
||||
*
|
||||
* @param array $values Values
|
||||
* @param \int $offset Offset for outlier
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @throws
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function arithmeticMean(array $values, \int $offset = 0)
|
||||
{
|
||||
sort($values);
|
||||
|
|
@ -61,8 +142,29 @@ class Average
|
|||
return array_sum($values) / $count;
|
||||
}
|
||||
|
||||
public static function geometricMean(array $values)
|
||||
/**
|
||||
* Calculate the geometric mean.
|
||||
*
|
||||
* Example: ([1, 2, 2, 3, 4, 4, 2])
|
||||
*
|
||||
* @param array $values Values
|
||||
* @param \int $offset Offset for outlier
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @throws
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function geometricMean(array $values, \int $offset = 0)
|
||||
{
|
||||
sort($values);
|
||||
|
||||
if ($offset > 0) {
|
||||
$values = array_slice($values, $offset, -$offset);
|
||||
}
|
||||
|
||||
$count = count($values);
|
||||
|
||||
if ($count === 0) {
|
||||
|
|
@ -72,8 +174,29 @@ class Average
|
|||
return pow(array_product($values), 1 / $count);
|
||||
}
|
||||
|
||||
public static function harmonicMean(array $values)
|
||||
/**
|
||||
* Calculate the harmonic mean.
|
||||
*
|
||||
* Example: ([1, 2, 2, 3, 4, 4, 2])
|
||||
*
|
||||
* @param array $values Values
|
||||
* @param \int $offset Offset for outlier
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @throws
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function harmonicMean(array $values, \int $offset = 0)
|
||||
{
|
||||
sort($values);
|
||||
|
||||
if ($offset > 0) {
|
||||
$values = array_slice($values, $offset, -$offset);
|
||||
}
|
||||
|
||||
$count = count($values);
|
||||
$sum = 0.0;
|
||||
|
||||
|
|
@ -88,8 +211,27 @@ class Average
|
|||
return 1 / ($sum / $count);
|
||||
}
|
||||
|
||||
public static function angleMean($angles)
|
||||
/**
|
||||
* Calculate the angle mean.
|
||||
*
|
||||
* Example: ([1, 2, 2, 3, 4, 4, 2])
|
||||
*
|
||||
* @param array $angles Angles
|
||||
* @param \int $offset Offset for outlier
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function angleMean($angles, \int $offset = 0)
|
||||
{
|
||||
sort($angles);
|
||||
|
||||
if ($offset > 0) {
|
||||
$angles = array_slice($angles, $offset, -$offset);
|
||||
}
|
||||
|
||||
$y = $x = 0;
|
||||
$size = count($angles);
|
||||
|
||||
|
|
@ -104,7 +246,21 @@ class Average
|
|||
return rad2deg(atan2($y, $x));
|
||||
}
|
||||
|
||||
public static function timeToAngle(\string $time)
|
||||
/**
|
||||
* Calculate angle based on time.
|
||||
*
|
||||
* Example: ('08:44:28')
|
||||
*
|
||||
* @param string $time Time
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @throws
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function timeToAngle(\string $time) : \float
|
||||
{
|
||||
$parts = explode(':', $time);
|
||||
|
||||
|
|
@ -118,27 +274,59 @@ class Average
|
|||
return $angle;
|
||||
}
|
||||
|
||||
public static function angleToTime(\float $angle)
|
||||
/**
|
||||
* Calculate time based on angle.
|
||||
*
|
||||
* Example: ('08:44:28')
|
||||
*
|
||||
* @param float $angle Angle
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @throws
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function angleToTime(\float $angle) : \string
|
||||
{
|
||||
$sec = 86400.0 * $angle / 360.0;
|
||||
$parts = [floor($sec / 3600), floor(($sec % 3600) / 60), $sec % 60];
|
||||
$time = sprintf('%02d:%02d:%02d', $parts[0], $parts[1], $parts[2]);
|
||||
$time = sprintf('%02d:%02d:%02d', floor($sec / 3600), floor(($sec % 3600) / 60), $sec % 60);
|
||||
|
||||
return $time;
|
||||
}
|
||||
|
||||
public static function angleMean2(array $angle)
|
||||
/**
|
||||
* Calculate the angle mean.
|
||||
*
|
||||
* Example: ([1, 2, 2, 3, 4, 4, 2])
|
||||
*
|
||||
* @param array $angles Angles
|
||||
* @param \int $offset Offset for outlier
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function angleMean2(array $angles, \int $offset = 0)
|
||||
{
|
||||
sort($angles);
|
||||
|
||||
if ($offset > 0) {
|
||||
$angles = array_slice($angles, $offset, -$offset);
|
||||
}
|
||||
|
||||
$sins = 0.0;
|
||||
$coss = 0.0;
|
||||
|
||||
foreach ($angle as $a) {
|
||||
foreach ($angles as $a) {
|
||||
$sins += sin(deg2rad($a));
|
||||
$coss += cos(deg2rad($a));
|
||||
}
|
||||
|
||||
$avgsin = $sins / (0.0 + count($angle));
|
||||
$avgcos = $coss / (0.0 + count($angle));
|
||||
$avgsin = $sins / (0.0 + count($angles));
|
||||
$avgcos = $coss / (0.0 + count($angles));
|
||||
$avgang = rad2deg(atan2($avgsin, $avgcos));
|
||||
|
||||
while ($avgang < 0.0) $avgang += 360.0;
|
||||
|
|
|
|||
|
|
@ -1,9 +1,48 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.0
|
||||
*
|
||||
* @category TBD
|
||||
* @package TBD
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @copyright 2013 Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link http://orange-management.com
|
||||
*/
|
||||
|
||||
namespace phpOMS\Math\Statistic;
|
||||
|
||||
/**
|
||||
* Basic statistic functions.
|
||||
*
|
||||
* @category Framework
|
||||
* @package phpOMS\DataStorage\Database
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @license OMS License 1.0
|
||||
* @link http://orange-management.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Basic
|
||||
{
|
||||
public static function freaquency(array $values) : \float
|
||||
|
||||
/**
|
||||
* Calculate frequency.
|
||||
*
|
||||
* Example: ([4, 5, 9, 1, 3])
|
||||
*
|
||||
* @param array $values Values
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function freaquency(array $values) : array
|
||||
{
|
||||
$freaquency = [];
|
||||
|
||||
|
|
|
|||
|
|
@ -1,17 +1,71 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.0
|
||||
*
|
||||
* @category TBD
|
||||
* @package TBD
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @copyright 2013 Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link http://orange-management.com
|
||||
*/
|
||||
|
||||
namespace phpOMS\Math\Statistic;
|
||||
|
||||
/**
|
||||
* Measure of dispersion.
|
||||
*
|
||||
* @category Framework
|
||||
* @package phpOMS\DataStorage\Database
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @license OMS License 1.0
|
||||
* @link http://orange-management.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class MeasureOfDispersion
|
||||
{
|
||||
public static function range($values)
|
||||
|
||||
/**
|
||||
* Get range.
|
||||
*
|
||||
* Example: ([4, 5, 9, 1, 3])
|
||||
*
|
||||
* @param array $values Values
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function range(array $values) : \float
|
||||
{
|
||||
sort($values);
|
||||
$end = end($values);
|
||||
$start = reset($values);
|
||||
|
||||
return $start - $end;
|
||||
}
|
||||
|
||||
public static function empiricalVariance($values)
|
||||
/**
|
||||
* Calculage empirical variance.
|
||||
*
|
||||
* Example: ([4, 5, 9, 1, 3])
|
||||
*
|
||||
* @param array $values Values
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @throws
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function empiricalVariance(array $values) : \float
|
||||
{
|
||||
$count = count($values);
|
||||
|
||||
|
|
@ -29,7 +83,21 @@ class MeasureOfDispersion
|
|||
return $sum / $count;
|
||||
}
|
||||
|
||||
public static function sampleVariance($values)
|
||||
/**
|
||||
* Calculage sample variance.
|
||||
*
|
||||
* Example: ([4, 5, 9, 1, 3])
|
||||
*
|
||||
* @param array $values Values
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @throws
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function sampleVariance(array $values) : \float
|
||||
{
|
||||
$count = count($values);
|
||||
|
||||
|
|
@ -40,12 +108,38 @@ class MeasureOfDispersion
|
|||
return $count * self::empiricalVariance($values) / ($count - 1);
|
||||
}
|
||||
|
||||
public static function standardDeviation($values)
|
||||
/**
|
||||
* Calculage standard deviation.
|
||||
*
|
||||
* Example: ([4, 5, 9, 1, 3])
|
||||
*
|
||||
* @param array $values Values
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function standardDeviation(array $values) : \float
|
||||
{
|
||||
return sqrt(self::sampleVariance($values));
|
||||
}
|
||||
|
||||
public static function empiricalVariationcofficient($values)
|
||||
/**
|
||||
* Calculage empirical variation coefficient.
|
||||
*
|
||||
* Example: ([4, 5, 9, 1, 3])
|
||||
*
|
||||
* @param array $values Values
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @throws
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function empiricalVariationcoefficient(array $values) : \float
|
||||
{
|
||||
$mean = Average::arithmeticMean($values);
|
||||
|
||||
|
|
@ -56,7 +150,22 @@ class MeasureOfDispersion
|
|||
return self::standardDeviation($values) / $mean;
|
||||
}
|
||||
|
||||
public static function empiricalCovariance($x, $y)
|
||||
/**
|
||||
* Calculage empirical covariance.
|
||||
*
|
||||
* Example: ([4, 5, 9, 1, 3], [4, 5, 9, 1, 3])
|
||||
*
|
||||
* @param array $x Values
|
||||
* @param array $y Values
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @throws
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function empiricalCovariance(array $x, array $y) : \float
|
||||
{
|
||||
$count = count($x);
|
||||
|
||||
|
|
@ -80,7 +189,20 @@ class MeasureOfDispersion
|
|||
return $sum / ($count - 1);
|
||||
}
|
||||
|
||||
public static function bravaisPersonCorrelationcoefficient($x, $y)
|
||||
/**
|
||||
* Calculage bravais person correlation coefficient.
|
||||
*
|
||||
* Example: ([4, 5, 9, 1, 3], [4, 5, 9, 1, 3])
|
||||
*
|
||||
* @param array $x Values
|
||||
* @param array $y Values
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function bravaisPersonCorrelationcoefficient(array $x, array $y) : \float
|
||||
{
|
||||
return self::empiricalCovariance($x, $y) / sqrt(self::empiricalCovariance($x, $x) * self::empiricalCovariance($y, $y));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,193 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.0
|
||||
*
|
||||
* @category TBD
|
||||
* @package TBD
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @copyright 2013 Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link http://orange-management.com
|
||||
*/
|
||||
|
||||
namespace phpOMS\Math\Stochastic\Distribution;
|
||||
|
||||
/**
|
||||
* Bernulli distribution.
|
||||
*
|
||||
* @category Framework
|
||||
* @package phpOMS\DataStorage\Database
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @license OMS License 1.0
|
||||
* @link http://orange-management.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class BernulliDistribution
|
||||
{
|
||||
/**
|
||||
* Get probability mass function.
|
||||
*
|
||||
* @param float $p
|
||||
* @param int $k
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @throws
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getPmf(\float $p, \int $k) : \float
|
||||
{
|
||||
if ($k === 0) {
|
||||
return 1 - $p;
|
||||
} elseif ($k === 1) {
|
||||
return $p;
|
||||
} else {
|
||||
throw new \Exception('wrong parameter');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get mode.
|
||||
*
|
||||
* @param \float $p
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getMode(\float $p) : \int
|
||||
{
|
||||
if ($p === 0.5) {
|
||||
return 0;
|
||||
} elseif ($p > 0.5) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get expected value.
|
||||
*
|
||||
* @param \float $p
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getMean(\float $p) : \float
|
||||
{
|
||||
return $p;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get expected value.
|
||||
*
|
||||
* @param \float $p
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getMedian(\float $p) : \float
|
||||
{
|
||||
if ($p === 0.5) {
|
||||
return 0.5;
|
||||
} elseif ($p > 0.5) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get variance.
|
||||
*
|
||||
* @param \float $p
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getVariance(\float $p) : \float
|
||||
{
|
||||
return $p * (1 - $p);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get moment generating function.
|
||||
*
|
||||
* @param float $p
|
||||
* @param float $t
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getMgf(\float $p, \float $t) : \float
|
||||
{
|
||||
return (1 - $p) + $p * exp($t);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get skewness.
|
||||
*
|
||||
* @param float $p
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getSkewness(\float $p) : \float
|
||||
{
|
||||
return (1 - 2 * $p) / sqrt($p * (1 - $p));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Fisher information.
|
||||
*
|
||||
* @param float $p
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getFisherInformation(\float $p) : \float
|
||||
{
|
||||
return 1 / ($p * (1 - $p));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Ex. kurtosis.
|
||||
*
|
||||
* @param float $p
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getExKurtosis(\float $p) : \float
|
||||
{
|
||||
return (1 - 6 * $p * (1 - $p)) / ($p * (1 - $p));
|
||||
}
|
||||
|
||||
public static function getRandom()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -1,36 +1,219 @@
|
|||
<?php
|
||||
namespace phpOMS\Math\Statistic;
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.0
|
||||
*
|
||||
* @category TBD
|
||||
* @package TBD
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @copyright 2013 Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link http://orange-management.com
|
||||
*/
|
||||
|
||||
namespace phpOMS\Math\Stochastic\Distribution;
|
||||
use phpOMS\Math\Functions;
|
||||
|
||||
/**
|
||||
* Binomial distribution.
|
||||
*
|
||||
* @category Framework
|
||||
* @package phpOMS\DataStorage\Database
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @license OMS License 1.0
|
||||
* @link http://orange-management.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class BinomialDistribution
|
||||
{
|
||||
public static function getDensity(\int $n, \int $k, \float $p)
|
||||
{
|
||||
$max = max([$k, $n - $k]);
|
||||
$min = min([$k, $n - $k]);
|
||||
|
||||
return Functions::fact($n, $max + 1) / Functions::fact($min) * pow($p, $k) * pow(1 - $p, $n - $k);
|
||||
/**
|
||||
* Get mode.
|
||||
*
|
||||
* @param int $n
|
||||
* @param float $p
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @throws
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getMode(\int $n, \float $p) : \float
|
||||
{
|
||||
if (($temp = ($n + 1) * $p) === 0 || !is_int($temp)) {
|
||||
return floor($temp);
|
||||
} elseif ($temp >= 1 && $temp <= $n) {
|
||||
return $temp;
|
||||
} elseif ($temp === $n + 1) {
|
||||
return $n;
|
||||
} else {
|
||||
throw new \Exception('Unexpected Values');
|
||||
}
|
||||
}
|
||||
|
||||
public function getDistribution(\int $n, \int $x, \float $p)
|
||||
/**
|
||||
* Get probability mass function.
|
||||
*
|
||||
* Formula: C(n, k) * p^k * (1-p)^(n-k)
|
||||
*
|
||||
* @param int $n
|
||||
* @param int $k
|
||||
* @param float $p
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getPmf(\int $n, \int $k, \float $p) : \float
|
||||
{
|
||||
return Functions::binomialCoefficient($n, $k) * pow($p, $k) * pow(1 - $p, $n - $k);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get moment generating function.
|
||||
*
|
||||
* @param int $n
|
||||
* @param float $t
|
||||
* @param float $p
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getMgf(\int $n, \float $t, \float $p) : \float
|
||||
{
|
||||
return pow(1 - $p + $p * exp($t), $n);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get skewness.
|
||||
*
|
||||
* @param int $n
|
||||
* @param float $p
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getSkewness(\int $n, \float $p) : \float
|
||||
{
|
||||
return (1 - 2 * $p) / sqrt($n * $p * (1 - $p));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Fisher information.
|
||||
*
|
||||
* @param int $n
|
||||
* @param float $p
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getFisherInformation(\int $n, \float $p) : \float
|
||||
{
|
||||
return $n / ($p * (1 - $p));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Ex. kurtosis.
|
||||
*
|
||||
* @param int $n
|
||||
* @param float $p
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getExKurtosis(\int $n, \float $p) : \float
|
||||
{
|
||||
return (1 - 6 * $p * (1 - $p)) / ($n * $p * (1 - $p));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cumulative distribution function.
|
||||
*
|
||||
* @param int $n
|
||||
* @param int $x
|
||||
* @param float $p
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getCdf(\int $n, \int $x, \float $p) : \float
|
||||
{
|
||||
$sum = 0.0;
|
||||
|
||||
for($i = 0; $i < $x; $i++) {
|
||||
$sum += self::getDensity($n, $i, $p);
|
||||
for ($i = 0; $i < $x; $i++) {
|
||||
$sum += self::getPmf($n, $i, $p);
|
||||
}
|
||||
|
||||
return $sum;
|
||||
}
|
||||
|
||||
public function getExpectedValue(\int $n, \float $p)
|
||||
/**
|
||||
* Get expected value.
|
||||
*
|
||||
* @param int $n
|
||||
* @param float $p
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getMedian(\int $n, \float $p) : \float
|
||||
{
|
||||
return floor($n * $p);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get expected value.
|
||||
*
|
||||
* @param int $n
|
||||
* @param float $p
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getMean(\int $n, \float $p) : \float
|
||||
{
|
||||
return $n * $p;
|
||||
}
|
||||
|
||||
public function getVariance(\int $n, \float $p)
|
||||
/**
|
||||
* Get variance.
|
||||
*
|
||||
* @param int $n
|
||||
* @param float $p
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getVariance(\int $n, \float $p) : \float
|
||||
{
|
||||
return $n * $p * (1 - $p);
|
||||
}
|
||||
|
||||
public static function getRandom()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,100 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.0
|
||||
*
|
||||
* @category TBD
|
||||
* @package TBD
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @copyright 2013 Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link http://orange-management.com
|
||||
*/
|
||||
|
||||
namespace phpOMS\Math\Stochastic\Distribution;
|
||||
|
||||
/**
|
||||
* Cauchy distribution.
|
||||
*
|
||||
* @category Framework
|
||||
* @package phpOMS\DataStorage\Database
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @license OMS License 1.0
|
||||
* @link http://orange-management.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class CauchyDistribution
|
||||
{
|
||||
/**
|
||||
* Get probability density function.
|
||||
*
|
||||
* @param float $x
|
||||
* @param float $x0
|
||||
* @param float $gamma
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getPdf(\float $x, \float $x0, \float $gamma) : \float
|
||||
{
|
||||
return 1 / (pi() * $gamma * (1 + (($x - $x0) / $gamma) ** 2));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cumulative distribution function.
|
||||
*
|
||||
* @param float $x
|
||||
* @param float $x0
|
||||
* @param float $gamma
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getCdf(\float $x, \float $x0, \float $gamma) : \float
|
||||
{
|
||||
return 1 / pi() * atan(($x - $x0) / $gamma) + 0.5;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get mode.
|
||||
*
|
||||
* @param float $x0
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getMode($x0) : \float
|
||||
{
|
||||
return $x0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get expected value.
|
||||
*
|
||||
* @param \float $x0
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getMedian(\float $x0) : \float
|
||||
{
|
||||
return $x0;
|
||||
}
|
||||
|
||||
public static function getRandom()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,42 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.0
|
||||
*
|
||||
* @category TBD
|
||||
* @package TBD
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @copyright 2013 Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link http://orange-management.com
|
||||
*/
|
||||
|
||||
class ChiSquareDistribution
|
||||
namespace phpOMS\Math\Stochastic\Distribution;
|
||||
use phpOMS\Math\Functions;
|
||||
|
||||
/**
|
||||
* Chi squared distribution.
|
||||
*
|
||||
* @category Framework
|
||||
* @package phpOMS\DataStorage\Database
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @license OMS License 1.0
|
||||
* @link http://orange-management.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class ChiSquaredDistribution
|
||||
{
|
||||
|
||||
/**
|
||||
* Chi square table.
|
||||
*
|
||||
* @var array<int, array>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
const TABLE = [
|
||||
1 => ['0.995' => 0.000, '0.99' => 0.000, '0.975' => 0.001, '0.95' => 0.004, '0.90' => 0.016, '0.10' => 2.706, '0.05' => 3.841, '0.025' => 5.024, '0.01' => 6.635, '0.005' => 7.879],
|
||||
2 => ['0.995' => 0.010, '0.99' => 0.020, '0.975' => 0.051, '0.95' => 0.103, '0.90' => 0.211, '0.10' => 4.605, '0.05' => 5.991, '0.025' => 7.378, '0.01' => 9.210, '0.005' => 10.597],
|
||||
|
|
@ -42,6 +77,16 @@ class ChiSquareDistribution
|
|||
100 => ['0.995' => 67.328, '0.99' => 70.065, '0.975' => 74.222, '0.95' => 77.929, '0.90' => 82.358, '0.10' => 118.498, '0.05' => 124.342, '0.025' => 129.561, '0.01' => 135.807, '0.005' => 140.169],
|
||||
];
|
||||
|
||||
/**
|
||||
* Get degrees of freedom of array.
|
||||
*
|
||||
* @param array $values Value matrix or vector (N or NxM)
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getDegreesOfFreedom(array $values) : \int
|
||||
{
|
||||
if (is_array($first = reset($values))) {
|
||||
|
|
@ -51,7 +96,22 @@ class ChiSquareDistribution
|
|||
}
|
||||
}
|
||||
|
||||
public static function hypothesis(array $dataset, array $expected, \float $significance = 0.05, \int $df = 0) : array
|
||||
/**
|
||||
* Test hypthesis.
|
||||
*
|
||||
* @param array $dataset Values
|
||||
* @param array $expected Expected values based on probability
|
||||
* @param float $significance Significance
|
||||
* @param int $df Degrees of freedom (optional)
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function testHypothesis(array $dataset, array $expected, \float $significance = 0.05, \int $df = 0) : array
|
||||
{
|
||||
if (($count = count($dataset)) !== count($expected)) {
|
||||
throw new \Exception('Dimension');
|
||||
|
|
@ -84,4 +144,143 @@ class ChiSquareDistribution
|
|||
|
||||
return ['P' => $P, 'H0' => ($P > $significance), 'df' => $df];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get probability density function.
|
||||
*
|
||||
* @param float $x
|
||||
* @param int $df Degreegs of freedom
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @throws
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getPdf(\float $x, \int $df) : \float
|
||||
{
|
||||
if ($x < 0) {
|
||||
throw new \Exception('Out of bounds');
|
||||
}
|
||||
|
||||
return 1 / (pow(2, $df / 2) * (Functions::getGammaInteger((int) $df / 2))) * pow($x, $df / 2 - 1) * exp(-$x / 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get mode.
|
||||
*
|
||||
* @param \int $df Degrees of freedom
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getMode(\int $df) : \int
|
||||
{
|
||||
return max([$df - 2, 0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get expected value.
|
||||
*
|
||||
* @param \int $df Degrees of freedom
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getMean(\int $df) : \float
|
||||
{
|
||||
return $df;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get expected value.
|
||||
*
|
||||
* @param \int $df Degrees of freedom
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getMedian(\int $df) : \float
|
||||
{
|
||||
return $df * (1 - 2 / (9 * $df)) ** 3;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get variance.
|
||||
*
|
||||
* @param \int $df Degrees of freedom
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getVariance(\int $df) : \float
|
||||
{
|
||||
return 2 * $df;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get moment generating function.
|
||||
*
|
||||
* @param int $df Degrees of freedom
|
||||
* @param float $t
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @throws
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getMgf(\int $df, \float $t) : \float
|
||||
{
|
||||
if ($t > 0.5) {
|
||||
throw new \Exception('Out of bounds');
|
||||
}
|
||||
|
||||
return pow(1 - 2 * $t, -$df / 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get skewness.
|
||||
*
|
||||
* @param int $df
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getSkewness(\int $df) : \float
|
||||
{
|
||||
return sqrt(8 / $df);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Ex. kurtosis.
|
||||
*
|
||||
* @param int $df
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getExKurtosis(\int $df) : \float
|
||||
{
|
||||
return 12 / $df;
|
||||
}
|
||||
|
||||
public static function getRandom()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,174 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.0
|
||||
*
|
||||
* @category TBD
|
||||
* @package TBD
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @copyright 2013 Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link http://orange-management.com
|
||||
*/
|
||||
|
||||
namespace phpOMS\Math\Stochastic\Distribution;
|
||||
|
||||
/**
|
||||
* Exponential distribution.
|
||||
*
|
||||
* @category Framework
|
||||
* @package phpOMS\DataStorage\Database
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @license OMS License 1.0
|
||||
* @link http://orange-management.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class ExponentialDistribution
|
||||
{
|
||||
/**
|
||||
* Get probability density function.
|
||||
*
|
||||
* @param float $x
|
||||
* @param float $lambda
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getPdf(\float $x, \float $lambda) : \float
|
||||
{
|
||||
return $x >= 0 ? $lambda * exp(-$lambda * $x) : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cumulative distribution function.
|
||||
*
|
||||
* @param float $x
|
||||
* @param float $lambda
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getCdf(\float $x, \float $lambda) : \float
|
||||
{
|
||||
return $x >= 0 ? 1 - exp($lambda * $x) : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get mode.
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getMode() : \float
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get expected value.
|
||||
*
|
||||
* @param \float $lambda
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getMean(\float $lambda) : \float
|
||||
{
|
||||
return 1 / $lambda;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get expected value.
|
||||
*
|
||||
* @param \float $lambda
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getMedian(\float $lambda) : \float
|
||||
{
|
||||
return 1 / $lambda;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get variance.
|
||||
*
|
||||
* @param \float $lambda
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getVariance(\float $lambda) : \float
|
||||
{
|
||||
return pow($lambda, -2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get moment generating function.
|
||||
*
|
||||
* @param float $t
|
||||
* @param float $lambda
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @throws
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getMgf(\float $t, \float $lambda) : \float
|
||||
{
|
||||
if ($t >= $lambda) {
|
||||
throw new \Exception('Out of bounds');
|
||||
}
|
||||
|
||||
return $lambda / ($lambda - $t);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get skewness.
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getSkewness() : \float
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Ex. kurtosis.
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getExKurtosis() : \float
|
||||
{
|
||||
return 6;
|
||||
}
|
||||
|
||||
public static function getRandom()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,176 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.0
|
||||
*
|
||||
* @category TBD
|
||||
* @package TBD
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @copyright 2013 Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link http://orange-management.com
|
||||
*/
|
||||
|
||||
namespace phpOMS\Math\Stochastic\Distribution;
|
||||
|
||||
/**
|
||||
* Geometric distribution.
|
||||
*
|
||||
* @category Framework
|
||||
* @package phpOMS\DataStorage\Database
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @license OMS License 1.0
|
||||
* @link http://orange-management.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class GeometricDistribution
|
||||
{
|
||||
/**
|
||||
* Get probability mass function.
|
||||
*
|
||||
* @param float $p
|
||||
* @param int $k
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @throws
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getPmf(\float $p, \int $k) : \float
|
||||
{
|
||||
return pow(1 - $p, $k - 1) * $p;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cumulative distribution function.
|
||||
*
|
||||
* @param float $p
|
||||
* @param int $k
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @throws
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getCdf(\float $p, \int $k) : \float
|
||||
{
|
||||
return 1 - pow(1 - $p, $k);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get mode.
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getMode() : \int
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get expected value.
|
||||
*
|
||||
* @param \float $p
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getMean(\float $p) : \float
|
||||
{
|
||||
return 1 / $p;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get expected value.
|
||||
*
|
||||
* @param \float $p
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getMedian(\float $p) : \float
|
||||
{
|
||||
return ceil(-1 / (log(1 - $p, 2)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get variance.
|
||||
*
|
||||
* @param \float $p
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getVariance(\float $p) : \float
|
||||
{
|
||||
return (1 - $p) / $p ** 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get moment generating function.
|
||||
*
|
||||
* @param float $p
|
||||
* @param float $t
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getMgf(\float $p, \float $t) : \float
|
||||
{
|
||||
return $p * exp($t) / (1 - (1 - $p) * exp($t));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get skewness.
|
||||
*
|
||||
* @param float $lambda
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getSkewness(\float $lambda) : \float
|
||||
{
|
||||
return (2 - $p) / sqrt(1 - $p);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Ex. kurtosis.
|
||||
*
|
||||
* @param float $lambda
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getExKurtosis(\float $lambda) : \float
|
||||
{
|
||||
return 6 + $p ** 2 / (1 - $p);
|
||||
}
|
||||
|
||||
public static function getRandom()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
179
Math/Stochastic/Distribution/LaplaceDistribution.php
Normal file
179
Math/Stochastic/Distribution/LaplaceDistribution.php
Normal file
|
|
@ -0,0 +1,179 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.0
|
||||
*
|
||||
* @category TBD
|
||||
* @package TBD
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @copyright 2013 Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link http://orange-management.com
|
||||
*/
|
||||
|
||||
namespace phpOMS\Math\Stochastic\Distribution;
|
||||
|
||||
/**
|
||||
* Laplace distribution.
|
||||
*
|
||||
* @category Framework
|
||||
* @package phpOMS\DataStorage\Database
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @license OMS License 1.0
|
||||
* @link http://orange-management.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class LaplaceDistribution
|
||||
{
|
||||
/**
|
||||
* Get probability density function.
|
||||
*
|
||||
* @param float $x
|
||||
* @param float $mu
|
||||
* @param float $b
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getPdf(\float $x, \float $mu, \float $b) : \float
|
||||
{
|
||||
return 1 / (2 * $b) * exp(-abs($x - $mu) / $b);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cumulative distribution function.
|
||||
*
|
||||
* @param float $x
|
||||
* @param float $mu
|
||||
* @param float $b
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getCdf(\float $x, \float $mu, \float $b) : \float
|
||||
{
|
||||
return $x < $mu ? exp(($x - $mu) / $b) / 2 : 1 - exp(-($x - $mu) / $b) / 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get mode.
|
||||
*
|
||||
* @param \float $mu
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getMode(\float $mu) : \float
|
||||
{
|
||||
return $mu;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get expected value.
|
||||
*
|
||||
* @param \float $mu
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getMean(\float $mu) : \float
|
||||
{
|
||||
return $mu;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get expected value.
|
||||
*
|
||||
* @param \float $mu
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getMedian(\float $mu) : \float
|
||||
{
|
||||
return $mu;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get variance.
|
||||
*
|
||||
* @param \float $b
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getVariance(\float $b) : \float
|
||||
{
|
||||
return 2 * $b ** 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get moment generating function.
|
||||
*
|
||||
* @param float $t
|
||||
* @param float $mu
|
||||
* @param float $b
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @throws
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getMgf(\float $t, \float $mu, \float $b) : \float
|
||||
{
|
||||
if ($t >= 1 / $b) {
|
||||
throw new \Exception('Out of bounds');
|
||||
}
|
||||
|
||||
return exp($mu * $t) / (1 - $b ** 2 * $t ** 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get skewness.
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getSkewness() : \float
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Ex. kurtosis.
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getExKurtosis() : \float
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
|
||||
public static function getRandom()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
172
Math/Stochastic/Distribution/NormalDistribution.php
Normal file
172
Math/Stochastic/Distribution/NormalDistribution.php
Normal file
|
|
@ -0,0 +1,172 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.0
|
||||
*
|
||||
* @category TBD
|
||||
* @package TBD
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @copyright 2013 Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link http://orange-management.com
|
||||
*/
|
||||
|
||||
namespace phpOMS\Math\Stochastic\Distribution;
|
||||
|
||||
/**
|
||||
* Normal distribution.
|
||||
*
|
||||
* @category Framework
|
||||
* @package phpOMS\DataStorage\Database
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @license OMS License 1.0
|
||||
* @link http://orange-management.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class NormalDistribution
|
||||
{
|
||||
|
||||
/**
|
||||
* Get probability density function.
|
||||
*
|
||||
* @param float $x
|
||||
* @param float $mu
|
||||
* @param float $sig
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getPdf(\float $x, \float $mu, \float $sig) : \float
|
||||
{
|
||||
return 1 / ($sig * sqrt(2 * pi())) * exp(-($x - $mu) ** 2 / (2 * $sig ** 2));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get mode.
|
||||
*
|
||||
* @param \float $mu
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getMode(\float $mu) : \float
|
||||
{
|
||||
return $mu;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get expected value.
|
||||
*
|
||||
* @param \float $mu
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getMean(\float $mu) : \float
|
||||
{
|
||||
return $mu;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get expected value.
|
||||
*
|
||||
* @param \float $mu
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getMedian(\float $mu) : \float
|
||||
{
|
||||
return $mu;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get variance.
|
||||
*
|
||||
* @param \float $sig
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getVariance(\float $sig) : \float
|
||||
{
|
||||
return $sig ** 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get moment generating function.
|
||||
*
|
||||
* @param float $t
|
||||
* @param float $mu
|
||||
* @param float $sig
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getMgf(\float $t, \float $mu, \float $sig) : \float
|
||||
{
|
||||
return exp($mu * $t + ($sig ** 2 * $t ** 2) / 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get skewness.
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getSkewness() : \float
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Fisher information.
|
||||
*
|
||||
* @param float $sig
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getFisherInformation(\float $sig) : \float
|
||||
{
|
||||
return [[1 / $sig ** 2, 0], [0, 1 / (2 * $sig ** 4)]];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Ex. kurtosis.
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getExKurtosis() : \float
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static function getRandom()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -1,12 +1,198 @@
|
|||
<?php
|
||||
namespace phpOMS\Math\Statistic;
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.0
|
||||
*
|
||||
* @category TBD
|
||||
* @package TBD
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @copyright 2013 Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link http://orange-management.com
|
||||
*/
|
||||
|
||||
namespace phpOMS\Math\Stochastic\Distribution;
|
||||
use phpOMS\Math\Functions;
|
||||
|
||||
/**
|
||||
* Well known functions class.
|
||||
*
|
||||
* @category Framework
|
||||
* @package phpOMS\DataStorage\Database
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @license OMS License 1.0
|
||||
* @link http://orange-management.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class PoissonDistribution
|
||||
{
|
||||
public static function getPoisson(\int $k, \float $lambda)
|
||||
/**
|
||||
* Get density.
|
||||
*
|
||||
* Formula: e^(k * ln(lambda) - lambda - log(gamma(k+1))
|
||||
*
|
||||
* @param int $k
|
||||
* @param float $lambda
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getPmf(\int $k, \float $lambda) : \float
|
||||
{
|
||||
return exp($k * log($lambda) - $lambda - log(Functions::getGammaInteger($k + 1)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cumulative distribution function.
|
||||
*
|
||||
* @param int $k
|
||||
* @param float $lambda
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getCdf(\int $k, \float $lambda) : \float
|
||||
{
|
||||
$sum = 0.0;
|
||||
|
||||
for ($i = 0; $i < $k + 1; $i++) {
|
||||
$sum += pow($lambda, $i) / Functions::fact($i);
|
||||
}
|
||||
|
||||
return exp(-$lambda) * $sum;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get mode.
|
||||
*
|
||||
* @param \float $lambda Lambda
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getMode(\float $lambda) : \float
|
||||
{
|
||||
return floor($lambda);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get expected value.
|
||||
*
|
||||
* @param \float $lambda Lambda
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getMean(\float $lambda) : \float
|
||||
{
|
||||
return $lambda;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get expected value.
|
||||
*
|
||||
* @param \float $lambda Lambda
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getMedian(\float $lambda) : \float
|
||||
{
|
||||
return floor($lambda + 1 / 3 - 0.02 / $lambda);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get variance.
|
||||
*
|
||||
* @param \float $lambda Lambda
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getVariance(\float $lambda) : \float
|
||||
{
|
||||
return $lambda;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get moment generating function.
|
||||
*
|
||||
* @param float $lambda
|
||||
* @param float $t
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getMgf(\float $lambda, \float $t) : \float
|
||||
{
|
||||
return exp($lambda * (exp($t) - 1));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get skewness.
|
||||
*
|
||||
* @param float $lambda
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getSkewness(\float $lambda) : \float
|
||||
{
|
||||
return pow($lambda, -1 / 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Fisher information.
|
||||
*
|
||||
* @param float $lambda
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getFisherInformation(\float $lambda) : \float
|
||||
{
|
||||
return pow($lambda, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Ex. kurtosis.
|
||||
*
|
||||
* @param float $lambda
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getExKurtosis(\float $lambda) : \float
|
||||
{
|
||||
return pow($lambda, -1);
|
||||
}
|
||||
|
||||
public static function getRandom()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,190 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.0
|
||||
*
|
||||
* @category TBD
|
||||
* @package TBD
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @copyright 2013 Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link http://orange-management.com
|
||||
*/
|
||||
|
||||
namespace phpOMS\Math\Stochastic\Distribution;
|
||||
|
||||
/**
|
||||
* Uniform (continuous) distribution.
|
||||
*
|
||||
* @category Framework
|
||||
* @package phpOMS\DataStorage\Database
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @license OMS License 1.0
|
||||
* @link http://orange-management.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class UniformDistributionContinuous
|
||||
{
|
||||
|
||||
/**
|
||||
* Get mode.
|
||||
*
|
||||
* @param float $a
|
||||
* @param float $b
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @throws
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getMode(\float $a, \float $b) : \float
|
||||
{
|
||||
return ($a + $b) / 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get probability density function.
|
||||
*
|
||||
* @param float $x
|
||||
* @param float $a
|
||||
* @param float $b
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @throws
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getPdf(\float $x, \float $a, \float $b) : \float
|
||||
{
|
||||
return $x > $a && $x < $b ? 1 / ($b - $a) : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cumulative distribution function.
|
||||
*
|
||||
* @param float $x
|
||||
* @param float $a
|
||||
* @param float $b
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @throws
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getCdf(\float $x, \float $a, \float $b) : \float
|
||||
{
|
||||
if ($x < $a) {
|
||||
return 0;
|
||||
} elseif ($x >= $a && $x < $b) {
|
||||
return ($x - $a) / ($b - $a);
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get moment generating function.
|
||||
*
|
||||
* @param int $t
|
||||
* @param float $a
|
||||
* @param float $b
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getMgf(\int $t, \float $a, \float $b) : \float
|
||||
{
|
||||
return $t === 0 ? 1 : (exp($t * $b) - exp($t * $a)) / ($t * ($b - $a));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get skewness.
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getSkewness() : \float
|
||||
{
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Ex. kurtosis.
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getExKurtosis() : \float
|
||||
{
|
||||
return -6 / 5;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get expected value.
|
||||
*
|
||||
* @param float $a
|
||||
* @param float $b
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getMedian(\float $a, \float $b) : \float
|
||||
{
|
||||
return ($a + $b) / 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get expected value.
|
||||
*
|
||||
* @param float $a
|
||||
* @param float $b
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getMean(\float $a, \float $b) : \float
|
||||
{
|
||||
return ($a + $b) / 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get variance.
|
||||
*
|
||||
* @param float $a
|
||||
* @param float $b
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getVariance(\float $a, \float $b) : \float
|
||||
{
|
||||
return 1 / 12 * ($b - $a) ** 2;
|
||||
}
|
||||
|
||||
public static function getRandom()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user