More type checks

This commit is contained in:
2023-08-01 12:13:24 +00:00
parent 068b6f18aa
commit d5bba04f4f
15 changed files with 72 additions and 73 deletions

View File

@ -14,6 +14,7 @@ use DNW\Skills\RankSorter;
use DNW\Skills\SkillCalculator;
use DNW\Skills\SkillCalculatorSupportedOptions;
use DNW\Skills\TeamsRange;
use DNW\Skills\RatingContainer;
/**
* Calculates TrueSkill using a full factor graph.
@ -27,7 +28,7 @@ class FactorGraphTrueSkillCalculator extends SkillCalculator
public function calculateNewRatings(GameInfo $gameInfo,
array $teams,
array $teamRanks)
array $teamRanks): RatingContainer
{
Guard::argumentNotNull($gameInfo, 'gameInfo');
$this->validateTeamCountAndPlayersCountPerTeam($teams);

View File

@ -6,6 +6,7 @@ use DNW\Skills\FactorGraphs\KeyedVariable;
use DNW\Skills\FactorGraphs\ScheduleStep;
use DNW\Skills\Numerics\BasicMath;
use DNW\Skills\TrueSkill\Factors\GaussianLikelihoodFactor;
use DNW\Skills\FactorGraphs\ScheduleSequence;
class PlayerSkillsToPerformancesLayer extends TrueSkillFactorGraphLayer
{
@ -30,7 +31,7 @@ class PlayerSkillsToPerformancesLayer extends TrueSkillFactorGraphLayer
}
}
private function createLikelihood(KeyedVariable $playerSkill, KeyedVariable $playerPerformance)
private function createLikelihood(KeyedVariable $playerSkill, KeyedVariable $playerPerformance): GaussianLikelihoodFactor
{
return new GaussianLikelihoodFactor(
BasicMath::square($this->getParentFactorGraph()->getGameInfo()->getBeta()),
@ -44,7 +45,7 @@ class PlayerSkillsToPerformancesLayer extends TrueSkillFactorGraphLayer
return $this->getParentFactorGraph()->getVariableFactory()->createKeyedVariable($key, $key."'s performance");
}
public function createPriorSchedule()
public function createPriorSchedule(): ScheduleSequence
{
$localFactors = $this->getLocalFactors();
@ -55,7 +56,7 @@ class PlayerSkillsToPerformancesLayer extends TrueSkillFactorGraphLayer
'All skill to performance sending');
}
public function createPosteriorSchedule()
public function createPosteriorSchedule(): ScheduleSequence
{
$localFactors = $this->getLocalFactors();

View File

@ -110,7 +110,7 @@ class TrueSkillFactorGraph extends FactorGraph
return new ScheduleSequence('Full schedule', $fullSchedule);
}
public function getUpdatedRatings()
public function getUpdatedRatings(): RatingContainer
{
$result = new RatingContainer();

View File

@ -17,9 +17,8 @@ class TruncatedGaussianCorrectionFunctions
* @param $teamPerformanceDifference
* @param number $drawMargin In the paper, it's referred to as just "ε".
* @param $c
* @return float
*/
public static function vExceedsMarginScaled($teamPerformanceDifference, $drawMargin, $c)
public static function vExceedsMarginScaled($teamPerformanceDifference, float|int $drawMargin, $c): float
{
return self::vExceedsMargin($teamPerformanceDifference / $c, $drawMargin / $c);
}
@ -44,14 +43,13 @@ class TruncatedGaussianCorrectionFunctions
* @param $teamPerformanceDifference
* @param $drawMargin
* @param $c
* @return float
*/
public static function wExceedsMarginScaled($teamPerformanceDifference, $drawMargin, $c)
public static function wExceedsMarginScaled($teamPerformanceDifference, float|int $drawMargin, $c): float
{
return self::wExceedsMargin($teamPerformanceDifference / $c, $drawMargin / $c);
}
public static function wExceedsMargin($teamPerformanceDifference, $drawMargin)
public static function wExceedsMargin($teamPerformanceDifference, $drawMargin): float
{
$denominator = GaussianDistribution::cumulativeTo($teamPerformanceDifference - $drawMargin);
@ -69,13 +67,13 @@ class TruncatedGaussianCorrectionFunctions
}
// the additive correction of a double-sided truncated Gaussian with unit variance
public static function vWithinMarginScaled($teamPerformanceDifference, $drawMargin, $c)
public static function vWithinMarginScaled($teamPerformanceDifference, float|int $drawMargin, $c): float
{
return self::vWithinMargin($teamPerformanceDifference / $c, $drawMargin / $c);
}
// from F#:
public static function vWithinMargin($teamPerformanceDifference, $drawMargin)
public static function vWithinMargin($teamPerformanceDifference, $drawMargin): float
{
$teamPerformanceDifferenceAbsoluteValue = abs($teamPerformanceDifference);
$denominator =
@ -101,13 +99,13 @@ class TruncatedGaussianCorrectionFunctions
}
// the multiplicative correction of a double-sided truncated Gaussian with unit variance
public static function wWithinMarginScaled($teamPerformanceDifference, $drawMargin, $c)
public static function wWithinMarginScaled($teamPerformanceDifference, float|int $drawMargin, $c): float
{
return self::wWithinMargin($teamPerformanceDifference / $c, $drawMargin / $c);
}
// From F#:
public static function wWithinMargin($teamPerformanceDifference, $drawMargin)
public static function wWithinMargin($teamPerformanceDifference, float|int $drawMargin)
{
$teamPerformanceDifferenceAbsoluteValue = abs($teamPerformanceDifference);
$denominator = GaussianDistribution::cumulativeTo($drawMargin - $teamPerformanceDifferenceAbsoluteValue)

View File

@ -29,7 +29,7 @@ class TwoPlayerTrueSkillCalculator extends SkillCalculator
public function calculateNewRatings(GameInfo $gameInfo,
array $teams,
array $teamRanks)
array $teamRanks): RatingContainer
{
// Basic argument checking
Guard::argumentNotNull($gameInfo, 'gameInfo');