Passed
Push — master ( 43f15d...7ab80b )
by Arkadiusz
03:44
created
src/Phpml/Math/Matrix.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -91,7 +91,7 @@
 block discarded – undo
91 91
     }
92 92
 
93 93
     /**
94
-     * @param $column
94
+     * @param integer $column
95 95
      *
96 96
      * @return array
97 97
      *
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 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
 
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
     public function transpose()
158 158
     {
159 159
         if ($this->rows == 1) {
160
-            $matrix = array_map(function ($el) {
160
+            $matrix = array_map(function($el) {
161 161
                 return [$el];
162 162
             }, $this->matrix[0]);
163 163
         } else {
Please login to merge, or discard this patch.
src/Phpml/Math/LinearAlgebra/LUDecomposition.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types=1);
3
+declare(strict_types = 1);
4 4
 /**
5 5
  *	@package JAMA
6 6
  *
Please login to merge, or discard this patch.
src/Phpml/Math/LinearAlgebra/EigenvalueDecomposition.php 1 patch
Spacing   +2 added lines, -2 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.
@@ -838,7 +838,7 @@  discard block
 block discarded – undo
838 838
 
839 839
         // Always return the eigenvectors of length 1.0
840 840
         $vectors = new Matrix($vectors);
841
-        $vectors = array_map(function ($vect) {
841
+        $vectors = array_map(function($vect) {
842 842
             $sum = 0;
843 843
             for ($i = 0; $i < count($vect); ++$i) {
844 844
                 $sum += $vect[$i] ** 2;
Please login to merge, or discard this patch.
src/Phpml/Math/Statistic/Covariance.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 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
 
Please login to merge, or discard this patch.
src/Phpml/DimensionReduction/PCA.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 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
 
Please login to merge, or discard this patch.
src/Phpml/DimensionReduction/KernelPCA.php 1 patch
Spacing   +7 added lines, -7 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
 
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
      */
134 134
     protected function centerMatrix(array $matrix, int $n)
