From a2c5252cf26ef453e85420a77ac8588678cac396 Mon Sep 17 00:00:00 2001 From: Jens True Date: Wed, 2 Aug 2023 13:29:14 +0000 Subject: [PATCH] More types --- src/FactorGraphs/Message.php | 5 ++--- src/FactorGraphs/ScheduleLoop.php | 2 +- src/FactorGraphs/ScheduleStep.php | 2 +- src/HashMap.php | 12 ++++++++++++ src/Numerics/GaussianDistribution.php | 14 +------------- .../Layers/IteratedTeamDifferencesInnerLayer.php | 2 +- 6 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/FactorGraphs/Message.php b/src/FactorGraphs/Message.php index 1dbe7c4..31f7cdc 100644 --- a/src/FactorGraphs/Message.php +++ b/src/FactorGraphs/Message.php @@ -6,15 +6,14 @@ class Message implements \Stringable { public function __construct(private ?object $value = null, private ?string $name = null) { - } - public function getValue() + public function getValue(): ?object { return $this->value; } - public function setValue($value) + public function setValue(?object $value): void { $this->value = $value; } diff --git a/src/FactorGraphs/ScheduleLoop.php b/src/FactorGraphs/ScheduleLoop.php index 5bc34c0..bf629d5 100644 --- a/src/FactorGraphs/ScheduleLoop.php +++ b/src/FactorGraphs/ScheduleLoop.php @@ -4,7 +4,7 @@ namespace DNW\Skills\FactorGraphs; class ScheduleLoop extends Schedule { - public function __construct($name, private readonly Schedule $scheduleToLoop, private $maxDelta) + public function __construct(string $name, private readonly Schedule $scheduleToLoop, private float $maxDelta) { parent::__construct($name); } diff --git a/src/FactorGraphs/ScheduleStep.php b/src/FactorGraphs/ScheduleStep.php index 306adcd..00b5b23 100644 --- a/src/FactorGraphs/ScheduleStep.php +++ b/src/FactorGraphs/ScheduleStep.php @@ -4,7 +4,7 @@ namespace DNW\Skills\FactorGraphs; class ScheduleStep extends Schedule { - public function __construct(string $name, private readonly Factor $factor, private $index) + public function __construct(string $name, private readonly Factor $factor, private int $index) { parent::__construct($name); } diff --git a/src/HashMap.php b/src/HashMap.php index 71be566..ba85e9a 100644 --- a/src/HashMap.php +++ b/src/HashMap.php @@ -7,8 +7,14 @@ namespace DNW\Skills; */ class HashMap { + /** + * @var mixed[] $hashToValue + */ private array $hashToValue = []; + /** + * @var mixed[] $hashToKey + */ private array $hashToKey = []; public function getValue(string|object $key): mixed @@ -27,11 +33,17 @@ class HashMap return $this; } + /** + * @return mixed[] + */ public function getAllKeys(): array { return array_values($this->hashToKey); } + /** + * @return mixed[] + */ public function getAllValues(): array { return array_values($this->hashToValue); diff --git a/src/Numerics/GaussianDistribution.php b/src/Numerics/GaussianDistribution.php index 6880baf..c27b561 100644 --- a/src/Numerics/GaussianDistribution.php +++ b/src/Numerics/GaussianDistribution.php @@ -63,18 +63,6 @@ class GaussianDistribution implements \Stringable return 1.0 / (sqrt(2 * M_PI) * $this->standardDeviation); } - public function __clone() - { - $result = new GaussianDistribution(); - $result->mean = $this->mean; - $result->standardDeviation = $this->standardDeviation; - $result->variance = $this->variance; - $result->precision = $this->precision; - $result->precisionMean = $this->precisionMean; - - return $result; - } - public static function fromPrecisionMean(float $precisionMean, float $precision): self { $result = new GaussianDistribution(); @@ -174,7 +162,7 @@ class GaussianDistribution implements \Stringable return 0.5 * $result; } - private static function errorFunctionCumulativeTo($x): float + private static function errorFunctionCumulativeTo(float $x): float { // Derived from page 265 of Numerical Recipes 3rd Edition $z = abs($x); diff --git a/src/TrueSkill/Layers/IteratedTeamDifferencesInnerLayer.php b/src/TrueSkill/Layers/IteratedTeamDifferencesInnerLayer.php index 9db37b2..4e687da 100644 --- a/src/TrueSkill/Layers/IteratedTeamDifferencesInnerLayer.php +++ b/src/TrueSkill/Layers/IteratedTeamDifferencesInnerLayer.php @@ -53,7 +53,7 @@ class IteratedTeamDifferencesInnerLayer extends TrueSkillFactorGraphLayer } // When dealing with differences, there are always (n-1) differences, so add in the 1 - $totalTeamDifferences = is_countable($this->TeamPerformancesToTeamPerformanceDifferencesLayer->getLocalFactors()) ? count($this->TeamPerformancesToTeamPerformanceDifferencesLayer->getLocalFactors()) : 0; + $totalTeamDifferences = count($this->TeamPerformancesToTeamPerformanceDifferencesLayer->getLocalFactors()); $localFactors = $this->TeamPerformancesToTeamPerformanceDifferencesLayer->getLocalFactors();