fix tests

This commit is contained in:
Dennis Eichhorn 2024-04-24 20:34:29 +00:00
parent 5230892673
commit 126fca5574
9 changed files with 34 additions and 26 deletions

View File

@ -104,7 +104,7 @@ final class AffinityPropagation implements ClusteringInterface
* Generate clusters for points * Generate clusters for points
* *
* @param Point[] $points Points to cluster * @param Point[] $points Points to cluster
* @param int $iterations Iterations for cluster generation * @param int $iterations Iterations for cluster generation
* *
* @return void * @return void
* *
@ -188,8 +188,8 @@ final class AffinityPropagation implements ClusteringInterface
/** /**
* Find the nearest group for a point * Find the nearest group for a point
* *
* @param array<int, array<int, int|float>> $similarityMatrix Similarity matrix * @param array<int, Point> $similarityMatrix Similarity matrix
* @param int $point Point id in the similarity matrix to compare * @param int $point Point id in the similarity matrix to compare
* *
* @return int * @return int
* *

View File

@ -42,7 +42,7 @@ final class AgglomerativeClustering implements ClusteringInterface
* @var \Closure * @var \Closure
* @since 1.0.0 * @since 1.0.0
*/ */
private \Closure $metric; public \Closure $metric;
/** /**
* Metric to calculate the distance between two points * Metric to calculate the distance between two points
@ -50,7 +50,7 @@ final class AgglomerativeClustering implements ClusteringInterface
* @var \Closure * @var \Closure
* @since 1.0.0 * @since 1.0.0
*/ */
private \Closure $linkage; public \Closure $linkage;
/** /**
* Constructor * Constructor

View File

@ -130,10 +130,10 @@ final class DBSCAN implements ClusteringInterface
* Expand cluster with additional point and potential neighbors. * Expand cluster with additional point and potential neighbors.
* *
* @param Point $point Point to add to a cluster * @param Point $point Point to add to a cluster
* @param array $neighbors Neighbors of point * @param array $neighbors Neighbors of point
* @param int $c Cluster id * @param int $c Cluster id
* @param float $epsilon Max distance * @param float $epsilon Max distance
* @param int $minPoints Min amount of points required for a cluster * @param int $minPoints Min amount of points required for a cluster
* *
* @return void * @return void
* *
@ -175,7 +175,7 @@ final class DBSCAN implements ClusteringInterface
* Find neighbors of a point * Find neighbors of a point
* *
* @param Point $point Base point for potential neighbors * @param Point $point Base point for potential neighbors
* @param float $epsilon Max distance to neighbor * @param float $epsilon Max distance to neighbor
* *
* @return array * @return array
* *
@ -252,8 +252,8 @@ final class DBSCAN implements ClusteringInterface
* Generate the clusters of the points * Generate the clusters of the points
* *
* @param Point[] $points Points to cluster * @param Point[] $points Points to cluster
* @param float $epsilon Max distance * @param float $epsilon Max distance
* @param int $minPoints Min amount of points required for a cluster * @param int $minPoints Min amount of points required for a cluster
* *
* @return void * @return void
* *

View File

@ -121,8 +121,8 @@ final class Kmeans implements ClusteringInterface
/** /**
* Generate the clusters of the points * Generate the clusters of the points
* *
* @param Point[] $points Points to cluster * @param Point[] $points Points to cluster
* @param int<1, max> $clusters Amount of clusters * @param int<1, max> $clusters Amount of clusters
* *
* @return void * @return void
* *
@ -210,8 +210,8 @@ final class Kmeans implements ClusteringInterface
/** /**
* Initialize cluster centers * Initialize cluster centers
* *
* @param Point[] $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 * @param int<0, max> $n Amount of clusters to use
* *
* @return Point[] * @return Point[]
* *

View File

@ -119,7 +119,7 @@ final class MeanShift implements ClusteringInterface
/** /**
* Generate the clusters of the points * Generate the clusters of the points
* *
* @param Point[] $points Points to cluster * @param Point[] $points Points to cluster
* @param array<int|float> $bandwidth Bandwidth(s) * @param array<int|float> $bandwidth Bandwidth(s)
* *
* @return void * @return void
@ -170,8 +170,8 @@ final class MeanShift implements ClusteringInterface
/** /**
* Perform shift on a point * Perform shift on a point
* *
* @param Point $point Point to shift * @param Point $point Point to shift
* @param Point $points Array of all points * @param Point $points Array of all points
* @param array<int|float> $bandwidth Bandwidth(s) * @param array<int|float> $bandwidth Bandwidth(s)
* *
* @return Point * @return Point

View File

@ -89,7 +89,7 @@ class Point implements PointInterface
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function isEquals(PointInterface $point) : bool public function isEquals(Point $point) : bool
{ {
return $this->name === $point->name && $this->coordinates === $point->coordinates; return $this->name === $point->name && $this->coordinates === $point->coordinates;
} }

View File

@ -67,11 +67,11 @@ interface PointInterface
/** /**
* Check if two points are equal * Check if two points are equal
* *
* @param self $point Point to compare with * @param Point $point Point to compare with
* *
* @return bool * @return bool
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public function isEquals(self $point) : bool; public function isEquals(Point $point) : bool;
} }

View File

@ -139,8 +139,8 @@ final class Loan
* *
* @param float $loan Loan amount * @param float $loan Loan amount
* @param float $r Rate * @param float $r Rate
* @param float $duration Loan duration * @param int $duration Loan duration
* @param float $interval Payment interval * @param int $interval Payment interval
* *
* @return float * @return float
* *
@ -156,7 +156,7 @@ final class Loan
* *
* @param float $loan Loan amount * @param float $loan Loan amount
* @param float $r Rate * @param float $r Rate
* @param float $interval Payment interval * @param int $interval Payment interval
* *
* @return float * @return float
* *
@ -171,7 +171,7 @@ final class Loan
* Calculate the principal for amortization loans * Calculate the principal for amortization loans
* *
* @param float $payment Total payment * @param float $payment Total payment
* @param float $interval Payment interval * @param float $interest Interest payment
* *
* @return float * @return float
* *
@ -183,6 +183,8 @@ final class Loan
} }
/** /**
* Calculate schedule for amortization loan
*
* @param float $loan Loan amount * @param float $loan Loan amount
* @param float $r Borrowing rate (annual) * @param float $r Borrowing rate (annual)
* @param int $duration Loan duration in months * @param int $duration Loan duration in months

View File

@ -217,6 +217,9 @@ abstract class CodeAbstract
public function saveToPngFile(string $file) : void public function saveToPngFile(string $file) : void
{ {
$res = $this->get(); $res = $this->get();
if ($res === null) {
return;
}
\imagepng($res, $file); \imagepng($res, $file);
\imagedestroy($res); \imagedestroy($res);
@ -234,6 +237,9 @@ abstract class CodeAbstract
public function saveToJpgFile(string $file) : void public function saveToJpgFile(string $file) : void
{ {
$res = $this->get(); $res = $this->get();
if ($res === null) {
return;
}
\imagejpeg($res, $file); \imagejpeg($res, $file);
\imagedestroy($res); \imagedestroy($res);