135 135
     {
136
-        $N = array_fill(0, $n, array_fill(0, $n, 1.0/$n));
136
+        $N = array_fill(0, $n, array_fill(0, $n, 1.0 / $n));
137 137
         $N = new Matrix($N, false);
138 138
         $K = new Matrix($matrix, false);
139 139
 
@@ -162,19 +162,19 @@  discard block
 block discarded – undo
162 162
         switch ($this->kernel) {
163 163
             case self::KERNEL_LINEAR:
164 164
                 // k(x,y) = xT.y
165
-                return function ($x, $y) {
165
+                return function($x, $y) {
166 166
                     return Matrix::dot($x, $y)[0];
167 167
                 };
168 168
             case self::KERNEL_RBF:
169 169
                 // k(x,y)=exp(-γ.|x-y|) where |..| is Euclidean distance
170 170
                 $dist = new Euclidean();
171
-                return function ($x, $y) use ($dist) {
171
+                return function($x, $y) use ($dist) {
172 172
                     return exp(-$this->gamma * $dist->sqDistance($x, $y));
173 173
                 };
174 174
 
175 175
             case self::KERNEL_SIGMOID:
176 176
                 // k(x,y)=tanh(γ.xT.y+c0) where c0=1
177
-                return function ($x, $y) {
177
+                return function($x, $y) {
178 178
                     $res = Matrix::dot($x, $y)[0] + 1.0;
179 179
                     return tanh($this->gamma * $res);
180 180
                 };
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
             case self::KERNEL_LAPLACIAN:
183 183
                 // k(x,y)=exp(-γ.|x-y|) where |..| is Manhattan distance
184 184
                 $dist = new Manhattan();
185
-                return function ($x, $y) use ($dist) {
185
+                return function($x, $y) use ($dist) {
186 186
                     return exp(-$this->gamma * $dist->distance($x, $y));
187 187
                 };
188 188
 
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
216 216
     protected function projectSample(array $pairs)
217 217
     {
218 218
         // Normalize eigenvectors by eig = eigVectors / eigValues
219
-        $func = function ($eigVal, $eigVect) {
219
+        $func = function($eigVal, $eigVect) {
220 220
             $m = new Matrix($eigVect, false);
221 221
             $a = $m->divideByScalar($eigVal)->toArray();
222 222
 
Please login to merge, or discard this patch.
src/Phpml/DimensionReduction/LDA.php 1 patch
Spacing   +3 added lines, -3 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
 
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
     protected function calculateMeans(array $data, array $classes) : array
119 119
     {
120 120
         $means = [];
121
-        $counts= [];
121
+        $counts = [];
122 122
         $overallMean = array_fill(0, count($data[0]), 0.0);
123 123
 
124 124
         foreach ($data as $index => $row) {
@@ -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);
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,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
 
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
     {
55 55
         $eig = new EigenvalueDecomposition($matrix);
56 56
         $eigVals = $eig->getRealEigenvalues();
57
-        $eigVects= $eig->getEigenvectors();
57
+        $eigVects = $eig->getEigenvectors();
58 58
 
59 59
         $totalEigVal = array_sum($eigVals);
60 60
         // Sort eigenvalues in descending order
Please login to merge, or discard this patch.
src/Phpml/Classification/NaiveBayes.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\Classification;
6 6
 
@@ -13,8 +13,8 @@  discard block
 block discarded – undo
13 13
 {
14 14
     use Trainable, Predictable;
15 15
 
16
-    const CONTINUOS    = 1;
17
-    const NOMINAL    = 2;
16
+    const CONTINUOS = 1;
17
+    const NOMINAL = 2;
18 18
     const EPSILON = 1e-10;
19 19
 
20 20
     /**
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
     /**
26 26
      * @var array
27 27
      */
28
-    private $mean= [];
28
+    private $mean = [];
29 29
 
30 30
     /**
31 31
      * @var array
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
     private function calculateStatistics($label, $samples)
87 87
     {
88 88
         $this->std[$label] = array_fill(0, $this->featureCount, 0);
89
-        $this->mean[$label]= array_fill(0, $this->featureCount, 0);
89
+        $this->mean[$label] = array_fill(0, $this->featureCount, 0);
90 90
         $this->dataType[$label] = array_fill(0, $this->featureCount, self::CONTINUOS);
91 91
         $this->discreteProb[$label] = array_fill(0, $this->featureCount, self::CONTINUOS);
92 92
         for ($i = 0; $i < $this->featureCount; ++$i) {
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
                 $this->dataType[$label][$i] = self::NOMINAL;
101 101
                 $this->discreteProb[$label][$i] = array_count_values($values);
102 102
                 $db = &$this->discreteProb[$label][$i];
103
-                $db = array_map(function ($el) use ($numValues) {
103
+                $db = array_map(function($el) use ($numValues) {
104 104
                     return $el / $numValues;
105 105
                 }, $db);
106 106
             } else {
@@ -130,8 +130,8 @@  discard block
 block discarded – undo
130 130
             }
131 131
             return $this->discreteProb[$label][$feature][$value];
132 132
         }
133
-        $std = $this->std[$label][$feature] ;
134
-        $mean= $this->mean[$label][$feature];
133
+        $std = $this->std[$label][$feature];
134
+        $mean = $this->mean[$label][$feature];
135 135
         // Calculate the probability density by use of normal/Gaussian distribution
136 136
         // Ref: https://en.wikipedia.org/wiki/Normal_distribution
137 137
         //
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
         // some libraries adopt taking log of calculations such as
140 140
         // scikit-learn did.
141 141
         // (See : https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/naive_bayes.py)
142
-        $pdf  =  -0.5 * log(2.0 * pi() * $std * $std);
142
+        $pdf  = -0.5 * log(2.0 * pi() * $std * $std);
143 143
         $pdf -= 0.5 * pow($value - $mean, 2) / ($std * $std);
144 144
         return $pdf;
145 145
     }
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
         $predictions = [];
175 175
         foreach ($this->labels as $label) {
176 176
             $p = $this->p[$label];
177
-            for ($i = 0; $i<$this->featureCount; ++$i) {
177
+            for ($i = 0; $i < $this->featureCount; ++$i) {
178 178
                 $Plf = $this->sampleProbability($sample, $i, $label);
179 179
                 $p += $Plf;
180 180
             }
Please login to merge, or discard this patch.