/** * @param array $sample * * @return array * * @throws \Phpml\Exception\InvalidArgumentException */ private function kNeighborsDistances(array $sample) { $distances = []; foreach ($this->samples as $index => $neighbor) { $distances[$index] = $this->distanceMetric->distance($sample, $neighbor); } asort($distances); return array_slice($distances, 0, $this->k, true); }
/** * @param array $localSample * @param array $samples * * @return array */ private function getSamplesInRegion($localSample, $samples) { $region = []; foreach ($samples as $index => $sample) { if ($this->distanceMetric->distance($localSample, $sample) < $this->epsilon) { $region[$index] = $sample; } } return $region; }