@@ -24,10 +24,14 @@ 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) { |
|
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 | } |
@@ -179,7 +179,9 @@ |
||
| 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 | } |
@@ -179,8 +179,7 @@ discard block |
||
| 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 |
||
| 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 | |
@@ -31,7 +31,9 @@ discard block |
||
| 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 = self::select_disjoint($data, $nclusters); |
| 37 | 39 | |
@@ -102,7 +104,9 @@ discard block |
||
| 102 | 104 | private static function contains_point($matrix, $array) |
| 103 | 105 | { |
| 104 | 106 | foreach ($matrix as $row){ |
| 105 | - if (self::isEqual($row, $array)) return true; |
|
| 107 | + if (self::isEqual($row, $array)) { |
|
| 108 | + return true; |
|
| 109 | + } |
|
| 106 | 110 | } |
| 107 | 111 | return false; |
| 108 | 112 | } |
@@ -113,9 +117,13 @@ discard block |
||
| 113 | 117 | private static function isEqual($array1, $array2) |
| 114 | 118 | { |
| 115 | 119 | $len = count($array1); |
| 116 | - if($len != count($array2) ) return false; |
|
| 120 | + if($len != count($array2) ) { |
|
| 121 | + return false; |
|
| 122 | + } |
|
| 117 | 123 | for ($i=0; $i<$len; $i++) { |
| 118 | - if ($array1[$i] != $array2[$i]) return false; |
|
| 124 | + if ($array1[$i] != $array2[$i]) { |
|
| 125 | + return false; |
|
| 126 | + } |
|
| 119 | 127 | } |
| 120 | 128 | return true; |
| 121 | 129 | } |