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

@@ 118-132 (lines=15) @@
115
     * Trains the perceptron model with Stochastic Gradient Descent optimization
116
     * to get the correct set of weights
117
     */
118
    protected function runTraining()
119
    {
120
        // The cost function is the sum of squares
121
        $callback = function ($weights, $sample, $target) {
122
            $this->weights = $weights;
123
124
            $prediction = $this->outputClass($sample);
125
            $gradient = $prediction - $target;
126
            $error = $gradient**2;
127
128
            return [$error, $gradient];
129
        };
130
131
        $this->runGradientDescent($callback);
132
    }
133
134
    /**
135
     * Executes Stochastic Gradient Descent algorithm for