fix tests

This commit is contained in:
Dennis Eichhorn 2024-04-24 20:20:57 +00:00
parent ca57051cd7
commit 5230892673
18 changed files with 111 additions and 67 deletions

View File

@ -28,7 +28,7 @@ final class AffinityPropagation implements ClusteringInterface
/**
* Points of the cluster centers
*
* @var PointInterface[]
* @var Point[]
* @since 1.0.0
*/
private array $clusterCenters = [];
@ -52,7 +52,7 @@ final class AffinityPropagation implements ClusteringInterface
/**
* Original points used for clusters
*
* @var PointInterface[]
* @var Point[]
* @since 1.0.0
*/
private array $points = [];
@ -60,7 +60,7 @@ final class AffinityPropagation implements ClusteringInterface
/**
* Create similarity matrix from points
*
* @param PointInterface[] $points Points to create the similarity matrix for
* @param Point[] $points Points to create the similarity matrix for
*
* @return array<int, array<int, int|float>>
*
@ -103,7 +103,7 @@ final class AffinityPropagation implements ClusteringInterface
/**
* Generate clusters for points
*
* @param PointInterface[] $points Points to cluster
* @param Point[] $points Points to cluster
* @param int $iterations Iterations for cluster generation
*
* @return void
@ -213,7 +213,7 @@ final class AffinityPropagation implements ClusteringInterface
/**
* {@inheritdoc}
*/
public function cluster(PointInterface $point) : ?PointInterface
public function cluster(Point $point) : ?Point
{
$points = $this->points;
$points[] = $point;

View File

@ -61,7 +61,7 @@ final class AgglomerativeClustering implements ClusteringInterface
*/
public function __construct(?\Closure $metric = null, ?\Closure $linkage = null)
{
$this->metric = $metric ?? function (PointInterface $a, PointInterface $b) {
$this->metric = $metric ?? function (Point $a, Point $b) {
$aCoordinates = $a->coordinates;
$bCoordinates = $b->coordinates;
@ -139,7 +139,7 @@ final class AgglomerativeClustering implements ClusteringInterface
/**
* {@inheritdoc}
*/
public function cluster(PointInterface $point) : ?PointInterface
public function cluster(Point $point) : ?Point
{
return null;
}

View File

@ -46,7 +46,7 @@ final class Birch implements ClusteringInterface
/**
* {@inheritdoc}
*/
public function cluster(PointInterface $point) : ?PointInterface
public function cluster(Point $point) : ?Point
{
return null;
}

View File

@ -27,7 +27,7 @@ interface ClusteringInterface
/**
* Get cluster centroids
*
* @return PointInterface[]
* @return Point[]
*
* @since 1.0.0
*/
@ -36,7 +36,7 @@ interface ClusteringInterface
/**
* Get cluster assignments of the training data
*
* @return PointInterface[]
* @return Point[]
*
* @since 1.0.0
*/
@ -47,20 +47,20 @@ interface ClusteringInterface
*
* This point doesn't have to be in the training data.
*
* @param PointInterface $point Point to cluster
* @param Point $point Point to cluster
*
* @return null|PointInterface
* @return null|Point
*
* @since 1.0.0
*/
public function cluster(PointInterface $point) : ?PointInterface;
public function cluster(Point $point) : ?Point;
/**
* Get noise data.
*
* Data points from the training data that are not part of a cluster.
*
* @return PointInterface[]
* @return Point[]
*
* @since 1.0.0
*/

View File

@ -50,7 +50,7 @@ final class DBSCAN implements ClusteringInterface
/**
* Points outside of any cluster
*
* @var PointInterface[]
* @var Point[]
* @since 1.0.0
*/
private array $noisePoints = [];
@ -58,7 +58,7 @@ final class DBSCAN implements ClusteringInterface
/**
* All points
*
* @var PointInterface[]
* @var Point[]
* @since 1.0.0
*/
private array $points = [];
@ -66,7 +66,7 @@ final class DBSCAN implements ClusteringInterface
/**
* Points of the cluster centers
*
* @var PointInterface[]
* @var Point[]
* @since 1.0.0
*/
private array $clusterCenters = [];
@ -76,7 +76,7 @@ final class DBSCAN implements ClusteringInterface
*
* Array of points assigned to a cluster
*
* @var array<int, PointInterface[]>
* @var array<int, Point[]>
* @since 1.0.0
*/
private array $clusters = [];
@ -118,7 +118,7 @@ final class DBSCAN implements ClusteringInterface
*/
public function __construct(?\Closure $metric = null)
{
$this->metric = $metric ?? function (PointInterface $a, PointInterface $b) {
$this->metric = $metric ?? function (Point $a, Point $b) {
$aCoordinates = $a->coordinates;
$bCoordinates = $b->coordinates;
@ -129,7 +129,7 @@ final class DBSCAN implements ClusteringInterface
/**
* Expand cluster with additional point and potential neighbors.
*
* @param PointInterface $point Point to add to a cluster
* @param Point $point Point to add to a cluster
* @param array $neighbors Neighbors of point
* @param int $c Cluster id
* @param float $epsilon Max distance
@ -140,7 +140,7 @@ final class DBSCAN implements ClusteringInterface
* @since 1.0.0
*/
private function expandCluster(
PointInterface $point,
Point $point,
array $neighbors,
int $c,
float $epsilon,
@ -174,14 +174,14 @@ final class DBSCAN implements ClusteringInterface
/**
* Find neighbors of a point
*
* @param PointInterface $point Base point for potential neighbors
* @param Point $point Base point for potential neighbors
* @param float $epsilon Max distance to neighbor
*
* @return array
*
* @since 1.0.0
*/
private function findNeighbors(PointInterface $point, float $epsilon) : array
private function findNeighbors(Point $point, float $epsilon) : array
{
$neighbors = [];
foreach ($this->points as $point2) {
@ -225,7 +225,7 @@ final class DBSCAN implements ClusteringInterface
/**
* {@inheritdoc}
*/
public function cluster(PointInterface $point) : ?PointInterface
public function cluster(Point $point) : ?Point
{
if ($this->convexHulls === []) {
foreach ($this->clusters as $c => $cluster) {
@ -251,7 +251,7 @@ final class DBSCAN implements ClusteringInterface
/**
* Generate the clusters of the points
*
* @param PointInterface[] $points Points to cluster
* @param Point[] $points Points to cluster
* @param float $epsilon Max distance
* @param int $minPoints Min amount of points required for a cluster
*

View File

@ -50,7 +50,7 @@ final class DivisiveClustering implements ClusteringInterface
/**
* {@inheritdoc}
*/
public function cluster(PointInterface $point) : ?PointInterface
public function cluster(Point $point) : ?Point
{
return null;
}

View File

@ -46,7 +46,7 @@ final class Kmeans implements ClusteringInterface
/**
* Points of the cluster centers
*
* @var PointInterface[]
* @var Point[]
* @since 1.0.0
*/
private array $clusterCenters = [];
@ -54,7 +54,7 @@ final class Kmeans implements ClusteringInterface
/**
* Points of the clusters
*
* @var PointInterface[]
* @var Point[]
* @since 1.0.0
*/
private array $clusters = [];
@ -62,7 +62,7 @@ final class Kmeans implements ClusteringInterface
/**
* Points
*
* @var PointInterface[]
* @var Point[]
* @since 1.0.0
*/
private array $points = [];
@ -76,7 +76,7 @@ final class Kmeans implements ClusteringInterface
*/
public function __construct(?\Closure $metric = null)
{
$this->metric = $metric ?? function (PointInterface $a, PointInterface $b) {
$this->metric = $metric ?? function (Point $a, Point $b) {
$aCoordinates = $a->coordinates;
$bCoordinates = $b->coordinates;
@ -87,7 +87,7 @@ final class Kmeans implements ClusteringInterface
/**
* {@inheritdoc}
*/
public function cluster(PointInterface $point) : ?PointInterface
public function cluster(Point $point) : ?Point
{
$bestCluster = null;
$bestDistance = \PHP_FLOAT_MAX;
@ -121,7 +121,7 @@ final class Kmeans implements ClusteringInterface
/**
* Generate the clusters of the points
*
* @param PointInterface[] $points Points to cluster
* @param Point[] $points Points to cluster
* @param int<1, max> $clusters Amount of clusters
*
* @return void
@ -183,14 +183,14 @@ final class Kmeans implements ClusteringInterface
/**
* Get the index and distance to the nearest cluster center
*
* @param PointInterface $point Point to get the cluster for
* @param PointInterface[] $clusterCenters All cluster centers
* @param Point $point Point to get the cluster for
* @param Point[] $clusterCenters All cluster centers
*
* @return array [index, distance]
*
* @since 1.0.0
*/
private function nearestClusterCenter(PointInterface $point, array $clusterCenters) : array
private function nearestClusterCenter(Point $point, array $clusterCenters) : array
{
$index = $point->group;
$dist = \PHP_FLOAT_MAX;
@ -208,12 +208,12 @@ final class Kmeans implements ClusteringInterface
}
/**
* Initializae cluster centers
* Initialize cluster centers
*
* @param PointInterface[] $points Points to use for the cluster center initialization
* @param Point[] $points Points to use for the cluster center initialization
* @param int<0, max> $n Amount of clusters to use
*
* @return PointInterface[]
* @return Point[]
*
* @since 1.0.0
*/

View File

@ -61,7 +61,7 @@ final class MeanShift implements ClusteringInterface
/**
* Points outside of any cluster
*
* @var PointInterface[]
* @var Point[]
* @since 1.0.0
*/
private array $noisePoints = [];
@ -79,7 +79,7 @@ final class MeanShift implements ClusteringInterface
/**
* Points of the cluster centers
*
* @var PointInterface[]
* @var Point[]
* @since 1.0.0
*/
private array $clusterCenters = [];
@ -104,7 +104,7 @@ final class MeanShift implements ClusteringInterface
*/
public function __construct(?\Closure $metric = null, ?\Closure $kernel = null)
{
$this->metric = $metric ?? function (PointInterface $a, PointInterface $b) {
$this->metric = $metric ?? function (Point $a, Point $b) {
$aCoordinates = $a->coordinates;
$bCoordinates = $b->coordinates;
@ -119,7 +119,7 @@ final class MeanShift implements ClusteringInterface
/**
* Generate the clusters of the points
*
* @param PointInterface[] $points Points to cluster
* @param Point[] $points Points to cluster
* @param array<int|float> $bandwidth Bandwidth(s)
*
* @return void
@ -170,15 +170,15 @@ final class MeanShift implements ClusteringInterface
/**
* Perform shift on a point
*
* @param PointInterface $point Point to shift
* @param PointInterface $points Array of all points
* @param Point $point Point to shift
* @param Point $points Array of all points
* @param array<int|float> $bandwidth Bandwidth(s)
*
* @return PointInterface
* @return Point
*
* @since 1.0.0
*/
private function shiftPoint(PointInterface $point, array $points, array $bandwidth) : PointInterface
private function shiftPoint(Point $point, array $points, array $bandwidth) : Point
{
$scaleFactor = 0.0;
@ -209,7 +209,7 @@ final class MeanShift implements ClusteringInterface
/**
* Group points together into clusters
*
* @param PointInterface[] $points Array of points to assign to groups
* @param Point[] $points Array of points to assign to groups
*
* @return array
*
@ -242,14 +242,14 @@ final class MeanShift implements ClusteringInterface
/**
* Find the closest cluster/group of a point
*
* @param PointInterface $point Point to find the cluster for
* @param array<PointInterface[]> $groups Clusters
* @param Point $point Point to find the cluster for
* @param array<Point[]> $groups Clusters
*
* @return int
*
* @since 1.0.0
*/
private function findNearestGroup(PointInterface $point, array $groups) : int
private function findNearestGroup(Point $point, array $groups) : int
{
$nearestGroupIndex = -1;
$index = 0;
@ -272,14 +272,14 @@ final class MeanShift implements ClusteringInterface
/**
* Find distance of point to best cluster/group
*
* @param PointInterface $point Point to find the cluster for
* @param PointInterface[] $group Clusters
* @param Point $point Point to find the cluster for
* @param Point[] $group Clusters
*
* @return float Distance
*
* @since 1.0.0
*/
private function distanceToGroup(PointInterface $point, array $group) : float
private function distanceToGroup(Point $point, array $group) : float
{
$minDistance = \PHP_FLOAT_MAX;
@ -305,7 +305,7 @@ final class MeanShift implements ClusteringInterface
/**
* {@inheritdoc}
*/
public function cluster(PointInterface $point) : ?PointInterface
public function cluster(Point $point) : ?Point
{
$clusterId = $this->findNearestGroup($point, $this->clusters);

View File

@ -46,7 +46,7 @@ final class SpectralClustering implements ClusteringInterface
/**
* {@inheritdoc}
*/
public function cluster(PointInterface $point) : ?PointInterface
public function cluster(Point $point) : ?Point
{
return null;
}

View File

@ -28,6 +28,7 @@ use phpOMS\Math\Stochastic\Distribution\NormalDistribution;
* @todo Implement https://github.com/sublee/trueskill/blob/master/trueskill/__init__.py
* https://github.com/Karaka-Management/phpOMS/issues/337
*/
// phpcs:ignoreFile
class TrueSkill
{
public const DEFAULT_MU = 25;

View File

@ -134,16 +134,49 @@ final class Loan
return $loan / $collateral;
}
/**
* Calculate the payment for amortization loans (interest + principal)
*
* @param float $loan Loan amount
* @param float $r Rate
* @param float $duration Loan duration
* @param float $interval Payment interval
*
* @return float
*
* @since 1.0.0
*/
public static function getAmortizationLoanPayment(float $loan, float $r, int $duration, int $interval) : float
{
return $loan * (($r / $interval * (1.0 + $r / $interval) / $duration) / ((1.0 + $r / $interval) / $duration) - 1);
}
/**
* Calculate the interest for amortization loans
*
* @param float $loan Loan amount
* @param float $r Rate
* @param float $interval Payment interval
*
* @return float
*
* @since 1.0.0
*/
public static function getAmortizationLoanInterest(float $loan, float $r, int $interval) : float
{
return $loan * $r / $interval;
}
/**
* Calculate the principal for amortization loans
*
* @param float $payment Total payment
* @param float $interval Payment interval
*
* @return float
*
* @since 1.0.0
*/
public static function getAmortizationPrincipalPayment(float $payment, float $interest) : float
{
return $payment - $interest;

View File

@ -1327,6 +1327,17 @@ final class ReadMapper extends DataMapperAbstract
}
}
/**
* Paginate results
*
* @param string $member Member to use for pagination
* @param null|string $ptype Pagination type (previous/next)
* @param mixed $offset Offset
*
* @return self
*
* @since 1.0.0
*/
public function paginate(string $member, ?string $ptype, mixed $offset) : self
{
if ($ptype === 'p') {

View File

@ -21,7 +21,6 @@ use phpOMS\Message\RequestAbstract;
use phpOMS\Router\RouteVerb;
use phpOMS\Security\Guard;
use phpOMS\Uri\HttpUri;
use phpOMS\Uri\UriInterface;
/**
* Request class.
@ -73,12 +72,12 @@ final class HttpRequest extends RequestAbstract
/**
* Constructor.
*
* @param UriInterface $uri Uri
* @param HttpUri $uri Uri
* @param Localization $l11n Localization
*
* @since 1.0.0
*/
public function __construct(?UriInterface $uri = null, ?Localization $l11n = null)
public function __construct(?HttpUri $uri = null, ?Localization $l11n = null)
{
$this->header = new HttpHeader();
$this->header->l11n = $l11n ?? new Localization();
@ -455,13 +454,13 @@ final class HttpRequest extends RequestAbstract
/**
* Set request uri.
*
* @param UriInterface $uri Uri
* @param HttpUri $uri Uri
*
* @return void
*
* @since 1.0.0
*/
public function setUri(UriInterface $uri) : void
public function setUri(HttpUri $uri) : void
{
$this->uri = $uri;
$this->data += $uri->getQueryArray();

View File

@ -29,7 +29,7 @@ final class SocketRouter implements RouterInterface
/**
* Routes.
*
* @var array<string, array<int, array{dest:string, verb:int, csrf?:bool, active?:bool, permission:array{module:string, type:int, category:int}, validation?:array, pattern?:string}>>
* @var array<string, array<int, array{dest:mixed, verb:int, csrf?:bool, active?:bool, permission?:array{module:string, type:int, category:int}, validation?:?array, pattern?:?string}>>
* @since 1.0.0
*/
private array $routes = [];

View File

@ -40,7 +40,7 @@ final class WebRouter implements RouterInterface
/**
* Routes.
*
* @var array<string, array<int, array{dest:string, verb:int, csrf?:bool, active?:bool, permission:array{module:string, type:int, category:int}, validation?:array, pattern?:string}>>
* @var array<string, array<int, array{dest:mixed, verb:int, csrf?:bool, active?:bool, permission?:array{module:string, type:int, category:int}, validation?:?array, pattern?:?string}>>
* @since 1.0.0
*/
private array $routes = [];

View File

@ -70,7 +70,7 @@ abstract class BarAbstract extends CodeAbstract
/**
* {@inheritdoc}
*/
public function get() : mixed
public function get() : ?\GdImage
{
$codeString = static::$CODE_START . $this->generateCodeString() . static::$CODE_END;
@ -137,7 +137,7 @@ abstract class BarAbstract extends CodeAbstract
*
* @since 1.0.0
*/
protected function createImage(string $codeString) : mixed
protected function createImage(string $codeString) : \GdImage
{
$dimensions = $this->calculateDimensions($codeString);
$image = \imagecreate($dimensions['width'], $dimensions['height']);

View File

@ -242,9 +242,9 @@ abstract class CodeAbstract
/**
* Get image reference
*
* @return \GdImage
* @return null|\GdImage
*
* @since 1.0.0
*/
abstract public function get() : mixed;
abstract public function get() : ?\GdImage;
}

View File

@ -28,7 +28,7 @@ abstract class TwoDAbstract extends CodeAbstract
/**
* {@inheritdoc}
*/
public function get() : mixed
public function get() : ?\GdImage
{
$codeArray = $this->generateCodeArray();