mirror of
https://github.com/furyfire/trueskill.git
synced 2025-04-18 20:04:28 +00:00
More type work
This commit is contained in:
@ -15,9 +15,9 @@ use Exception;
|
||||
*/
|
||||
class GaussianLikelihoodFactor extends GaussianFactor
|
||||
{
|
||||
private $precision;
|
||||
private float $precision;
|
||||
|
||||
public function __construct($betaSquared, Variable $variable1, Variable $variable2)
|
||||
public function __construct(float $betaSquared, Variable $variable1, Variable $variable2)
|
||||
{
|
||||
parent::__construct(sprintf('Likelihood of %s going to %s', $variable2, $variable1));
|
||||
$this->precision = 1.0 / $betaSquared;
|
||||
@ -42,7 +42,7 @@ class GaussianLikelihoodFactor extends GaussianFactor
|
||||
);
|
||||
}
|
||||
|
||||
private function updateHelper(Message $message1, Message $message2, Variable $variable1, Variable $variable2)
|
||||
private function updateHelper(Message $message1, Message $message2, Variable $variable1, Variable $variable2): float
|
||||
{
|
||||
$message1Value = clone $message1->getValue();
|
||||
$message2Value = clone $message2->getValue();
|
||||
@ -70,7 +70,7 @@ class GaussianLikelihoodFactor extends GaussianFactor
|
||||
return GaussianDistribution::subtract($newMarginal, $marginal1);
|
||||
}
|
||||
|
||||
public function updateMessageIndex($messageIndex)
|
||||
public function updateMessageIndex($messageIndex): float
|
||||
{
|
||||
$messages = $this->getMessages();
|
||||
$vars = $this->getVariables();
|
||||
|
@ -14,16 +14,16 @@ use DNW\Skills\TrueSkill\TruncatedGaussianCorrectionFunctions;
|
||||
*/
|
||||
class GaussianWithinFactor extends GaussianFactor
|
||||
{
|
||||
private $epsilon;
|
||||
private float $epsilon;
|
||||
|
||||
public function __construct($epsilon, Variable $variable)
|
||||
public function __construct(float $epsilon, Variable $variable)
|
||||
{
|
||||
parent::__construct(sprintf('%s <= %.2f', $variable, $epsilon));
|
||||
$this->epsilon = $epsilon;
|
||||
$this->createVariableToMessageBinding($variable);
|
||||
}
|
||||
|
||||
public function getLogNormalization()
|
||||
public function getLogNormalization(): float
|
||||
{
|
||||
/**
|
||||
* @var Variable[] $variables
|
||||
@ -46,7 +46,7 @@ class GaussianWithinFactor extends GaussianFactor
|
||||
return -GaussianDistribution::logProductNormalization($messageFromVariable, $message) + log($z);
|
||||
}
|
||||
|
||||
protected function updateMessageVariable(Message $message, Variable $variable)
|
||||
protected function updateMessageVariable(Message $message, Variable $variable): float
|
||||
{
|
||||
$oldMarginal = clone $variable->getValue();
|
||||
$oldMessage = clone $message->getValue();
|
||||
|
@ -4,6 +4,7 @@ namespace DNW\Skills\TrueSkill\Layers;
|
||||
|
||||
use DNW\Skills\FactorGraphs\ScheduleStep;
|
||||
use DNW\Skills\FactorGraphs\Variable;
|
||||
use DNW\Skills\FactorGraphs\KeyedVariable;
|
||||
use DNW\Skills\Numerics\BasicMath;
|
||||
use DNW\Skills\Rating;
|
||||
use DNW\Skills\TrueSkill\Factors\GaussianPriorFactor;
|
||||
@ -63,7 +64,7 @@ class PlayerPriorValuesToSkillsLayer extends TrueSkillFactorGraphLayer
|
||||
);
|
||||
}
|
||||
|
||||
private function createSkillOutputVariable($key)
|
||||
private function createSkillOutputVariable(mixed $key) : KeyedVariable
|
||||
{
|
||||
$parentFactorGraph = $this->getParentFactorGraph();
|
||||
$variableFactory = $parentFactorGraph->getVariableFactory();
|
||||
|
@ -40,7 +40,7 @@ class PlayerSkillsToPerformancesLayer extends TrueSkillFactorGraphLayer
|
||||
);
|
||||
}
|
||||
|
||||
private function createOutputVariable($key): KeyedVariable
|
||||
private function createOutputVariable(mixed $key): KeyedVariable
|
||||
{
|
||||
return $this->getParentFactorGraph()->getVariableFactory()->createKeyedVariable($key, $key . "'s performance");
|
||||
}
|
||||
|
@ -19,9 +19,12 @@ use DNW\Skills\TrueSkill\Layers\TeamPerformancesToTeamPerformanceDifferencesLaye
|
||||
|
||||
class TrueSkillFactorGraph extends FactorGraph
|
||||
{
|
||||
private $layers;
|
||||
/**
|
||||
* @var FactorGraphLayer[] $layers
|
||||
*/
|
||||
private array $layers;
|
||||
|
||||
private $priorLayer;
|
||||
private PlayerPriorValuesToSkillsLayer $priorLayer;
|
||||
|
||||
public function __construct(private readonly GameInfo $gameInfo, array $teams, array $teamRanks)
|
||||
{
|
||||
@ -43,7 +46,7 @@ class TrueSkillFactorGraph extends FactorGraph
|
||||
];
|
||||
}
|
||||
|
||||
public function getGameInfo()
|
||||
public function getGameInfo(): GameInfo
|
||||
{
|
||||
return $this->gameInfo;
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ class TwoPlayerTrueSkillCalculator extends SkillCalculator
|
||||
return $results;
|
||||
}
|
||||
|
||||
private static function calculateNewRating(GameInfo $gameInfo, Rating $selfRating, Rating $opponentRating, $comparison): Rating
|
||||
private static function calculateNewRating(GameInfo $gameInfo, Rating $selfRating, Rating $opponentRating, PairwiseComparison $comparison): Rating
|
||||
{
|
||||
$drawMargin = DrawMargin::getDrawMarginFromDrawProbability(
|
||||
$gameInfo->getDrawProbability(),
|
||||
|
Reference in New Issue
Block a user