@@ -175,7 +175,7 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 | |
@@ -76,7 +76,7 @@ |
||
| 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 | } |
@@ -82,7 +82,7 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 | } |
@@ -24,13 +24,13 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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; |
@@ -26,14 +26,14 @@ |
||
| 26 | 26 | public static function ABtest($testCounts, $targetCounts) |
| 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 | |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | $bdist = INF; |
| 45 | 45 | for ($i = 0; $i < $nclusters; $i++) { |
| 46 | 46 | $ndist = self::eclideanDistance($data[$j], $centroids[$i]); |
| 47 | - if($bdist > $ndist) { |
|
| 47 | + if ($bdist > $ndist) { |
|
| 48 | 48 | $bdist = $ndist; |
| 49 | 49 | $best = $i; |
| 50 | 50 | } |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | // Check change |
| 57 | 57 | $finished = true; |
| 58 | 58 | if (count($resp) > 0) { |
| 59 | - for ($j=0; $j < $npoints; $j++) { |
|
| 59 | + for ($j = 0; $j < $npoints; $j++) { |
|
| 60 | 60 | if ($resp[$j]!==$nresp[$j]) { |
| 61 | 61 | $finished = false; |
| 62 | 62 | break; |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | } |
| 68 | 68 | $resp = $nresp; |
| 69 | 69 | // Recalculate the centroids |
| 70 | - $centroids = self::initCentroids($nclusters, $ndimensions, function(){return 0;}); |
|
| 70 | + $centroids = self::initCentroids($nclusters, $ndimensions, function() {return 0; }); |
|
| 71 | 71 | $counts = array_fill(0, $nclusters, 0); |
| 72 | 72 | for ($j = 0; $j < $npoints; $j++) { |
| 73 | 73 | $centroids[$resp[$j]] = Matrix::sumArray($centroids[$resp[$j]], $data[$j]); |
@@ -86,10 +86,10 @@ discard block |
||
| 86 | 86 | { |
| 87 | 87 | $resp = []; |
| 88 | 88 | foreach ($data as $row) { |
| 89 | - if ( !self::contains_point($resp, $row) ) { |
|
| 89 | + if (!self::contains_point($resp, $row)) { |
|
| 90 | 90 | $resp[] = $row; |
| 91 | 91 | } |
| 92 | - if (count($resp) == $n) { |
|
| 92 | + if (count($resp)==$n) { |
|
| 93 | 93 | return $resp; |
| 94 | 94 | } |
| 95 | 95 | } |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | */ |
| 102 | 102 | private static function contains_point($matrix, $array) |
| 103 | 103 | { |
| 104 | - foreach ($matrix as $row){ |
|
| 104 | + foreach ($matrix as $row) { |
|
| 105 | 105 | if (self::isEqual($row, $array)) return true; |
| 106 | 106 | } |
| 107 | 107 | return false; |
@@ -113,9 +113,9 @@ discard block |
||
| 113 | 113 | private static function isEqual($array1, $array2) |
| 114 | 114 | { |
| 115 | 115 | $len = count($array1); |
| 116 | - if($len != count($array2) ) return false; |
|
| 117 | - for ($i=0; $i<$len; $i++) { |
|
| 118 | - if ($array1[$i] != $array2[$i]) return false; |
|
| 116 | + if ($len!=count($array2)) return false; |
|
| 117 | + for ($i = 0; $i < $len; $i++) { |
|
| 118 | + if ($array1[$i]!=$array2[$i]) return false; |
|
| 119 | 119 | } |
| 120 | 120 | return true; |
| 121 | 121 | } |
@@ -128,10 +128,10 @@ discard block |
||
| 128 | 128 | $resp = []; |
| 129 | 129 | $n = count($centroids); |
| 130 | 130 | $d = count($centroids[0]); |
| 131 | - for ($i=0;$i<$n;$i++) { |
|
| 131 | + for ($i = 0; $i < $n; $i++) { |
|
| 132 | 132 | $tmp = []; |
| 133 | - for ($j=0;$j<$d;$j++){ |
|
| 134 | - $tmp[] = $centroids[$i][$j]/$counts[$i]; |
|
| 133 | + for ($j = 0; $j < $d; $j++) { |
|
| 134 | + $tmp[] = $centroids[$i][$j] / $counts[$i]; |
|
| 135 | 135 | } |
| 136 | 136 | $resp[] = $tmp; |
| 137 | 137 | } |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | public static function eclideanDistance($p1, $p2) { |
| 161 | 161 | $len = count($p1); |
| 162 | 162 | $acum = 0; |
| 163 | - for($i=0; $i<$len; $i++) { |
|
| 163 | + for ($i = 0; $i < $len; $i++) { |
|
| 164 | 164 | $acum += ($p1[$i] - $p2[$i])**2; |
| 165 | 165 | } |
| 166 | 166 | return sqrt($acum); |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | sort($array); |
| 60 | 60 | $this->encodedValues = []; |
| 61 | 61 | $this->sortedEncodedFeatures = $array; |
| 62 | - foreach($this->sortedEncodedFeatures as $col){ |
|
| 62 | + foreach ($this->sortedEncodedFeatures as $col) { |
|
| 63 | 63 | $vals = $this->getUniqueValues($col); |
| 64 | 64 | $this->encodedValues[$col] = $vals; |
| 65 | 65 | $this->featIndexMap[$col] = count($vals); |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | $tmp = Matrix::getColumn($this->data, $col); |
| 82 | 82 | $n = count($tmp); |
| 83 | 83 | $resp = []; |
| 84 | - for ($i=0; $i<$n; $i++) { |
|
| 84 | + for ($i = 0; $i < $n; $i++) { |
|
| 85 | 85 | if (!in_array($tmp[$i], $resp)) { |
| 86 | 86 | $resp[] = $tmp[$i]; |
| 87 | 87 | } |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | { |
| 98 | 98 | $size = count($array); |
| 99 | 99 | $resp = []; |
| 100 | - for ($i=0;$i<$size;$i++) { |
|
| 100 | + for ($i = 0; $i < $size; $i++) { |
|
| 101 | 101 | $tmp = array_fill(0, $size, 0); |
| 102 | 102 | $tmp[$i] = 1; |
| 103 | 103 | $resp[$array[$i]] = $tmp; |
@@ -108,21 +108,21 @@ discard block |
||
| 108 | 108 | /* |
| 109 | 109 | * @param |
| 110 | 110 | */ |
| 111 | - public function encode(){ |
|
| 112 | - $transformer = []; |
|
| 111 | + public function encode() { |
|
| 112 | + $transformer = []; |
|
| 113 | 113 | $n = count($this->data); |
| 114 | 114 | $ndim = count($this->data[0]); |
| 115 | - for ($j=0; $j<$ndim; $j++) { |
|
| 116 | - $transformer[] = function($val){ return [$val]; }; |
|
| 115 | + for ($j = 0; $j < $ndim; $j++) { |
|
| 116 | + $transformer[] = function($val) { return [$val]; }; |
|
| 117 | 117 | } |
| 118 | - foreach($this->sortedEncodedFeatures as $col) { |
|
| 119 | - $transformer[$col] = function ($val) use ($col) { return $this->featEncode[$col][$val]; }; |
|
| 118 | + foreach ($this->sortedEncodedFeatures as $col) { |
|
| 119 | + $transformer[$col] = function($val) use ($col) { return $this->featEncode[$col][$val]; }; |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | $ndata = []; |
| 123 | - for ($i=0; $i<$n; $i++) { |
|
| 123 | + for ($i = 0; $i < $n; $i++) { |
|
| 124 | 124 | $npoint = []; |
| 125 | - for ($j=0; $j<$ndim; $j++) { |
|
| 125 | + for ($j = 0; $j < $ndim; $j++) { |
|
| 126 | 126 | $npoint = array_merge($npoint, $transformer[$j]($this->data[$i][$j])); |
| 127 | 127 | } |
| 128 | 128 | $ndata[] = $npoint; |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | { |
| 138 | 138 | $resp = []; |
| 139 | 139 | $len = count($this->data[0]); |
| 140 | - for ($i=0; $i<$len; $i++) { |
|
| 140 | + for ($i = 0; $i < $len; $i++) { |
|
| 141 | 141 | if (isset($this->encodedValues[$i])) { |
| 142 | 142 | $resp = array_merge($resp, $this->encodedValues[$i]); |
| 143 | 143 | } else { |