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