public function range(array $sample, float $radius) : array
    {
        if ($radius <= 0.) {
            throw new InvalidArgumentException('Radius must be'
                . " greater than 0, $radius given.");
        }

        $samples = $labels = $distances = [];

        $stack = [$this->root];

        while ($stack) {
            $current = array_pop($stack);

            if (!$current instanceof BinaryNode) {
                continue 1;
            }

            if ($current instanceof Cluster) {
                foreach ($current->samples() as $i => $neighbor) {
                    $distance = $this->kernel->compute($sample, $neighbor);

                    if ($distance <= $radius) {
                        $samples[] = $neighbor;
                        $labels[] = $current->label($i);
                        $distances[] = $distance;
                    }
                }

                continue 1;
            }

            foreach ($current->children() as $child) {
                if ($child instanceof Ball) {
                    $distance = $this->kernel->compute($sample, $child->center());

                    if ($distance <= ($child->radius() + $radius)) {
                        $stack[] = $child;
                    }
                }
            }
        }

        return [$samples, $labels, $distances];
    }
public function range(array $sample, float $radius) : array
    {
        if ($radius <= 0.) {
            throw new InvalidArgumentException('Radius must be'
                . " greater than 0, $radius given.");
        }

        $samples = $labels = $distances = [];

        $stack = [$this->root];

        while ($stack) {
            $current = array_pop($stack);

            if (!$current instanceof BinaryNode) {
                continue 1;
            }

            if ($current instanceof Cluster) {
                foreach ($current->samples() as $i => $neighbor) {
                    $distance = $this->kernel->compute($sample, $neighbor);

                    if ($distance <= $radius) {
                        $samples[] = $neighbor;
                        $labels[] = $current->label($i);
                        $distances[] = $distance;
                    }
                }

                continue 1;
            }

            foreach ($current->children() as $child) {
                if ($child instanceof Ball) {
                    $distance = $this->kernel->compute($sample, $child->center());

                    if ($distance <= ($child->radius() + $radius)) {
                        $stack[] = $child;
                    }
                }
            }
        }

        return [$samples, $labels, $distances];
    }
public function range ( array $ sample , float $ radius ) : array { if ( $ radius <= 0. ) { throw new InvalidArgumentException ( 'Radius must be' . " greater than 0, $radius given." ) ; } $ samples = $ labels = $ distances = [ ] ; $ stack = [ $ this -> root ] ; while ( $ stack ) { $ current = array_pop ( $ stack ) ; if ( ! $ current instanceof BinaryNode ) { continue 1 ; } if ( $ current instanceof Cluster ) { foreach ( $ current -> samples ( ) as $ i => $ neighbor ) { $ distance = $ this -> kernel -> compute ( $ sample , $ neighbor ) ; if ( $ distance <= $ radius ) { $ samples [ ] = $ neighbor ; $ labels [ ] = $ current -> label ( $ i ) ; $ distances [ ] = $ distance ; } } continue 1 ; } foreach ( $ current -> children ( ) as $ child ) { if ( $ child instanceof Ball ) { $ distance = $ this -> kernel -> compute ( $ sample , $ child -> center ( ) ) ; if ( $ distance <= ( $ child -> radius ( ) + $ radius ) ) { $ stack [ ] = $ child ; } } } } return [ $ samples , $ labels , $ distances ] ; }
Run a range search over every cluster within radius and return
the labels and distances in a 2-tuple.

@param array $sample
@param float $radius
@throws \InvalidArgumentException
@return array[]
Run a range search over every cluster within radius and return the labels and distances in a 2 - tuple .