protected function runGradientDescent(array $samples, array $targets, \Closure $gradientFunc, bool $isBatch = false)
    {
        $class = $isBatch ? GD::class : StochasticGD::class;

        if (empty($this->optimizer)) {
            $this->optimizer = (new $class($this->featureCount))
                ->setLearningRate($this->learningRate)
                ->setMaxIterations($this->maxIterations)
                ->setChangeThreshold(1e-6)
                ->setEarlyStop($this->enableEarlyStop);
        }

        $this->weights = $this->optimizer->runOptimization($samples, $targets, $gradientFunc);
        $this->costValues = $this->optimizer->getCostValues();
    }
protected function runGradientDescent(array $samples, array $targets, \Closure $gradientFunc, bool $isBatch = false)
    {
        $class = $isBatch ? GD::class : StochasticGD::class;

        if (empty($this->optimizer)) {
            $this->optimizer = (new $class($this->featureCount))
                ->setLearningRate($this->learningRate)
                ->setMaxIterations($this->maxIterations)
                ->setChangeThreshold(1e-6)
                ->setEarlyStop($this->enableEarlyStop);
        }

        $this->weights = $this->optimizer->runOptimization($samples, $targets, $gradientFunc);
        $this->costValues = $this->optimizer->getCostValues();
    }
protected function runGradientDescent ( array $ samples , array $ targets , \ Closure $ gradientFunc , bool $ isBatch = false ) { $ class = $ isBatch ? GD :: class : StochasticGD :: class ; if ( empty ( $ this -> optimizer ) ) { $ this -> optimizer = ( new $ class ( $ this -> featureCount ) ) -> setLearningRate ( $ this -> learningRate ) -> setMaxIterations ( $ this -> maxIterations ) -> setChangeThreshold ( 1e-6 ) -> setEarlyStop ( $ this -> enableEarlyStop ) ; } $ this -> weights = $ this -> optimizer -> runOptimization ( $ samples , $ targets , $ gradientFunc ) ; $ this -> costValues = $ this -> optimizer -> getCostValues ( ) ; }
Executes a Gradient Descent algorithm for
the given cost function

@param array    $samples
@param array    $targets
@param \Closure $gradientFunc
@param bool     $isBatch
Executes a Gradient Descent algorithm for the given cost function