From e49f01cd689c17498b1bb9231b95d10208358066 Mon Sep 17 00:00:00 2001 From: Jens True Date: Tue, 8 Aug 2023 07:51:05 +0000 Subject: [PATCH] More warnings resolved. --- src/FactorGraphs/FactorGraph.php | 5 +++++ src/FactorGraphs/Message.php | 8 +++++--- src/FactorGraphs/Variable.php | 8 +++++--- src/Numerics/Matrix.php | 5 ----- src/PartialPlay.php | 5 ----- src/RankSorter.php | 2 +- src/TrueSkill/Factors/GaussianWeightedSumFactor.php | 10 +++++----- .../Layers/PlayerPriorValuesToSkillsLayer.php | 3 ++- 8 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/FactorGraphs/FactorGraph.php b/src/FactorGraphs/FactorGraph.php index 387c256..83fb81a 100644 --- a/src/FactorGraphs/FactorGraph.php +++ b/src/FactorGraphs/FactorGraph.php @@ -6,6 +6,11 @@ class FactorGraph { private VariableFactory $variableFactory; + public function __construct(VariableFactory $factory) + { + $this->variableFactory = $factory; + } + public function getVariableFactory(): VariableFactory { return $this->variableFactory; diff --git a/src/FactorGraphs/Message.php b/src/FactorGraphs/Message.php index 31f7cdc..ce926f4 100644 --- a/src/FactorGraphs/Message.php +++ b/src/FactorGraphs/Message.php @@ -2,18 +2,20 @@ namespace DNW\Skills\FactorGraphs; +use DNW\Skills\Numerics\GaussianDistribution; + class Message implements \Stringable { - public function __construct(private ?object $value = null, private ?string $name = null) + public function __construct(private GaussianDistribution $value, private string $name) { } - public function getValue(): ?object + public function getValue(): GaussianDistribution { return $this->value; } - public function setValue(?object $value): void + public function setValue(GaussianDistribution $value): void { $this->value = $value; } diff --git a/src/FactorGraphs/Variable.php b/src/FactorGraphs/Variable.php index 027eb68..e3c76d6 100644 --- a/src/FactorGraphs/Variable.php +++ b/src/FactorGraphs/Variable.php @@ -2,24 +2,26 @@ namespace DNW\Skills\FactorGraphs; +use DNW\Skills\Numerics\GaussianDistribution; + class Variable implements \Stringable { private string $name; private mixed $value; - public function __construct(string $name, private mixed $prior) + public function __construct(string $name, private GaussianDistribution $prior) { $this->name = 'Variable[' . $name . ']'; $this->resetToPrior(); } - public function getValue(): mixed + public function getValue(): GaussianDistribution { return $this->value; } - public function setValue(mixed $value): void + public function setValue(GaussianDistribution $value): void { $this->value = $value; } diff --git a/src/Numerics/Matrix.php b/src/Numerics/Matrix.php index 9081825..c591476 100644 --- a/src/Numerics/Matrix.php +++ b/src/Numerics/Matrix.php @@ -318,11 +318,6 @@ class Matrix public function equals(Matrix $otherMatrix): bool { - // If one is null, but not both, return false. - if ($otherMatrix == null) { - return false; - } - if (($this->rowCount != $otherMatrix->getRowCount()) || ($this->columnCount != $otherMatrix->getColumnCount())) { return false; } diff --git a/src/PartialPlay.php b/src/PartialPlay.php index 966aca5..a168c12 100644 --- a/src/PartialPlay.php +++ b/src/PartialPlay.php @@ -6,11 +6,6 @@ class PartialPlay { public static function getPartialPlayPercentage(Player $player): float { - // If the player doesn't support the interface, assume 1.0 == 100% - if (! $player instanceof ISupportPartialPlay) { - return 1.0; - } - $partialPlayPercentage = $player->getPartialPlayPercentage(); // HACK to get around bug near 0 diff --git a/src/RankSorter.php b/src/RankSorter.php index 7cd8cf6..8f8f26a 100644 --- a/src/RankSorter.php +++ b/src/RankSorter.php @@ -12,7 +12,7 @@ class RankSorter * * @param array $teams The items to sort according to the order specified by ranks. * @param array $teamRanks The ranks for each item where 1 is first place. - * @return array + * @return array */ public static function sort(array &$teams, array &$teamRanks): array { diff --git a/src/TrueSkill/Factors/GaussianWeightedSumFactor.php b/src/TrueSkill/Factors/GaussianWeightedSumFactor.php index c6a11de..fab4c68 100644 --- a/src/TrueSkill/Factors/GaussianWeightedSumFactor.php +++ b/src/TrueSkill/Factors/GaussianWeightedSumFactor.php @@ -17,7 +17,7 @@ use DNW\Skills\Numerics\GaussianDistribution; class GaussianWeightedSumFactor extends GaussianFactor { /** - * @var array $variableIndexOrdersForWeights + * @var array $variableIndexOrdersForWeights */ private array $variableIndexOrdersForWeights = []; @@ -42,8 +42,8 @@ class GaussianWeightedSumFactor extends GaussianFactor // The first weights are a straightforward copy // v_0 = a_1*v_1 + a_2*v_2 + ... + a_n * v_n - $variableWeightsLength = count((array) $variableWeights); - $this->weights[0] = array_fill(0, count((array) $variableWeights), 0); + $variableWeightsLength = count($variableWeights); + $this->weights[0] = array_fill(0, count($variableWeights), 0); for ($i = 0; $i < $variableWeightsLength; $i++) { $weight = &$variableWeights[$i]; @@ -59,7 +59,7 @@ class GaussianWeightedSumFactor extends GaussianFactor $this->variableIndexOrdersForWeights[0][] = $i; } - $variableWeightsLength = count((array) $variableWeights); + $variableWeightsLength = count($variableWeights); // The rest move the variables around and divide out the constant. // For example: @@ -111,7 +111,7 @@ class GaussianWeightedSumFactor extends GaussianFactor } $currentWeights[$currentDestinationWeightIndex] = $finalWeight; $currentWeightsSquared[$currentDestinationWeightIndex] = BasicMath::square($finalWeight); - $variableIndices[count((array) $variableWeights)] = 0; + $variableIndices[count($variableWeights)] = 0; $this->variableIndexOrdersForWeights[] = $variableIndices; $this->weights[$weightsIndex] = $currentWeights; diff --git a/src/TrueSkill/Layers/PlayerPriorValuesToSkillsLayer.php b/src/TrueSkill/Layers/PlayerPriorValuesToSkillsLayer.php index d25c6a5..ac1b3d5 100644 --- a/src/TrueSkill/Layers/PlayerPriorValuesToSkillsLayer.php +++ b/src/TrueSkill/Layers/PlayerPriorValuesToSkillsLayer.php @@ -8,6 +8,7 @@ use DNW\Skills\FactorGraphs\KeyedVariable; use DNW\Skills\Numerics\BasicMath; use DNW\Skills\Rating; use DNW\Skills\Team; +use DNW\Skills\Player; use DNW\Skills\TrueSkill\Factors\GaussianPriorFactor; use DNW\Skills\TrueSkill\TrueSkillFactorGraph; use DNW\Skills\FactorGraphs\ScheduleSequence; @@ -69,7 +70,7 @@ class PlayerPriorValuesToSkillsLayer extends TrueSkillFactorGraphLayer ); } - private function createSkillOutputVariable(mixed $key): KeyedVariable + private function createSkillOutputVariable(Player $key): KeyedVariable { $parentFactorGraph = $this->getParentFactorGraph(); $variableFactory = $parentFactorGraph->getVariableFactory();