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