Passed
Push — master ( 3989eb...44f0a8 )
by Ruben
01:51
created
src/Configuration.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -197,7 +197,7 @@
 block discarded – undo
197 197
      */
198 198
     private static function getStringParameter($config, $section, $name)
199 199
     {    
200
-        return isset($config[$section][$name]) ?  $config[$section][$name] : NULL;
200
+        return isset($config[$section][$name]) ? $config[$section][$name] : NULL;
201 201
     }
202 202
     
203 203
     /*
Please login to merge, or discard this patch.
src/Matrix.php 3 patches
Braces   +24 added lines, -8 removed lines patch added patch discarded remove patch
@@ -24,10 +24,14 @@  discard block
 block discarded – undo
24 24
     public static function submatrix($matrix, $columns)
25 25
     {
26 26
         $n = count($matrix);
27
-        if ($n == 0) return [];
27
+        if ($n == 0) {
28
+            return [];
29
+        }
28 30
        
29 31
         $m = count($matrix[0]);
30
-        if ($m == 0) return $matrix;
32
+        if ($m == 0) {
33
+            return $matrix;
34
+        }
31 35
        
32 36
         $result = [];       
33 37
         for ($i=0; $i<$n; $i++) {
@@ -47,7 +51,9 @@  discard block
 block discarded – undo
47 51
     public static function toSquareMatrix($matrix, $ncol, $mcol, $vcol, $sparse = False)
48 52
     {
49 53
         $n = count($matrix);
50
-        if ($n == 0) return [];
54
+        if ($n == 0) {
55
+            return [];
56
+        }
51 57
         
52 58
         $labels = [];
53 59
         $id = 0;
@@ -64,7 +70,9 @@  discard block
 block discarded – undo
64 70
             $val = $matrix[$i][$vcol];
65 71
             $data[] = [$nid, $mid, $val];
66 72
         }
67
-        if ($sparse) return ["data" => $data, "labels" => $labels];
73
+        if ($sparse) {
74
+            return ["data" => $data, "labels" => $labels];
75
+        }
68 76
         $nlab = count($labels);
69 77
         $result = [];
70 78
         for ($i=0; $i<$nlab; $i++) {           
@@ -84,7 +92,9 @@  discard block
 block discarded – undo
84 92
     {
85 93
         $result = [];
86 94
         $n = count($matrix1);        
87
-        if ($n != count($matrix2)) throw new \Exception("Summing non compatible matrices. ");
95
+        if ($n != count($matrix2)) {
96
+            throw new \Exception("Summing non compatible matrices. ");
97
+        }
88 98
         $m = count($matrix1[0]);
89 99
         for ($i=0;$i<$n;$i++) {
90 100
             $tmp = [];
@@ -107,7 +117,9 @@  discard block
 block discarded – undo
107 117
         $n2 = count($matrix2);        
108 118
         $m2 = count($matrix2[0]);
109 119
         
110
-        if ($n2 !== $m1) throw new \Exception("Incompatible matrices: matrix1.columns != matrix2.rows");
120
+        if ($n2 !== $m1) {
121
+            throw new \Exception("Incompatible matrices: matrix1.columns != matrix2.rows");
122
+        }
111 123
 
112 124
         $result = [];
113 125
         for ($i=0; $i<$n1; $i++) {           
@@ -154,9 +166,13 @@  discard block
 block discarded – undo
154 166
      */
155 167
     public static function power($matrix, $n)
