Bunch of generic code standard items. Will need a cleanup.
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed

This commit is contained in:
2024-02-02 15:16:11 +00:00
parent 3dddfc05db
commit c18ccd38e2
38 changed files with 117 additions and 26 deletions

View File

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace DNW\Skills\TrueSkill;
use DNW\Skills\GameInfo;
@ -34,7 +36,8 @@ class FactorGraphTrueSkillCalculator extends SkillCalculator
GameInfo $gameInfo,
array $teams,
array $teamRanks
): RatingContainer {
): RatingContainer
{
Guard::argumentNotNull($gameInfo, 'gameInfo');
$this->validateTeamCountAndPlayersCountPerTeam($teams);
@ -124,7 +127,9 @@ class FactorGraphTrueSkillCalculator extends SkillCalculator
/**
* Helper function that gets a list of values for all player ratings
*
* @param Team[] $teamAssignmentsList
*
* @return int[]
*/
private static function getPlayerRatingValues(array $teamAssignmentsList, \Closure $playerRatingFunction): array

View File

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace DNW\Skills\TrueSkill\Factors;
use DNW\Skills\FactorGraphs\Factor;

View File

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace DNW\Skills\TrueSkill\Factors;
use DNW\Skills\FactorGraphs\Message;
@ -62,11 +64,9 @@ class GaussianGreaterThanFactor extends GaussianFactor
$denom = 1.0 - TruncatedGaussianCorrectionFunctions::wExceedsMargin($dOnSqrtC, $epsilsonTimesSqrtC);
$newPrecision = $c / $denom;
$newPrecisionMean = (
$d +
$newPrecisionMean = ($d +
$sqrtC *
TruncatedGaussianCorrectionFunctions::vExceedsMargin($dOnSqrtC, $epsilsonTimesSqrtC)
) / $denom;
TruncatedGaussianCorrectionFunctions::vExceedsMargin($dOnSqrtC, $epsilsonTimesSqrtC)) / $denom;
$newMarginal = GaussianDistribution::fromPrecisionMean($newPrecisionMean, $newPrecision);

View File

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace DNW\Skills\TrueSkill\Factors;
use DNW\Skills\FactorGraphs\KeyedVariable;

View File

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace DNW\Skills\TrueSkill\Factors;
use DNW\Skills\FactorGraphs\Message;

View File

@ -26,6 +26,7 @@ class GaussianWeightedSumFactor extends GaussianFactor
/**
* 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<float[]> $weights
*/
private array $weights = [];
@ -249,7 +250,7 @@ class GaussianWeightedSumFactor extends GaussianFactor
$absValue = sprintf('%.2f', \abs($weights[$i])); // 0.00?
$result .= $absValue;
$result .= '*[';
$result .= (string) $variablesToSum[$i];
$result .= (string)$variablesToSum[$i];
$result .= ']';
$isLast = ($i === $totalVars - 1);

View File

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace DNW\Skills\TrueSkill\Factors;
use DNW\Skills\FactorGraphs\Message;
@ -65,8 +67,7 @@ class GaussianWithinFactor extends GaussianFactor
$newPrecision = $c / $denominator;
$newPrecisionMean = ($d +
$sqrtC *
TruncatedGaussianCorrectionFunctions::vWithinMargin($dOnSqrtC, $epsilonTimesSqrtC)
) / $denominator;
TruncatedGaussianCorrectionFunctions::vWithinMargin($dOnSqrtC, $epsilonTimesSqrtC)) / $denominator;
$newMarginal = GaussianDistribution::fromPrecisionMean($newPrecisionMean, $newPrecision);
$newMessage = GaussianDistribution::divide(

View File

@ -17,7 +17,8 @@ class IteratedTeamDifferencesInnerLayer extends TrueSkillFactorGraphLayer
TrueSkillFactorGraph $parentGraph,
private readonly TeamPerformancesToTeamPerformanceDifferencesLayer $TeamPerformancesToTeamPerformanceDifferencesLayer,
private readonly TeamDifferencesComparisonLayer $TeamDifferencesComparisonLayer
) {
)
{
parent::__construct($parentGraph);
}

View File

@ -32,7 +32,8 @@ class TeamPerformancesToTeamPerformanceDifferencesLayer extends TrueSkillFactorG
Variable $strongerTeam,
Variable $weakerTeam,
Variable $output
): GaussianWeightedSumFactor {
): GaussianWeightedSumFactor
{
$teams = [$strongerTeam, $weakerTeam];
$weights = [1.0, -1.0];

View File

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace DNW\Skills\TrueSkill\Layers;
use DNW\Skills\FactorGraphs\FactorGraphLayer;

View File

@ -31,9 +31,9 @@ class TrueSkillFactorGraph extends FactorGraph
private PlayerPriorValuesToSkillsLayer $priorLayer;
/**
* @param GameInfo $gameInfo Parameters for the game.
* @param Team[] $teams A mapping of team players and their ratings.
* @param int[] $teamRanks The ranks of the teams where 1 is first place. For a tie, repeat the number (e.g. 1, 2, 2).
* @param GameInfo $gameInfo Parameters for the game.
* @param Team[] $teams A mapping of team players and their ratings.
* @param int[] $teamRanks The ranks of the teams where 1 is first place. For a tie, repeat the number (e.g. 1, 2, 2).
*/
public function __construct(private readonly GameInfo $gameInfo, array $teams, array $teamRanks)
{

View File

@ -122,8 +122,7 @@ class TruncatedGaussianCorrectionFunctions
$vt = self::vWithinMargin($teamPerformanceDifferenceAbsoluteValue, $drawMargin);
return $vt * $vt +
(
($drawMargin - $teamPerformanceDifferenceAbsoluteValue)
(($drawMargin - $teamPerformanceDifferenceAbsoluteValue)
*
GaussianDistribution::at(
$drawMargin - $teamPerformanceDifferenceAbsoluteValue

View File

@ -37,7 +37,8 @@ class TwoPlayerTrueSkillCalculator extends SkillCalculator
GameInfo $gameInfo,
array $teams,
array $teamRanks
): RatingContainer {
): RatingContainer
{
// Basic argument checking
Guard::argumentNotNull($gameInfo, 'gameInfo');
$this->validateTeamCountAndPlayersCountPerTeam($teams);

View File

@ -70,7 +70,8 @@ class TwoTeamTrueSkillCalculator extends SkillCalculator
Team $selfTeam,
Team $otherTeam,
PairwiseComparison $selfToOtherTeamComparison
): void {
): void
{
$drawMargin = DrawMargin::getDrawMarginFromDrawProbability(
$gameInfo->getDrawProbability(),
$gameInfo->getBeta()