@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare(strict_types=1); |
|
3 | +declare(strict_types = 1); |
|
4 | 4 | |
5 | 5 | namespace Phpml\Classification\Linear; |
6 | 6 | |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | protected function runTraining(array $samples, array $targets) |
171 | 171 | { |
172 | 172 | // The cost function is the sum of squares |
173 | - $callback = function ($weights, $sample, $target) { |
|
173 | + $callback = function($weights, $sample, $target) { |
|
174 | 174 | $this->weights = $weights; |
175 | 175 | |
176 | 176 | $prediction = $this->outputClass($sample); |
@@ -100,10 +100,10 @@ |
||
100 | 100 | } |
101 | 101 | |
102 | 102 | /** |
103 | - * @param array $samples |
|
104 | - * @param array $targets |
|
105 | - * @param array $labels |
|
106 | - */ |
|
103 | + * @param array $samples |
|
104 | + * @param array $targets |
|
105 | + * @param array $labels |
|
106 | + */ |
|
107 | 107 | public function trainBinary(array $samples, array $targets, array $labels) |
108 | 108 | { |
109 | 109 | if ($this->normalizer) { |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare(strict_types=1); |
|
3 | +declare(strict_types = 1); |
|
4 | 4 | |
5 | 5 | namespace Phpml\Classification\Ensemble; |
6 | 6 | |
@@ -175,14 +175,14 @@ discard block |
||
175 | 175 | { |
176 | 176 | $weights = $this->weights; |
177 | 177 | $std = StandardDeviation::population($weights); |
178 | - $mean= Mean::arithmetic($weights); |
|
178 | + $mean = Mean::arithmetic($weights); |
|
179 | 179 | $min = min($weights); |
180 | - $minZ= (int)round(($min - $mean) / $std); |
|
180 | + $minZ = (int) round(($min - $mean) / $std); |
|
181 | 181 | |
182 | 182 | $samples = []; |
183 | 183 | $targets = []; |
184 | 184 | foreach ($weights as $index => $weight) { |
185 | - $z = (int)round(($weight - $mean) / $std) - $minZ + 1; |
|
185 | + $z = (int) round(($weight - $mean) / $std) - $minZ + 1; |
|
186 | 186 | for ($i = 0; $i < $z; ++$i) { |
187 | 187 | if (rand(0, 1) == 0) { |
188 | 188 | continue; |
@@ -264,6 +264,6 @@ discard block |
||
264 | 264 | $sum += $h * $alpha; |
265 | 265 | } |
266 | 266 | |
267 | - return $this->labels[ $sum > 0 ? 1 : -1]; |
|
267 | + return $this->labels[$sum > 0 ? 1 : -1]; |
|
268 | 268 | } |
269 | 269 | } |
@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare(strict_types=1); |
|
3 | +declare(strict_types = 1); |
|
4 | 4 | |
5 | 5 | namespace Phpml\Classification\Ensemble; |
6 | 6 |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare(strict_types=1); |
|
3 | +declare(strict_types = 1); |
|
4 | 4 | |
5 | 5 | namespace Phpml\Classification\Ensemble; |
6 | 6 | |
@@ -137,11 +137,11 @@ discard block |
||
137 | 137 | protected function initSingleClassifier($classifier) |
138 | 138 | { |
139 | 139 | if (is_float($this->featureSubsetRatio)) { |
140 | - $featureCount = (int)($this->featureSubsetRatio * $this->featureCount); |
|
140 | + $featureCount = (int) ($this->featureSubsetRatio * $this->featureCount); |
|
141 | 141 | } elseif ($this->featureCount == 'sqrt') { |
142 | - $featureCount = (int)sqrt($this->featureCount) + 1; |
|
142 | + $featureCount = (int) sqrt($this->featureCount) + 1; |
|
143 | 143 | } else { |
144 | - $featureCount = (int)log($this->featureCount, 2) + 1; |
|
144 | + $featureCount = (int) log($this->featureCount, 2) + 1; |
|
145 | 145 | } |
146 | 146 | |
147 | 147 | if ($featureCount >= $this->featureCount) { |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare(strict_types=1); |
|
3 | +declare(strict_types = 1); |
|
4 | 4 | |
5 | 5 | namespace Phpml\Classification\DecisionTree; |
6 | 6 | |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | /** |
35 | 35 | * @var DecisionTreeLeaf |
36 | 36 | */ |
37 | - public $rightLeaf= null; |
|
37 | + public $rightLeaf = null; |
|
38 | 38 | |
39 | 39 | /** |
40 | 40 | * @var array |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | |
80 | 80 | if ($this->isContinuous) { |
81 | 81 | $op = $this->operator; |
82 | - $value= $this->numericValue; |
|
82 | + $value = $this->numericValue; |
|
83 | 83 | $recordField = strval($recordField); |
84 | 84 | eval("\$result = $recordField $op $value;"); |
85 | 85 | return $result; |
@@ -102,16 +102,16 @@ discard block |
||
102 | 102 | return 0.0; |
103 | 103 | } |
104 | 104 | |
105 | - $nodeSampleCount = (float)count($this->records); |
|
105 | + $nodeSampleCount = (float) count($this->records); |
|
106 | 106 | $iT = $this->giniIndex; |
107 | 107 | |
108 | 108 | if ($this->leftLeaf) { |
109 | - $pL = count($this->leftLeaf->records)/$nodeSampleCount; |
|
109 | + $pL = count($this->leftLeaf->records) / $nodeSampleCount; |
|
110 | 110 | $iT -= $pL * $this->leftLeaf->giniIndex; |
111 | 111 | } |
112 | 112 | |
113 | 113 | if ($this->rightLeaf) { |
114 | - $pR = count($this->rightLeaf->records)/$nodeSampleCount; |
|
114 | + $pR = count($this->rightLeaf->records) / $nodeSampleCount; |
|
115 | 115 | $iT -= $pR * $this->rightLeaf->giniIndex; |
116 | 116 | } |
117 | 117 | |
@@ -138,22 +138,22 @@ discard block |
||
138 | 138 | if (!preg_match("/^[<>=]{1,2}/", $value)) { |
139 | 139 | $value = "=$value"; |
140 | 140 | } |
141 | - $value = "<b>$col $value</b><br>Gini: ". number_format($this->giniIndex, 2); |
|
141 | + $value = "<b>$col $value</b><br>Gini: ".number_format($this->giniIndex, 2); |
|
142 | 142 | } |
143 | 143 | $str = "<table ><tr><td colspan=3 align=center style='border:1px solid;'> |
144 | 144 | $value</td></tr>"; |
145 | 145 | if ($this->leftLeaf || $this->rightLeaf) { |
146 | - $str .='<tr>'; |
|
146 | + $str .= '<tr>'; |
|
147 | 147 | if ($this->leftLeaf) { |
148 | - $str .="<td valign=top><b>| Yes</b><br>" . $this->leftLeaf->getHTML($columnNames) . "</td>"; |
|
148 | + $str .= "<td valign=top><b>| Yes</b><br>".$this->leftLeaf->getHTML($columnNames)."</td>"; |
|
149 | 149 | } else { |
150 | - $str .='<td></td>'; |
|
150 | + $str .= '<td></td>'; |
|
151 | 151 | } |
152 | - $str .='<td> </td>'; |
|
152 | + $str .= '<td> </td>'; |
|
153 | 153 | if ($this->rightLeaf) { |
154 | - $str .="<td valign=top align=right><b>No |</b><br>" . $this->rightLeaf->getHTML($columnNames) . "</td>"; |
|
154 | + $str .= "<td valign=top align=right><b>No |</b><br>".$this->rightLeaf->getHTML($columnNames)."</td>"; |
|
155 | 155 | } else { |
156 | - $str .='<td></td>'; |
|
156 | + $str .= '<td></td>'; |
|
157 | 157 | } |
158 | 158 | $str .= '</tr>'; |
159 | 159 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare(strict_types=1); |
|
3 | +declare(strict_types = 1); |
|
4 | 4 | |
5 | 5 | namespace Phpml\Classification; |
6 | 6 | |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | // otherwise group the records so that we can classify the leaf |
144 | 144 | // in case maximum depth is reached |
145 | 145 | $leftRecords = []; |
146 | - $rightRecords= []; |
|
146 | + $rightRecords = []; |
|
147 | 147 | $remainingTargets = []; |
148 | 148 | $prevRecord = null; |
149 | 149 | $allSame = true; |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | if ($split->evaluate($record)) { |
162 | 162 | $leftRecords[] = $recordNo; |
163 | 163 | } else { |
164 | - $rightRecords[]= $recordNo; |
|
164 | + $rightRecords[] = $recordNo; |
|
165 | 165 | } |
166 | 166 | |
167 | 167 | // Group remaining targets |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | $split->leftLeaf = $this->getSplitLeaf($leftRecords, $depth + 1); |
183 | 183 | } |
184 | 184 | if ($rightRecords) { |
185 | - $split->rightLeaf= $this->getSplitLeaf($rightRecords, $depth + 1); |
|
185 | + $split->rightLeaf = $this->getSplitLeaf($rightRecords, $depth + 1); |
|
186 | 186 | } |
187 | 187 | } |
188 | 188 |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare(strict_types=1); |
|
3 | +declare(strict_types = 1); |
|
4 | 4 | |
5 | 5 | namespace Phpml\Clustering; |
6 | 6 | |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | $total += $val; |
102 | 102 | } |
103 | 103 | |
104 | - $this->membership[] = array_map(function ($val) use ($total) { |
|
104 | + $this->membership[] = array_map(function($val) use ($total) { |
|
105 | 105 | return $val / $total; |
106 | 106 | }, $row); |
107 | 107 | } |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | { |
219 | 219 | // Initialize variables, clusters and membership matrix |
220 | 220 | $this->sampleCount = count($samples); |
221 | - $this->samples =& $samples; |
|
221 | + $this->samples = & $samples; |
|
222 | 222 | $this->space = new Space(count($samples[0])); |
223 | 223 | $this->initClusters(); |
224 | 224 |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare(strict_types=1); |
|
3 | +declare(strict_types = 1); |
|
4 | 4 | |
5 | 5 | namespace Phpml\Helper\Optimizer; |
6 | 6 | |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | |
43 | 43 | $this->updateWeightsWithUpdates($updates, $totalPenalty); |
44 | 44 | |
45 | - $this->costValues[] = array_sum($errors)/$this->sampleCount; |
|
45 | + $this->costValues[] = array_sum($errors) / $this->sampleCount; |
|
46 | 46 | |
47 | 47 | if ($this->earlyStop($theta)) { |
48 | 48 | break; |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | protected function gradient(array $theta) |
66 | 66 | { |
67 | 67 | $costs = []; |
68 | - $gradient= []; |
|
68 | + $gradient = []; |
|
69 | 69 | $totalPenalty = 0; |
70 | 70 | |
71 | 71 | foreach ($this->samples as $index => $sample) { |
@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare(strict_types=1); |
|
3 | +declare(strict_types = 1); |
|
4 | 4 | |
5 | 5 | namespace Phpml\Helper\Optimizer; |
6 | 6 |