Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
5 / 5 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
1 / 1 |
| CauchyDistribution | |
100.00% |
5 / 5 |
|
100.00% |
5 / 5 |
5 | |
100.00% |
1 / 1 |
| getPdf | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getCdf | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getMode | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getMedian | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getEntropy | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Jingga |
| 4 | * |
| 5 | * PHP Version 8.1 |
| 6 | * |
| 7 | * @package phpOMS\Math\Stochastic\Distribution |
| 8 | * @copyright Dennis Eichhorn |
| 9 | * @license OMS License 2.0 |
| 10 | * @version 1.0.0 |
| 11 | * @link https://jingga.app |
| 12 | */ |
| 13 | declare(strict_types=1); |
| 14 | |
| 15 | namespace phpOMS\Math\Stochastic\Distribution; |
| 16 | |
| 17 | /** |
| 18 | * Cauchy distribution. |
| 19 | * |
| 20 | * @package phpOMS\Math\Stochastic\Distribution |
| 21 | * @license OMS License 2.0 |
| 22 | * @link https://jingga.app |
| 23 | * @since 1.0.0 |
| 24 | */ |
| 25 | final class CauchyDistribution |
| 26 | { |
| 27 | /** |
| 28 | * Get probability density function. |
| 29 | * |
| 30 | * @param float $x Value x |
| 31 | * @param float $x0 Value x0 |
| 32 | * @param float $gamma Gamma |
| 33 | * |
| 34 | * @return float |
| 35 | * |
| 36 | * @since 1.0.0 |
| 37 | */ |
| 38 | public static function getPdf(float $x, float $x0, float $gamma) : float |
| 39 | { |
| 40 | return 1 / (\M_PI * $gamma * (1 + (($x - $x0) / $gamma) ** 2)); |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Get cumulative distribution function. |
| 45 | * |
| 46 | * @param float $x Value x |
| 47 | * @param float $x0 Value x0 |
| 48 | * @param float $gamma Gamma |
| 49 | * |
| 50 | * @return float |
| 51 | * |
| 52 | * @since 1.0.0 |
| 53 | */ |
| 54 | public static function getCdf(float $x, float $x0, float $gamma) : float |
| 55 | { |
| 56 | return 1 / \M_PI * \atan(($x - $x0) / $gamma) + 0.5; |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Get mode. |
| 61 | * |
| 62 | * @param float $x0 Value x0 |
| 63 | * |
| 64 | * @return float |
| 65 | * |
| 66 | * @since 1.0.0 |
| 67 | */ |
| 68 | public static function getMode(float $x0) : float |
| 69 | { |
| 70 | return $x0; |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * Get median. |
| 75 | * |
| 76 | * @param float $x0 Value x0 |
| 77 | * |
| 78 | * @return float |
| 79 | * |
| 80 | * @since 1.0.0 |
| 81 | */ |
| 82 | public static function getMedian(float $x0) : float |
| 83 | { |
| 84 | return $x0; |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * Get entropy. |
| 89 | * |
| 90 | * @param float $gamma Gamma / scale parameter |
| 91 | * |
| 92 | * @return float |
| 93 | * |
| 94 | * @since 1.0.0 |
| 95 | */ |
| 96 | public static function getEntropy(float $gamma) : float |
| 97 | { |
| 98 | return \log(4 * \M_PI * $gamma); |
| 99 | } |
| 100 | } |