Test Failed
Pull Request — master (#81)
by
unknown
04:16
created
src/Phpml/DimensionReduction/KernelPCA.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types=1);
3
+declare(strict_types = 1);
4 4
 
5 5
 namespace Phpml\DimensionReduction;
6 6
 
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
      */
47 47
     public function __construct(int $kernel = self::KERNEL_RBF, $totalVariance = null, $numFeatures = null, $gamma = null)
48 48
     {
49
-        if (! in_array($kernel, [self::KERNEL_RBF, self::KERNEL_SIGMOID, self::KERNEL_LAPLACIAN])) {
49
+        if (!in_array($kernel, [self::KERNEL_RBF, self::KERNEL_SIGMOID, self::KERNEL_LAPLACIAN])) {
50 50
             throw new \Exception("KernelPCA can be initialized with the following kernels only: RBF, Sigmoid and Laplacian");
51 51
         }
52 52
 
@@ -100,8 +100,8 @@  discard block
 block discarded – undo
100 100
         $kernelFunc = $this->getKernel();
101 101
 
102 102
         $matrix = [];
103
-        for ($i=0; $i < $numRows; $i++) {
104
-            for ($k=0; $k < $numRows; $k++) {
103
+        for ($i = 0; $i < $numRows; $i++) {
104
+            for ($k = 0; $k < $numRows; $k++) {
105 105
                 if ($i <= $k) {
106 106
                     $matrix[$i][$k] = $kernelFunc($data[$i], $data[$k]);
107 107
                 } else {
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
      */
125 125
     protected function centerMatrix(array $matrix, int $n)
126 126
     {
127
-        $N = array_fill(0, $n, array_fill(0, $n, 1.0/$n));
127
+        $N = array_fill(0, $n, array_fill(0, $n, 1.0 / $n));
128 128
         $N = new Matrix($N, false);
129 129
         $K = new Matrix($matrix, false);
130 130
 
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
             case self::KERNEL_RBF:
158 158
                 // k(x,y)=exp(-γ.|x-y|) where |..| is Euclidean distance
159 159
                 $dist = new Euclidean();
160
-                return function ($x, $y = null) use ($dist) {
160
+                return function($x, $y = null) use ($dist) {
161 161
                     if ($y === null) {
162 162
                         foreach ($x as $i => $element) {
163 163
                             $x[$i] = exp(-$this->gamma * $element);
@@ -166,12 +166,12 @@  discard block
 block discarded – undo
166 166
                         return $x;
167 167
                     }
168 168
 
169
-                    return exp(-$this->gamma *    $dist->distance($x, $y));
169
+                    return exp(-$this->gamma * $dist->distance($x, $y));
170 170
                 };
171 171
 
172 172
             case self::KERNEL_SIGMOID:
173 173
                 // k(x,y)=tanh(γ.xT.y+c0) where c0=0
174
-                return function ($x, $y = null) {
174
+                return function($x, $y = null) {
175 175
                     if ($y === null) {
176 176
                         foreach ($x as $i => $element) {
177 177
                             $x[$i] = tanh($this->gamma * $element);
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
             case self::KERNEL_LAPLACIAN:
191 191
                 // k(x,y)=exp(-γ.|x-y|) where |..| is Manhattan distance
192 192
                 $dist = new Manhattan();
193
-                return function ($x, $y = null) use ($dist) {
193
+                return function($x, $y = null) use ($dist) {
194 194
                     if ($y === null) {
195 195
                         foreach ($x as $i => $element) {
196 196
                             $x[$i] = exp(-$this->gamma * $element);
@@ -228,7 +228,7 @@  discard block
 block discarded – undo
228 228
     protected function projectSample(array $pairs)
229 229
     {
230 230
         // Normalize eigenvectors by eig = eigVectors / eigValues
231
-        $func = function ($eigVal, $eigVect) {
231
+        $func = function($eigVal, $eigVect) {
232 232
             $m = new Matrix($eigVect, false);
233 233
             $a = $m->divideByScalar(sqrt($eigVal))->toArray();
234 234
 
Please login to merge, or discard this patch.
src/Phpml/DimensionReduction/PCA.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types=1);
3
+declare(strict_types = 1);
4 4
 
5 5
 namespace Phpml\DimensionReduction;
6 6
 
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
     {
116 116
         // Calculate means for each dimension
117 117
         $this->means = [];
118
-        for ($i=0; $i < $n; $i++) {
118
+        for ($i = 0; $i < $n; $i++) {
119 119
             $column = array_column($data, $i);
120 120
             $this->means[] = Mean::arithmetic($column);
121 121
         }
@@ -138,7 +138,7 @@  discard block
 block discarded – undo
138 138
 
139 139
         // Normalize data
140 140
         foreach ($data as $i => $row) {
141
-            for ($k=0; $k < $n; $k++) {
141
+            for ($k = 0; $k < $n; $k++) {
142 142
                 $data[$i][$k] -= $this->means[$k];
143 143
             }
144 144
         }
@@ -160,13 +160,13 @@  discard block
 block discarded – undo
160 160
     {
161 161
         $eig = new EigenvalueDecomposition($matrix);
162 162
         $eigVals = $eig->getRealEigenvalues();
163
-        $eigVects= $eig->getEigenvectors();
163
+        $eigVects = $eig->getEigenvectors();
164 164
         $totalEigVal = array_sum($eigVals);
165 165
 
166 166
         $explainedVar = 0.0;
167 167
         $vectors = [];
168 168
         $values = [];
169
-        for ($i=$n - 1; $i >= 0; $i--) {
169
+        for ($i = $n - 1; $i >= 0; $i--) {
170 170
             $explainedVar += $eigVals[$i] / $totalEigVal;
171 171
             $vectors[] = $eigVects[$i];
172 172
             $values[] = $eigVals[$i];
@@ -214,7 +214,7 @@  discard block
 block discarded – undo
214 214
             throw new \Exception("PCA has not been fitted with respect to original dataset, please run PCA::fit() first");
215 215
         }
216 216
 
217
-        if (! is_array($sample[0])) {
217
+        if (!is_array($sample[0])) {
218 218
             $sample = [$sample];
219 219
         }
220 220
 
Please login to merge, or discard this patch.
src/Phpml/Math/Matrix.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types=1);
3
+declare(strict_types = 1);
4 4
 
5 5
 namespace Phpml\Math;
6 6
 
@@ -286,8 +286,8 @@  discard block
 block discarded – undo
286 286
         $a2 = $other->toArray();
287 287
 
288 288
         $newMatrix = [];
289
-        for ($i=0; $i < $this->rows; $i++) {
290
-            for ($k=0; $k < $this->columns; $k++) {
289
+        for ($i = 0; $i < $this->rows; $i++) {
290
+            for ($k = 0; $k < $this->columns; $k++) {
291 291
                 $newMatrix[$i][$k] = $a1[$i][$k] + $sign * $a2[$i][$k];
292 292
             }
293 293
         }
@@ -428,7 +428,7 @@  discard block
 block discarded – undo
428 428
      */
429 429
     public static function map(array $array, $callable)
430 430
     {
431
-        $func = function ($row) use ($callable) {
431
+        $func = function($row) use ($callable) {
432 432
             return array_map($callable, $row);
433 433
         };
434 434
 
Please login to merge, or discard this patch.
src/Phpml/Math/Statistic/Covariance.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types=1);
3
+declare(strict_types = 1);
4 4
 
5 5
 namespace Phpml\Math\Statistic;
6 6
 
@@ -133,14 +133,14 @@  discard block
 block discarded – undo
133 133
 
134 134
         if ($means === null) {
135 135
             $means = [];
136
-            for ($i=0; $i < $n; $i++) {
136
+            for ($i = 0; $i < $n; $i++) {
137 137
                 $means[] = Mean::arithmetic(array_column($data, $i));
138 138
             }
139 139
         }
140 140
 
141 141
         $cov = [];
142
-        for ($i=0; $i < $n; $i++) {
143
-            for ($k=0; $k < $n; $k++) {
142
+        for ($i = 0; $i < $n; $i++) {
143
+            for ($k = 0; $k < $n; $k++) {
144 144
                 if ($i > $k) {
145 145
                     $cov[$i][$k] = $cov[$k][$i];
146 146
                 } else {
Please login to merge, or discard this patch.
src/Phpml/Math/LinAlg/EigenValueDecomposition.php 1 patch
Spacing   +119 added lines, -119 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php declare(strict_types=1);
1
+<?php declare(strict_types = 1);
2 2
 /**
3 3
  *
4 4
  *	Class to obtain eigenvalues and eigenvectors of a real matrix.
@@ -86,10 +86,10 @@  discard block
 block discarded – undo
86 86
         //  Bowdler, Martin, Reinsch, and Wilkinson, Handbook for
87 87
         //  Auto. Comp., Vol.ii-Linear Algebra, and the corresponding
88 88
         //  Fortran subroutine in EISPACK.
89
-        $this->d = $this->V[$this->n-1];
89
+        $this->d = $this->V[$this->n - 1];
90 90
         // Householder reduction to tridiagonal form.
91
-        for ($i = $this->n-1; $i > 0; --$i) {
92
-            $i_ = $i -1;
91
+        for ($i = $this->n - 1; $i > 0; --$i) {
92
+            $i_ = $i - 1;
93 93
             // Scale to avoid under/overflow.
94 94
             $h = $scale = 0.0;
95 95
             $scale += array_sum(array_map('abs', $this->d));
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
                     $f = $this->d[$j];
122 122
                     $this->V[$j][$i] = $f;
123 123
                     $g = $this->e[$j] + $this->V[$j][$j] * $f;
124
-                    for ($k = $j+1; $k <= $i_; ++$k) {
124
+                    for ($k = $j + 1; $k <= $i_; ++$k) {
125 125
                         $g += $this->V[$k][$j] * $this->d[$k];
126 126
                         $this->e[$k] += $this->V[$k][$j] * $f;
127 127
                     }
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
                     $f += $this->e[$j] * $this->d[$j];
137 137
                 }
138 138
                 $hh = $f / (2 * $h);
139
-                for ($j=0; $j < $i; ++$j) {
139
+                for ($j = 0; $j < $i; ++$j) {
140 140
                     $this->e[$j] -= $hh * $this->d[$j];
141 141
                 }
142 142
                 for ($j = 0; $j < $i; ++$j) {
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
                     for ($k = $j; $k <= $i_; ++$k) {
146 146
                         $this->V[$k][$j] -= ($f * $this->e[$k] + $g * $this->d[$k]);
147 147
                     }
148
-                    $this->d[$j] = $this->V[$i-1][$j];
148
+                    $this->d[$j] = $this->V[$i - 1][$j];
149 149
                     $this->V[$i][$j] = 0.0;
150 150
                 }
151 151
             }
@@ -153,18 +153,18 @@  discard block
 block discarded – undo
153 153
         }
154 154
 
155 155
         // Accumulate transformations.
156
-        for ($i = 0; $i < $this->n-1; ++$i) {
157
-            $this->V[$this->n-1][$i] = $this->V[$i][$i];
156
+        for ($i = 0; $i < $this->n - 1; ++$i) {
157
+            $this->V[$this->n - 1][$i] = $this->V[$i][$i];
158 158
             $this->V[$i][$i] = 1.0;
159
-            $h = $this->d[$i+1];
159
+            $h = $this->d[$i + 1];
160 160
             if ($h != 0.0) {
161 161
                 for ($k = 0; $k <= $i; ++$k) {
162
-                    $this->d[$k] = $this->V[$k][$i+1] / $h;
162
+                    $this->d[$k] = $this->V[$k][$i + 1] / $h;
163 163
                 }
164 164
                 for ($j = 0; $j <= $i; ++$j) {
165 165
                     $g = 0.0;
166 166
                     for ($k = 0; $k <= $i; ++$k) {
167
-                        $g += $this->V[$k][$i+1] * $this->V[$k][$j];
167
+                        $g += $this->V[$k][$i + 1] * $this->V[$k][$j];
168 168
                     }
169 169
                     for ($k = 0; $k <= $i; ++$k) {
170 170
                         $this->V[$k][$j] -= $g * $this->d[$k];
@@ -172,13 +172,13 @@  discard block
 block discarded – undo
172 172
                 }
173 173
             }
174 174
             for ($k = 0; $k <= $i; ++$k) {
175
-                $this->V[$k][$i+1] = 0.0;
175
+                $this->V[$k][$i + 1] = 0.0;
176 176
             }
177 177
         }
178 178
 
179
-        $this->d = $this->V[$this->n-1];
180
-        $this->V[$this->n-1] = array_fill(0, $j, 0.0);
181
-        $this->V[$this->n-1][$this->n-1] = 1.0;
179
+        $this->d = $this->V[$this->n - 1];
180
+        $this->V[$this->n - 1] = array_fill(0, $j, 0.0);
181
+        $this->V[$this->n - 1][$this->n - 1] = 1.0;
182 182
         $this->e[0] = 0.0;
183 183
     }
184 184
 
@@ -194,9 +194,9 @@  discard block
 block discarded – undo
194 194
     private function tql2()
195 195
     {
196 196
         for ($i = 1; $i < $this->n; ++$i) {
197
-            $this->e[$i-1] = $this->e[$i];
197
+            $this->e[$i - 1] = $this->e[$i];
198 198
         }
199
-        $this->e[$this->n-1] = 0.0;
199
+        $this->e[$this->n - 1] = 0.0;
200 200
         $f = 0.0;
201 201
         $tst1 = 0.0;
202 202
         $eps  = pow(2.0, -52.0);
@@ -220,14 +220,14 @@  discard block
 block discarded – undo
220 220
                     $iter += 1;
221 221
                     // Compute implicit shift
222 222
                     $g = $this->d[$l];
223
-                    $p = ($this->d[$l+1] - $g) / (2.0 * $this->e[$l]);
223
+                    $p = ($this->d[$l + 1] - $g) / (2.0 * $this->e[$l]);
224 224
                     $r = hypot($p, 1.0);
225 225
                     if ($p < 0) {
226 226
                         $r *= -1;
227 227
                     }
228 228
                     $this->d[$l] = $this->e[$l] / ($p + $r);
229
-                    $this->d[$l+1] = $this->e[$l] * ($p + $r);
230
-                    $dl1 = $this->d[$l+1];
229
+                    $this->d[$l + 1] = $this->e[$l] * ($p + $r);
230
+                    $dl1 = $this->d[$l + 1];
231 231
                     $h = $g - $this->d[$l];
232 232
                     for ($i = $l + 2; $i < $this->n; ++$i) {
233 233
                         $this->d[$i] -= $h;
@@ -239,22 +239,22 @@  discard block
 block discarded – undo
239 239
                     $c2 = $c3 = $c;
240 240
                     $el1 = $this->e[$l + 1];
241 241
                     $s = $s2 = 0.0;
242
-                    for ($i = $m-1; $i >= $l; --$i) {
242
+                    for ($i = $m - 1; $i >= $l; --$i) {
243 243
                         $c3 = $c2;
244 244
                         $c2 = $c;
245 245
                         $s2 = $s;
246 246
                         $g  = $c * $this->e[$i];
247 247
                         $h  = $c * $p;
248 248
                         $r  = hypot($p, $this->e[$i]);
249
-                        $this->e[$i+1] = $s * $r;
249
+                        $this->e[$i + 1] = $s * $r;
250 250
                         $s = $this->e[$i] / $r;
251 251
                         $c = $p / $r;
252 252
                         $p = $c * $this->d[$i] - $s * $g;
253
-                        $this->d[$i+1] = $h + $s * ($c * $g + $s * $this->d[$i]);
253
+                        $this->d[$i + 1] = $h + $s * ($c * $g + $s * $this->d[$i]);
254 254
                         // Accumulate transformation.
255 255
                         for ($k = 0; $k < $this->n; ++$k) {
256
-                            $h = $this->V[$k][$i+1];
257
-                            $this->V[$k][$i+1] = $s * $this->V[$k][$i] + $c * $h;
256
+                            $h = $this->V[$k][$i + 1];
257
+                            $this->V[$k][$i + 1] = $s * $this->V[$k][$i] + $c * $h;
258 258
                             $this->V[$k][$i] = $c * $this->V[$k][$i] - $s * $h;
259 259
                         }
260 260
                     }
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
272 272
         for ($i = 0; $i < $this->n - 1; ++$i) {
273 273
             $k = $i;
274 274
             $p = $this->d[$i];
275
-            for ($j = $i+1; $j < $this->n; ++$j) {
275
+            for ($j = $i + 1; $j < $this->n; ++$j) {
276 276
                 if ($this->d[$j] < $p) {
277 277
                     $k = $j;
278 278
                     $p = $this->d[$j];
@@ -302,19 +302,19 @@  discard block
 block discarded – undo
302 302
     private function orthes()
303 303
     {
304 304
         $low  = 0;
305
-        $high = $this->n-1;
305
+        $high = $this->n - 1;
306 306
 
307
-        for ($m = $low+1; $m <= $high-1; ++$m) {
307
+        for ($m = $low + 1; $m <= $high - 1; ++$m) {
308 308
             // Scale column.
309 309
             $scale = 0.0;
310 310
             for ($i = $m; $i <= $high; ++$i) {
311
-                $scale = $scale + abs($this->H[$i][$m-1]);
311
+                $scale = $scale + abs($this->H[$i][$m - 1]);
312 312
             }
313 313
             if ($scale != 0.0) {
314 314
                 // Compute Householder transformation.
315 315
                 $h = 0.0;
316 316
                 for ($i = $high; $i >= $m; --$i) {
317
-                    $this->ort[$i] = $this->H[$i][$m-1] / $scale;
317
+                    $this->ort[$i] = $this->H[$i][$m - 1] / $scale;
318 318
                     $h += $this->ort[$i] * $this->ort[$i];
319 319
                 }
320 320
                 $g = sqrt($h);
@@ -346,7 +346,7 @@  discard block
 block discarded – undo
346 346
                     }
347 347
                 }
348 348
                 $this->ort[$m] = $scale * $this->ort[$m];
349
-                $this->H[$m][$m-1] = $scale * $g;
349
+                $this->H[$m][$m - 1] = $scale * $g;
350 350
             }
351 351
         }
352 352
 
@@ -356,10 +356,10 @@  discard block
 block discarded – undo
356 356
                 $this->V[$i][$j] = ($i == $j ? 1.0 : 0.0);
357 357
             }
358 358
         }
359
-        for ($m = $high-1; $m >= $low+1; --$m) {
360
-            if ($this->H[$m][$m-1] != 0.0) {
361
-                for ($i = $m+1; $i <= $high; ++$i) {
362
-                    $this->ort[$i] = $this->H[$i][$m-1];
359
+        for ($m = $high - 1; $m >= $low + 1; --$m) {
360
+            if ($this->H[$m][$m - 1] != 0.0) {
361
+                for ($i = $m + 1; $i <= $high; ++$i) {
362
+                    $this->ort[$i] = $this->H[$i][$m - 1];
363 363
                 }
364 364
                 for ($j = $m; $j <= $high; ++$j) {
365 365
                     $g = 0.0;
@@ -367,7 +367,7 @@  discard block
 block discarded – undo
367 367
                         $g += $this->ort[$i] * $this->V[$i][$j];
368 368
                     }
369 369
                     // Double division avoids possible underflow
370
-                    $g = ($g / $this->ort[$m]) / $this->H[$m][$m-1];
370
+                    $g = ($g / $this->ort[$m]) / $this->H[$m][$m - 1];
371 371
                     for ($i = $m; $i <= $high; ++$i) {
372 372
                         $this->V[$i][$j] += $g * $this->ort[$i];
373 373
                     }
@@ -422,7 +422,7 @@  discard block
 block discarded – undo
422 422
                 $this->d[$i] = $this->H[$i][$i];
423 423
                 $this->e[$i] = 0.0;
424 424
             }
425
-            for ($j = max($i-1, 0); $j < $nn; ++$j) {
425
+            for ($j = max($i - 1, 0); $j < $nn; ++$j) {
426 426
                 $norm = $norm + abs($this->H[$i][$j]);
427 427
             }
428 428
         }
@@ -433,11 +433,11 @@  discard block
 block discarded – undo
433 433
             // Look for single small sub-diagonal element
434 434
             $l = $n;
435 435
             while ($l > $low) {
436
-                $s = abs($this->H[$l-1][$l-1]) + abs($this->H[$l][$l]);
436
+                $s = abs($this->H[$l - 1][$l - 1]) + abs($this->H[$l][$l]);
437 437
                 if ($s == 0.0) {
438 438
                     $s = $norm;
439 439
                 }
440
-                if (abs($this->H[$l][$l-1]) < $eps * $s) {
440
+                if (abs($this->H[$l][$l - 1]) < $eps * $s) {
441 441
                     break;
442 442
                 }
443 443
                 --$l;
@@ -451,13 +451,13 @@  discard block
 block discarded – undo
451 451
                 --$n;
452 452
                 $iter = 0;
453 453
             // Two roots found
454
-            } elseif ($l == $n-1) {
455
-                $w = $this->H[$n][$n-1] * $this->H[$n-1][$n];
456
-                $p = ($this->H[$n-1][$n-1] - $this->H[$n][$n]) / 2.0;
454
+            } elseif ($l == $n - 1) {
455
+                $w = $this->H[$n][$n - 1] * $this->H[$n - 1][$n];
456
+                $p = ($this->H[$n - 1][$n - 1] - $this->H[$n][$n]) / 2.0;
457 457
                 $q = $p * $p + $w;
458 458
                 $z = sqrt(abs($q));
459 459
                 $this->H[$n][$n] = $this->H[$n][$n] + $exshift;
460
-                $this->H[$n-1][$n-1] = $this->H[$n-1][$n-1] + $exshift;
460
+                $this->H[$n - 1][$n - 1] = $this->H[$n - 1][$n - 1] + $exshift;
461 461
                 $x = $this->H[$n][$n];
462 462
                 // Real pair
463 463
                 if ($q >= 0) {
@@ -466,14 +466,14 @@  discard block
 block discarded – undo
466 466
                     } else {
467 467
                         $z = $p - $z;
468 468
                     }
469
-                    $this->d[$n-1] = $x + $z;
470
-                    $this->d[$n] = $this->d[$n-1];
469
+                    $this->d[$n - 1] = $x + $z;
470
+                    $this->d[$n] = $this->d[$n - 1];
471 471
                     if ($z != 0.0) {
472 472
                         $this->d[$n] = $x - $w / $z;
473 473
                     }
474
-                    $this->e[$n-1] = 0.0;
474
+                    $this->e[$n - 1] = 0.0;
475 475
                     $this->e[$n] = 0.0;
476
-                    $x = $this->H[$n][$n-1];
476
+                    $x = $this->H[$n][$n - 1];
477 477
                     $s = abs($x) + abs($z);
478 478
                     $p = $x / $s;
479 479
                     $q = $z / $s;
@@ -481,28 +481,28 @@  discard block
 block discarded – undo
481 481
                     $p = $p / $r;
482 482
                     $q = $q / $r;
483 483
                     // Row modification
484
-                    for ($j = $n-1; $j < $nn; ++$j) {
485
-                        $z = $this->H[$n-1][$j];
486
-                        $this->H[$n-1][$j] = $q * $z + $p * $this->H[$n][$j];
484
+                    for ($j = $n - 1; $j < $nn; ++$j) {
485
+                        $z = $this->H[$n - 1][$j];
486
+                        $this->H[$n - 1][$j] = $q * $z + $p * $this->H[$n][$j];
487 487
                         $this->H[$n][$j] = $q * $this->H[$n][$j] - $p * $z;
488 488
                     }
489 489
                     // Column modification
490 490
                     for ($i = 0; $i <= $n; ++$i) {
491
-                        $z = $this->H[$i][$n-1];
492
-                        $this->H[$i][$n-1] = $q * $z + $p * $this->H[$i][$n];
491
+                        $z = $this->H[$i][$n - 1];
492
+                        $this->H[$i][$n - 1] = $q * $z + $p * $this->H[$i][$n];
493 493
                         $this->H[$i][$n] = $q * $this->H[$i][$n] - $p * $z;
494 494
                     }
495 495
                     // Accumulate transformations
496 496
                     for ($i = $low; $i <= $high; ++$i) {
497
-                        $z = $this->V[$i][$n-1];
498
-                        $this->V[$i][$n-1] = $q * $z + $p * $this->V[$i][$n];
497
+                        $z = $this->V[$i][$n - 1];
498
+                        $this->V[$i][$n - 1] = $q * $z + $p * $this->V[$i][$n];
499 499
                         $this->V[$i][$n] = $q * $this->V[$i][$n] - $p * $z;
500 500
                     }
501 501
                 // Complex pair
502 502
                 } else {
503
-                    $this->d[$n-1] = $x + $p;
503
+                    $this->d[$n - 1] = $x + $p;
504 504
                     $this->d[$n] = $x + $p;
505
-                    $this->e[$n-1] = $z;
505
+                    $this->e[$n - 1] = $z;
506 506
                     $this->e[$n] = -$z;
507 507
                 }
508 508
                 $n = $n - 2;
@@ -514,8 +514,8 @@  discard block
 block discarded – undo
514 514
                 $y = 0.0;
515 515
                 $w = 0.0;
516 516
                 if ($l < $n) {
517
-                    $y = $this->H[$n-1][$n-1];
518
-                    $w = $this->H[$n][$n-1] * $this->H[$n-1][$n];
517
+                    $y = $this->H[$n - 1][$n - 1];
518
+                    $w = $this->H[$n][$n - 1] * $this->H[$n - 1][$n];
519 519
                 }
520 520
                 // Wilkinson's original ad hoc shift
521 521
                 if ($iter == 10) {
@@ -523,7 +523,7 @@  discard block
 block discarded – undo
523 523
                     for ($i = $low; $i <= $n; ++$i) {
524 524
                         $this->H[$i][$i] -= $x;
525 525
                     }
526
-                    $s = abs($this->H[$n][$n-1]) + abs($this->H[$n-1][$n-2]);
526
+                    $s = abs($this->H[$n][$n - 1]) + abs($this->H[$n - 1][$n - 2]);
527 527
                     $x = $y = 0.75 * $s;
528 528
                     $w = -0.4375 * $s * $s;
529 529
                 }
@@ -552,9 +552,9 @@  discard block
 block discarded – undo
552 552
                     $z = $this->H[$m][$m];
553 553
                     $r = $x - $z;
554 554
                     $s = $y - $z;
555
-                    $p = ($r * $s - $w) / $this->H[$m+1][$m] + $this->H[$m][$m+1];
556
-                    $q = $this->H[$m+1][$m+1] - $z - $r - $s;
557
-                    $r = $this->H[$m+2][$m+1];
555
+                    $p = ($r * $s - $w) / $this->H[$m + 1][$m] + $this->H[$m][$m + 1];
556
+                    $q = $this->H[$m + 1][$m + 1] - $z - $r - $s;
557
+                    $r = $this->H[$m + 2][$m + 1];
558 558
                     $s = abs($p) + abs($q) + abs($r);
559 559
                     $p = $p / $s;
560 560
                     $q = $q / $s;
@@ -562,25 +562,25 @@  discard block
 block discarded – undo
562 562
                     if ($m == $l) {
563 563
                         break;
564 564
                     }
565
-                    if (abs($this->H[$m][$m-1]) * (abs($q) + abs($r)) <
566
-                        $eps * (abs($p) * (abs($this->H[$m-1][$m-1]) + abs($z) + abs($this->H[$m+1][$m+1])))) {
565
+                    if (abs($this->H[$m][$m - 1]) * (abs($q) + abs($r)) <
566
+                        $eps * (abs($p) * (abs($this->H[$m - 1][$m - 1]) + abs($z) + abs($this->H[$m + 1][$m + 1])))) {
567 567
                         break;
568 568
                     }
569 569
                     --$m;
570 570
                 }
571 571
                 for ($i = $m + 2; $i <= $n; ++$i) {
572
-                    $this->H[$i][$i-2] = 0.0;
573
-                    if ($i > $m+2) {
574
-                        $this->H[$i][$i-3] = 0.0;
572
+                    $this->H[$i][$i - 2] = 0.0;
573
+                    if ($i > $m + 2) {
574
+                        $this->H[$i][$i - 3] = 0.0;
575 575
                     }
576 576
                 }
577 577
                 // Double QR step involving rows l:n and columns m:n
578
-                for ($k = $m; $k <= $n-1; ++$k) {
579
-                    $notlast = ($k != $n-1);
578
+                for ($k = $m; $k <= $n - 1; ++$k) {
579
+                    $notlast = ($k != $n - 1);
580 580
                     if ($k != $m) {
581
-                        $p = $this->H[$k][$k-1];
582
-                        $q = $this->H[$k+1][$k-1];
583
-                        $r = ($notlast ? $this->H[$k+2][$k-1] : 0.0);
581
+                        $p = $this->H[$k][$k - 1];
582
+                        $q = $this->H[$k + 1][$k - 1];
583
+                        $r = ($notlast ? $this->H[$k + 2][$k - 1] : 0.0);
584 584
                         $x = abs($p) + abs($q) + abs($r);
585 585
                         if ($x != 0.0) {
586 586
                             $p = $p / $x;
@@ -597,9 +597,9 @@  discard block
 block discarded – undo
597 597
                     }
598 598
                     if ($s != 0) {
599 599
                         if ($k != $m) {
600
-                            $this->H[$k][$k-1] = -$s * $x;
600
+                            $this->H[$k][$k - 1] = -$s * $x;
601 601
                         } elseif ($l != $m) {
602
-                            $this->H[$k][$k-1] = -$this->H[$k][$k-1];
602
+                            $this->H[$k][$k - 1] = -$this->H[$k][$k - 1];
603 603
                         }
604 604
                         $p = $p + $s;
605 605
                         $x = $p / $s;
@@ -609,33 +609,33 @@  discard block
 block discarded – undo
609 609
                         $r = $r / $p;
610 610
                         // Row modification
611 611
                         for ($j = $k; $j < $nn; ++$j) {
612
-                            $p = $this->H[$k][$j] + $q * $this->H[$k+1][$j];
612
+                            $p = $this->H[$k][$j] + $q * $this->H[$k + 1][$j];
613 613
                             if ($notlast) {
614
-                                $p = $p + $r * $this->H[$k+2][$j];
615
-                                $this->H[$k+2][$j] = $this->H[$k+2][$j] - $p * $z;
614
+                                $p = $p + $r * $this->H[$k + 2][$j];
615
+                                $this->H[$k + 2][$j] = $this->H[$k + 2][$j] - $p * $z;
616 616
                             }
617 617
                             $this->H[$k][$j] = $this->H[$k][$j] - $p * $x;
618
-                            $this->H[$k+1][$j] = $this->H[$k+1][$j] - $p * $y;
618
+                            $this->H[$k + 1][$j] = $this->H[$k + 1][$j] - $p * $y;
619 619
                         }
620 620
                         // Column modification
621
-                        for ($i = 0; $i <= min($n, $k+3); ++$i) {
622
-                            $p = $x * $this->H[$i][$k] + $y * $this->H[$i][$k+1];
621
+                        for ($i = 0; $i <= min($n, $k + 3); ++$i) {
622
+                            $p = $x * $this->H[$i][$k] + $y * $this->H[$i][$k + 1];
623 623
                             if ($notlast) {
624
-                                $p = $p + $z * $this->H[$i][$k+2];
625
-                                $this->H[$i][$k+2] = $this->H[$i][$k+2] - $p * $r;
624
+                                $p = $p + $z * $this->H[$i][$k + 2];
625
+                                $this->H[$i][$k + 2] = $this->H[$i][$k + 2] - $p * $r;
626 626
                             }
627 627
                             $this->H[$i][$k] = $this->H[$i][$k] - $p;
628
-                            $this->H[$i][$k+1] = $this->H[$i][$k+1] - $p * $q;
628
+                            $this->H[$i][$k + 1] = $this->H[$i][$k + 1] - $p * $q;
629 629
                         }
630 630
                         // Accumulate transformations
631 631
                         for ($i = $low; $i <= $high; ++$i) {
632
-                            $p = $x * $this->V[$i][$k] + $y * $this->V[$i][$k+1];
632
+                            $p = $x * $this->V[$i][$k] + $y * $this->V[$i][$k + 1];
633 633
                             if ($notlast) {
634
-                                $p = $p + $z * $this->V[$i][$k+2];
635
-                                $this->V[$i][$k+2] = $this->V[$i][$k+2] - $p * $r;
634
+                                $p = $p + $z * $this->V[$i][$k + 2];
635
+                                $this->V[$i][$k + 2] = $this->V[$i][$k + 2] - $p * $r;
636 636
                             }
637 637
                             $this->V[$i][$k] = $this->V[$i][$k] - $p;
638
-                            $this->V[$i][$k+1] = $this->V[$i][$k+1] - $p * $q;
638
+                            $this->V[$i][$k + 1] = $this->V[$i][$k + 1] - $p * $q;
639 639
                         }
640 640
                     }  // ($s != 0)
641 641
                 }  // k loop
@@ -647,14 +647,14 @@  discard block
 block discarded – undo
647 647
             return;
648 648
         }
649 649
 
650
-        for ($n = $nn-1; $n >= 0; --$n) {
650
+        for ($n = $nn - 1; $n >= 0; --$n) {
651 651
             $p = $this->d[$n];
652 652
             $q = $this->e[$n];
653 653
             // Real vector
654 654
             if ($q == 0) {
655 655
                 $l = $n;
656 656
                 $this->H[$n][$n] = 1.0;
657
-                for ($i = $n-1; $i >= 0; --$i) {
657
+                for ($i = $n - 1; $i >= 0; --$i) {
658 658
                     $w = $this->H[$i][$i] - $p;
659 659
                     $r = 0.0;
660 660
                     for ($j = $l; $j <= $n; ++$j) {
@@ -673,15 +673,15 @@  discard block
 block discarded – undo
673 673
                             }
674 674
                         // Solve real equations
675 675
                         } else {
676
-                            $x = $this->H[$i][$i+1];
677
-                            $y = $this->H[$i+1][$i];
676
+                            $x = $this->H[$i][$i + 1];
677
+                            $y = $this->H[$i + 1][$i];
678 678
                             $q = ($this->d[$i] - $p) * ($this->d[$i] - $p) + $this->e[$i] * $this->e[$i];
679 679
                             $t = ($x * $s - $z * $r) / $q;
680 680
                             $this->H[$i][$n] = $t;
681 681
                             if (abs($x) > abs($z)) {
682
-                                $this->H[$i+1][$n] = (-$r - $w * $t) / $x;
682
+                                $this->H[$i + 1][$n] = (-$r - $w * $t) / $x;
683 683
                             } else {
684
-                                $this->H[$i+1][$n] = (-$s - $y * $t) / $z;
684
+                                $this->H[$i + 1][$n] = (-$s - $y * $t) / $z;
685 685
                             }
686 686
                         }
687 687
                         // Overflow control
@@ -695,24 +695,24 @@  discard block
 block discarded – undo
695 695
                 }
696 696
             // Complex vector
697 697
             } elseif ($q < 0) {
698
-                $l = $n-1;
698
+                $l = $n - 1;
699 699
                 // Last vector component imaginary so matrix is triangular
700
-                if (abs($this->H[$n][$n-1]) > abs($this->H[$n-1][$n])) {
701
-                    $this->H[$n-1][$n-1] = $q / $this->H[$n][$n-1];
702
-                    $this->H[$n-1][$n] = -($this->H[$n][$n] - $p) / $this->H[$n][$n-1];
700
+                if (abs($this->H[$n][$n - 1]) > abs($this->H[$n - 1][$n])) {
701
+                    $this->H[$n - 1][$n - 1] = $q / $this->H[$n][$n - 1];
702
+                    $this->H[$n - 1][$n] = -($this->H[$n][$n] - $p) / $this->H[$n][$n - 1];
703 703
                 } else {
704
-                    $this->cdiv(0.0, -$this->H[$n-1][$n], $this->H[$n-1][$n-1] - $p, $q);
705
-                    $this->H[$n-1][$n-1] = $this->cdivr;
706
-                    $this->H[$n-1][$n]   = $this->cdivi;
704
+                    $this->cdiv(0.0, -$this->H[$n - 1][$n], $this->H[$n - 1][$n - 1] - $p, $q);
705
+                    $this->H[$n - 1][$n - 1] = $this->cdivr;
706
+                    $this->H[$n - 1][$n]   = $this->cdivi;
707 707
                 }
708
-                $this->H[$n][$n-1] = 0.0;
708
+                $this->H[$n][$n - 1] = 0.0;
709 709
                 $this->H[$n][$n] = 1.0;
710
-                for ($i = $n-2; $i >= 0; --$i) {
710
+                for ($i = $n - 2; $i >= 0; --$i) {
711 711
                     // double ra,sa,vr,vi;
712 712
                     $ra = 0.0;
713 713
                     $sa = 0.0;
714 714
                     for ($j = $l; $j <= $n; ++$j) {
715
-                        $ra = $ra + $this->H[$i][$j] * $this->H[$j][$n-1];
715
+                        $ra = $ra + $this->H[$i][$j] * $this->H[$j][$n - 1];
716 716
                         $sa = $sa + $this->H[$i][$j] * $this->H[$j][$n];
717 717
                     }
718 718
                     $w = $this->H[$i][$i] - $p;
@@ -724,34 +724,34 @@  discard block
 block discarded – undo
724 724
                         $l = $i;
725 725
                         if ($this->e[$i] == 0) {
726 726
                             $this->cdiv(-$ra, -$sa, $w, $q);
727
-                            $this->H[$i][$n-1] = $this->cdivr;
727
+                            $this->H[$i][$n - 1] = $this->cdivr;
728 728
                             $this->H[$i][$n]   = $this->cdivi;
729 729
                         } else {
730 730
                             // Solve complex equations
731
-                            $x = $this->H[$i][$i+1];
732
-                            $y = $this->H[$i+1][$i];
731
+                            $x = $this->H[$i][$i + 1];
732
+                            $y = $this->H[$i + 1][$i];
733 733
                             $vr = ($this->d[$i] - $p) * ($this->d[$i] - $p) + $this->e[$i] * $this->e[$i] - $q * $q;
734 734
                             $vi = ($this->d[$i] - $p) * 2.0 * $q;
735 735
                             if ($vr == 0.0 & $vi == 0.0) {
736 736
                                 $vr = $eps * $norm * (abs($w) + abs($q) + abs($x) + abs($y) + abs($z));
737 737
                             }
738 738
                             $this->cdiv($x * $r - $z * $ra + $q * $sa, $x * $s - $z * $sa - $q * $ra, $vr, $vi);
739
-                            $this->H[$i][$n-1] = $this->cdivr;
739
+                            $this->H[$i][$n - 1] = $this->cdivr;
740 740
                             $this->H[$i][$n]   = $this->cdivi;
741 741
                             if (abs($x) > (abs($z) + abs($q))) {
742
-                                $this->H[$i+1][$n-1] = (-$ra - $w * $this->H[$i][$n-1] + $q * $this->H[$i][$n]) / $x;
743
-                                $this->H[$i+1][$n] = (-$sa - $w * $this->H[$i][$n] - $q * $this->H[$i][$n-1]) / $x;
742
+                                $this->H[$i + 1][$n - 1] = (-$ra - $w * $this->H[$i][$n - 1] + $q * $this->H[$i][$n]) / $x;
743
+                                $this->H[$i + 1][$n] = (-$sa - $w * $this->H[$i][$n] - $q * $this->H[$i][$n - 1]) / $x;
744 744
                             } else {
745
-                                $this->cdiv(-$r - $y * $this->H[$i][$n-1], -$s - $y * $this->H[$i][$n], $z, $q);
746
-                                $this->H[$i+1][$n-1] = $this->cdivr;
747
-                                $this->H[$i+1][$n]   = $this->cdivi;
745
+                                $this->cdiv(-$r - $y * $this->H[$i][$n - 1], -$s - $y * $this->H[$i][$n], $z, $q);
746
+                                $this->H[$i + 1][$n - 1] = $this->cdivr;
747
+                                $this->H[$i + 1][$n]   = $this->cdivi;
748 748
                             }
749 749
                         }
750 750
                         // Overflow control
751
-                        $t = max(abs($this->H[$i][$n-1]), abs($this->H[$i][$n]));
751
+                        $t = max(abs($this->H[$i][$n - 1]), abs($this->H[$i][$n]));
752 752
                         if (($eps * $t) * $t > 1) {
753 753
                             for ($j = $i; $j <= $n; ++$j) {
754
-                                $this->H[$j][$n-1] = $this->H[$j][$n-1] / $t;
754
+                                $this->H[$j][$n - 1] = $this->H[$j][$n - 1] / $t;
755 755
                                 $this->H[$j][$n]   = $this->H[$j][$n] / $t;
756 756
                             }
757 757
                         }
@@ -770,7 +770,7 @@  discard block
 block discarded – undo
770 770
         }
771 771
 
772 772
         // Back transformation to get eigenvectors of original matrix
773
-        for ($j = $nn-1; $j >= $low; --$j) {
773
+        for ($j = $nn - 1; $j >= $low; --$j) {
774 774
             for ($i = $low; $i <= $high; ++$i) {
775 775
                 $z = 0.0;
776 776
                 for ($k = $low; $k <= min($j, $high); ++$k) {
@@ -827,13 +827,13 @@  discard block
 block discarded – undo
827 827
 
828 828
         // Always return the eigenvectors of length 1.0
829 829
         $vectors = new Matrix($vectors);
830
-        $vectors = array_map(function ($vect) {
830
+        $vectors = array_map(function($vect) {
831 831
             $sum = 0;
832
-            for ($i=0; $i<count($vect); $i++) {
832
+            for ($i = 0; $i < count($vect); $i++) {
833 833
                 $sum += $vect[$i] ** 2;
834 834
             }
835 835
             $sum = sqrt($sum);
836
-            for ($i=0; $i<count($vect); $i++) {
836
+            for ($i = 0; $i < count($vect); $i++) {
837 837
                 $vect[$i] /= $sum;
838 838
             }
839 839
             return $vect;
Please login to merge, or discard this patch.