Passed
Push — master ( 12b8b1...5b373f )
by Arkadiusz
04:53
created
src/Phpml/DimensionReduction/LDA.php 2 patches
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -5,7 +5,6 @@
 block discarded – undo
5 5
 namespace Phpml\DimensionReduction;
6 6
 
7 7
 
8
-use Phpml\Math\Statistic\Mean;
9 8
 use Phpml\Math\Matrix;
10 9
 
11 10
 class LDA extends EigenTransformerBase
Please login to merge, or discard this 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
 
@@ -119,21 +119,21 @@  discard block
 block discarded – undo
119 119
     protected function calculateMeans($data, $classes) : array
120 120
     {
121 121
         $means = [];
122
-        $counts= [];
122
+        $counts = [];
123 123
         $overallMean = array_fill(0, count($data[0]), 0.0);
124 124
 
125 125
         foreach ($data as $index => $row) {
126 126
             $label = array_search($classes[$index], $this->labels);
127 127
 
128 128
             foreach ($row as $col => $val) {
129
-                if (! isset($means[$label][$col])) {
129
+                if (!isset($means[$label][$col])) {
130 130
                     $means[$label][$col] = 0.0;
131 131
                 }
132 132
                 $means[$label][$col] += $val;
133 133
                 $overallMean[$col] += $val;
134 134
             }
135 135
 
136
-            if (! isset($counts[$label])) {
136
+            if (!isset($counts[$label])) {
137 137
                 $counts[$label] = 0;
138 138
             }
139 139
             $counts[$label]++;
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
 
148 148
         // Calculate overall mean of the dataset for each column
149 149
         $numElements = array_sum($counts);
150
-        $map = function ($el) use ($numElements) {
150
+        $map = function($el) use ($numElements) {
151 151
             return $el / $numElements;
152 152
         };
153 153
         $this->overallMean = array_map($map, $overallMean);
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
             throw new \Exception("LDA has not been fitted with respect to original dataset, please run LDA::fit() first");
239 239
         }
240 240
 
241
-        if (! is_array($sample[0])) {
241
+        if (!is_array($sample[0])) {
242 242
             $sample = [$sample];
243 243
         }
244 244
 
Please login to merge, or discard this patch.
src/Phpml/DimensionReduction/EigenTransformerBase.php 1 patch
Spacing   +2 added lines, -2 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
 namespace Phpml\DimensionReduction;
4 4
 
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
     {
53 53
         $eig = new EigenvalueDecomposition($matrix);
54 54
         $eigVals = $eig->getRealEigenvalues();
55
-        $eigVects= $eig->getEigenvectors();
55
+        $eigVects = $eig->getEigenvectors();
56 56
 
57 57
         $totalEigVal = array_sum($eigVals);
58 58
         // Sort eigenvalues in descending order
Please login to merge, or discard this patch.
src/Phpml/DimensionReduction/PCA.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\DimensionReduction;
6 6
 
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
     {
87 87
         // Calculate means for each dimension
88 88
         $this->means = [];
89
-        for ($i=0; $i < $n; $i++) {
89
+        for ($i = 0; $i < $n; $i++) {
90 90
             $column = array_column($data, $i);
91 91
             $this->means[] = Mean::arithmetic($column);
92 92
         }
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
 
110 110
         // Normalize data
111 111
         foreach ($data as $i => $row) {
112
-            for ($k=0; $k < $n; $k++) {
112
+            for ($k = 0; $k < $n; $k++) {
113 113
                 $data[$i][$k] -= $this->means[$k];
114 114
             }
115 115
         }
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
             throw new \Exception("PCA has not been fitted with respect to original dataset, please run PCA::fit() first");
132 132
         }
133 133
 
134
-        if (! is_array($sample[0])) {
134
+        if (!is_array($sample[0])) {
135 135
             $sample = [$sample];
136 136
         }
137 137
 
Please login to merge, or discard this patch.
src/Phpml/Math/LinearAlgebra/LUDecomposition.php 2 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
     /**
132 132
      *	Get lower triangular factor.
133 133
      *
134
-     *	@return array Lower triangular factor
134
+     *	@return Matrix Lower triangular factor
135 135
      */
136 136
     public function getL()
137 137
     {
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
     /**
155 155
      *	Get upper triangular factor.
156 156
      *
157
-     *	@return array Upper triangular factor
157
+     *	@return Matrix Upper triangular factor
158 158
      */
159 159
     public function getU()
160 160
     {
@@ -197,7 +197,7 @@  discard block
 block discarded – undo
197 197
     /**
198 198
      *	Is the matrix nonsingular?
199 199
      *
200
-     *	@return true if U, and hence A, is nonsingular.
200
+     *	@return boolean if U, and hence A, is nonsingular.
201 201
      */
202 202
     public function isNonsingular()
203 203
     {
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 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
  *	@package JAMA
4 4
  *
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
             }
103 103
             // Find pivot and exchange if necessary.
104 104
             $p = $j;
105
-            for ($i = $j+1; $i < $this->m; ++$i) {
105
+            for ($i = $j + 1; $i < $this->m; ++$i) {
106 106
                 if (abs($LUcolj[$i]) > abs($LUcolj[$p])) {
107 107
                     $p = $i;
108 108
                 }
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
             }
121 121
             // Compute multipliers.
122 122
             if (($j < $this->m) && ($this->LU[$j][$j] != 0.0)) {
123
-                for ($i = $j+1; $i < $this->m; ++$i) {
123
+                for ($i = $j + 1; $i < $this->m; ++$i) {
124 124
                     $this->LU[$i][$j] /= $this->LU[$j][$j];
125 125
                 }
126 126
             }
@@ -244,23 +244,23 @@  discard block
 block discarded – undo
244 244
             throw MatrixException::notSquareMatrix();
245 245
         }
246 246
 
247
-        if (! $this->isNonsingular()) {
247
+        if (!$this->isNonsingular()) {
248 248
             throw MatrixException::singularMatrix();
249 249
         }
250 250
 
251 251
         // Copy right hand side with pivoting
252 252
         $nx = $B->getColumns();
253
-        $X  = $this->getSubMatrix($B->toArray(), $this->piv, 0, $nx-1);
253
+        $X  = $this->getSubMatrix($B->toArray(), $this->piv, 0, $nx - 1);
254 254
         // Solve L*Y = B(piv,:)
255 255
         for ($k = 0; $k < $this->n; ++$k) {
256
-            for ($i = $k+1; $i < $this->n; ++$i) {
256
+            for ($i = $k + 1; $i < $this->n; ++$i) {
257 257
                 for ($j = 0; $j < $nx; ++$j) {
258 258
                     $X[$i][$j] -= $X[$k][$j] * $this->LU[$i][$k];
259 259
                 }
260 260
             }
261 261
         }
262 262
         // Solve U*X = Y;
263
-        for ($k = $this->n-1; $k >= 0; --$k) {
263
+        for ($k = $this->n - 1; $k >= 0; --$k) {
264 264
             for ($j = 0; $j < $nx; ++$j) {
265 265
                 $X[$k][$j] /= $this->LU[$k][$k];
266 266
             }
@@ -284,11 +284,11 @@  discard block
 block discarded – undo
284 284
     {
285 285
         $m = count($RL);
286 286
         $n = $jF - $j0;
287
-        $R = array_fill(0, $m, array_fill(0, $n+1, 0.0));
287
+        $R = array_fill(0, $m, array_fill(0, $n + 1, 0.0));
288 288
 
289 289
         for ($i = 0; $i < $m; ++$i) {
290 290
             for ($j = $j0; $j <= $jF; ++$j) {
291
-                $R[$i][$j - $j0]= $matrix[ $RL[$i] ][$j];
291
+                $R[$i][$j - $j0] = $matrix[$RL[$i]][$j];
292 292
             }
293 293
         }
294 294
 
Please login to merge, or discard this patch.
src/Phpml/Math/Matrix.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\Math;
6 6
 
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
     public function transpose()
181 181
     {
182 182
         if ($this->rows == 1) {
183
-            $matrix = array_map(function ($el) {
183
+            $matrix = array_map(function($el) {
184 184
                 return [$el];
185 185
             }, $this->matrix[0]);
186 186
         } else {
@@ -284,8 +284,8 @@  discard block
 block discarded – undo
284 284
         $a2 = $other->toArray();
285 285
 
286 286
         $newMatrix = [];
287
-        for ($i=0; $i < $this->rows; $i++) {
288
-            for ($k=0; $k < $this->columns; $k++) {
287
+        for ($i = 0; $i < $this->rows; $i++) {
288
+            for ($k = 0; $k < $this->columns; $k++) {
289 289
                 $newMatrix[$i][$k] = $a1[$i][$k] + $sign * $a2[$i][$k];
290 290
             }
291 291
         }
@@ -349,7 +349,7 @@  discard block
 block discarded – undo
349 349
     protected function getIdentity()
350 350
     {
351 351
         $array = array_fill(0, $this->rows, array_fill(0, $this->columns, 0));
352
-        for ($i=0; $i < $this->rows; $i++) {
352
+        for ($i = 0; $i < $this->rows; $i++) {
353 353
             $array[$i][$i] = 1;
354 354
         }
355 355
 
Please login to merge, or discard this patch.