Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
12 / 12 |
|
100.00% |
10 / 10 |
CRAP | |
100.00% |
1 / 1 |
LaplaceDistribution | |
100.00% |
12 / 12 |
|
100.00% |
10 / 10 |
12 | |
100.00% |
1 / 1 |
getPdf | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getCdf | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
getMode | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getMean | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getMedian | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getVariance | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getStandardDeviation | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getMgf | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
getSkewness | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getExKurtosis | |
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 | * Laplace 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 LaplaceDistribution |
26 | { |
27 | /** |
28 | * Get probability density function. |
29 | * |
30 | * @param float $x Value x |
31 | * @param float $mu Mean |
32 | * @param float $b Value b |
33 | * |
34 | * @return float |
35 | * |
36 | * @since 1.0.0 |
37 | */ |
38 | public static function getPdf(float $x, float $mu, float $b) : float |
39 | { |
40 | return 1 / (2 * $b) * \exp(-\abs($x - $mu) / $b); |
41 | } |
42 | |
43 | /** |
44 | * Get cumulative distribution function. |
45 | * |
46 | * @param float $x Value x |
47 | * @param float $mu Mean |
48 | * @param float $b Value b |
49 | * |
50 | * @return float |
51 | * |
52 | * @since 1.0.0 |
53 | */ |
54 | public static function getCdf(float $x, float $mu, float $b) : float |
55 | { |
56 | return $x < $mu ? \exp(($x - $mu) / $b) / 2 : 1 - \exp(-($x - $mu) / $b) / 2; |
57 | } |
58 | |
59 | /** |
60 | * Get mode. |
61 | * |
62 | * @param float $mu Mean |
63 | * |
64 | * @return float |
65 | * |
66 | * @since 1.0.0 |
67 | */ |
68 | public static function getMode(float $mu) : float |
69 | { |
70 | return $mu; |
71 | } |
72 | |
73 | /** |
74 | * Get expected value. |
75 | * |
76 | * @param float $mu Mean |
77 | * |
78 | * @return float |
79 | * |
80 | * @since 1.0.0 |
81 | */ |
82 | public static function getMean(float $mu) : float |
83 | { |
84 | return $mu; |
85 | } |
86 | |
87 | /** |
88 | * Get median. |
89 | * |
90 | * @param float $mu Mean |
91 | * |
92 | * @return float |
93 | * |
94 | * @since 1.0.0 |
95 | */ |
96 | public static function getMedian(float $mu) : float |
97 | { |
98 | return $mu; |
99 | } |
100 | |
101 | /** |
102 | * Get variance. |
103 | * |
104 | * @param float $b Value b |
105 | * |
106 | * @return float |
107 | * |
108 | * @since 1.0.0 |
109 | */ |
110 | public static function getVariance(float $b) : float |
111 | { |
112 | return 2 * $b ** 2; |
113 | } |
114 | |
115 | /** |
116 | * Get standard deviation. |
117 | * |
118 | * @param float $b Value b |
119 | * |
120 | * @return float |
121 | * |
122 | * @since 1.0.0 |
123 | */ |
124 | public static function getStandardDeviation(float $b) : float |
125 | { |
126 | return \sqrt(self::getVariance($b)); |
127 | } |
128 | |
129 | /** |
130 | * Get moment generating function. |
131 | * |
132 | * @param float $t Valute t |
133 | * @param float $mu Mean |
134 | * @param float $b Value b |
135 | * |
136 | * @return float |
137 | * |
138 | * @throws \OutOfBoundsException |
139 | * |
140 | * @since 1.0.0 |
141 | */ |
142 | public static function getMgf(float $t, float $mu, float $b) : float |
143 | { |
144 | if (\abs($t) >= 1 / $b) { |
145 | throw new \OutOfBoundsException('Out of bounds'); |
146 | } |
147 | |
148 | return \exp($mu * $t) / (1 - $b ** 2 * $t ** 2); |
149 | } |
150 | |
151 | /** |
152 | * Get skewness. |
153 | * |
154 | * @return float |
155 | * |
156 | * @since 1.0.0 |
157 | */ |
158 | public static function getSkewness() : float |
159 | { |
160 | return 0; |
161 | } |
162 | |
163 | /** |
164 | * Get Ex. kurtosis. |
165 | * |
166 | * @return float |
167 | * |
168 | * @since 1.0.0 |
169 | */ |
170 | public static function getExKurtosis() : float |
171 | { |
172 | return 3; |
173 | } |
174 | } |