@@ -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 | } |
@@ -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); |
@@ -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 | } |