Completed
Push — master ( 6296e4...a87859 )
by Arkadiusz
18:50
created
src/Phpml/Math/Matrix.php 2 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
     }
107 107
 
108 108
     /**
109
-     * @param $column
109
+     * @param integer $column
110 110
      *
111 111
      * @return array
112 112
      *
@@ -278,7 +278,7 @@  discard block
 block discarded – undo
278 278
      * Element-wise addition or substraction depending on the given sign parameter
279 279
      *
280 280
      * @param Matrix $other
281
-     * @param type $sign
281
+     * @param integer $sign
282 282
      */
283 283
     protected function _add(Matrix $other, $sign = 1)
284 284
     {
Please login to merge, or discard this 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
 
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
     public function transpose()
180 180
     {
181 181
         if ($this->rows == 1) {
182
-            $matrix = array_map(function ($el) {
182
+            $matrix = array_map(function($el) {
183 183
                 return [$el];
184 184
             }, $this->matrix[0]);
185 185
         } else {
@@ -283,8 +283,8 @@  discard block
 block discarded – undo
283 283
         $a2 = $other->toArray();
284 284
 
285 285
         $newMatrix = [];
286
-        for ($i=0; $i < $this->rows; $i++) {
287
-            for ($k=0; $k < $this->columns; $k++) {
286
+        for ($i = 0; $i < $this->rows; $i++) {
287
+            for ($k = 0; $k < $this->columns; $k++) {
288 288
                 $newMatrix[$i][$k] = $a1[$i][$k] + $sign * $a2[$i][$k];
289 289
             }
290 290
         }
Please login to merge, or discard this patch.
src/Phpml/Math/Statistic/Covariance.php 2 patches
Doc Comments   -1 removed lines patch added patch discarded remove patch
@@ -60,7 +60,6 @@
 block discarded – undo
60 60
      * @param int $i
61 61
      * @param int $k
62 62
      * @param type $sample
63
-     * @param int $n
64 63
      * @param float $meanX
65 64
      * @param float $meanY
66 65
      */
Please login to merge, or discard this 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/DimensionReduction/KernelPCA.php 2 patches
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -136,9 +136,9 @@
 block discarded – undo
136 136
         $N_K_N = $N->multiply($K_N);
137 137
 
138 138
         return $K->subtract($N_K)
139
-                 ->subtract($K_N)
140
-                 ->add($N_K_N)
141
-                 ->toArray();
139
+                    ->subtract($K_N)
140
+                    ->add($N_K_N)
141
+                    ->toArray();
142 142
     }
143 143
 
144 144
     /**
Please login to merge, or discard this 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
 
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
     public function __construct(int $kernel = self::KERNEL_RBF, $totalVariance = null, $numFeatures = null, $gamma = null)
49 49
     {
50 50
         $availableKernels = [self::KERNEL_RBF, self::KERNEL_SIGMOID, self::KERNEL_LAPLACIAN, self::KERNEL_LINEAR];
51
-        if (! in_array($kernel, $availableKernels)) {
51
+        if (!in_array($kernel, $availableKernels)) {
52 52
             throw new \Exception("KernelPCA can be initialized with the following kernels only: Linear, RBF, Sigmoid and Laplacian");
53 53
         }
54 54
 
@@ -102,8 +102,8 @@  discard block
 block discarded – undo
102 102
         $kernelFunc = $this->getKernel();
103 103
 
104 104
         $matrix = [];
105
-        for ($i=0; $i < $numRows; $i++) {
106
-            for ($k=0; $k < $numRows; $k++) {
105
+        for ($i = 0; $i < $numRows; $i++) {
106
+            for ($k = 0; $k < $numRows; $k++) {
107 107
                 if ($i <= $k) {
108 108
                     $matrix[$i][$k] = $kernelFunc($data[$i], $data[$k]);
109 109
                 } else {
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
      */
127 127
     protected function centerMatrix(array $matrix, int $n)
128 128
     {
129
-        $N = array_fill(0, $n, array_fill(0, $n, 1.0/$n));
129
+        $N = array_fill(0, $n, array_fill(0, $n, 1.0 / $n));
130 130
         $N = new Matrix($N, false);
131 131
         $K = new Matrix($matrix, false);
132 132
 
@@ -153,19 +153,19 @@  discard block
 block discarded – undo
153 153
         switch ($this->kernel) {
154 154
             case self::KERNEL_LINEAR:
155 155
                 // k(x,y) = xT.y
156
-                return function ($x, $y) {
156
+                return function($x, $y) {
157 157
                     return Matrix::dot($x, $y)[0];
158 158
                 };
159 159
             case self::KERNEL_RBF:
160 160
                 // k(x,y)=exp(-γ.|x-y|) where |..| is Euclidean distance
161 161
                 $dist = new Euclidean();
162
-                return function ($x, $y) use ($dist) {
162
+                return function($x, $y) use ($dist) {
163 163
                     return exp(-$this->gamma * $dist->sqDistance($x, $y));
164 164
                 };
165 165
 
166 166
             case self::KERNEL_SIGMOID:
167 167
                 // k(x,y)=tanh(γ.xT.y+c0) where c0=1
168
-                return function ($x, $y) {
168
+                return function($x, $y) {
169 169
                     $res = Matrix::dot($x, $y)[0] + 1.0;
170 170
                     return tanh($this->gamma * $res);
171 171
                 };
@@ -173,7 +173,7 @@  discard block
 block discarded – undo
173 173
             case self::KERNEL_LAPLACIAN:
174 174
                 // k(x,y)=exp(-γ.|x-y|) where |..| is Manhattan distance
175 175
                 $dist = new Manhattan();
176
-                return function ($x, $y) use ($dist) {
176
+                return function($x, $y) use ($dist) {
177 177
                     return exp(-$this->gamma * $dist->distance($x, $y));
178 178
                 };
179 179
         }
@@ -204,7 +204,7 @@  discard block
 block discarded – undo
204 204
     protected function projectSample(array $pairs)
205 205
     {
206 206
         // Normalize eigenvectors by eig = eigVectors / eigValues
207
-        $func = function ($eigVal, $eigVect) {
207
+        $func = function($eigVal, $eigVect) {
208 208
             $m = new Matrix($eigVect, false);
209 209
             $a = $m->divideByScalar($eigVal)->toArray();
210 210
 
Please login to merge, or discard this patch.
src/Phpml/DimensionReduction/PCA.php 1 patch
Spacing   +5 added lines, -5 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,7 +160,7 @@  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
 
165 165
         $totalEigVal = array_sum($eigVals);
166 166
         // Sort eigenvalues in descending order
@@ -217,7 +217,7 @@  discard block
 block discarded – undo
217 217
             throw new \Exception("PCA has not been fitted with respect to original dataset, please run PCA::fit() first");
218 218
         }
219 219
 
220
-        if (! is_array($sample[0])) {
220
+        if (!is_array($sample[0])) {
221 221
             $sample = [$sample];
222 222
         }
223 223
 
Please login to merge, or discard this patch.
src/Phpml/Math/LinearAlgebra/EigenvalueDecomposition.php 2 patches
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -58,21 +58,21 @@
 block discarded – undo
58 58
     private $V = [];
59 59
 
60 60
     /**
61
-    *	Array for internal storage of nonsymmetric Hessenberg form.
62
-    *	@var array
63
-    */
61
+     *	Array for internal storage of nonsymmetric Hessenberg form.
62
+     *	@var array
63
+     */
64 64
     private $H = [];
65 65
 
66 66
     /**
67
-    *	Working storage for nonsymmetric algorithm.
68
-    *	@var array
69
-    */
67
+     *	Working storage for nonsymmetric algorithm.
68
+     *	@var array
69
+     */
70 70
     private $ort;
71 71
 
72 72
     /**
73
-    *	Used for complex scalar division.
74
-    *	@var float
75
-    */
73
+     *	Used for complex scalar division.
74
+     *	@var float
75
+     */
76 76
     private $cdivr;
77 77
     private $cdivi;
78 78
 
Please login to merge, or discard this patch.
Spacing   +119 added lines, -119 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
  *
6 6
  *	Class to obtain eigenvalues and eigenvectors of a real matrix.
@@ -88,10 +88,10 @@  discard block
 block discarded – undo
88 88
         //  Bowdler, Martin, Reinsch, and Wilkinson, Handbook for
89 89
         //  Auto. Comp., Vol.ii-Linear Algebra, and the corresponding
90 90
         //  Fortran subroutine in EISPACK.
91
-        $this->d = $this->V[$this->n-1];
91
+        $this->d = $this->V[$this->n - 1];
92 92
         // Householder reduction to tridiagonal form.
93
-        for ($i = $this->n-1; $i > 0; --$i) {
94
-            $i_ = $i -1;
93
+        for ($i = $this->n - 1; $i > 0; --$i) {
94
+            $i_ = $i - 1;
95 95
             // Scale to avoid under/overflow.
96 96
             $h = $scale = 0.0;
97 97
             $scale += array_sum(array_map('abs', $this->d));
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
                     $f = $this->d[$j];
124 124
                     $this->V[$j][$i] = $f;
125 125
                     $g = $this->e[$j] + $this->V[$j][$j] * $f;
126
-                    for ($k = $j+1; $k <= $i_; ++$k) {
126
+                    for ($k = $j + 1; $k <= $i_; ++$k) {
127 127
                         $g += $this->V[$k][$j] * $this->d[$k];
128 128
                         $this->e[$k] += $this->V[$k][$j] * $f;
129 129
                     }
@@ -138,7 +138,7 @@  discard block
 block discarded – undo
138 138
                     $f += $this->e[$j] * $this->d[$j];
139 139
                 }
140 140
                 $hh = $f / (2 * $h);
141
-                for ($j=0; $j < $i; ++$j) {
141
+                for ($j = 0; $j < $i; ++$j) {
142 142
                     $this->e[$j] -= $hh * $this->d[$j];
143 143
                 }
144 144
                 for ($j = 0; $j < $i; ++$j) {
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
                     for ($k = $j; $k <= $i_; ++$k) {
148 148
                         $this->V[$k][$j] -= ($f * $this->e[$k] + $g * $this->d[$k]);
149 149
                     }
150
-                    $this->d[$j] = $this->V[$i-1][$j];
150
+                    $this->d[$j] = $this->V[$i - 1][$j];
151 151
                     $this->V[$i][$j] = 0.0;
152 152
                 }
153 153
             }
@@ -155,18 +155,18 @@  discard block
 block discarded – undo
155 155
         }
156 156
 
157 157
         // Accumulate transformations.
158
-        for ($i = 0; $i < $this->n-1; ++$i) {
159
-            $this->V[$this->n-1][$i] = $this->V[$i][$i];
158
+        for ($i = 0; $i < $this->n - 1; ++$i) {
159
+            $this->V[$this->n - 1][$i] = $this->V[$i][$i];
160 160
             $this->V[$i][$i] = 1.0;
161
-            $h = $this->d[$i+1];
161
+            $h = $this->d[$i + 1];
162 162
             if ($h != 0.0) {
163 163
                 for ($k = 0; $k <= $i; ++$k) {
164
-                    $this->d[$k] = $this->V[$k][$i+1] / $h;
164
+                    $this->d[$k] = $this->V[$k][$i + 1] / $h;
165 165
                 }
166 166
                 for ($j = 0; $j <= $i; ++$j) {
167 167
                     $g = 0.0;
168 168
                     for ($k = 0; $k <= $i; ++$k) {
169
-                        $g += $this->V[$k][$i+1] * $this->V[$k][$j];
169
+                        $g += $this->V[$k][$i + 1] * $this->V[$k][$j];
170 170
                     }
171 171
                     for ($k = 0; $k <= $i; ++$k) {
172 172
                         $this->V[$k][$j] -= $g * $this->d[$k];
@@ -174,13 +174,13 @@  discard block
 block discarded – undo
174 174
                 }
175 175
             }
176 176
             for ($k = 0; $k <= $i; ++$k) {
177
-                $this->V[$k][$i+1] = 0.0;
177
+                $this->V[$k][$i + 1] = 0.0;
178 178
             }
179 179
         }
180 180
 
181
-        $this->d = $this->V[$this->n-1];
182
-        $this->V[$this->n-1] = array_fill(0, $j, 0.0);
183
-        $this->V[$this->n-1][$this->n-1] = 1.0;
181
+        $this->d = $this->V[$this->n - 1];
182
+        $this->V[$this->n - 1] = array_fill(0, $j, 0.0);
183
+        $this->V[$this->n - 1][$this->n - 1] = 1.0;
184 184
         $this->e[0] = 0.0;
185 185
     }
186 186
 
@@ -196,9 +196,9 @@  discard block
 block discarded – undo
196 196
     private function tql2()
197 197
     {
198 198
         for ($i = 1; $i < $this->n; ++$i) {
199
-            $this->e[$i-1] = $this->e[$i];
199
+            $this->e[$i - 1] = $this->e[$i];
200 200
         }
201
-        $this->e[$this->n-1] = 0.0;
201
+        $this->e[$this->n - 1] = 0.0;
202 202
         $f = 0.0;
203 203
         $tst1 = 0.0;
204 204
         $eps  = pow(2.0, -52.0);
@@ -222,14 +222,14 @@  discard block
 block discarded – undo
222 222
                     $iter += 1;
223 223
                     // Compute implicit shift
224 224
                     $g = $this->d[$l];
225
-                    $p = ($this->d[$l+1] - $g) / (2.0 * $this->e[$l]);
225
+                    $p = ($this->d[$l + 1] - $g) / (2.0 * $this->e[$l]);
226 226
                     $r = hypot($p, 1.0);
227 227
                     if ($p < 0) {
228 228
                         $r *= -1;
229 229
                     }
230 230
                     $this->d[$l] = $this->e[$l] / ($p + $r);
231
-                    $this->d[$l+1] = $this->e[$l] * ($p + $r);
232
-                    $dl1 = $this->d[$l+1];
231
+                    $this->d[$l + 1] = $this->e[$l] * ($p + $r);
232
+                    $dl1 = $this->d[$l + 1];
233 233
                     $h = $g - $this->d[$l];
234 234
                     for ($i = $l + 2; $i < $this->n; ++$i) {
235 235
                         $this->d[$i] -= $h;
@@ -241,22 +241,22 @@  discard block
 block discarded – undo
241 241
                     $c2 = $c3 = $c;
242 242
                     $el1 = $this->e[$l + 1];
243 243
                     $s = $s2 = 0.0;
244
-                    for ($i = $m-1; $i >= $l; --$i) {
244
+                    for ($i = $m - 1; $i >= $l; --$i) {
245 245
                         $c3 = $c2;
246 246
                         $c2 = $c;
247 247
                         $s2 = $s;
248 248
                         $g  = $c * $this->e[$i];
249 249
                         $h  = $c * $p;
250 250
                         $r  = hypot($p, $this->e[$i]);
251
-                        $this->e[$i+1] = $s * $r;
251
+                        $this->e[$i + 1] = $s * $r;
252 252
                         $s = $this->e[$i] / $r;
253 253
                         $c = $p / $r;
254 254
                         $p = $c * $this->d[$i] - $s * $g;
255
-                        $this->d[$i+1] = $h + $s * ($c * $g + $s * $this->d[$i]);
255
+                        $this->d[$i + 1] = $h + $s * ($c * $g + $s * $this->d[$i]);
256 256
                         // Accumulate transformation.
257 257
                         for ($k = 0; $k < $this->n; ++$k) {
258
-                            $h = $this->V[$k][$i+1];
259
-                            $this->V[$k][$i+1] = $s * $this->V[$k][$i] + $c * $h;
258
+                            $h = $this->V[$k][$i + 1];
259
+                            $this->V[$k][$i + 1] = $s * $this->V[$k][$i] + $c * $h;
260 260
                             $this->V[$k][$i] = $c * $this->V[$k][$i] - $s * $h;
261 261
                         }
262 262
                     }
@@ -274,7 +274,7 @@  discard block
 block discarded – undo
274 274
         for ($i = 0; $i < $this->n - 1; ++$i) {
275 275
             $k = $i;
276 276
             $p = $this->d[$i];
277
-            for ($j = $i+1; $j < $this->n; ++$j) {
277
+            for ($j = $i + 1; $j < $this->n; ++$j) {
278 278
                 if ($this->d[$j] < $p) {
279 279
                     $k = $j;
280 280
                     $p = $this->d[$j];
@@ -304,19 +304,19 @@  discard block
 block discarded – undo
304 304
     private function orthes()
305 305
     {
306 306
         $low  = 0;
307
-        $high = $this->n-1;
307
+        $high = $this->n - 1;
308 308
 
309
-        for ($m = $low+1; $m <= $high-1; ++$m) {
309
+        for ($m = $low + 1; $m <= $high - 1; ++$m) {
310 310
             // Scale column.
311 311
             $scale = 0.0;
312 312
             for ($i = $m; $i <= $high; ++$i) {
313
-                $scale = $scale + abs($this->H[$i][$m-1]);
313
+                $scale = $scale + abs($this->H[$i][$m - 1]);
314 314
             }
315 315
             if ($scale != 0.0) {
316 316
                 // Compute Householder transformation.
317 317
                 $h = 0.0;
318 318
                 for ($i = $high; $i >= $m; --$i) {
319
-                    $this->ort[$i] = $this->H[$i][$m-1] / $scale;
319
+                    $this->ort[$i] = $this->H[$i][$m - 1] / $scale;
320 320
                     $h += $this->ort[$i] * $this->ort[$i];
321 321
                 }
322 322
                 $g = sqrt($h);
@@ -348,7 +348,7 @@  discard block
 block discarded – undo
348 348
                     }
349 349
                 }
350 350
                 $this->ort[$m] = $scale * $this->ort[$m];
351
-                $this->H[$m][$m-1] = $scale * $g;
351
+                $this->H[$m][$m - 1] = $scale * $g;
352 352
             }
353 353
         }
354 354
 
@@ -358,10 +358,10 @@  discard block
 block discarded – undo
358 358
                 $this->V[$i][$j] = ($i == $j ? 1.0 : 0.0);
359 359
             }
360 360
         }
361
-        for ($m = $high-1; $m >= $low+1; --$m) {
362
-            if ($this->H[$m][$m-1] != 0.0) {
363
-                for ($i = $m+1; $i <= $high; ++$i) {
364
-                    $this->ort[$i] = $this->H[$i][$m-1];
361
+        for ($m = $high - 1; $m >= $low + 1; --$m) {
362
+            if ($this->H[$m][$m - 1] != 0.0) {
363
+                for ($i = $m + 1; $i <= $high; ++$i) {
364
+                    $this->ort[$i] = $this->H[$i][$m - 1];
365 365
                 }
366 366
                 for ($j = $m; $j <= $high; ++$j) {
367 367
                     $g = 0.0;
@@ -369,7 +369,7 @@  discard block
 block discarded – undo
369 369
                         $g += $this->ort[$i] * $this->V[$i][$j];
370 370
                     }
371 371
                     // Double division avoids possible underflow
372
-                    $g = ($g / $this->ort[$m]) / $this->H[$m][$m-1];
372
+                    $g = ($g / $this->ort[$m]) / $this->H[$m][$m - 1];
373 373
                     for ($i = $m; $i <= $high; ++$i) {
374 374
                         $this->V[$i][$j] += $g * $this->ort[$i];
375 375
                     }
@@ -424,7 +424,7 @@  discard block
 block discarded – undo
424 424
                 $this->d[$i] = $this->H[$i][$i];
425 425
                 $this->e[$i] = 0.0;
426 426
             }
427
-            for ($j = max($i-1, 0); $j < $nn; ++$j) {
427
+            for ($j = max($i - 1, 0); $j < $nn; ++$j) {
428 428
                 $norm = $norm + abs($this->H[$i][$j]);
429 429
             }
430 430
         }
@@ -435,11 +435,11 @@  discard block
 block discarded – undo
435 435
             // Look for single small sub-diagonal element
436 436
             $l = $n;
437 437
             while ($l > $low) {
438
-                $s = abs($this->H[$l-1][$l-1]) + abs($this->H[$l][$l]);
438
+                $s = abs($this->H[$l - 1][$l - 1]) + abs($this->H[$l][$l]);
439 439
                 if ($s == 0.0) {
440 440
                     $s = $norm;
441 441
                 }
442
-                if (abs($this->H[$l][$l-1]) < $eps * $s) {
442
+                if (abs($this->H[$l][$l - 1]) < $eps * $s) {
443 443
                     break;
444 444
                 }
445 445
                 --$l;
@@ -453,13 +453,13 @@  discard block
 block discarded – undo
453 453
                 --$n;
454 454
                 $iter = 0;
455 455
             // Two roots found
456
-            } elseif ($l == $n-1) {
457
-                $w = $this->H[$n][$n-1] * $this->H[$n-1][$n];
458
-                $p = ($this->H[$n-1][$n-1] - $this->H[$n][$n]) / 2.0;
456
+            } elseif ($l == $n - 1) {
457
+                $w = $this->H[$n][$n - 1] * $this->H[$n - 1][$n];
458
+                $p = ($this->H[$n - 1][$n - 1] - $this->H[$n][$n]) / 2.0;
459 459
                 $q = $p * $p + $w;
460 460
                 $z = sqrt(abs($q));
461 461
                 $this->H[$n][$n] = $this->H[$n][$n] + $exshift;
462
-                $this->H[$n-1][$n-1] = $this->H[$n-1][$n-1] + $exshift;
462
+                $this->H[$n - 1][$n - 1] = $this->H[$n - 1][$n - 1] + $exshift;
463 463
                 $x = $this->H[$n][$n];
464 464
                 // Real pair
465 465
                 if ($q >= 0) {
@@ -468,14 +468,14 @@  discard block
 block discarded – undo
468 468
                     } else {
469 469
                         $z = $p - $z;
470 470
                     }
471
-                    $this->d[$n-1] = $x + $z;
472
-                    $this->d[$n] = $this->d[$n-1];
471
+                    $this->d[$n - 1] = $x + $z;
472
+                    $this->d[$n] = $this->d[$n - 1];
473 473
                     if ($z != 0.0) {
474 474
                         $this->d[$n] = $x - $w / $z;
475 475
                     }
476
-                    $this->e[$n-1] = 0.0;
476
+                    $this->e[$n - 1] = 0.0;
477 477
                     $this->e[$n] = 0.0;
478
-                    $x = $this->H[$n][$n-1];
478
+                    $x = $this->H[$n][$n - 1];
479 479
                     $s = abs($x) + abs($z);
480 480
                     $p = $x / $s;
481 481
                     $q = $z / $s;
@@ -483,28 +483,28 @@  discard block
 block discarded – undo
483 483
                     $p = $p / $r;
484 484
                     $q = $q / $r;
485 485
                     // Row modification
486
-                    for ($j = $n-1; $j < $nn; ++$j) {
487
-                        $z = $this->H[$n-1][$j];
488
-                        $this->H[$n-1][$j] = $q * $z + $p * $this->H[$n][$j];
486
+                    for ($j = $n - 1; $j < $nn; ++$j) {
487
+                        $z = $this->H[$n - 1][$j];
488
+                        $this->H[$n - 1][$j] = $q * $z + $p * $this->H[$n][$j];
489 489
                         $this->H[$n][$j] = $q * $this->H[$n][$j] - $p * $z;
490 490
                     }
491 491
                     // Column modification
492 492
                     for ($i = 0; $i <= $n; ++$i) {
493
-                        $z = $this->H[$i][$n-1];
494
-                        $this->H[$i][$n-1] = $q * $z + $p * $this->H[$i][$n];
493
+                        $z = $this->H[$i][$n - 1];
494
+                        $this->H[$i][$n - 1] = $q * $z + $p * $this->H[$i][$n];
495 495
                         $this->H[$i][$n] = $q * $this->H[$i][$n] - $p * $z;
496 496
                     }
497 497
                     // Accumulate transformations
498 498
                     for ($i = $low; $i <= $high; ++$i) {
499
-                        $z = $this->V[$i][$n-1];
500
-                        $this->V[$i][$n-1] = $q * $z + $p * $this->V[$i][$n];
499
+                        $z = $this->V[$i][$n - 1];
500
+                        $this->V[$i][$n - 1] = $q * $z + $p * $this->V[$i][$n];
501 501
                         $this->V[$i][$n] = $q * $this->V[$i][$n] - $p * $z;
502 502
                     }
503 503
                 // Complex pair
504 504
                 } else {
505
-                    $this->d[$n-1] = $x + $p;
505
+                    $this->d[$n - 1] = $x + $p;
506 506
                     $this->d[$n] = $x + $p;
507
-                    $this->e[$n-1] = $z;
507
+                    $this->e[$n - 1] = $z;
508 508
                     $this->e[$n] = -$z;
509 509
                 }
510 510
                 $n = $n - 2;
@@ -516,8 +516,8 @@  discard block
 block discarded – undo
516 516
                 $y = 0.0;
517 517
                 $w = 0.0;
518 518
                 if ($l < $n) {
519
-                    $y = $this->H[$n-1][$n-1];
520
-                    $w = $this->H[$n][$n-1] * $this->H[$n-1][$n];
519
+                    $y = $this->H[$n - 1][$n - 1];
520
+                    $w = $this->H[$n][$n - 1] * $this->H[$n - 1][$n];
521 521
                 }
522 522
                 // Wilkinson's original ad hoc shift
523 523
                 if ($iter == 10) {
@@ -525,7 +525,7 @@  discard block
 block discarded – undo
525 525
                     for ($i = $low; $i <= $n; ++$i) {
526 526
                         $this->H[$i][$i] -= $x;
527 527
                     }
528
-                    $s = abs($this->H[$n][$n-1]) + abs($this->H[$n-1][$n-2]);
528
+                    $s = abs($this->H[$n][$n - 1]) + abs($this->H[$n - 1][$n - 2]);
529 529
                     $x = $y = 0.75 * $s;
530 530
                     $w = -0.4375 * $s * $s;
531 531
                 }
@@ -554,9 +554,9 @@  discard block
 block discarded – undo
554 554
                     $z = $this->H[$m][$m];
555 555
                     $r = $x - $z;
556 556
                     $s = $y - $z;
557
-                    $p = ($r * $s - $w) / $this->H[$m+1][$m] + $this->H[$m][$m+1];
558
-                    $q = $this->H[$m+1][$m+1] - $z - $r - $s;
559
-                    $r = $this->H[$m+2][$m+1];
557
+                    $p = ($r * $s - $w) / $this->H[$m + 1][$m] + $this->H[$m][$m + 1];
558
+                    $q = $this->H[$m + 1][$m + 1] - $z - $r - $s;
559
+                    $r = $this->H[$m + 2][$m + 1];
560 560
                     $s = abs($p) + abs($q) + abs($r);
561 561
                     $p = $p / $s;
562 562
                     $q = $q / $s;
@@ -564,25 +564,25 @@  discard block
 block discarded – undo
564 564
                     if ($m == $l) {
565 565
                         break;
566 566
                     }
567
-                    if (abs($this->H[$m][$m-1]) * (abs($q) + abs($r)) <
568
-                        $eps * (abs($p) * (abs($this->H[$m-1][$m-1]) + abs($z) + abs($this->H[$m+1][$m+1])))) {
567
+                    if (abs($this->H[$m][$m - 1]) * (abs($q) + abs($r)) <
568
+                        $eps * (abs($p) * (abs($this->H[$m - 1][$m - 1]) + abs($z) + abs($this->H[$m + 1][$m + 1])))) {
569 569
                         break;
570 570
                     }
571 571
                     --$m;
572 572
                 }
573 573
                 for ($i = $m + 2; $i <= $n; ++$i) {
574
-                    $this->H[$i][$i-2] = 0.0;
575
-                    if ($i > $m+2) {
576
-                        $this->H[$i][$i-3] = 0.0;
574
+                    $this->H[$i][$i - 2] = 0.0;
575
+                    if ($i > $m + 2) {
576
+                        $this->H[$i][$i - 3] = 0.0;
577 577
                     }
578 578
                 }
579 579
                 // Double QR step involving rows l:n and columns m:n
580
-                for ($k = $m; $k <= $n-1; ++$k) {
581
-                    $notlast = ($k != $n-1);
580
+                for ($k = $m; $k <= $n - 1; ++$k) {
581
+                    $notlast = ($k != $n - 1);
582 582
                     if ($k != $m) {
583
-                        $p = $this->H[$k][$k-1];
584
-                        $q = $this->H[$k+1][$k-1];
585
-                        $r = ($notlast ? $this->H[$k+2][$k-1] : 0.0);
583
+                        $p = $this->H[$k][$k - 1];
584
+                        $q = $this->H[$k + 1][$k - 1];
585
+                        $r = ($notlast ? $this->H[$k + 2][$k - 1] : 0.0);
586 586
                         $x = abs($p) + abs($q) + abs($r);
587 587
                         if ($x != 0.0) {
588 588
                             $p = $p / $x;
@@ -599,9 +599,9 @@  discard block
 block discarded – undo
599 599
                     }
600 600
                     if ($s != 0) {
601 601
                         if ($k != $m) {
602
-                            $this->H[$k][$k-1] = -$s * $x;
602
+                            $this->H[$k][$k - 1] = -$s * $x;
603 603
                         } elseif ($l != $m) {
604
-                            $this->H[$k][$k-1] = -$this->H[$k][$k-1];
604
+                            $this->H[$k][$k - 1] = -$this->H[$k][$k - 1];
605 605
                         }
606 606
                         $p = $p + $s;
607 607
                         $x = $p / $s;
@@ -611,33 +611,33 @@  discard block
 block discarded – undo
611 611
                         $r = $r / $p;
612 612
                         // Row modification
613 613
                         for ($j = $k; $j < $nn; ++$j) {
614
-                            $p = $this->H[$k][$j] + $q * $this->H[$k+1][$j];
614
+                            $p = $this->H[$k][$j] + $q * $this->H[$k + 1][$j];
615 615
                             if ($notlast) {
616
-                                $p = $p + $r * $this->H[$k+2][$j];
617
-                                $this->H[$k+2][$j] = $this->H[$k+2][$j] - $p * $z;
616
+                                $p = $p + $r * $this->H[$k + 2][$j];
617
+                                $this->H[$k + 2][$j] = $this->H[$k + 2][$j] - $p * $z;
618 618
                             }
619 619
                             $this->H[$k][$j] = $this->H[$k][$j] - $p * $x;
620
-                            $this->H[$k+1][$j] = $this->H[$k+1][$j] - $p * $y;
620
+                            $this->H[$k + 1][$j] = $this->H[$k + 1][$j] - $p * $y;
621 621
                         }
622 622
                         // Column modification
623
-                        for ($i = 0; $i <= min($n, $k+3); ++$i) {
624
-                            $p = $x * $this->H[$i][$k] + $y * $this->H[$i][$k+1];
623
+                        for ($i = 0; $i <= min($n, $k + 3); ++$i) {
624
+                            $p = $x * $this->H[$i][$k] + $y * $this->H[$i][$k + 1];
625 625
                             if ($notlast) {
626
-                                $p = $p + $z * $this->H[$i][$k+2];
627
-                                $this->H[$i][$k+2] = $this->H[$i][$k+2] - $p * $r;
626
+                                $p = $p + $z * $this->H[$i][$k + 2];
627
+                                $this->H[$i][$k + 2] = $this->H[$i][$k + 2] - $p * $r;
628 628
                             }
629 629
                             $this->H[$i][$k] = $this->H[$i][$k] - $p;
630
-                            $this->H[$i][$k+1] = $this->H[$i][$k+1] - $p * $q;
630
+                            $this->H[$i][$k + 1] = $this->H[$i][$k + 1] - $p * $q;
631 631
                         }
632 632
                         // Accumulate transformations
633 633
                         for ($i = $low; $i <= $high; ++$i) {
634
-                            $p = $x * $this->V[$i][$k] + $y * $this->V[$i][$k+1];
634
+                            $p = $x * $this->V[$i][$k] + $y * $this->V[$i][$k + 1];
635 635
                             if ($notlast) {
636
-                                $p = $p + $z * $this->V[$i][$k+2];
637
-                                $this->V[$i][$k+2] = $this->V[$i][$k+2] - $p * $r;
636
+                                $p = $p + $z * $this->V[$i][$k + 2];
637
+                                $this->V[$i][$k + 2] = $this->V[$i][$k + 2] - $p * $r;
638 638
                             }
639 639
                             $this->V[$i][$k] = $this->V[$i][$k] - $p;
640
-                            $this->V[$i][$k+1] = $this->V[$i][$k+1] - $p * $q;
640
+                            $this->V[$i][$k + 1] = $this->V[$i][$k + 1] - $p * $q;
641 641
                         }
642 642
                     }  // ($s != 0)
643 643
                 }  // k loop
@@ -649,14 +649,14 @@  discard block
 block discarded – undo
649 649
             return;
650 650
         }
651 651
 
652
-        for ($n = $nn-1; $n >= 0; --$n) {
652
+        for ($n = $nn - 1; $n >= 0; --$n) {
653 653
             $p = $this->d[$n];
654 654
             $q = $this->e[$n];
655 655
             // Real vector
656 656
             if ($q == 0) {
657 657
                 $l = $n;
658 658
                 $this->H[$n][$n] = 1.0;
659
-                for ($i = $n-1; $i >= 0; --$i) {
659
+                for ($i = $n - 1; $i >= 0; --$i) {
660 660
                     $w = $this->H[$i][$i] - $p;
661 661
                     $r = 0.0;
662 662
                     for ($j = $l; $j <= $n; ++$j) {
@@ -675,15 +675,15 @@  discard block
 block discarded – undo
675 675
                             }
676 676
                         // Solve real equations
677 677
                         } else {
678
-                            $x = $this->H[$i][$i+1];
679
-                            $y = $this->H[$i+1][$i];
678
+                            $x = $this->H[$i][$i + 1];
679
+                            $y = $this->H[$i + 1][$i];
680 680
                             $q = ($this->d[$i] - $p) * ($this->d[$i] - $p) + $this->e[$i] * $this->e[$i];
681 681
                             $t = ($x * $s - $z * $r) / $q;
682 682
                             $this->H[$i][$n] = $t;
683 683
                             if (abs($x) > abs($z)) {
684
-                                $this->H[$i+1][$n] = (-$r - $w * $t) / $x;
684
+                                $this->H[$i + 1][$n] = (-$r - $w * $t) / $x;
685 685
                             } else {
686
-                                $this->H[$i+1][$n] = (-$s - $y * $t) / $z;
686
+                                $this->H[$i + 1][$n] = (-$s - $y * $t) / $z;
687 687
                             }
688 688
                         }
689 689
                         // Overflow control
@@ -697,24 +697,24 @@  discard block
 block discarded – undo
697 697
                 }
698 698
             // Complex vector
699 699
             } elseif ($q < 0) {
700
-                $l = $n-1;
700
+                $l = $n - 1;
701 701
                 // Last vector component imaginary so matrix is triangular
702
-                if (abs($this->H[$n][$n-1]) > abs($this->H[$n-1][$n])) {
703
-                    $this->H[$n-1][$n-1] = $q / $this->H[$n][$n-1];
704
-                    $this->H[$n-1][$n] = -($this->H[$n][$n] - $p) / $this->H[$n][$n-1];
702
+                if (abs($this->H[$n][$n - 1]) > abs($this->H[$n - 1][$n])) {
703
+                    $this->H[$n - 1][$n - 1] = $q / $this->H[$n][$n - 1];
704
+                    $this->H[$n - 1][$n] = -($this->H[$n][$n] - $p) / $this->H[$n][$n - 1];
705 705
                 } else {
706
-                    $this->cdiv(0.0, -$this->H[$n-1][$n], $this->H[$n-1][$n-1] - $p, $q);
707
-                    $this->H[$n-1][$n-1] = $this->cdivr;
708
-                    $this->H[$n-1][$n]   = $this->cdivi;
706
+                    $this->cdiv(0.0, -$this->H[$n - 1][$n], $this->H[$n - 1][$n - 1] - $p, $q);
707
+                    $this->H[$n - 1][$n - 1] = $this->cdivr;
708
+                    $this->H[$n - 1][$n]   = $this->cdivi;
709 709
                 }
710
-                $this->H[$n][$n-1] = 0.0;
710
+                $this->H[$n][$n - 1] = 0.0;
711 711
                 $this->H[$n][$n] = 1.0;
712
-                for ($i = $n-2; $i >= 0; --$i) {
712
+                for ($i = $n - 2; $i >= 0; --$i) {
713 713
                     // double ra,sa,vr,vi;
714 714
                     $ra = 0.0;
715 715
                     $sa = 0.0;
716 716
                     for ($j = $l; $j <= $n; ++$j) {
717
-                        $ra = $ra + $this->H[$i][$j] * $this->H[$j][$n-1];
717
+                        $ra = $ra + $this->H[$i][$j] * $this->H[$j][$n - 1];
718 718
                         $sa = $sa + $this->H[$i][$j] * $this->H[$j][$n];
719 719
                     }
720 720
                     $w = $this->H[$i][$i] - $p;
@@ -726,34 +726,34 @@  discard block
 block discarded – undo
726 726
                         $l = $i;
727 727
                         if ($this->e[$i] == 0) {
728 728
                             $this->cdiv(-$ra, -$sa, $w, $q);
729
-                            $this->H[$i][$n-1] = $this->cdivr;
729
+                            $this->H[$i][$n - 1] = $this->cdivr;
730 730
                             $this->H[$i][$n]   = $this->cdivi;
731 731
                         } else {
732 732
                             // Solve complex equations
733
-                            $x = $this->H[$i][$i+1];
734
-                            $y = $this->H[$i+1][$i];
733
+                            $x = $this->H[$i][$i + 1];
734
+                            $y = $this->H[$i + 1][$i];
735 735
                             $vr = ($this->d[$i] - $p) * ($this->d[$i] - $p) + $this->e[$i] * $this->e[$i] - $q * $q;
736 736
                             $vi = ($this->d[$i] - $p) * 2.0 * $q;
737 737
                             if ($vr == 0.0 & $vi == 0.0) {
738 738
                                 $vr = $eps * $norm * (abs($w) + abs($q) + abs($x) + abs($y) + abs($z));
739 739
                             }
740 740
                             $this->cdiv($x * $r - $z * $ra + $q * $sa, $x * $s - $z * $sa - $q * $ra, $vr, $vi);
741
-                            $this->H[$i][$n-1] = $this->cdivr;
741
+                            $this->H[$i][$n - 1] = $this->cdivr;
742 742
                             $this->H[$i][$n]   = $this->cdivi;
743 743
                             if (abs($x) > (abs($z) + abs($q))) {
744
-                                $this->H[$i+1][$n-1] = (-$ra - $w * $this->H[$i][$n-1] + $q * $this->H[$i][$n]) / $x;
745
-                                $this->H[$i+1][$n] = (-$sa - $w * $this->H[$i][$n] - $q * $this->H[$i][$n-1]) / $x;
744
+                                $this->H[$i + 1][$n - 1] = (-$ra - $w * $this->H[$i][$n - 1] + $q * $this->H[$i][$n]) / $x;
745
+                                $this->H[$i + 1][$n] = (-$sa - $w * $this->H[$i][$n] - $q * $this->H[$i][$n - 1]) / $x;
746 746
                             } else {
747
-                                $this->cdiv(-$r - $y * $this->H[$i][$n-1], -$s - $y * $this->H[$i][$n], $z, $q);
748
-                                $this->H[$i+1][$n-1] = $this->cdivr;
749
-                                $this->H[$i+1][$n]   = $this->cdivi;
747
+                                $this->cdiv(-$r - $y * $this->H[$i][$n - 1], -$s - $y * $this->H[$i][$n], $z, $q);
748
+                                $this->H[$i + 1][$n - 1] = $this->cdivr;
749
+                                $this->H[$i + 1][$n]   = $this->cdivi;
750 750
                             }
751 751
                         }
752 752
                         // Overflow control
753
-                        $t = max(abs($this->H[$i][$n-1]), abs($this->H[$i][$n]));
753
+                        $t = max(abs($this->H[$i][$n - 1]), abs($this->H[$i][$n]));
754 754
                         if (($eps * $t) * $t > 1) {
755 755
                             for ($j = $i; $j <= $n; ++$j) {
756
-                                $this->H[$j][$n-1] = $this->H[$j][$n-1] / $t;
756
+                                $this->H[$j][$n - 1] = $this->H[$j][$n - 1] / $t;
757 757
                                 $this->H[$j][$n]   = $this->H[$j][$n] / $t;
758 758
                             }
759 759
                         }
@@ -772,7 +772,7 @@  discard block
 block discarded – undo
772 772
         }
773 773
 
774 774
         // Back transformation to get eigenvectors of original matrix
775
-        for ($j = $nn-1; $j >= $low; --$j) {
775
+        for ($j = $nn - 1; $j >= $low; --$j) {
776 776
             for ($i = $low; $i <= $high; ++$i) {
777 777
                 $z = 0.0;
778 778
                 for ($k = $low; $k <= min($j, $high); ++$k) {
@@ -829,13 +829,13 @@  discard block
 block discarded – undo
829 829
 
830 830
         // Always return the eigenvectors of length 1.0
831 831
         $vectors = new Matrix($vectors);
832
-        $vectors = array_map(function ($vect) {
832
+        $vectors = array_map(function($vect) {
833 833
             $sum = 0;
834
-            for ($i=0; $i<count($vect); $i++) {
834
+            for ($i = 0; $i < count($vect); $i++) {
835 835
                 $sum += $vect[$i] ** 2;
836 836
             }
837 837
             $sum = sqrt($sum);
838
-            for ($i=0; $i<count($vect); $i++) {
838
+            for ($i = 0; $i < count($vect); $i++) {
839 839
                 $vect[$i] /= $sum;
840 840
             }
841 841
             return $vect;
Please login to merge, or discard this patch.