Completed
Push — master ( cf222b...4daa0a )
by Arkadiusz
03:24
created
src/Phpml/Classification/Linear/Adaline.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\Linear;
6 6
 
@@ -15,12 +15,12 @@  discard block
 block discarded – undo
15 15
     /**
16 16
      * Batch training is the default Adaline training algorithm
17 17
      */
18
-    const BATCH_TRAINING    = 1;
18
+    const BATCH_TRAINING = 1;
19 19
 
20 20
     /**
21 21
      * Online training: Stochastic gradient descent learning
22 22
      */
23
-    const ONLINE_TRAINING    = 2;
23
+    const ONLINE_TRAINING = 2;
24 24
 
25 25
     /**
26 26
      * The function whose result will be used to calculate the network error
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
     public function __construct(float $learningRate = 0.001, int $maxIterations = 1000,
53 53
         bool $normalizeInputs = true, int $trainingType = self::BATCH_TRAINING)
54 54
     {
55
-        if (! in_array($trainingType, [self::BATCH_TRAINING, self::ONLINE_TRAINING])) {
55
+        if (!in_array($trainingType, [self::BATCH_TRAINING, self::ONLINE_TRAINING])) {
56 56
             throw new \Exception("Adaline can only be trained with batch and online/stochastic gradient descent algorithm");
57 57
         }
58 58
 
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
     protected function updateWeights(array $updates)
105 105
     {
106 106
         // Updates all weights at once
107
-        for ($i=0; $i <= $this->featureCount; $i++) {
107
+        for ($i = 0; $i <= $this->featureCount; $i++) {
108 108
             if ($i == 0) {
109 109
                 $this->weights[0] += $this->learningRate * array_sum($updates);
110 110
             } else {
Please login to merge, or discard this patch.
src/Phpml/Classification/Linear/Perceptron.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\Classification\Linear;
6 6
 
@@ -138,7 +138,7 @@  discard block
 block discarded – undo
138 138
                 // Update bias
139 139
                 $this->weights[0] += $update * $this->learningRate; // Bias
140 140
                 // Update other weights
141
-                for ($i=1; $i <= $this->featureCount; $i++) {
141
+                for ($i = 1; $i <= $this->featureCount; $i++) {
142 142
                     $this->weights[$i] += $update * $sample[$i - 1] * $this->learningRate;
143 143
                 }
144 144
             }
@@ -190,6 +190,6 @@  discard block
 block discarded – undo
190 190
 
191 191
         $predictedClass = $this->outputClass($sample);
192 192
 
193
-        return $this->labels[ $predictedClass ];
193
+        return $this->labels[$predictedClass];
194 194
     }
195 195
 }
Please login to merge, or discard this patch.
src/Phpml/Classification/Linear/DecisionStump.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
 
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
         $stepSize = ($maxValue - $minValue) / 100.0;
123 123
 
124 124
         $leftLabel = $this->tree->leftLeaf->classValue;
125
-        $rightLabel= $this->tree->rightLeaf->classValue;
125
+        $rightLabel = $this->tree->rightLeaf->classValue;
126 126
 
127 127
         $bestOperator = $this->tree->operator;
128 128
         $bestThreshold = $this->tree->numericValue;
@@ -130,8 +130,8 @@  discard block
 block discarded – undo
130 130
                 $bestThreshold, $bestOperator, $values, $targets, $leftLabel, $rightLabel);
131 131
 
132 132
         foreach (['<=', '>'] as $operator) {
133
-            for ($step = $minValue; $step <= $maxValue; $step+= $stepSize) {
134
-                $threshold = (float)$step;
133
+            for ($step = $minValue; $step <= $maxValue; $step += $stepSize) {
134
+                $threshold = (float) $step;
135 135
                 $errorRate = $this->calculateErrorRate(
136 136
                     $threshold, $operator, $values, $targets, $leftLabel, $rightLabel);
137 137
 
Please login to merge, or discard this patch.
src/Phpml/Classification/Ensemble/AdaBoost.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\Classification\Ensemble;
6 6
 
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
         //  classifiers as well
123 123
         $minErrorRate = 1.0;
124 124
         $bestClassifier = null;
125
-        for ($i=0; $i < $this->featureCount; $i++) {
125
+        for ($i = 0; $i < $this->featureCount; $i++) {
126 126
             $stump = new DecisionStump($i);
127 127
             $stump->setSampleWeights($this->weights);
128 128
             $stump->train($this->samples, $this->targets);
@@ -185,6 +185,6 @@  discard block
 block discarded – undo
185 185
             $sum += $h * $alpha;
186 186
         }
187 187
 
188
-        return $this->labels[ $sum > 0 ? 1 : -1];
188
+        return $this->labels[$sum > 0 ? 1 : -1];
189 189
     }
190 190
 }
Please login to merge, or discard this patch.
src/Phpml/Classification/DecisionTree/DecisionTreeLeaf.php 1 patch
Spacing   +14 added lines, -14 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\DecisionTree;
6 6
 
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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;
@@ -100,16 +100,16 @@  discard block
 block discarded – undo
100 100
             return 0.0;
101 101
         }
102 102
 
103
-        $nodeSampleCount = (float)count($this->records);
103
+        $nodeSampleCount = (float) count($this->records);
104 104
         $iT = $this->giniIndex;
105 105
 
106 106
         if ($this->leftLeaf) {
107
-            $pL = count($this->leftLeaf->records)/$nodeSampleCount;
107
+            $pL = count($this->leftLeaf->records) / $nodeSampleCount;
108 108
             $iT -= $pL * $this->leftLeaf->giniIndex;
109 109
         }
110 110
 
111 111
         if ($this->rightLeaf) {
112
-            $pR = count($this->rightLeaf->records)/$nodeSampleCount;
112
+            $pR = count($this->rightLeaf->records) / $nodeSampleCount;
113 113
             $iT -= $pR * $this->rightLeaf->giniIndex;
114 114
         }
115 115
 
@@ -133,25 +133,25 @@  discard block
 block discarded – undo
133 133
             } else {
134 134
                 $col = "col_$this->columnIndex";
135 135
             }
136
-            if (! preg_match("/^[<>=]{1,2}/", $value)) {
136
+            if (!preg_match("/^[<>=]{1,2}/", $value)) {
137 137
                 $value = "=$value";
138 138
             }
139
-            $value = "<b>$col $value</b><br>Gini: ". number_format($this->giniIndex, 2);
139
+            $value = "<b>$col $value</b><br>Gini: ".number_format($this->giniIndex, 2);
140 140
         }
141 141
         $str = "<table ><tr><td colspan=3 align=center style='border:1px solid;'>
142 142
 				$value</td></tr>";
143 143
         if ($this->leftLeaf || $this->rightLeaf) {
144
-            $str .='<tr>';
144
+            $str .= '<tr>';
145 145
             if ($this->leftLeaf) {
146
-                $str .="<td valign=top><b>| Yes</b><br>" . $this->leftLeaf->getHTML($columnNames) . "</td>";
146
+                $str .= "<td valign=top><b>| Yes</b><br>".$this->leftLeaf->getHTML($columnNames)."</td>";
147 147
             } else {
148
-                $str .='<td></td>';
148
+                $str .= '<td></td>';
149 149
             }
150
-            $str .='<td>&nbsp;</td>';
150
+            $str .= '<td>&nbsp;</td>';
151 151
             if ($this->rightLeaf) {
152
-                $str .="<td valign=top align=right><b>No |</b><br>" . $this->rightLeaf->getHTML($columnNames) . "</td>";
152
+                $str .= "<td valign=top align=right><b>No |</b><br>".$this->rightLeaf->getHTML($columnNames)."</td>";
153 153
             } else {
154
-                $str .='<td></td>';
154
+                $str .= '<td></td>';
155 155
             }
156 156
             $str .= '</tr>';
157 157
         }
Please login to merge, or discard this patch.