MCordingley\Regression\Algorithm\GradientDescent\Batch::calculateGradient PHP Méthode

calculateGradient() protected méthode

protected calculateGradient ( Observations $observations, array $coefficients ) : array
$observations MCordingley\Regression\Observations
$coefficients array
Résultat array
    protected function calculateGradient(Observations $observations, array $coefficients) : array
    {
        $gradient = array_fill(0, count($observations->getObservation(0)->getFeatures()), 0.0);
        $batchSize = count($observations);
        /** @var Observation $observation */
        foreach ($observations as $observation) {
            $observationGradient = $this->gradient->gradient($coefficients, $observation->getFeatures(), $observation->getOutcome());
            foreach ($observationGradient as $i => $observationSlope) {
                $gradient[$i] += $observationSlope / $batchSize;
            }
        }
        return $gradient;
    }