2016-04-11 19:35:17 +00:00
|
|
|
<?php
|
|
|
|
|
2016-11-20 21:53:17 +00:00
|
|
|
declare(strict_types=1);
|
2016-04-11 19:35:17 +00:00
|
|
|
|
2016-04-20 21:56:33 +00:00
|
|
|
namespace Phpml\Math\Distance;
|
2016-04-11 19:35:17 +00:00
|
|
|
|
2019-02-06 07:00:17 +00:00
|
|
|
/**
|
|
|
|
* Class Euclidean
|
|
|
|
*
|
|
|
|
* L^2 Metric.
|
|
|
|
*/
|
|
|
|
class Euclidean extends Distance
|
2016-04-11 19:35:17 +00:00
|
|
|
{
|
|
|
|
/**
|
2019-02-06 07:00:17 +00:00
|
|
|
* Euclidean constructor.
|
2016-04-11 19:35:17 +00:00
|
|
|
*/
|
2019-02-06 07:00:17 +00:00
|
|
|
public function __construct()
|
2016-04-11 19:35:17 +00:00
|
|
|
{
|
2019-02-06 07:00:17 +00:00
|
|
|
parent::__construct(2.0);
|
2016-04-11 19:35:17 +00:00
|
|
|
}
|
2017-04-23 07:03:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Square of Euclidean distance
|
2019-02-06 07:00:17 +00:00
|
|
|
*
|
|
|
|
* @throws \Phpml\Exception\InvalidArgumentException
|
2017-04-23 07:03:30 +00:00
|
|
|
*/
|
2017-11-22 21:16:10 +00:00
|
|
|
public function sqDistance(array $a, array $b): float
|
2017-04-23 07:03:30 +00:00
|
|
|
{
|
|
|
|
return $this->distance($a, $b) ** 2;
|
|
|
|
}
|
2016-04-11 19:35:17 +00:00
|
|
|
}
|