@@ -174,20 +174,20 @@ discard block |
||
174 | 174 | switch ($this->kernel) { |
175 | 175 | case self::KERNEL_LINEAR: |
176 | 176 | // k(x,y) = xT.y |
177 | - return function ($x, $y) { |
|
177 | + return function($x, $y) { |
|
178 | 178 | return Matrix::dot($x, $y)[0]; |
179 | 179 | }; |
180 | 180 | case self::KERNEL_RBF: |
181 | 181 | // k(x,y)=exp(-γ.|x-y|) where |..| is Euclidean distance |
182 | 182 | $dist = new Euclidean(); |
183 | 183 | |
184 | - return function ($x, $y) use ($dist) { |
|
184 | + return function($x, $y) use ($dist) { |
|
185 | 185 | return exp(-$this->gamma * $dist->sqDistance($x, $y)); |
186 | 186 | }; |
187 | 187 | |
188 | 188 | case self::KERNEL_SIGMOID: |
189 | 189 | // k(x,y)=tanh(γ.xT.y+c0) where c0=1 |
190 | - return function ($x, $y) { |
|
190 | + return function($x, $y) { |
|
191 | 191 | $res = Matrix::dot($x, $y)[0] + 1.0; |
192 | 192 | |
193 | 193 | return tanh($this->gamma * $res); |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | // k(x,y)=exp(-γ.|x-y|) where |..| is Manhattan distance |
198 | 198 | $dist = new Manhattan(); |
199 | 199 | |
200 | - return function ($x, $y) use ($dist) { |
|
200 | + return function($x, $y) use ($dist) { |
|
201 | 201 | return exp(-$this->gamma * $dist->distance($x, $y)); |
202 | 202 | }; |
203 | 203 | |
@@ -222,7 +222,7 @@ discard block |
||
222 | 222 | protected function projectSample(array $pairs): array |
223 | 223 | { |
224 | 224 | // Normalize eigenvectors by eig = eigVectors / eigValues |
225 | - $func = function ($eigVal, $eigVect) { |
|
225 | + $func = function($eigVal, $eigVect) { |
|
226 | 226 | $m = new Matrix($eigVect, false); |
227 | 227 | $a = $m->divideByScalar($eigVal)->toArray(); |
228 | 228 |
@@ -157,7 +157,7 @@ |
||
157 | 157 | |
158 | 158 | // Calculate overall mean of the dataset for each column |
159 | 159 | $numElements = array_sum($counts); |
160 | - $map = function ($el) use ($numElements) { |
|
160 | + $map = function($el) use ($numElements) { |
|
161 | 161 | return $el / $numElements; |
162 | 162 | }; |
163 | 163 | $this->overallMean = array_map($map, $overallMean); |
@@ -143,7 +143,7 @@ |
||
143 | 143 | $total += $val; |
144 | 144 | } |
145 | 145 | |
146 | - $this->membership[] = array_map(function ($val) use ($total) { |
|
146 | + $this->membership[] = array_map(function($val) use ($total) { |
|
147 | 147 | return $val / $total; |
148 | 148 | }, $row); |
149 | 149 | } |
@@ -37,7 +37,7 @@ |
||
37 | 37 | |
38 | 38 | public function fit(array $samples, ?array $targets = null): void |
39 | 39 | { |
40 | - $this->variances = array_map(function (array $column) { |
|
40 | + $this->variances = array_map(function(array $column) { |
|
41 | 41 | return Variance::population($column); |
42 | 42 | }, Matrix::transposeArray($samples)); |
43 | 43 |
@@ -52,7 +52,7 @@ |
||
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 | } |
@@ -241,7 +241,7 @@ |
||
241 | 241 | { |
242 | 242 | // Check for early stop: No change larger than threshold (default 1e-5) |
243 | 243 | $diff = array_map( |
244 | - function ($w1, $w2) { |
|
244 | + function($w1, $w2) { |
|
245 | 245 | return abs($w1 - $w2) > $this->threshold ? 1 : 0; |
246 | 246 | }, |
247 | 247 | $oldTheta, |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | $this->dataType[$label][$i] = self::NOMINAL; |
121 | 121 | $this->discreteProb[$label][$i] = array_count_values($values); |
122 | 122 | $db = &$this->discreteProb[$label][$i]; |
123 | - $db = array_map(function ($el) use ($numValues) { |
|
123 | + $db = array_map(function($el) use ($numValues) { |
|
124 | 124 | return $el / $numValues; |
125 | 125 | }, $db); |
126 | 126 | } else { |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | */ |
137 | 137 | private function sampleProbability(array $sample, int $feature, string $label): float |
138 | 138 | { |
139 | - $value = (isset($sample[$feature]))? $sample[$feature] : null; |
|
139 | + $value = (isset($sample[$feature])) ? $sample[$feature] : null; |
|
140 | 140 | if ($this->dataType[$label][$feature] == self::NOMINAL) { |
141 | 141 | if (!isset($this->discreteProb[$label][$feature][$value]) || |
142 | 142 | $this->discreteProb[$label][$feature][$value] == 0) { |