156 168
     {
157
-        if($n <= 1) return $matrix;        
169
+        if($n <= 1) {
170
+            return $matrix;
171
+        }
158 172
         $resp = self::multiply($matrix, $matrix);
159
-        if($n == 2) return $resp;
173
+        if($n == 2) {
174
+            return $resp;
175
+        }
160 176
         for($i=2; $i<$n; $i++) {
161 177
             $resp = self::multiply($resp, $matrix);
162 178
         }
Please login to merge, or discard this patch.
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -24,13 +24,13 @@  discard block
 block discarded – undo
24 24
     public static function submatrix($matrix, $columns)
25 25
     {
26 26
         $n = count($matrix);
27
-        if ($n == 0) return [];
27
+        if ($n==0) return [];
28 28
        
29 29
         $m = count($matrix[0]);
30
-        if ($m == 0) return $matrix;
30
+        if ($m==0) return $matrix;
31 31
        
32 32
         $result = [];       
33
-        for ($i=0; $i<$n; $i++) {
33
+        for ($i = 0; $i < $n; $i++) {
34 34
             $tmp = [];
35 35
             foreach ($columns as $col) {
36 36
                 $tmp[] = $matrix[$i][$col];
@@ -47,17 +47,17 @@  discard block
 block discarded – undo
47 47
     public static function toSquareMatrix($matrix, $ncol, $mcol, $vcol, $sparse = False)
48 48
     {
49 49
         $n = count($matrix);
50
-        if ($n == 0) return [];
50
+        if ($n==0) return [];
51 51
         
52 52
         $labels = [];
53 53
         $id = 0;
54 54
         $data = [];
55
-        for ($i=0; $i<$n; $i++) {  
56
-            if (!array_key_exists($matrix[$i][$ncol],$labels)) {
55
+        for ($i = 0; $i < $n; $i++) {  
56
+            if (!array_key_exists($matrix[$i][$ncol], $labels)) {
57 57
                 $labels[$matrix[$i][$ncol]] = $id++;
58 58
             }      
59 59
             $nid = $labels[$matrix[$i][$ncol]];
60
-            if (!array_key_exists($matrix[$i][$mcol],$labels)) {
60
+            if (!array_key_exists($matrix[$i][$mcol], $labels)) {
61 61
                 $labels[$matrix[$i][$mcol]] = $id++;
62 62
             }
63 63
             $mid = $labels[$matrix[$i][$mcol]];
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
         if ($sparse) return ["data" => $data, "labels" => $labels];
68 68
         $nlab = count($labels);
69 69
         $result = [];
70
-        for ($i=0; $i<$nlab; $i++) {           
70
+        for ($i = 0; $i < $nlab; $i++) {           
71 71
             $tmp = array_fill(0, $nlab, 0);
72 72
             $result[] = $tmp;
73 73
         }
@@ -84,11 +84,11 @@  discard block
 block discarded – undo
84 84
     {
85 85
         $result = [];
86 86
         $n = count($matrix1);        
87
-        if ($n != count($matrix2)) throw new \Exception("Summing non compatible matrices. ");
87
+        if ($n!=count($matrix2)) throw new \Exception("Summing non compatible matrices. ");
88 88
         $m = count($matrix1[0]);
89
-        for ($i=0;$i<$n;$i++) {
89
+        for ($i = 0; $i < $n; $i++) {
90 90
             $tmp = [];
91
-            for($j=0;$j<$m;$j++) {
91
+            for ($j = 0; $j < $m; $j++) {
92 92
                 $tmp[] = $matrix1[$i][$j] + $matrix2[$i][$j];
93 93
             }
94 94
             $result[] = $tmp;
@@ -107,16 +107,16 @@  discard block
 block discarded – undo
107 107
         $n2 = count($matrix2);        
108 108
         $m2 = count($matrix2[0]);
109 109
         
110
-        if ($n2 !== $m1) throw new \Exception("Incompatible matrices: matrix1.columns != matrix2.rows");
110
+        if ($n2!==$m1) throw new \Exception("Incompatible matrices: matrix1.columns != matrix2.rows");
111 111
 
112 112
         $result = [];
113
-        for ($i=0; $i<$n1; $i++) {           
113
+        for ($i = 0; $i < $n1; $i++) {           
114 114
             $result[] = array_fill(0, $m2, 0);                    
115 115
         }
116
-        for ($i=0; $i<$n1; $i++) {
117
-            for ($j=0; $j<$m2; $j++) {
118
-                 for ($k=0; $k<$n2; $k++) {
119
-                     $result[$i][$j] += $matrix1[$i][$k]*$matrix2[$k][$j];
116
+        for ($i = 0; $i < $n1; $i++) {
117
+            for ($j = 0; $j < $m2; $j++) {
118
+                 for ($k = 0; $k < $n2; $k++) {
119
+                     $result[$i][$j] += $matrix1[$i][$k] * $matrix2[$k][$j];
120 120
                  }
121 121
             }
122 122
         }        
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
         foreach ($matrix as $row) {
132 132
             $tmp = [];
133 133
             foreach ($row as $dat) {
134
-                $tmp[] = $dat == 0 ? 0 : 1;
134
+                $tmp[] = $dat==0 ? 0 : 1;
135 135
             }
136 136
             $resp[] = $tmp;
137 137
         }
@@ -154,10 +154,10 @@  discard block
 block discarded – undo
154 154
      */
155 155
     public static function power($matrix, $n)
156 156
     {
157
-        if($n <= 1) return $matrix;        
157
+        if ($n <= 1) return $matrix;        
158 158
         $resp = self::multiply($matrix, $matrix);
159
-        if($n == 2) return $resp;
160
-        for($i=2; $i<$n; $i++) {
159
+        if ($n==2) return $resp;
160
+        for ($i = 2; $i < $n; $i++) {
161 161
             $resp = self::multiply($resp, $matrix);
162 162
         }
163 163
         return $resp;
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
     public static function sumArray($array1, $array2) {
170 170
         $resp = [];
171 171
         $n = min([count($array1), count($array2)]);
172
-        for ($i=0;$i<$n;$i++){
172
+        for ($i = 0; $i < $n; $i++) {
173 173
             $resp[] = $array1[$i] + $array2[$i];
174 174
         }
175 175
         return $resp;
Please login to merge, or discard this patch.
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
     {
85 85
         $resp = [];
86 86
         foreach ($matrix as $row) {
87
-           $resp[] = $row[$col];
87
+            $resp[] = $row[$col];
88 88
         }
89 89
         return $resp;
90 90
     }
@@ -127,9 +127,9 @@  discard block
 block discarded – undo
127 127
         }
128 128
         for ($i=0; $i<$n1; $i++) {
129 129
             for ($j=0; $j<$m2; $j++) {
130
-                 for ($k=0; $k<$n2; $k++) {
131
-                     $result[$i][$j] += $matrix1[$i][$k]*$matrix2[$k][$j];
132
-                 }
130
+                    for ($k=0; $k<$n2; $k++) {
131
+                        $result[$i][$j] += $matrix1[$i][$k]*$matrix2[$k][$j];
132
+                    }
133 133
             }
134 134
         }        
135 135
         return $result;
Please login to merge, or discard this patch.
src/Persistence.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
      * @param $config Configuration
176 176
      *
177 177
      */
178
-    public static function getCountsFromTest($pdo, $config, $tests){
178
+    public static function getCountsFromTest($pdo, $config, $tests) {
179 179
         $resp = [];
180 180
         foreach ($tests as $test) {
181 181
             $counts = self::getCountsById($pdo, $config, $test[0]);
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
      * @param $config Configuration
190 190
      *
191 191
      */
192
-    public static function getFromByTest($pdo, $config, $tests){
192
+    public static function getFromByTest($pdo, $config, $tests) {
193 193
         $resp = [];
194 194
         foreach ($tests as $test) {
195 195
             $counts = FromDAO::findByFromById($pdo, $config, $test[1][1], $test[1][0]);
@@ -274,7 +274,7 @@  discard block
 block discarded – undo
274 274
      * @param $config Configuration
275 275
      *
276 276
      */
277
-    public static function findIdByTimeUser($pdo, $config, $by=[]) {
277
+    public static function findIdByTimeUser($pdo, $config, $by = []) {
278 278
         return OptionsDAO::findIdByTimeUser($pdo, $config, $by);
279 279
     }
280 280
     
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -179,7 +179,9 @@
 block discarded – undo
179 179
         $resp = [];
180 180
         foreach ($tests as $test) {
181 181
             $counts = self::getCountsById($pdo, $config, $test[0]);
182
-            if (count($counts) > 0) $resp[] = $counts;            
182
+            if (count($counts) > 0) {
183
+                $resp[] = $counts;
184
+            }
183 185
         }   
184 186
         return $resp;
185 187
     }
Please login to merge, or discard this patch.
src/FromDAO.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -76,7 +76,7 @@
 block discarded – undo
76 76
         $dbFromtable = $config->getFromTableName();
77 77
         $qdata = [$id];
78 78
         $tquery = "SELECT f.* FROM $dbFromtable f WHERE f.id = ?";
79
-        if ($from_id != null) {
79
+        if ($from_id!=null) {
80 80
             $tquery = $tquery." AND f.from_id = ?";
81 81
             $qdata[] = $from_id;
82 82
         }
Please login to merge, or discard this patch.
src/SiteAnalyzer.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
      */
83 83
     public static function getPDO($config, $options)
84 84
     {
85
-        if (array_key_exists("pdo",$options)) {
85
+        if (array_key_exists("pdo", $options)) {
86 86
             return $options["pdo"];
87 87
         }         
88 88
         return  Persistence::getPDO($config);
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
         }
186 186
         
187 187
         $result = $data;
188
-        for ($i=1;$i<$level;$i++) {
188
+        for ($i = 1; $i < $level; $i++) {
189 189
             $tmp = Matrix::multiply($result, $data);
190 190
             $result = Matrix::sum($result, $tmp);
191 191
         }
@@ -218,7 +218,7 @@  discard block
 block discarded – undo
218 218
         }
219 219
         
220 220
         $result = $data;
221
-        for ($i=1;$i<$level;$i++) {
221
+        for ($i = 1; $i < $level; $i++) {
222 222
             $tmp = Matrix::multiply($result, $data);
223 223
             $result = Matrix::sum($result, $tmp);
224 224
         }
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -179,8 +179,7 @@  discard block
 block discarded – undo
179 179
         
180 180
         if (array_key_exists("level", $options)) {
181 181
             $level = $options["level"];
182
-        }
183
-        else {
182
+        } else {
184 183
             $level = count($labels) - 1;
185 184
         }
186 185
         
@@ -212,8 +211,7 @@  discard block
 block discarded – undo
212 211
         
213 212
         if (array_key_exists("level", $options)) {
214 213
             $level = $options["level"];
215
-        }
216
-        else {
214
+        } else {
217 215
             $level = count($labels) - 1;
218 216
         }
219 217
         
Please login to merge, or discard this patch.
src/Statistics.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -26,14 +26,14 @@
 block discarded – undo
26 26
     public static function ABtest($testCounts, $targetCounts, $options)
27 27
     {
28 28
         $ntotal = 0;
29
-        $resp  = [];
30
-        foreach($testCounts as $testCount) {
29
+        $resp = [];
30
+        foreach ($testCounts as $testCount) {
31 31
             $ntotal += $testCount[1];
32 32
         }
33
-        foreach($testCounts as $testCount) {
33
+        foreach ($testCounts as $testCount) {
34 34
             foreach ($targetCounts as $targetCount) {
35
-                if ($testCount[0] === $targetCount[1]) {
36
-                    $resp[] = [$testCount[0], $testCount[1], $testCount[1]/$ntotal, $targetCount[2], $targetCount[2]/$testCount[1],$targetCount[2]/$ntotal];
35
+                if ($testCount[0]===$targetCount[1]) {
36
+                    $resp[] = [$testCount[0], $testCount[1], $testCount[1] / $ntotal, $targetCount[2], $targetCount[2] / $testCount[1], $targetCount[2] / $ntotal];
37 37
                 }                
38 38
             }
39 39
             
Please login to merge, or discard this patch.
src/ML.php 3 patches
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -122,12 +122,12 @@
 block discarded – undo
122 122
      * @param
123 123
      */
124 124
     public static function eclideanDistance($p1, $p2) {
125
-       $len = count($p1);
126
-       $acum = 0;
127
-       for($i=0; $i<$len; $i++) {
128
-           $acum += ($p1[$i] - $p2[$i])**2;
129
-       }
130
-       return sqrt($acum);
125
+        $len = count($p1);
126
+        $acum = 0;
127
+        for($i=0; $i<$len; $i++) {
128
+            $acum += ($p1[$i] - $p2[$i])**2;
129
+        }
130
+        return sqrt($acum);
131 131
     }
132 132
     
133 133
 }
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -31,7 +31,9 @@
 block discarded – undo
31 31
         $niter = 0;
32 32
         $maxiter = 100;
33 33
         $npoints = count($data);
34
-        if ($npoints <= 0) throw new \Exception("Not enough data. ");    
34
+        if ($npoints <= 0) {
35
+            throw new \Exception("Not enough data. ");
36
+        }
35 37
         $ndimensions = count($data[0]);
36 38
         $centroids = [];
37 39
         for ($i=0;$i<$nclusters;$i++){
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
         if ($npoints <= 0) throw new \Exception("Not enough data. ");    
35 35
         $ndimensions = count($data[0]);
36 36
         $centroids = [];
37
-        for ($i=0;$i<$nclusters;$i++){
37
+        for ($i = 0; $i < $nclusters; $i++) {
38 38
             $centroids[] = $data[$i];
39 39
         }
40 40
         //$centroids = self::initCentroids($nclusters, $ndimensions, function(){return rand(0,100)/100;});   
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
                 $bdist = INF;
48 48
                 for ($i = 0; $i < $nclusters; $i++) {
49 49
                     $ndist = self::eclideanDistance($data[$j], $centroids[$i]);
50
-                    if($bdist > $ndist) {
50
+                    if ($bdist > $ndist) {
51 51
                         $bdist = $ndist;
52 52
                         $best = $i;
53 53
                     }            
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
             // Check change 
60 60
             $finished = true;
61 61
             if (count($resp) > 0) {
62
-                for ($j=0; $j < $npoints; $j++) {        
62
+                for ($j = 0; $j < $npoints; $j++) {        
63 63
                     if ($resp[$j]!==$nresp[$j]) {
64 64
                         $finished = false;
65 65
                         break;
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
             $resp = $nresp;
72 72
             
73 73
             // Recalculate the centroids
74
-            $centroids = self::initCentroids($nclusters, $ndimensions, function(){return 0;});
74
+            $centroids = self::initCentroids($nclusters, $ndimensions, function() {return 0; });
75 75
             $counts = array_fill(0, $nclusters, 0);
76 76
             for ($j = 0; $j < $npoints; $j++) {    
77 77
                 $centroids[$resp[$j]] = Matrix::sumArray($centroids[$resp[$j]], $data[$j]);
@@ -91,10 +91,10 @@  discard block
 block discarded – undo
91 91
         $resp = [];
92 92
         $n = count($centroids);
93 93
         $d = count($centroids[0]);
94
-        for ($i=0;$i<$n;$i++) {
94
+        for ($i = 0; $i < $n; $i++) {
95 95
             $tmp = [];
96
-            for ($j=0;$j<$d;$j++){
97
-                $tmp[] = $centroids[$i][$j]/$counts[$i];
96
+            for ($j = 0; $j < $d; $j++) {
97
+                $tmp[] = $centroids[$i][$j] / $counts[$i];
98 98
             }
99 99
             $resp[] = $tmp;
100 100
         }
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
     public static function eclideanDistance($p1, $p2) {
124 124
        $len = count($p1);
125 125
        $acum = 0;
126
-       for($i=0; $i<$len; $i++) {
126
+       for ($i = 0; $i < $len; $i++) {
127 127
            $acum += ($p1[$i] - $p2[$i])**2;
128 128
        }
129 129
        return sqrt($acum);
Please login to merge, or discard this patch.
src/CategoricalDataset.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
         $array = sort($array);
61 61
         $this->encodedValues = [];
62 62
         $this->sortedEncodedFeatures = $array;
63
-        foreach($this->sortedEncodedFeatures as $col){
63
+        foreach ($this->sortedEncodedFeatures as $col) {
64 64
             $vals = $this->getUniqueValues($col);
65 65
             $this->encodedValues[] = $vals;
66 66
             $this->featIndexMap[$col] = count($vals);
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
     private function encodeFeature($size) 
93 93
     {
94 94
         $resp = [];
95
-        for ($i=0;$i<$size;$i++) {
95
+        for ($i = 0; $i < $size; $i++) {
96 96
             $tmp = array_fill(0, $size, 0);
97 97
             $tmp[$i] = 1;  
98 98
             $resp[] = $tmp;
@@ -103,21 +103,21 @@  discard block
 block discarded – undo
103 103
     /*
104 104
      * @param
105 105
      */  
106
-    public function encode(){
107
-        $transformer  = [];
106
+    public function encode() {
107
+        $transformer = [];
108 108
         $ndata = [];
109 109
         $n = count($this->data);
110 110
         $ndim = count($this->data[0]);
111
-        for ($j=0; $j<$d; $j++) {
112
-            $transformer[] = function($val){ return [$val]; };
111
+        for ($j = 0; $j < $d; $j++) {
112
+            $transformer[] = function($val) { return [$val]; };
113 113
         }
114
-        foreach($this->sortedEncodedFeatures as $col) {
114
+        foreach ($this->sortedEncodedFeatures as $col) {
115 115
             $transformer[$col] = function($val) { return $this->featEncode[$col][$val]; };
116 116
         }
117 117
         $ndata = [];
118
-        for ($i=0; $i<$n; $i++) {
118
+        for ($i = 0; $i < $n; $i++) {
119 119
             $npoint = [];
120
-            for ($j=0; $j<$ndim; $j++) {
120
+            for ($j = 0; $j < $ndim; $j++) {
121 121
                 $npoint += $transformer[$j]($data[$i][$j]);
122 122
             }
123 123
             $ndata[] = $npoint;
Please login to merge, or discard this patch.