for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace Phpml\Math\Distance;
use Phpml\Exception\InvalidArgumentException;
use Phpml\Math\Distance as DistanceInterface;
/**
* Class Distance
*/
abstract class Distance implements DistanceInterface
{
* @var float|int
public $norm;
* Distance constructor.
public function __construct(float $norm = 3.0)
$this->norm = $norm;
}
* @throws InvalidArgumentException
public function distance(array $a, array $b): float
$norm = $this->norm;
return array_sum(
array_map(
function ($a) use ($norm) {
return $a ** $norm;
},
$this->deltas($a, $b)
)
) ** (1 / $norm);
protected function deltas(array $a, array $b): array
if (count($a) !== count($b)) {
throw new InvalidArgumentException('Size of given arrays does not match');
return array_map(
function ($a, $b) {
return abs($a - $b);
$a,
$b
);