Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 27
0.00% covered (danger)
0.00%
0 / 9
CRAP
0.00% covered (danger)
0.00%
0 / 1
Kernels2D
0.00% covered (danger)
0.00%
0 / 27
0.00% covered (danger)
0.00%
0 / 9
306
0.00% covered (danger)
0.00%
0 / 1
 __construct
n/a
0 / 0
n/a
0 / 0
1
 uniformKernel
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
 triangularKernel
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
 epanechnikovKernel
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
6
 quarticKernel
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
6
 triweightKernel
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
6
 tricubeKernel
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
6
 gaussianKernel
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 cosineKernel
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
 logisticKernel
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2/**
3 * Jingga
4 *
5 * PHP Version 8.1
6 *
7 * @package   phpOMS\Math\Topology
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\Topology;
16
17/**
18 * Kernels.
19 *
20 * @package phpOMS\Math\Topology
21 * @license OMS License 2.0
22 * @link    https://jingga.app
23 * @since   1.0.0
24 */
25final class Kernels2D
26{
27    /**
28     * Constructor
29     *
30     * @since 1.0.0
31     * @codeCoverageIgnore
32     */
33    private function __construct()
34    {
35    }
36
37    /**
38     * Uniform kernel.
39     *
40     * @param float $distance  Distance
41     * @param float $bandwidth Bandwidth
42     *
43     * @return float
44     *
45     * @since 1.0.0
46     */
47    public static function uniformKernel(float $distance, float $bandwidth) : float
48    {
49        return \abs($distance) <= $bandwidth / 2
50            ? 1 / $bandwidth
51            : 0.0;
52    }
53
54    /**
55     * Triangular kernel.
56     *
57     * @param float $distance  Distance
58     * @param float $bandwidth Bandwidth
59     *
60     * @return float
61     *
62     * @since 1.0.0
63     */
64    public static function triangularKernel(float $distance, float $bandwidth) : float
65    {
66        return \abs($distance) <= $bandwidth / 2
67            ? 1 - \abs($distance) / ($bandwidth / 2)
68            : 0.0;
69    }
70
71    /**
72     * Epanechnikov kernel.
73     *
74     * @param float $distance  Distance
75     * @param float $bandwidth Bandwidth
76     *
77     * @return float
78     *
79     * @since 1.0.0
80     */
81    public static function epanechnikovKernel(float $distance, float $bandwidth) : float
82    {
83        if (\abs($distance) <= $bandwidth) {
84            $u = \abs($distance) / $bandwidth;
85
86            return 0.75 * (1 - $u * $u) / $bandwidth;
87        } else {
88            return 0.0;
89        }
90    }
91
92    /**
93     * Quartic kernel.
94     *
95     * @param float $distance  Distance
96     * @param float $bandwidth Bandwidth
97     *
98     * @return float
99     *
100     * @since 1.0.0
101     */
102    public static function quarticKernel(float $distance, float $bandwidth) : float
103    {
104        if (\abs($distance) <= $bandwidth) {
105            $u = \abs($distance) / $bandwidth;
106
107            return (15 / 16) * (1 - $u * $u) * (1 - $u * $u) / $bandwidth;
108        } else {
109            return 0.0;
110        }
111    }
112
113    /**
114     * Triweight kernel.
115     *
116     * @param float $distance  Distance
117     * @param float $bandwidth Bandwidth
118     *
119     * @return float
120     *
121     * @since 1.0.0
122     */
123    public static function triweightKernel(float $distance, float $bandwidth) : float
124    {
125        if (\abs($distance) <= $bandwidth) {
126            $u = \abs($distance) / $bandwidth;
127
128            return (35 / 32) * (1 - $u * $u) * (1 - $u * $u) * (1 - $u * $u) / $bandwidth;
129        } else {
130            return 0.0;
131        }
132    }
133
134    /**
135     * Tricube kernel.
136     *
137     * @param float $distance  Distance
138     * @param float $bandwidth Bandwidth
139     *
140     * @return float
141     *
142     * @since 1.0.0
143     */
144    public static function tricubeKernel(float $distance, float $bandwidth) : float
145    {
146        if (\abs($distance) <= $bandwidth) {
147            $u = \abs($distance) / $bandwidth;
148
149            return (70 / 81) * (1 - $u * $u * $u) * (1 - $u * $u * $u) * (1 - $u * $u * $u) / $bandwidth;
150        } else {
151            return 0.0;
152        }
153    }
154
155    /**
156     * Gaussian kernel.
157     *
158     * @param float $distance  Distance
159     * @param float $bandwidth Bandwidth
160     *
161     * @return float
162     *
163     * @since 1.0.0
164     */
165    public static function gaussianKernel(float $distance, float $bandwidth) : float
166    {
167        return \exp(-($distance * $distance) / (2 * $bandwidth * $bandwidth)) / ($bandwidth * \sqrt(2 * \M_PI));
168    }
169
170    /**
171     * Cosine kernel.
172     *
173     * @param float $distance  Distance
174     * @param float $bandwidth Bandwidth
175     *
176     * @return float
177     *
178     * @since 1.0.0
179     */
180    public static function cosineKernel(float $distance, float $bandwidth) : float
181    {
182        return \abs($distance) <= $bandwidth
183            ? (\M_PI / 4) * \cos(\M_PI * $distance / (2 * $bandwidth)) / $bandwidth
184            : 0.0;
185    }
186
187    /**
188     * Logistic kernel.
189     *
190     * @param float $distance  Distance
191     * @param float $bandwidth Bandwidth
192     *
193     * @return float
194     *
195     * @since 1.0.0
196     */
197    public static function logisticKernel(float $distance, float $bandwidth) : float
198    {
199        return 1 / (\exp($distance / $bandwidth) + 2 + \exp(-$distance / $bandwidth));
200    }
201}