mirror of
				https://github.com/furyfire/trueskill.git
				synced 2025-11-04 10:12:28 +01:00 
			
		
		
		
	Additional Psalm warnings resolving
This commit is contained in:
		@@ -8,7 +8,7 @@ class Team extends RatingContainer
 | 
			
		||||
    {
 | 
			
		||||
        parent::__construct();
 | 
			
		||||
 | 
			
		||||
        if (! is_null($player)) {
 | 
			
		||||
        if (! is_null($player) && ! is_null($rating)) {
 | 
			
		||||
            $this->addPlayer($player, $rating);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -16,6 +16,7 @@ use DNW\Skills\SkillCalculatorSupportedOptions;
 | 
			
		||||
use DNW\Skills\Team;
 | 
			
		||||
use DNW\Skills\TeamsRange;
 | 
			
		||||
use DNW\Skills\RatingContainer;
 | 
			
		||||
use DNW\Skills\Rating;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Calculates TrueSkill using a full factor graph.
 | 
			
		||||
@@ -100,7 +101,7 @@ class FactorGraphTrueSkillCalculator extends SkillCalculator
 | 
			
		||||
        return new Vector(
 | 
			
		||||
            self::getPlayerRatingValues(
 | 
			
		||||
                $teamAssignmentsList,
 | 
			
		||||
                fn ($rating) => $rating->getMean()
 | 
			
		||||
                fn (Rating $rating): float => $rating->getMean()
 | 
			
		||||
            )
 | 
			
		||||
        );
 | 
			
		||||
    }
 | 
			
		||||
@@ -115,7 +116,7 @@ class FactorGraphTrueSkillCalculator extends SkillCalculator
 | 
			
		||||
        return new DiagonalMatrix(
 | 
			
		||||
            self::getPlayerRatingValues(
 | 
			
		||||
                $teamAssignmentsList,
 | 
			
		||||
                fn ($rating) => BasicMath::square($rating->getStandardDeviation())
 | 
			
		||||
                fn (Rating $rating): float => BasicMath::square($rating->getStandardDeviation())
 | 
			
		||||
            )
 | 
			
		||||
        );
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -30,7 +30,7 @@ abstract class GaussianFactor extends Factor
 | 
			
		||||
            $variable,
 | 
			
		||||
            new Message(
 | 
			
		||||
                $newDistribution,
 | 
			
		||||
                sprintf('message from %s to %s', $this, $variable)
 | 
			
		||||
                sprintf('message from %s to %s', (string)$this, (string)$variable)
 | 
			
		||||
            )
 | 
			
		||||
        );
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -18,7 +18,7 @@ class GaussianGreaterThanFactor extends GaussianFactor
 | 
			
		||||
 | 
			
		||||
    public function __construct(float $epsilon, Variable $variable)
 | 
			
		||||
    {
 | 
			
		||||
        parent::__construct(\sprintf('%s > %.2f', $variable, $epsilon));
 | 
			
		||||
        parent::__construct(\sprintf('%s > %.2f', (string)$variable, $epsilon));
 | 
			
		||||
        $this->epsilon = $epsilon;
 | 
			
		||||
        $this->createVariableToMessageBinding($variable);
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -19,7 +19,7 @@ class GaussianLikelihoodFactor extends GaussianFactor
 | 
			
		||||
 | 
			
		||||
    public function __construct(float $betaSquared, Variable $variable1, Variable $variable2)
 | 
			
		||||
    {
 | 
			
		||||
        parent::__construct(sprintf('Likelihood of %s going to %s', $variable2, $variable1));
 | 
			
		||||
        parent::__construct(sprintf('Likelihood of %s going to %s', (string)$variable2, (string)$variable1));
 | 
			
		||||
        $this->precision = 1.0 / $betaSquared;
 | 
			
		||||
        $this->createVariableToMessageBinding($variable1);
 | 
			
		||||
        $this->createVariableToMessageBinding($variable2);
 | 
			
		||||
 
 | 
			
		||||
@@ -17,11 +17,11 @@ class GaussianPriorFactor extends GaussianFactor
 | 
			
		||||
 | 
			
		||||
    public function __construct(float $mean, float $variance, Variable $variable)
 | 
			
		||||
    {
 | 
			
		||||
        parent::__construct(sprintf('Prior value going to %s', $variable));
 | 
			
		||||
        parent::__construct(sprintf('Prior value going to %s', (string)$variable));
 | 
			
		||||
        $this->newMessage = new GaussianDistribution($mean, sqrt($variance));
 | 
			
		||||
        $newMessage = new Message(
 | 
			
		||||
            GaussianDistribution::fromPrecisionMean(0, 0),
 | 
			
		||||
            sprintf('message from %s to %s', $this, $variable)
 | 
			
		||||
            sprintf('message from %s to %s', (string)$this, (string)$variable)
 | 
			
		||||
        );
 | 
			
		||||
 | 
			
		||||
        $this->createVariableToMessageBindingWithMessage($variable, $newMessage);
 | 
			
		||||
 
 | 
			
		||||
@@ -38,7 +38,7 @@ class GaussianWeightedSumFactor extends GaussianFactor
 | 
			
		||||
     */
 | 
			
		||||
    public function __construct(Variable $sumVariable, array $variablesToSum, array $variableWeights = null)
 | 
			
		||||
    {
 | 
			
		||||
        parent::__construct(self::createName($sumVariable, $variablesToSum, $variableWeights));
 | 
			
		||||
        parent::__construct(self::createName((string)$sumVariable, $variablesToSum, $variableWeights));
 | 
			
		||||
 | 
			
		||||
        // The first weights are a straightforward copy
 | 
			
		||||
        // v_0 = a_1*v_1 + a_2*v_2 + ... + a_n * v_n
 | 
			
		||||
@@ -237,7 +237,7 @@ class GaussianWeightedSumFactor extends GaussianFactor
 | 
			
		||||
    private static function createName(string $sumVariable, array $variablesToSum, array $weights): string
 | 
			
		||||
    {
 | 
			
		||||
        // TODO: Perf? Use PHP equivalent of StringBuilder? implode on arrays?
 | 
			
		||||
        $result = (string) $sumVariable;
 | 
			
		||||
        $result = $sumVariable;
 | 
			
		||||
        $result .= ' = ';
 | 
			
		||||
 | 
			
		||||
        $totalVars = count($variablesToSum);
 | 
			
		||||
 
 | 
			
		||||
@@ -18,7 +18,7 @@ class GaussianWithinFactor extends GaussianFactor
 | 
			
		||||
 | 
			
		||||
    public function __construct(float $epsilon, Variable $variable)
 | 
			
		||||
    {
 | 
			
		||||
        parent::__construct(sprintf('%s <= %.2f', $variable, $epsilon));
 | 
			
		||||
        parent::__construct(sprintf('%s <= %.2f', (string)$variable, $epsilon));
 | 
			
		||||
        $this->epsilon = $epsilon;
 | 
			
		||||
        $this->createVariableToMessageBinding($variable);
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -79,12 +79,12 @@ class TwoTeamTrueSkillCalculator extends SkillCalculator
 | 
			
		||||
 | 
			
		||||
        $totalPlayers = $selfTeam->count() + $otherTeam->count();
 | 
			
		||||
 | 
			
		||||
        $meanGetter = fn ($currentRating) => $currentRating->getMean();
 | 
			
		||||
        $meanGetter = fn (Rating $currentRating): float => $currentRating->getMean();
 | 
			
		||||
 | 
			
		||||
        $selfMeanSum = BasicMath::sum($selfTeam->getAllRatings(), $meanGetter);
 | 
			
		||||
        $otherTeamMeanSum = BasicMath::sum($otherTeam->getAllRatings(), $meanGetter);
 | 
			
		||||
 | 
			
		||||
        $varianceGetter = fn ($currentRating): float => BasicMath::square($currentRating->getStandardDeviation());
 | 
			
		||||
        $varianceGetter = fn (Rating $currentRating): float => BasicMath::square($currentRating->getStandardDeviation());
 | 
			
		||||
 | 
			
		||||
        $c = sqrt(
 | 
			
		||||
            BasicMath::sum($selfTeam->getAllRatings(), $varianceGetter)
 | 
			
		||||
@@ -160,9 +160,9 @@ class TwoTeamTrueSkillCalculator extends SkillCalculator
 | 
			
		||||
 | 
			
		||||
        $betaSquared = BasicMath::square($gameInfo->getBeta());
 | 
			
		||||
 | 
			
		||||
        $meanGetter = fn ($currentRating) => $currentRating->getMean();
 | 
			
		||||
        $meanGetter = fn (Rating $currentRating): float => $currentRating->getMean();
 | 
			
		||||
 | 
			
		||||
        $varianceGetter = fn ($currentRating): float => BasicMath::square($currentRating->getStandardDeviation());
 | 
			
		||||
        $varianceGetter = fn (Rating $currentRating): float => BasicMath::square($currentRating->getStandardDeviation());
 | 
			
		||||
 | 
			
		||||
        $team1MeanSum = BasicMath::sum($team1Ratings, $meanGetter);
 | 
			
		||||
        $team1StdDevSquared = BasicMath::sum($team1Ratings, $varianceGetter);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user