From f0f4a0c2d6874bd27e6d85619ca7c8493ab88126 Mon Sep 17 00:00:00 2001 From: Jens True Date: Thu, 3 Aug 2023 10:09:24 +0000 Subject: [PATCH] More types. --- src/FactorGraphs/ScheduleSequence.php | 3 +++ src/Numerics/BasicMath.php | 2 +- src/Numerics/Vector.php | 3 +++ src/RankSorter.php | 2 +- .../FactorGraphTrueSkillCalculator.php | 7 +++++++ .../Factors/GaussianWeightedSumFactor.php | 21 ++++++++++++++++--- ...yerPerformancesToTeamPerformancesLayer.php | 1 + 7 files changed, 34 insertions(+), 5 deletions(-) diff --git a/src/FactorGraphs/ScheduleSequence.php b/src/FactorGraphs/ScheduleSequence.php index e947acf..c1b7d4c 100644 --- a/src/FactorGraphs/ScheduleSequence.php +++ b/src/FactorGraphs/ScheduleSequence.php @@ -4,6 +4,9 @@ namespace DNW\Skills\FactorGraphs; class ScheduleSequence extends Schedule { + /** + * @param Schedule[] $schedules + */ public function __construct(string $name, private readonly array $schedules) { parent::__construct($name); diff --git a/src/Numerics/BasicMath.php b/src/Numerics/BasicMath.php index bfe0a1f..9126f1b 100644 --- a/src/Numerics/BasicMath.php +++ b/src/Numerics/BasicMath.php @@ -24,7 +24,7 @@ class BasicMath /** * Sums the items in $itemsToSum * - * @param array $itemsToSum The items to sum, + * @param mixed[] $itemsToSum The items to sum, * @param \Closure $callback The function to apply to each array element before summing. * @return number The sum. */ diff --git a/src/Numerics/Vector.php b/src/Numerics/Vector.php index 993cb94..f334bb9 100644 --- a/src/Numerics/Vector.php +++ b/src/Numerics/Vector.php @@ -4,6 +4,9 @@ namespace DNW\Skills\Numerics; class Vector extends Matrix { + /** + * @param float[] $vectorValues + */ public function __construct(array $vectorValues) { $columnValues = []; diff --git a/src/RankSorter.php b/src/RankSorter.php index 011a09b..8b9e344 100644 --- a/src/RankSorter.php +++ b/src/RankSorter.php @@ -11,7 +11,7 @@ class RankSorter * Performs an in-place sort of the items in according to the ranks in non-decreasing order. * * @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. + * @param array $teamRanks The ranks for each item where 1 is first place. * @return array */ public static function sort(array &$teams, array &$teamRanks): array diff --git a/src/TrueSkill/FactorGraphTrueSkillCalculator.php b/src/TrueSkill/FactorGraphTrueSkillCalculator.php index f76d7fe..28d25ef 100644 --- a/src/TrueSkill/FactorGraphTrueSkillCalculator.php +++ b/src/TrueSkill/FactorGraphTrueSkillCalculator.php @@ -91,6 +91,9 @@ class FactorGraphTrueSkillCalculator extends SkillCalculator return exp($expPart) * sqrt($sqrtPart); } + /** + * @var Team[] $teamAssignmentsList + */ private static function getPlayerMeansVector(array $teamAssignmentsList): Vector { // A simple vector of all the player means. @@ -102,6 +105,9 @@ class FactorGraphTrueSkillCalculator extends SkillCalculator ); } + /** + * @var Team[] $teamAssignmentsList + */ private static function getPlayerCovarianceMatrix(array $teamAssignmentsList): DiagonalMatrix { // This is a square matrix whose diagonal values represent the variance (square of standard deviation) of all @@ -117,6 +123,7 @@ class FactorGraphTrueSkillCalculator extends SkillCalculator /** * Helper function that gets a list of values for all player ratings + * @var Team[] $teamAssignmentsList * @return int[] */ private static function getPlayerRatingValues(array $teamAssignmentsList, \Closure $playerRatingFunction): array diff --git a/src/TrueSkill/Factors/GaussianWeightedSumFactor.php b/src/TrueSkill/Factors/GaussianWeightedSumFactor.php index 5ae4ca7..907f840 100644 --- a/src/TrueSkill/Factors/GaussianWeightedSumFactor.php +++ b/src/TrueSkill/Factors/GaussianWeightedSumFactor.php @@ -5,6 +5,7 @@ namespace DNW\Skills\TrueSkill\Factors; use DNW\Skills\FactorGraphs\Message; use DNW\Skills\FactorGraphs\Variable; use DNW\Skills\Guard; +use DNW\Skills\Team; use DNW\Skills\Numerics\BasicMath; use DNW\Skills\Numerics\GaussianDistribution; @@ -15,18 +16,26 @@ use DNW\Skills\Numerics\GaussianDistribution; */ class GaussianWeightedSumFactor extends GaussianFactor { + /** + * @var array $variableIndexOrdersForWeights + */ private array $variableIndexOrdersForWeights = []; - /** * This following is used for convenience, for example, the first entry is [0, 1, 2] * corresponding to v[0] = a1*v[1] + a2*v[2] - * @var array $weights + * @var array $weights */ private array $weights = []; - + /** + * @var array $weightsSquared + */ private array $weightsSquared = []; + /** + * @param Variable[] $variablesToSum + * @param array $variableWeights + */ public function __construct(Variable $sumVariable, array $variablesToSum, array $variableWeights = null) { parent::__construct(self::createName($sumVariable, $variablesToSum, $variableWeights)); @@ -132,6 +141,12 @@ class GaussianWeightedSumFactor extends GaussianFactor return $result; } + /** + * @param float[] $weights + * @param float[] $weightsSquared + * @param Message[] $messages + * @param Variable[] $variables + */ private function updateHelper(array $weights, array $weightsSquared, array $messages, array $variables): float { // Potentially look at http://mathworld.wolfram.com/NormalSumDistribution.html for clues as diff --git a/src/TrueSkill/Layers/PlayerPerformancesToTeamPerformancesLayer.php b/src/TrueSkill/Layers/PlayerPerformancesToTeamPerformancesLayer.php index 26f0a42..1260ec3 100644 --- a/src/TrueSkill/Layers/PlayerPerformancesToTeamPerformancesLayer.php +++ b/src/TrueSkill/Layers/PlayerPerformancesToTeamPerformancesLayer.php @@ -6,6 +6,7 @@ use DNW\Skills\FactorGraphs\ScheduleStep; use DNW\Skills\FactorGraphs\ScheduleSequence; use DNW\Skills\PartialPlay; use DNW\Skills\Player; +use DNW\Skills\Team; use DNW\Skills\TrueSkill\Factors\GaussianWeightedSumFactor; use DNW\Skills\FactorGraphs\Variable;