mirror of
https://github.com/Llewellynvdm/php-ml.git
synced 2024-11-15 09:54:08 +00:00
f4650c696c
* fix imports order * drop unused docs typehints, make use of return types where possible
31 lines
611 B
PHP
31 lines
611 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Phpml\Math\Distance;
|
|
|
|
use Phpml\Exception\InvalidArgumentException;
|
|
use Phpml\Math\Distance;
|
|
|
|
class Chebyshev implements Distance
|
|
{
|
|
/**
|
|
* @throws InvalidArgumentException
|
|
*/
|
|
public function distance(array $a, array $b) : float
|
|
{
|
|
if (count($a) !== count($b)) {
|
|
throw InvalidArgumentException::arraySizeNotMatch();
|
|
}
|
|
|
|
$differences = [];
|
|
$count = count($a);
|
|
|
|
for ($i = 0; $i < $count; ++$i) {
|
|
$differences[] = abs($a[$i] - $b[$i]);
|
|
}
|
|
|
|
return max($differences);
|
|
}
|
|
}
|