mirror of
https://github.com/Llewellynvdm/php-ml.git
synced 2024-06-26 11:52:36 +00:00
* Issue #347: Reduce duplicated code. * Issue #347: Replace array_* with regular loops for better perfomance.
32 lines
505 B
PHP
32 lines
505 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Phpml\Math\Distance;
|
|
|
|
/**
|
|
* Class Euclidean
|
|
*
|
|
* L^2 Metric.
|
|
*/
|
|
class Euclidean extends Distance
|
|
{
|
|
/**
|
|
* Euclidean constructor.
|
|
*/
|
|
public function __construct()
|
|
{
|
|
parent::__construct(2.0);
|
|
}
|
|
|
|
/**
|
|
* Square of Euclidean distance
|
|
*
|
|
* @throws \Phpml\Exception\InvalidArgumentException
|
|
*/
|
|
public function sqDistance(array $a, array $b): float
|
|
{
|
|
return $this->distance($a, $b) ** 2;
|
|
}
|
|
}
|