@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | $count = count($sample); |
94 | 94 | $sample = array_fill(0, $count, 1.0 / $count); |
95 | 95 | } else { |
96 | - array_walk($sample, function (&$feature) use ($norm1): void { |
|
96 | + array_walk($sample, function(&$feature) use ($norm1): void { |
|
97 | 97 | $feature /= $norm1; |
98 | 98 | }); |
99 | 99 | } |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | if ($norm2 == 0) { |
112 | 112 | $sample = array_fill(0, count($sample), 1); |
113 | 113 | } else { |
114 | - array_walk($sample, function (&$feature) use ($norm2): void { |
|
114 | + array_walk($sample, function(&$feature) use ($norm2): void { |
|
115 | 115 | $feature /= $norm2; |
116 | 116 | }); |
117 | 117 | } |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | |
53 | 53 | $degreesOfFreedom = count($targets) - ($this->center ? 2 : 1); |
54 | 54 | |
55 | - return array_map(function (float $correlation) use ($degreesOfFreedom): float { |
|
55 | + return array_map(function(float $correlation) use ($degreesOfFreedom): float { |
|
56 | 56 | return $correlation ** 2 / (1 - $correlation ** 2) * $degreesOfFreedom; |
57 | 57 | }, $correlations); |
58 | 58 | } |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | private function centerTargets(array &$targets): void |
61 | 61 | { |
62 | 62 | $mean = Mean::arithmetic($targets); |
63 | - array_walk($targets, function (&$target) use ($mean): void { |
|
63 | + array_walk($targets, function(&$target) use ($mean): void { |
|
64 | 64 | $target -= $mean; |
65 | 65 | }); |
66 | 66 | } |
@@ -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) { |
|
61 | + $callback = function($weights, $sample, $target) { |
|
62 | 62 | $this->weights = $weights; |
63 | 63 | |
64 | 64 | $output = $this->output($sample); |
@@ -154,7 +154,7 @@ |
||
154 | 154 | protected function runTraining(array $samples, array $targets): void |
155 | 155 | { |
156 | 156 | // The cost function is the sum of squares |
157 | - $callback = function ($weights, $sample, $target) { |
|
157 | + $callback = function($weights, $sample, $target) { |
|
158 | 158 | $this->weights = $weights; |
159 | 159 | |
160 | 160 | $prediction = $this->outputClass($sample); |
@@ -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) { |
|
182 | + return function($x, $y) use ($dist) { |
|
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) { |
|
188 | + return function($x, $y) { |
|
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) { |
|
198 | + return function($x, $y) use ($dist) { |
|
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 |
@@ -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(function (array $class): int { |
|
31 | + $samplesPerClass = array_map(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(function ($s) use ($dfbn) { |
|
44 | + $msb = array_map(function($s) use ($dfbn) { |
|
45 | 45 | return $s / $dfbn; |
46 | 46 | }, $ssbn); |
47 | - $msw = array_map(function ($s) use ($dfwn) { |
|
47 | + $msw = array_map(function($s) use ($dfwn) { |
|
48 | 48 | return $s / $dfwn; |
49 | 49 | }, $sswn); |
50 | 50 | |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | |
73 | 73 | private static function sumOfFeaturesPerClass(array $samples): array |
74 | 74 | { |
75 | - return array_map(function (array $class) { |
|
75 | + return array_map(function(array $class) { |
|
76 | 76 | $sum = array_fill(0, count($class[0]), 0); |
77 | 77 | foreach ($class as $sample) { |
78 | 78 | foreach ($sample as $index => $feature) { |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | } |
94 | 94 | } |
95 | 95 | |
96 | - return array_map(function ($sum) { |
|
96 | + return array_map(function($sum) { |
|
97 | 97 | return $sum ** 2; |
98 | 98 | }, $squares); |
99 | 99 | } |
@@ -126,7 +126,7 @@ |
||
126 | 126 | public function transpose(): self |
127 | 127 | { |
128 | 128 | if ($this->rows === 1) { |
129 | - $matrix = array_map(function ($el) { |
|
129 | + $matrix = array_map(function($el) { |
|
130 | 130 | return [$el]; |
131 | 131 | }, $this->matrix[0]); |
132 | 132 | } else { |
@@ -61,7 +61,7 @@ |
||
61 | 61 | $imageBytes = fread($stream, $fields['rows'] * $fields['cols']); |
62 | 62 | |
63 | 63 | // Convert to float between 0 and 1 |
64 | - $images[] = array_map(function ($b) { |
|
64 | + $images[] = array_map(function($b) { |
|
65 | 65 | return $b / 255; |
66 | 66 | }, array_values(unpack('C*', (string) $imageBytes))); |
67 | 67 | } |
@@ -59,7 +59,7 @@ |
||
59 | 59 | } |
60 | 60 | |
61 | 61 | /** |
62 | - * @param object $point |
|
62 | + * @param Point $point |
|
63 | 63 | * @param mixed $data |
64 | 64 | */ |
65 | 65 | public function attach($point, $data = null): void |