From 0095829906bdb40576ea309f2d5a777f753690e9 Mon Sep 17 00:00:00 2001 From: Jens True Date: Tue, 19 Mar 2024 14:38:55 +0000 Subject: [PATCH] Stringable removed. --- src/Numerics/GaussianDistribution.php | 7 ++++--- src/Player.php | 5 ----- src/Rating.php | 7 +------ src/TrueSkill/Layers/PlayerPriorValuesToSkillsLayer.php | 2 +- src/TrueSkill/Layers/PlayerSkillsToPerformancesLayer.php | 2 +- tests/RatingTest.php | 3 --- 6 files changed, 7 insertions(+), 19 deletions(-) diff --git a/src/Numerics/GaussianDistribution.php b/src/Numerics/GaussianDistribution.php index 2948a10..c96d8e9 100644 --- a/src/Numerics/GaussianDistribution.php +++ b/src/Numerics/GaussianDistribution.php @@ -13,7 +13,9 @@ namespace DNW\Skills\Numerics; class GaussianDistribution { private const DEFAULT_STANDARD_DEVIATION = 1.0; + private const DEFAULT_MEAN = 0.0; + /** * Square Root 2π. * Precalculated constant for performance reasons @@ -42,8 +44,7 @@ class GaussianDistribution public function __construct(private float $mean = self::DEFAULT_MEAN, private float $standardDeviation = self::DEFAULT_STANDARD_DEVIATION) { - if($mean == self::DEFAULT_MEAN && $standardDeviation == self::DEFAULT_STANDARD_DEVIATION) - { + if ($mean == self::DEFAULT_MEAN && $standardDeviation == self::DEFAULT_STANDARD_DEVIATION) { //Use all the defaults return; } @@ -187,7 +188,7 @@ class GaussianDistribution return $multiplier * $expPart; } - public static function cumulativeTo(float $x, float $mean = 0.0, float $standardDeviation = 1.0): float + public static function cumulativeTo(float $x): float { $result = GaussianDistribution::errorFunctionCumulativeTo(-M_SQRT1_2 * $x); diff --git a/src/Player.php b/src/Player.php index 668b395..e9e46c2 100644 --- a/src/Player.php +++ b/src/Player.php @@ -59,9 +59,4 @@ class Player implements ISupportPartialPlay, ISupportPartialUpdate { return $this->PartialUpdatePercentage; } -/* - public function __toString(): string - { - return (string)$this->Id; - }*/ } diff --git a/src/Rating.php b/src/Rating.php index c0c1187..b411b4f 100644 --- a/src/Rating.php +++ b/src/Rating.php @@ -9,7 +9,7 @@ use DNW\Skills\Numerics\GaussianDistribution; /** * Container for a player's rating. */ -class Rating implements \Stringable +class Rating { private const CONSERVATIVE_STANDARD_DEVIATION_MULTIPLIER = 3; @@ -73,9 +73,4 @@ class Rating implements \Stringable return new Rating($partialPosteriorGaussion->getMean(), $partialPosteriorGaussion->getStandardDeviation(), $prior->conservativeStandardDeviationMultiplier); } - - public function __toString(): string - { - return sprintf('mean=%.4f, standardDeviation=%.4f', $this->mean, $this->standardDeviation); - } } diff --git a/src/TrueSkill/Layers/PlayerPriorValuesToSkillsLayer.php b/src/TrueSkill/Layers/PlayerPriorValuesToSkillsLayer.php index 9c0a657..36f9f52 100644 --- a/src/TrueSkill/Layers/PlayerPriorValuesToSkillsLayer.php +++ b/src/TrueSkill/Layers/PlayerPriorValuesToSkillsLayer.php @@ -77,6 +77,6 @@ class PlayerPriorValuesToSkillsLayer extends TrueSkillFactorGraphLayer $parentFactorGraph = $this->getParentFactorGraph(); $variableFactory = $parentFactorGraph->getVariableFactory(); - return $variableFactory->createKeyedVariable($key, (string)$key->getId() . "'s skill"); + return $variableFactory->createKeyedVariable($key, $key->getId() . "'s skill"); } } diff --git a/src/TrueSkill/Layers/PlayerSkillsToPerformancesLayer.php b/src/TrueSkill/Layers/PlayerSkillsToPerformancesLayer.php index d7c5363..bbe4e11 100644 --- a/src/TrueSkill/Layers/PlayerSkillsToPerformancesLayer.php +++ b/src/TrueSkill/Layers/PlayerSkillsToPerformancesLayer.php @@ -48,7 +48,7 @@ class PlayerSkillsToPerformancesLayer extends TrueSkillFactorGraphLayer private function createOutputVariable(mixed $key): KeyedVariable { - return $this->getParentFactorGraph()->getVariableFactory()->createKeyedVariable($key, (string)$key->getId() . "'s performance"); + return $this->getParentFactorGraph()->getVariableFactory()->createKeyedVariable($key, $key->getId() . "'s performance"); } public function createPriorSchedule(): ?ScheduleSequence diff --git a/tests/RatingTest.php b/tests/RatingTest.php index bdd8603..80cb8b5 100644 --- a/tests/RatingTest.php +++ b/tests/RatingTest.php @@ -15,7 +15,6 @@ class RatingTest extends TestCase $this->assertEquals(100, $rating->getMean()); $this->assertEquals(10, $rating->getStandardDeviation()); $this->assertEquals(50, $rating->getConservativeRating()); - $this->assertEquals("mean=100.0000, standardDeviation=10.0000", (string)$rating); } public function testPartialUpdate(): void @@ -26,10 +25,8 @@ class RatingTest extends TestCase $rating_partial = $rating->getPartialUpdate($ratingOld, $ratingNew, 0.5); - $this->assertEquals(150, $rating_partial->getMean()); $this->assertEquals(10, $rating_partial->getStandardDeviation()); $this->assertEquals(100, $rating_partial->getConservativeRating()); - $this->assertEquals("mean=150.0000, standardDeviation=10.0000", (string)$rating_partial); } }