protected function assign(array $sample) : int
    {
        $bestDistance = INF;
        $bestCluster = -1;

        foreach ($this->centroids as $cluster => $centroid) {
            $distance = $this->kernel->compute($sample, $centroid);

            if ($distance < $bestDistance) {
                $bestDistance = $distance;
                $bestCluster = $cluster;
            }
        }

        return (int) $bestCluster;
    }
protected function assign(array $sample) : int
    {
        $bestDistance = INF;
        $bestCluster = -1;

        foreach ($this->centroids as $cluster => $centroid) {
            $distance = $this->kernel->compute($sample, $centroid);

            if ($distance < $bestDistance) {
                $bestDistance = $distance;
                $bestCluster = $cluster;
            }
        }

        return (int) $bestCluster;
    }
protected function assign ( array $ sample ) : int { $ bestDistance = INF ; $ bestCluster = - 1 ; foreach ( $ this -> centroids as $ cluster => $ centroid ) { $ distance = $ this -> kernel -> compute ( $ sample , $ centroid ) ; if ( $ distance < $ bestDistance ) { $ bestDistance = $ distance ; $ bestCluster = $ cluster ; } } return ( int ) $ bestCluster ; }
Label a given sample based on its distance from a particular centroid.

@param array $sample
@return int
Label a given sample based on its distance from a particular centroid .