public static function split(Dataset $dataset, Distance $kernel) : self
    {
        $samples = $dataset->samples();

        $center = Matrix::quick($samples)
            ->transpose()
            ->mean()
            ->asArray();
            
        $distances = [];

        foreach ($samples as $sample) {
            $distances[] = $kernel->compute($sample, $center);
        }

        $radius = max($distances);

        $leftCentroid = $dataset->row(argmax($distances));

        $distances = [];

        foreach ($samples as $sample) {
            $distances[] = $kernel->compute($sample, $leftCentroid);
        }

        $rightCentroid = $dataset->row(argmax($distances));
        
        $subsets = $dataset->spatialPartition($leftCentroid, $rightCentroid, $kernel);

        return new self($center, $radius, $subsets);
    }
public static function split(Dataset $dataset, Distance $kernel) : self
    {
        $samples = $dataset->samples();

        $center = Matrix::quick($samples)
            ->transpose()
            ->mean()
            ->asArray();
            
        $distances = [];

        foreach ($samples as $sample) {
            $distances[] = $kernel->compute($sample, $center);
        }

        $radius = max($distances);

        $leftCentroid = $dataset->row(argmax($distances));

        $distances = [];

        foreach ($samples as $sample) {
            $distances[] = $kernel->compute($sample, $leftCentroid);
        }

        $rightCentroid = $dataset->row(argmax($distances));
        
        $subsets = $dataset->spatialPartition($leftCentroid, $rightCentroid, $kernel);

        return new self($center, $radius, $subsets);
    }
public static function split ( Dataset $ dataset , Distance $ kernel ) : self { $ samples = $ dataset -> samples ( ) ; $ center = Matrix :: quick ( $ samples ) -> transpose ( ) -> mean ( ) -> asArray ( ) ; $ distances = [ ] ; foreach ( $ samples as $ sample ) { $ distances [ ] = $ kernel -> compute ( $ sample , $ center ) ; } $ radius = max ( $ distances ) ; $ leftCentroid = $ dataset -> row ( argmax ( $ distances ) ) ; $ distances = [ ] ; foreach ( $ samples as $ sample ) { $ distances [ ] = $ kernel -> compute ( $ sample , $ leftCentroid ) ; } $ rightCentroid = $ dataset -> row ( argmax ( $ distances ) ) ; $ subsets = $ dataset -> spatialPartition ( $ leftCentroid , $ rightCentroid , $ kernel ) ; return new self ( $ center , $ radius , $ subsets ) ; }
Factory method to build a centroid node from a labeled dataset
using the column with the highest variance as the column for the
split.

@param \Rubix\ML\Datasets\Dataset $dataset
@param \Rubix\ML\Kernels\Distance\Distance $kernel
@return self
Factory method to build a centroid node from a labeled dataset using the column with the highest variance as the column for the split .