*/ public function compatibility() : array { return [ DataType::continuous(), ]; } /** * Compute the distance between two vectors. * * @internal * * @param list $a * @param list $b * @return float */ public function compute(array $a, array $b) : float { $distance = 0.0; $numNaNs = 0; foreach ($a as $i => $valueA) { $valueB = $b[$i]; if (is_float($valueA) and is_nan($valueA)) { ++$numNaNs; continue; } if (is_float($valueB) and is_nan($valueB)) { ++$numNaNs; continue; } $distance += ($valueA - $valueB) ** 2; } $n = count($a); if ($numNaNs === $n) { return NAN; } return sqrt($n / ($n - $numNaNs) * $distance); } /** * Return the string representation of the object. * * @internal * * @return string */ public function __toString() : string { return 'Safe Euclidean'; } }