Test Failed
Pull Request — master (#100)
by Никита
04:12
created
src/Phpml/Classification/Linear/DecisionStump.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
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
 
@@ -192,8 +192,8 @@  discard block
 block discarded – undo
192 192
             }
193 193
 
194 194
             // Try other possible points one by one
195
-            for ($step = $minValue; $step <= $maxValue; $step+= $stepSize) {
196
-                $threshold = (float)$step;
195
+            for ($step = $minValue; $step <= $maxValue; $step += $stepSize) {
196
+                $threshold = (float) $step;
197 197
                 list($errorRate, $prob) = $this->calculateErrorRate($targets, $threshold, $operator, $values);
198 198
                 if ($errorRate < $split['trainingErrorRate']) {
199 199
                     $split = ['value' => $threshold, 'operator' => $operator,
@@ -217,7 +217,7 @@  discard block
 block discarded – undo
217 217
     {
218 218
         $values = array_column($samples, $col);
219 219
         $valueCounts = array_count_values($values);
220
-        $distinctVals= array_keys($valueCounts);
220
+        $distinctVals = array_keys($valueCounts);
221 221
 
222 222
         $split = null;
223 223
 
@@ -276,7 +276,7 @@  discard block
 block discarded – undo
276 276
         $wrong = 0.0;
277 277
         $prob = [];
278 278
         $leftLabel = $this->binaryLabels[0];
279
-        $rightLabel= $this->binaryLabels[1];
279
+        $rightLabel = $this->binaryLabels[1];
280 280
 
281 281
         foreach ($values as $index => $value) {
282 282
             if ($this->evaluate($value, $operator, $threshold)) {
@@ -299,7 +299,7 @@  discard block
 block discarded – undo
299 299
         // Calculate probabilities: Proportion of labels in each leaf
300 300
         $dist = array_combine($this->binaryLabels, array_fill(0, 2, 0.0));
301 301
         foreach ($prob as $leaf => $counts) {
302
-            $leafTotal = (float)array_sum($prob[$leaf]);
302
+            $leafTotal = (float) array_sum($prob[$leaf]);
303 303
             foreach ($counts as $label => $count) {
304 304
                 if (strval($leaf) == strval($label)) {
305 305
                     $dist[$leaf] = $count / $leafTotal;
@@ -357,8 +357,8 @@  discard block
 block discarded – undo
357 357
      */
358 358
     public function __toString()
359 359
     {
360
-        return "IF $this->column $this->operator $this->value " .
361
-            "THEN " . $this->binaryLabels[0] . " ".
362
-            "ELSE " . $this->binaryLabels[1];
360
+        return "IF $this->column $this->operator $this->value ".
361
+            "THEN ".$this->binaryLabels[0]." ".
362
+            "ELSE ".$this->binaryLabels[1];
363 363
     }
364 364
 }
Please login to merge, or discard this patch.
src/Phpml/Classification/Linear/Adaline.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
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
 
@@ -9,12 +9,12 @@  discard block
 block discarded – undo
9 9
     /**
10 10
      * Batch training is the default Adaline training algorithm
11 11
      */
12
-    const BATCH_TRAINING    = 1;
12
+    const BATCH_TRAINING = 1;
13 13
 
14 14
     /**
15 15
      * Online training: Stochastic gradient descent learning
16 16
      */
17
-    const ONLINE_TRAINING    = 2;
17
+    const ONLINE_TRAINING = 2;
18 18
 
19 19
     /**
20 20
      * Training type may be either 'Batch' or 'Online' learning
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
     protected function runTraining(array $samples, array $targets)
62 62
     {
63 63
         // The cost function is the sum of squares
64
-        $callback = function ($weights, $sample, $target) {
64
+        $callback = function($weights, $sample, $target) {
65 65
             $this->weights = $weights;
66 66
 
67 67
             $output = $this->output($sample);
Please login to merge, or discard this patch.
src/Phpml/Classification/Linear/Perceptron.php 2 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -99,7 +99,7 @@
 block discarded – undo
99 99
         $this->trainByLabel($samples, $targets, $labels);
100 100
     }
101 101
 
102
-   /**
102
+    /**
103 103
      * @param array $samples
104 104
      * @param array $targets
105 105
      * @param array $labels
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
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
 block discarded – undo
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);
Please login to merge, or discard this patch.
src/Phpml/Classification/Ensemble/AdaBoost.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
src/Phpml/Classification/Ensemble/Bagging.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
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
 
Please login to merge, or discard this patch.
src/Phpml/Classification/Ensemble/RandomForest.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
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
 block discarded – undo
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) {
Please login to merge, or discard this patch.
src/Phpml/Classification/DecisionTree.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 
Please login to merge, or discard this patch.
src/Phpml/Clustering/FuzzyCMeans.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 
Please login to merge, or discard this patch.
src/Phpml/Helper/Optimizer/StochasticGD.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
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
 
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
      *
73 73
      * @var array
74 74
      */
75
-    protected $costValues= [];
75
+    protected $costValues = [];
76 76
 
77 77
     /**
78 78
      * Initializes the SGD optimizer for the given number of dimensions
@@ -240,7 +240,7 @@  discard block
 block discarded – undo
240 240
     {
241 241
         // Check for early stop: No change larger than threshold (default 1e-5)
242 242
         $diff = array_map(
243
-            function ($w1, $w2) {
243
+            function($w1, $w2) {
244 244
                 return abs($w1 - $w2) > $this->threshold ? 1 : 0;
245 245
             },
246 246
             $oldTheta, $this->theta);
Please login to merge, or discard this patch.