@@ -128,7 +128,7 @@ |
||
128 | 128 | } |
129 | 129 | |
130 | 130 | /** |
131 | - * @return mixed |
|
131 | + * @return integer |
|
132 | 132 | */ |
133 | 133 | public function count() |
134 | 134 | { |
@@ -142,6 +142,9 @@ |
||
142 | 142 | $this->addLayer(new Layer($nodes, Input::class)); |
143 | 143 | } |
144 | 144 | |
145 | + /** |
|
146 | + * @param ActivationFunction $defaultActivationFunction |
|
147 | + */ |
|
145 | 148 | private function addNeuronLayers(array $layers, ?ActivationFunction $defaultActivationFunction = null): void |
146 | 149 | { |
147 | 150 | foreach ($layers as $layer) { |
@@ -18,7 +18,7 @@ |
||
18 | 18 | throw new InvalidArgumentException('Size of given arrays does not match'); |
19 | 19 | } |
20 | 20 | |
21 | - return array_sum(array_map(function ($m, $n) { |
|
21 | + return array_sum(array_map(function($m, $n) { |
|
22 | 22 | return abs($m - $n); |
23 | 23 | }, $a, $b)); |
24 | 24 | } |
@@ -51,7 +51,7 @@ |
||
51 | 51 | $mean = Mean::arithmetic($numbers); |
52 | 52 | |
53 | 53 | return array_sum(array_map( |
54 | - function ($val) use ($mean) { |
|
54 | + function($val) use ($mean) { |
|
55 | 55 | return ($val - $mean) ** 2; |
56 | 56 | }, |
57 | 57 | $numbers |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | throw new InvalidArgumentException('The array must have at least 2 elements'); |
29 | 29 | } |
30 | 30 | |
31 | - $samplesPerClass = array_map(function (array $class): int { |
|
31 | + $samplesPerClass = array_map(function(array $class): int { |
|
32 | 32 | return count($class); |
33 | 33 | }, $samples); |
34 | 34 | $allSamples = array_sum($samplesPerClass); |
@@ -41,10 +41,10 @@ discard block |
||
41 | 41 | $dfbn = $classes - 1; |
42 | 42 | $dfwn = $allSamples - $classes; |
43 | 43 | |
44 | - $msb = array_map(function ($s) use ($dfbn) { |
|
44 | + $msb = array_map(function($s) use ($dfbn) { |
|
45 | 45 | return $s / $dfbn; |
46 | 46 | }, $ssbn); |
47 | - $msw = array_map(function ($s) use ($dfwn) { |
|
47 | + $msw = array_map(function($s) use ($dfwn) { |
|
48 | 48 | return $s / $dfwn; |
49 | 49 | }, $sswn); |
50 | 50 | |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | |
73 | 73 | private static function sumOfFeaturesPerClass(array $samples): array |
74 | 74 | { |
75 | - return array_map(function (array $class) { |
|
75 | + return array_map(function(array $class) { |
|
76 | 76 | $sum = array_fill(0, count($class[0]), 0); |
77 | 77 | foreach ($class as $sample) { |
78 | 78 | foreach ($sample as $index => $feature) { |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | } |
94 | 94 | } |
95 | 95 | |
96 | - return array_map(function ($sum) { |
|
96 | + return array_map(function($sum) { |
|
97 | 97 | return $sum ** 2; |
98 | 98 | }, $squares); |
99 | 99 | } |
@@ -126,7 +126,7 @@ |
||
126 | 126 | public function transpose(): self |
127 | 127 | { |
128 | 128 | if ($this->rows == 1) { |
129 | - $matrix = array_map(function ($el) { |
|
129 | + $matrix = array_map(function($el) { |
|
130 | 130 | return [$el]; |
131 | 131 | }, $this->matrix[0]); |
132 | 132 | } else { |
@@ -103,11 +103,11 @@ discard block |
||
103 | 103 | */ |
104 | 104 | protected function predictSample(array $sample): array |
105 | 105 | { |
106 | - $predicts = array_values(array_filter($this->getRules(), function ($rule) use ($sample) { |
|
106 | + $predicts = array_values(array_filter($this->getRules(), function($rule) use ($sample) { |
|
107 | 107 | return $this->equals($rule[self::ARRAY_KEY_ANTECEDENT], $sample); |
108 | 108 | })); |
109 | 109 | |
110 | - return array_map(function ($rule) { |
|
110 | + return array_map(function($rule) { |
|
111 | 111 | return $rule[self::ARRAY_KEY_CONSEQUENT]; |
112 | 112 | }, $predicts); |
113 | 113 | } |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | $cardinality = count($sample); |
177 | 177 | $antecedents = $this->powerSet($sample); |
178 | 178 | |
179 | - return array_filter($antecedents, function ($antecedent) use ($cardinality) { |
|
179 | + return array_filter($antecedents, function($antecedent) use ($cardinality) { |
|
180 | 180 | return (count($antecedent) != $cardinality) && ($antecedent != []); |
181 | 181 | }); |
182 | 182 | } |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | } |
199 | 199 | } |
200 | 200 | |
201 | - return array_map(function ($entry) { |
|
201 | + return array_map(function($entry) { |
|
202 | 202 | return [$entry]; |
203 | 203 | }, $items); |
204 | 204 | } |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | */ |
213 | 213 | private function frequent(array $samples): array |
214 | 214 | { |
215 | - return array_values(array_filter($samples, function ($entry) { |
|
215 | + return array_values(array_filter($samples, function($entry) { |
|
216 | 216 | return $this->support($entry) >= $this->support; |
217 | 217 | })); |
218 | 218 | } |
@@ -287,7 +287,7 @@ discard block |
||
287 | 287 | */ |
288 | 288 | private function frequency(array $sample): int |
289 | 289 | { |
290 | - return count(array_filter($this->samples, function ($entry) use ($sample) { |
|
290 | + return count(array_filter($this->samples, function($entry) use ($sample) { |
|
291 | 291 | return $this->subset($entry, $sample); |
292 | 292 | })); |
293 | 293 | } |
@@ -302,7 +302,7 @@ discard block |
||
302 | 302 | */ |
303 | 303 | private function contains(array $system, array $set): bool |
304 | 304 | { |
305 | - return (bool) array_filter($system, function ($entry) use ($set) { |
|
305 | + return (bool) array_filter($system, function($entry) use ($set) { |
|
306 | 306 | return $this->equals($entry, $set); |
307 | 307 | }); |
308 | 308 | } |
@@ -120,7 +120,7 @@ |
||
120 | 120 | $this->dataType[$label][$i] = self::NOMINAL; |
121 | 121 | $this->discreteProb[$label][$i] = array_count_values($values); |
122 | 122 | $db = &$this->discreteProb[$label][$i]; |
123 | - $db = array_map(function ($el) use ($numValues) { |
|
123 | + $db = array_map(function($el) use ($numValues) { |
|
124 | 124 | return $el / $numValues; |
125 | 125 | }, $db); |
126 | 126 | } else { |
@@ -157,7 +157,7 @@ |
||
157 | 157 | protected function runTraining(array $samples, array $targets) |
158 | 158 | { |
159 | 159 | // The cost function is the sum of squares |
160 | - $callback = function ($weights, $sample, $target) { |
|
160 | + $callback = function($weights, $sample, $target) { |
|
161 | 161 | $this->weights = $weights; |
162 | 162 | |
163 | 163 | $prediction = $this->outputClass($sample); |