From 796bd993d0d093411dd2ccb7a5dd424a9618a99b Mon Sep 17 00:00:00 2001 From: Jens True Date: Tue, 19 Mar 2024 15:56:57 +0000 Subject: [PATCH] Even less strings --- src/FactorGraphs/Factor.php | 12 ++---------- src/FactorGraphs/Message.php | 9 ++------- src/TrueSkill/Factors/GaussianFactor.php | 2 +- src/TrueSkill/Factors/GaussianGreaterThanFactor.php | 2 +- src/TrueSkill/Factors/GaussianLikelihoodFactor.php | 3 ++- src/TrueSkill/Factors/GaussianPriorFactor.php | 6 +++--- src/TrueSkill/Factors/GaussianWeightedSumFactor.php | 2 +- src/TrueSkill/Factors/GaussianWithinFactor.php | 3 ++- 8 files changed, 14 insertions(+), 25 deletions(-) diff --git a/src/FactorGraphs/Factor.php b/src/FactorGraphs/Factor.php index 841b584..ad15957 100644 --- a/src/FactorGraphs/Factor.php +++ b/src/FactorGraphs/Factor.php @@ -8,7 +8,7 @@ use DNW\Skills\Guard; use DNW\Skills\HashMap; use Exception; -abstract class Factor implements \Stringable +abstract class Factor { /** * @var Message[] $messages @@ -17,16 +17,13 @@ abstract class Factor implements \Stringable private readonly HashMap $messageToVariableBinding; - private readonly string $name; - /** * @var Variable[] $variables */ private array $variables = []; - protected function __construct(string $name) + protected function __construct() { - $this->name = 'Factor[' . $name . ']'; $this->messageToVariableBinding = new HashMap(); } @@ -121,9 +118,4 @@ abstract class Factor implements \Stringable return $message; } - - public function __toString(): string - { - return $this->name; - } } diff --git a/src/FactorGraphs/Message.php b/src/FactorGraphs/Message.php index fbdbc4f..7d7d40d 100644 --- a/src/FactorGraphs/Message.php +++ b/src/FactorGraphs/Message.php @@ -6,9 +6,9 @@ namespace DNW\Skills\FactorGraphs; use DNW\Skills\Numerics\GaussianDistribution; -class Message implements \Stringable +class Message { - public function __construct(private GaussianDistribution $value, private readonly string $name) + public function __construct(private GaussianDistribution $value) { } @@ -21,9 +21,4 @@ class Message implements \Stringable { $this->value = $value; } - - public function __toString(): string - { - return $this->name; - } } diff --git a/src/TrueSkill/Factors/GaussianFactor.php b/src/TrueSkill/Factors/GaussianFactor.php index b581cb3..dbd86e4 100644 --- a/src/TrueSkill/Factors/GaussianFactor.php +++ b/src/TrueSkill/Factors/GaussianFactor.php @@ -31,7 +31,7 @@ abstract class GaussianFactor extends Factor return parent::createVariableToMessageBindingWithMessage( $variable, new Message( - $newDistribution,'message from %s to %s' + $newDistribution, ) ); } diff --git a/src/TrueSkill/Factors/GaussianGreaterThanFactor.php b/src/TrueSkill/Factors/GaussianGreaterThanFactor.php index 2e23a14..85c2979 100644 --- a/src/TrueSkill/Factors/GaussianGreaterThanFactor.php +++ b/src/TrueSkill/Factors/GaussianGreaterThanFactor.php @@ -18,7 +18,7 @@ class GaussianGreaterThanFactor extends GaussianFactor { public function __construct(private readonly float $epsilon, Variable $variable) { - parent::__construct('%s > %.2f'); + parent::__construct(); $this->createVariableToMessageBinding($variable); } diff --git a/src/TrueSkill/Factors/GaussianLikelihoodFactor.php b/src/TrueSkill/Factors/GaussianLikelihoodFactor.php index 10902bb..6250f6d 100644 --- a/src/TrueSkill/Factors/GaussianLikelihoodFactor.php +++ b/src/TrueSkill/Factors/GaussianLikelihoodFactor.php @@ -21,7 +21,8 @@ class GaussianLikelihoodFactor extends GaussianFactor public function __construct(float $betaSquared, Variable $variable1, Variable $variable2) { - parent::__construct('Likelihood of %s going to %s'); + //Likelihood of $variable1 going to $variable2 + parent::__construct(); $this->precision = 1.0 / $betaSquared; $this->createVariableToMessageBinding($variable1); $this->createVariableToMessageBinding($variable2); diff --git a/src/TrueSkill/Factors/GaussianPriorFactor.php b/src/TrueSkill/Factors/GaussianPriorFactor.php index e703aba..0644ff1 100644 --- a/src/TrueSkill/Factors/GaussianPriorFactor.php +++ b/src/TrueSkill/Factors/GaussianPriorFactor.php @@ -19,11 +19,11 @@ class GaussianPriorFactor extends GaussianFactor public function __construct(float $mean, float $variance, Variable $variable) { - parent::__construct('Prior value going to %s'); + //Prior value going to $variable + parent::__construct(); $this->newMessage = new GaussianDistribution($mean, sqrt($variance)); $newMessage = new Message( - GaussianDistribution::fromPrecisionMean(0, 0), - 'message from %s to %s' + GaussianDistribution::fromPrecisionMean(0, 0) ); $this->createVariableToMessageBindingWithMessage($variable, $newMessage); diff --git a/src/TrueSkill/Factors/GaussianWeightedSumFactor.php b/src/TrueSkill/Factors/GaussianWeightedSumFactor.php index 7e7b407..74d688b 100644 --- a/src/TrueSkill/Factors/GaussianWeightedSumFactor.php +++ b/src/TrueSkill/Factors/GaussianWeightedSumFactor.php @@ -42,7 +42,7 @@ class GaussianWeightedSumFactor extends GaussianFactor */ public function __construct(Variable $sumVariable, array $variablesToSum, array $variableWeights) { - parent::__construct('$sumVariable, $variablesToSum, $variableWeights'); + parent::__construct(); // The first weights are a straightforward copy // v_0 = a_1*v_1 + a_2*v_2 + ... + a_n * v_n diff --git a/src/TrueSkill/Factors/GaussianWithinFactor.php b/src/TrueSkill/Factors/GaussianWithinFactor.php index 24cbbb2..3ce8316 100644 --- a/src/TrueSkill/Factors/GaussianWithinFactor.php +++ b/src/TrueSkill/Factors/GaussianWithinFactor.php @@ -18,7 +18,8 @@ class GaussianWithinFactor extends GaussianFactor { public function __construct(private readonly float $epsilon, Variable $variable) { - parent::__construct('%s <= %.2f'); + //$epsilon <= $variable + parent::__construct(); $this->createVariableToMessageBinding($variable); }