@@ -100,7 +100,7 @@ |
||
100 | 100 | |
101 | 101 | // Normalize & sort the importance values |
102 | 102 | $total = array_sum($sum); |
103 | - array_walk($sum, function (&$importance) use ($total): void { |
|
103 | + array_walk($sum, function(&$importance) use ($total): void { |
|
104 | 104 | $importance /= $total; |
105 | 105 | }); |
106 | 106 | arsort($sum); |
@@ -220,7 +220,7 @@ |
||
220 | 220 | // Normalize & sort the importances |
221 | 221 | $total = array_sum($this->featureImportances); |
222 | 222 | if ($total > 0) { |
223 | - array_walk($this->featureImportances, function (&$importance) use ($total): void { |
|
223 | + array_walk($this->featureImportances, function(&$importance) use ($total): void { |
|
224 | 224 | $importance /= $total; |
225 | 225 | }); |
226 | 226 | arsort($this->featureImportances); |
@@ -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 | } |
@@ -48,7 +48,7 @@ |
||
48 | 48 | |
49 | 49 | public function transform(array &$samples): void |
50 | 50 | { |
51 | - array_walk($samples, function (string &$sample): void { |
|
51 | + array_walk($samples, function(string &$sample): void { |
|
52 | 52 | $this->transformSample($sample); |
53 | 53 | }); |
54 | 54 |
@@ -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 | } |
@@ -59,7 +59,7 @@ discard block |
||
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 |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | } |
130 | 130 | |
131 | 131 | /** |
132 | - * @return array|Cluster[] |
|
132 | + * @return Cluster[] |
|
133 | 133 | */ |
134 | 134 | protected function initializeClusters(int $clustersNumber, int $initMethod): array |
135 | 135 | { |
@@ -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 |