Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
18 / 18
100.00% covered (success)
100.00%
18 / 18
CRAP
100.00% covered (success)
100.00%
1 / 1
GammaDistribution
100.00% covered (success)
100.00%
18 / 18
100.00% covered (success)
100.00%
18 / 18
18
100.00% covered (success)
100.00%
1 / 1
 getPdfScale
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getPdfRate
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getPdfIntegerScale
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getPdfIntegerRate
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getCdfScale
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getCdfRate
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getMeanScale
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getMeanRate
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getModeScale
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getModeRate
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getSkewness
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getExKurtosis
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getVarianceScale
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getStandardDeviationScale
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getVarianceRate
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getStandardDeviationRate
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getMgfScale
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getMgfRate
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
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 */
13declare(strict_types=1);
14
15namespace phpOMS\Math\Stochastic\Distribution;
16
17use phpOMS\Math\Functions\Gamma;
18
19/**
20 * Gamma distribution.
21 *
22 * @package phpOMS\Math\Stochastic\Distribution
23 * @license OMS License 2.0
24 * @link    https://jingga.app
25 * @since   1.0.0
26 */
27final class GammaDistribution
28{
29    /**
30     * Get probability density function for shape and scale.
31     *
32     * @param float $x     Value x
33     * @param float $k     k shape
34     * @param float $theta Theta scale
35     *
36     * @return float
37     *
38     * @since 1.0.0
39     */
40    public static function getPdfScale(float $x, float $k, float $theta) : float
41    {
42        return 1 / (Gamma::gamma($k) * $theta ** $k) * \pow($x, $k - 1) * \exp(-$x / $theta);
43    }
44
45    /**
46     * Get probability density function for shape and rate.
47     *
48     * @param float $x     Value x
49     * @param float $alpha Alpha shape
50     * @param float $beta  Beta rate
51     *
52     * @return float
53     *
54     * @since 1.0.0
55     */
56    public static function getPdfRate(float $x, float $alpha, float $beta) : float
57    {
58        return $beta ** $alpha / Gamma::gamma($alpha) * \pow($x, $alpha - 1) * \exp(-$beta * $x);
59    }
60
61    /**
62     * Get probability density function for shape and scale.
63     *
64     * @param float $x     Value x
65     * @param int   $k     k shape
66     * @param float $theta Theta scale
67     *
68     * @return float
69     *
70     * @since 1.0.0
71     */
72    public static function getPdfIntegerScale(float $x, int $k, float $theta) : float
73    {
74        return 1 / (Gamma::getGammaInteger($k) * $theta ** $k) * \pow($x, $k - 1) * \exp(-$x / $theta);
75    }
76
77    /**
78     * Get probability density function for shape and rate.
79     *
80     * @param float $x     Value x
81     * @param int   $alpha Alpha shape
82     * @param float $beta  Beta rate
83     *
84     * @return float
85     *
86     * @since 1.0.0
87     */
88    public static function getPdfIntegerRate(float $x, int $alpha, float $beta) : float
89    {
90        return $beta ** $alpha / Gamma::getGammaInteger($alpha) * \pow($x, $alpha - 1) * \exp(-$beta * $x);
91    }
92
93    /**
94     * Get cumulative density function for shape and scale.
95     *
96     * @param float $x     Value x
97     * @param float $k     k shape
98     * @param float $theta Theta scale
99     *
100     * @return float
101     *
102     * @since 1.0.0
103     */
104    public static function getCdfScale(float $x, float $k, float $theta) : float
105    {
106        return 1 / Gamma::gamma($k) * Gamma::incompleteGammaFirst($k, $x / $theta);
107    }
108
109    /**
110     * Get cumulative density function for shape and rate.
111     *
112     * @param float $x     Value x
113     * @param float $alpha Alpha shape
114     * @param float $beta  Beta rate
115     *
116     * @return float
117     *
118     * @since 1.0.0
119     */
120    public static function getCdfRate(float $x, float $alpha, float $beta) : float
121    {
122        return 1 / Gamma::gamma($alpha) * Gamma::incompleteGammaFirst($alpha, $beta * $x);
123    }
124
125    /**
126     * Get expected value.
127     *
128     * @param float $k     k shape
129     * @param float $theta Theta scale
130     *
131     * @return float
132     *
133     * @since 1.0.0
134     */
135    public static function getMeanScale(float $k, float $theta) : float
136    {
137        return $k * $theta;
138    }
139
140    /**
141     * Get expected value.
142     *
143     * @param float $alpha Alpha shape
144     * @param float $beta  Beta rate
145     *
146     * @return float
147     *
148     * @since 1.0.0
149     */
150    public static function getMeanRate(float $alpha, float $beta) : float
151    {
152        return $alpha / $beta;
153    }
154
155    /**
156     * Get mode.
157     *
158     * @param float $k     k shape
159     * @param float $theta Theta scale
160     *
161     * @return float
162     *
163     * @since 1.0.0
164     */
165    public static function getModeScale(float $k, float $theta) : float
166    {
167        return ($k - 1) * $theta;
168    }
169
170    /**
171     * Get mode.
172     *
173     * @param float $alpha Alpha shape
174     * @param float $beta  Beta scale
175     *
176     * @return float
177     *
178     * @since 1.0.0
179     */
180    public static function getModeRate(float $alpha, float $beta) : float
181    {
182        return ($alpha - 1) / $beta;
183    }
184
185    /**
186     * Get skewness.
187     *
188     * @param float $k Shape k or alpha
189     *
190     * @return float
191     *
192     * @since 1.0.0
193     */
194    public static function getSkewness(float $k) : float
195    {
196        return 2 / \sqrt($k);
197    }
198
199    /**
200     * Get Ex. kurtosis.
201     *
202     * @param float $k Shape k or alpha
203     *
204     * @return float
205     *
206     * @since 1.0.0
207     */
208    public static function getExKurtosis(float $k) : float
209    {
210        return 6 / $k;
211    }
212
213    /**
214     * Get variance.
215     *
216     * @param float $k     k shape
217     * @param float $theta Theta scale
218     *
219     * @return float
220     *
221     * @since 1.0.0
222     */
223    public static function getVarianceScale(float $k, float $theta) : float
224    {
225        return $k * $theta ** 2;
226    }
227
228    /**
229     * Get standard deviation.
230     *
231     * @param float $k     k shape
232     * @param float $theta Theta scale
233     *
234     * @return float
235     *
236     * @since 1.0.0
237     */
238    public static function getStandardDeviationScale(float $k, float $theta) : float
239    {
240        return \sqrt(self::getVarianceScale($k, $theta));
241    }
242
243    /**
244     * Get variance.
245     *
246     * @param float $alpha Alpha shape
247     * @param float $beta  Beta scale
248     *
249     * @return float
250     *
251     * @since 1.0.0
252     */
253    public static function getVarianceRate(float $alpha, float $beta) : float
254    {
255        return $alpha / ($beta ** 2);
256    }
257
258    /**
259     * Get standard deviation.
260     *
261     * @param float $alpha Alpha shape
262     * @param float $beta  Beta scale
263     *
264     * @return float
265     *
266     * @since 1.0.0
267     */
268    public static function getStandardDeviationRate(float $alpha, float $beta) : float
269    {
270        return \sqrt(self::getVarianceRate($alpha, $beta));
271    }
272
273    /**
274     * Get moment generating function.
275     *
276     * @param float $k     k shape
277     * @param float $t     Value t
278     * @param float $theta Theta scale
279     *
280     * @return float
281     *
282     * @since 1.0.0
283     */
284    public static function getMgfScale(float $k, float $t, float $theta) : float
285    {
286        return \pow(1 - $theta * $t, -$k);
287    }
288
289    /**
290     * Get moment generating function.
291     *
292     * @param float $t     Value t
293     * @param float $alpha Alpha shape
294     * @param float $beta  Beta scale
295     *
296     * @return float
297     *
298     * @since 1.0.0
299     */
300    public static function getMgfRate(float $t, float $alpha, float $beta) : float
301    {
302        return \pow(1 - $t / $beta, -$alpha);
303    }
304}