@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | * The gradient of the cost function to be used with gradient descent: |
191 | 191 | * ∇J(x) = -(y - h(x)) = (h(x) - y) |
192 | 192 | */ |
193 | - $callback = function ($weights, $sample, $y) use ($penalty) { |
|
193 | + $callback = function($weights, $sample, $y) use ($penalty) { |
|
194 | 194 | $this->weights = $weights; |
195 | 195 | $hX = $this->output($sample); |
196 | 196 | |
@@ -225,7 +225,7 @@ discard block |
||
225 | 225 | * The gradient of the cost function: |
226 | 226 | * ∇J(x) = -(h(x) - y) . h(x) . (1 - h(x)) |
227 | 227 | */ |
228 | - $callback = function ($weights, $sample, $y) use ($penalty) { |
|
228 | + $callback = function($weights, $sample, $y) use ($penalty) { |
|
229 | 229 | $this->weights = $weights; |
230 | 230 | $hX = $this->output($sample); |
231 | 231 |
@@ -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, |