Passed
Push — master ( 97ab44...6cbf2c )
by Iván
02:52
created
src/MachineLearning/Application/Normalization/MeanScaleNormalization.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -24,10 +24,10 @@  discard block
 block discarded – undo
24 24
         $rawValue = $value->getValue();
25 25
 
26 26
         $numberColumns = count($rawValue);
27
-        for ($i=0; $i<$numberColumns; $i++) {
27
+        for ($i = 0; $i < $numberColumns; $i++) {
28 28
             $rawValue[$i] =
29 29
                 (
30
-                    $rawValue[$i] - $rawCoefficient[static::COEFFICIENT_AVERAGE][$i]
30
+                    $rawValue[$i]-$rawCoefficient[static::COEFFICIENT_AVERAGE][$i]
31 31
                 )
32 32
                 / $rawCoefficient[static::COEFFICIENT_RANGE][$i]
33 33
             ;
@@ -62,8 +62,8 @@  discard block
 block discarded – undo
62 62
 
63 63
         foreach ($featuresSum as $i => $featureSum) {
64 64
             $featuresAverage[$i] = $featureSum / $numberRows;
65
-            $featuresRange[$i] = ($featuresMaximumValue[$i] - $featuresMinimumValue[$i]) > 0 ?
66
-                ($featuresMaximumValue[$i] - $featuresMinimumValue[$i])
65
+            $featuresRange[$i] = ($featuresMaximumValue[$i]-$featuresMinimumValue[$i]) > 0 ?
66
+                ($featuresMaximumValue[$i]-$featuresMinimumValue[$i])
67 67
                 : 1;
68 68
         }
69 69
 
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
                 if (!isset($featuresMinimumValue[$i]) || $featuresMinimumValue[$i] > $features[$i]) {
93 93
                     $featuresMinimumValue[$i] = $features[$i];
94 94
                 }
95
-                $featuresSum[$i] = $featuresSum[$i] + $features[$i];
95
+                $featuresSum[$i] = $featuresSum[$i]+$features[$i];
96 96
             }
97 97
         }
98 98
         return array($featuresMaximumValue, $featuresMinimumValue, $featuresSum);
Please login to merge, or discard this patch.
src/MachineLearning/Application/Algorithm/GradientDescendent.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
         $coefficientVector[0] = 0;
73 73
         $incrementVector = array_fill(0, $features+1, 0);
74 74
 
75
-        while(!$convergence && !$divergence) {
75
+        while (!$convergence && !$divergence) {
76 76
             list($convergence, $divergence, $coefficientVector) = $this->doStep(
77 77
                 $dataset,
78 78
                 $coefficientVector,
@@ -100,20 +100,20 @@  discard block
 block discarded – undo
100 100
     protected function doStep(Dataset $dataset, $coefficientVector, $features, $total, $incrementVector)
101 101
     {
102 102
         $coefficient = new VectorValue($coefficientVector);
103
-        $costVector = array_fill(0, $features + 1, 0);
103
+        $costVector = array_fill(0, $features+1, 0);
104 104
 
105 105
         foreach ($dataset as $result) {
106 106
             $costVector = $this->calculateStepCost($features, $coefficient, $result, $costVector);
107 107
         }
108 108
 
109
-        for ($j = 0; $j < $features + 1; $j++) {
109
+        for ($j = 0; $j < $features+1; $j++) {
110 110
             $incrementVector[$j] = $this->learningRate * -(1 / ($total)) * $costVector[$j];
111 111
         }
112 112
 
113
-        $convergence = (bool)(abs(array_sum($incrementVector)) < $this->convergenceCriteria);
114
-        $divergence = (bool)(abs(array_sum($incrementVector)) > $this->divergenceCriteria);
113
+        $convergence = (bool) (abs(array_sum($incrementVector)) < $this->convergenceCriteria);
114
+        $divergence = (bool) (abs(array_sum($incrementVector)) > $this->divergenceCriteria);
115 115
 
116
-        for ($j = 0; $j < $features + 1; $j++) {
116
+        for ($j = 0; $j < $features+1; $j++) {
117 117
             $coefficientVector[$j] += $incrementVector[$j];
118 118
         }
119 119
         return array($convergence, $divergence, $coefficientVector);
@@ -128,20 +128,20 @@  discard block
 block discarded – undo
128 128
     protected function calculateStepCost($features, ValueInterface $coefficient, Result $result, array $costVector)
129 129
     {
130 130
         $firstOrderIncrement = (
131
-            (float)$this->hypothesis->calculate(
131
+            (float) $this->hypothesis->calculate(
132 132
                 $coefficient,
133 133
                 $result->getIndependentVariable()
134 134
             )->getValue()
135
-            - (float)$result->getDependentVariable()->getValue()
135
+            - (float) $result->getDependentVariable()->getValue()
136 136
         );
137 137
         $costVector[0] += $firstOrderIncrement;
138 138
 
139
-        for ($j = 1; $j < $features + 1; $j++) {
139
+        for ($j = 1; $j < $features+1; $j++) {
140 140
             $costVector[$j] += $firstOrderIncrement
141
-                * (float)$this->hypothesis->derivative(
141
+                * (float) $this->hypothesis->derivative(
142 142
                     $coefficient,
143 143
                     $result->getIndependentVariable(),
144
-                    $j - 1
144
+                    $j-1
145 145
                 )->getValue();
146 146
         }
147 147
         return $costVector;
Please login to merge, or discard this patch.
src/MachineLearning/Domain/Model/Value/VectorValue.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -32,8 +32,8 @@
 block discarded – undo
32 32
     {
33 33
         $result = 0;
34 34
         $columns = count($this->value);
35
-        for ($i=0; $i<$columns; $i++) {
36
-            $result += $this->value[$i]*$value->getValue()[$i];
35
+        for ($i = 0; $i < $columns; $i++) {
36
+            $result += $this->value[$i] * $value->getValue()[$i];
37 37
         }
38 38
         return $result;
39 39
     }
Please login to merge, or discard this patch.