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