@@ -126,7 +126,7 @@ |
||
126 | 126 | public function transpose(): self |
127 | 127 | { |
128 | 128 | if ($this->rows === 1) { |
129 | - $matrix = array_map(static function ($el): array { |
|
129 | + $matrix = array_map(static function($el): array { |
|
130 | 130 | return [$el]; |
131 | 131 | }, $this->matrix[0]); |
132 | 132 | } else { |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | throw new InvalidArgumentException('The array must have at least 2 elements'); |
29 | 29 | } |
30 | 30 | |
31 | - $samplesPerClass = array_map(static function (array $class): int { |
|
31 | + $samplesPerClass = array_map(static function(array $class): int { |
|
32 | 32 | return count($class); |
33 | 33 | }, $samples); |
34 | 34 | $allSamples = (int) array_sum($samplesPerClass); |
@@ -41,10 +41,10 @@ discard block |
||
41 | 41 | $dfbn = $classes - 1; |
42 | 42 | $dfwn = $allSamples - $classes; |
43 | 43 | |
44 | - $msb = array_map(static function ($s) use ($dfbn) { |
|
44 | + $msb = array_map(static function($s) use ($dfbn) { |
|
45 | 45 | return $s / $dfbn; |
46 | 46 | }, $ssbn); |
47 | - $msw = array_map(static function ($s) use ($dfwn) { |
|
47 | + $msw = array_map(static function($s) use ($dfwn) { |
|
48 | 48 | if ($dfwn === 0) { |
49 | 49 | return 1; |
50 | 50 | } |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | |
77 | 77 | private static function sumOfFeaturesPerClass(array $samples): array |
78 | 78 | { |
79 | - return array_map(static function (array $class): array { |
|
79 | + return array_map(static function(array $class): array { |
|
80 | 80 | $sum = array_fill(0, count($class[0]), 0); |
81 | 81 | foreach ($class as $sample) { |
82 | 82 | foreach ($sample as $index => $feature) { |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | } |
98 | 98 | } |
99 | 99 | |
100 | - return array_map(static function ($sum) { |
|
100 | + return array_map(static function($sum) { |
|
101 | 101 | return $sum ** 2; |
102 | 102 | }, $squares); |
103 | 103 | } |
@@ -50,7 +50,7 @@ |
||
50 | 50 | $mean = Mean::arithmetic($numbers); |
51 | 51 | |
52 | 52 | return array_sum(array_map( |
53 | - static function ($val) use ($mean): float { |
|
53 | + static function($val) use ($mean): float { |
|
54 | 54 | return ($val - $mean) ** 2; |
55 | 55 | }, |
56 | 56 | $numbers |
@@ -37,7 +37,7 @@ |
||
37 | 37 | |
38 | 38 | public function fit(array $samples, ?array $targets = null): void |
39 | 39 | { |
40 | - $this->variances = array_map(static function (array $column): float { |
|
40 | + $this->variances = array_map(static function(array $column): float { |
|
41 | 41 | return Variance::population($column); |
42 | 42 | }, Matrix::transposeArray($samples)); |
43 | 43 |
@@ -50,7 +50,7 @@ |
||
50 | 50 | $this->value = $value; |
51 | 51 | $this->groups = $groups; |
52 | 52 | $this->impurity = $impurity; |
53 | - $this->samplesCount = (int) array_sum(array_map(static function (array $group): int { |
|
53 | + $this->samplesCount = (int) array_sum(array_map(static function(array $group): int { |
|
54 | 54 | return count($group[0]); |
55 | 55 | }, $groups)); |
56 | 56 | } |
@@ -139,7 +139,7 @@ |
||
139 | 139 | $total += $val; |
140 | 140 | } |
141 | 141 | |
142 | - $this->membership[] = array_map(static function ($val) use ($total): float { |
|
142 | + $this->membership[] = array_map(static function($val) use ($total): float { |
|
143 | 143 | return $val / $total; |
144 | 144 | }, $row); |
145 | 145 | } |
@@ -172,20 +172,20 @@ discard block |
||
172 | 172 | switch ($this->kernel) { |
173 | 173 | case self::KERNEL_LINEAR: |
174 | 174 | // k(x,y) = xT.y |
175 | - return function ($x, $y) { |
|
175 | + return function($x, $y) { |
|
176 | 176 | return Matrix::dot($x, $y)[0]; |
177 | 177 | }; |
178 | 178 | case self::KERNEL_RBF: |
179 | 179 | // k(x,y)=exp(-γ.|x-y|) where |..| is Euclidean distance |
180 | 180 | $dist = new Euclidean(); |
181 | 181 | |
182 | - return function ($x, $y) use ($dist): float { |
|
182 | + return function($x, $y) use ($dist): float { |
|
183 | 183 | return exp(-$this->gamma * $dist->sqDistance($x, $y)); |
184 | 184 | }; |
185 | 185 | |
186 | 186 | case self::KERNEL_SIGMOID: |
187 | 187 | // k(x,y)=tanh(γ.xT.y+c0) where c0=1 |
188 | - return function ($x, $y): float { |
|
188 | + return function($x, $y): float { |
|
189 | 189 | $res = Matrix::dot($x, $y)[0] + 1.0; |
190 | 190 | |
191 | 191 | return tanh((float) $this->gamma * $res); |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | // k(x,y)=exp(-γ.|x-y|) where |..| is Manhattan distance |
196 | 196 | $dist = new Manhattan(); |
197 | 197 | |
198 | - return function ($x, $y) use ($dist): float { |
|
198 | + return function($x, $y) use ($dist): float { |
|
199 | 199 | return exp(-$this->gamma * $dist->distance($x, $y)); |
200 | 200 | }; |
201 | 201 | |
@@ -220,7 +220,7 @@ discard block |
||
220 | 220 | protected function projectSample(array $pairs): array |
221 | 221 | { |
222 | 222 | // Normalize eigenvectors by eig = eigVectors / eigValues |
223 | - $func = function ($eigVal, $eigVect) { |
|
223 | + $func = function($eigVal, $eigVect) { |
|
224 | 224 | $m = new Matrix($eigVect, false); |
225 | 225 | $a = $m->divideByScalar($eigVal)->toArray(); |
226 | 226 |
@@ -104,11 +104,11 @@ discard block |
||
104 | 104 | */ |
105 | 105 | protected function predictSample(array $sample): array |
106 | 106 | { |
107 | - $predicts = array_values(array_filter($this->getRules(), function ($rule) use ($sample): bool { |
|
107 | + $predicts = array_values(array_filter($this->getRules(), function($rule) use ($sample): bool { |
|
108 | 108 | return $this->equals($rule[self::ARRAY_KEY_ANTECEDENT], $sample); |
109 | 109 | })); |
110 | 110 | |
111 | - return array_map(static function ($rule) { |
|
111 | + return array_map(static function($rule) { |
|
112 | 112 | return $rule[self::ARRAY_KEY_CONSEQUENT]; |
113 | 113 | }, $predicts); |
114 | 114 | } |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | $cardinality = count($sample); |
178 | 178 | $antecedents = $this->powerSet($sample); |
179 | 179 | |
180 | - return array_filter($antecedents, static function ($antecedent) use ($cardinality): bool { |
|
180 | + return array_filter($antecedents, static function($antecedent) use ($cardinality): bool { |
|
181 | 181 | return (count($antecedent) != $cardinality) && ($antecedent != []); |
182 | 182 | }); |
183 | 183 | } |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | } |
200 | 200 | } |
201 | 201 | |
202 | - return array_map(static function ($entry): array { |
|
202 | + return array_map(static function($entry): array { |
|
203 | 203 | return [$entry]; |
204 | 204 | }, $items); |
205 | 205 | } |
@@ -213,7 +213,7 @@ discard block |
||
213 | 213 | */ |
214 | 214 | private function frequent(array $samples): array |
215 | 215 | { |
216 | - return array_values(array_filter($samples, function ($entry): bool { |
|
216 | + return array_values(array_filter($samples, function($entry): bool { |
|
217 | 217 | return $this->support($entry) >= $this->support; |
218 | 218 | })); |
219 | 219 | } |
@@ -288,7 +288,7 @@ discard block |
||
288 | 288 | */ |
289 | 289 | private function frequency(array $sample): int |
290 | 290 | { |
291 | - return count(array_filter($this->samples, function ($entry) use ($sample): bool { |
|
291 | + return count(array_filter($this->samples, function($entry) use ($sample): bool { |
|
292 | 292 | return $this->subset($entry, $sample); |
293 | 293 | })); |
294 | 294 | } |
@@ -303,7 +303,7 @@ discard block |
||
303 | 303 | */ |
304 | 304 | private function contains(array $system, array $set): bool |
305 | 305 | { |
306 | - return (bool) array_filter($system, function ($entry) use ($set): bool { |
|
306 | + return (bool) array_filter($system, function($entry) use ($set): bool { |
|
307 | 307 | return $this->equals($entry, $set); |
308 | 308 | }); |
309 | 309 | } |
@@ -58,7 +58,7 @@ |
||
58 | 58 | protected function runTraining(array $samples, array $targets): void |
59 | 59 | { |
60 | 60 | // The cost function is the sum of squares |
61 | - $callback = function ($weights, $sample, $target): array { |
|
61 | + $callback = function($weights, $sample, $target): array { |
|
62 | 62 | $this->weights = $weights; |
63 | 63 | |
64 | 64 | $output = $this->output($sample); |