Code Duplication    Length = 9-15 lines in 2 locations

src/Phpml/Classification/Linear/Adaline.php 1 location

@@ 60-68 (lines=9) @@
57
    protected function runTraining()
58
    {
59
        // The cost function is the sum of squares
60
        $callback = function ($weights, $sample, $target) {
61
            $this->weights = $weights;
62
63
            $output = $this->output($sample);
64
            $gradient = $output - $target;
65
            $error = $gradient ** 2;
66
67
            return [$error, $gradient];
68
        };
69
70
        $isBatch = $this->trainingType == self::BATCH_TRAINING;
71

src/Phpml/Classification/Linear/Perceptron.php 1 location

@@ 155-169 (lines=15) @@
152
     * Trains the perceptron model with Stochastic Gradient Descent optimization
153
     * to get the correct set of weights
154
     */
155
    protected function runTraining()
156
    {
157
        // The cost function is the sum of squares
158
        $callback = function ($weights, $sample, $target) {
159
            $this->weights = $weights;
160
161
            $prediction = $this->outputClass($sample);
162
            $gradient = $prediction - $target;
163
            $error = $gradient**2;
164
165
            return [$error, $gradient];
166
        };
167
168
        $this->runGradientDescent($callback);
169
    }
170
171
    /**
172
     * Executes Stochastic Gradient Descent algorithm for