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:
@ -86,7 +86,7 @@ class FactorGraphTrueSkillCalculator extends SkillCalculator
|
||||
return exp($expPart) * sqrt($sqrtPart);
|
||||
}
|
||||
|
||||
private static function getPlayerMeansVector(array $teamAssignmentsList)
|
||||
private static function getPlayerMeansVector(array $teamAssignmentsList): Vector
|
||||
{
|
||||
// A simple vector of all the player means.
|
||||
return new Vector(
|
||||
@ -97,7 +97,7 @@ class FactorGraphTrueSkillCalculator extends SkillCalculator
|
||||
);
|
||||
}
|
||||
|
||||
private static function getPlayerCovarianceMatrix(array $teamAssignmentsList)
|
||||
private static function getPlayerCovarianceMatrix(array $teamAssignmentsList): DiagonalMatrix
|
||||
{
|
||||
// This is a square matrix whose diagonal values represent the variance (square of standard deviation) of all
|
||||
// players.
|
||||
@ -110,7 +110,7 @@ class FactorGraphTrueSkillCalculator extends SkillCalculator
|
||||
}
|
||||
|
||||
// Helper function that gets a list of values for all player ratings
|
||||
private static function getPlayerRatingValues(array $teamAssignmentsList, $playerRatingFunction)
|
||||
private static function getPlayerRatingValues(array $teamAssignmentsList, \Closure $playerRatingFunction): array
|
||||
{
|
||||
$playerRatingValues = [];
|
||||
|
||||
|
@ -14,16 +14,16 @@ use DNW\Skills\TrueSkill\TruncatedGaussianCorrectionFunctions;
|
||||
*/
|
||||
class GaussianGreaterThanFactor 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[] $vars
|
||||
@ -48,7 +48,7 @@ class GaussianGreaterThanFactor extends GaussianFactor
|
||||
);
|
||||
}
|
||||
|
||||
protected function updateMessageVariable(Message $message, Variable $variable)
|
||||
protected function updateMessageVariable(Message $message, Variable $variable): float
|
||||
{
|
||||
$oldMarginal = clone $variable->getValue();
|
||||
$oldMessage = clone $message->getValue();
|
||||
|
@ -70,7 +70,7 @@ class GaussianLikelihoodFactor extends GaussianFactor
|
||||
return GaussianDistribution::subtract($newMarginal, $marginal1);
|
||||
}
|
||||
|
||||
public function updateMessageIndex($messageIndex): float
|
||||
public function updateMessageIndex(int $messageIndex): float
|
||||
{
|
||||
$messages = $this->getMessages();
|
||||
$vars = $this->getVariables();
|
||||
|
@ -6,10 +6,11 @@ use DNW\Skills\FactorGraphs\ScheduleStep;
|
||||
use DNW\Skills\FactorGraphs\ScheduleSequence;
|
||||
use DNW\Skills\PartialPlay;
|
||||
use DNW\Skills\TrueSkill\Factors\GaussianWeightedSumFactor;
|
||||
use DNW\Skills\FactorGraphs\Variable;
|
||||
|
||||
class PlayerPerformancesToTeamPerformancesLayer extends TrueSkillFactorGraphLayer
|
||||
{
|
||||
public function buildLayer()
|
||||
public function buildLayer(): void
|
||||
{
|
||||
$inputVariablesGroups = $this->getInputVariablesGroups();
|
||||
foreach ($inputVariablesGroups as $currentTeam) {
|
||||
@ -38,7 +39,7 @@ class PlayerPerformancesToTeamPerformancesLayer extends TrueSkillFactorGraphLaye
|
||||
);
|
||||
}
|
||||
|
||||
protected function createPlayerToTeamSumFactor($teamMembers, $sumVariable): GaussianWeightedSumFactor
|
||||
protected function createPlayerToTeamSumFactor(array $teamMembers, Variable $sumVariable): GaussianWeightedSumFactor
|
||||
{
|
||||
$weights = array_map(
|
||||
function ($v) {
|
||||
@ -75,7 +76,7 @@ class PlayerPerformancesToTeamPerformancesLayer extends TrueSkillFactorGraphLaye
|
||||
return $this->scheduleSequence($allFactors, "all of the team's sum iterations");
|
||||
}
|
||||
|
||||
private function createOutputVariable($team)
|
||||
private function createOutputVariable(array $team): Variable
|
||||
{
|
||||
$memberNames = array_map(fn ($currentPlayer) => (string) ($currentPlayer->getKey()), $team);
|
||||
|
||||
|
@ -9,6 +9,7 @@ use DNW\Skills\Numerics\BasicMath;
|
||||
use DNW\Skills\Rating;
|
||||
use DNW\Skills\TrueSkill\Factors\GaussianPriorFactor;
|
||||
use DNW\Skills\TrueSkill\TrueSkillFactorGraph;
|
||||
use DNW\Skills\FactorGraphs\ScheduleSequence;
|
||||
|
||||
// We intentionally have no Posterior schedule since the only purpose here is to
|
||||
// start the process.
|
||||
@ -19,7 +20,7 @@ class PlayerPriorValuesToSkillsLayer extends TrueSkillFactorGraphLayer
|
||||
parent::__construct($parentGraph);
|
||||
}
|
||||
|
||||
public function buildLayer()
|
||||
public function buildLayer(): void
|
||||
{
|
||||
$teams = $this->teams;
|
||||
foreach ($teams as $currentTeam) {
|
||||
@ -41,7 +42,7 @@ class PlayerPriorValuesToSkillsLayer extends TrueSkillFactorGraphLayer
|
||||
}
|
||||
}
|
||||
|
||||
public function createPriorSchedule()
|
||||
public function createPriorSchedule(): ScheduleSequence
|
||||
{
|
||||
$localFactors = $this->getLocalFactors();
|
||||
|
||||
@ -54,7 +55,7 @@ class PlayerPriorValuesToSkillsLayer extends TrueSkillFactorGraphLayer
|
||||
);
|
||||
}
|
||||
|
||||
private function createPriorFactor(Rating $priorRating, Variable $skillsVariable)
|
||||
private function createPriorFactor(Rating $priorRating, Variable $skillsVariable): GaussianPriorFactor
|
||||
{
|
||||
return new GaussianPriorFactor(
|
||||
$priorRating->getMean(),
|
||||
|
@ -7,7 +7,7 @@ use DNW\Skills\TrueSkill\Factors\GaussianWeightedSumFactor;
|
||||
|
||||
class TeamPerformancesToTeamPerformanceDifferencesLayer extends TrueSkillFactorGraphLayer
|
||||
{
|
||||
public function buildLayer()
|
||||
public function buildLayer(): void
|
||||
{
|
||||
$inputVariablesGroups = $this->getInputVariablesGroups();
|
||||
$inputVariablesGroupsCount = is_countable($inputVariablesGroups) ? count($inputVariablesGroups) : 0;
|
||||
@ -30,14 +30,14 @@ class TeamPerformancesToTeamPerformanceDifferencesLayer extends TrueSkillFactorG
|
||||
Variable $strongerTeam,
|
||||
Variable $weakerTeam,
|
||||
Variable $output
|
||||
) {
|
||||
): GaussianWeightedSumFactor {
|
||||
$teams = [$strongerTeam, $weakerTeam];
|
||||
$weights = [1.0, -1.0];
|
||||
|
||||
return new GaussianWeightedSumFactor($output, $teams, $weights);
|
||||
}
|
||||
|
||||
private function createOutputVariable()
|
||||
private function createOutputVariable(): Variable
|
||||
{
|
||||
return $this->getParentFactorGraph()->getVariableFactory()->createBasicVariable('Team performance difference');
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ use DNW\Skills\GameInfo;
|
||||
use DNW\Skills\Numerics\GaussianDistribution;
|
||||
use DNW\Skills\Rating;
|
||||
use DNW\Skills\RatingContainer;
|
||||
use DNW\Skills\FactorGraphs\FactorGraphLayer;
|
||||
use DNW\Skills\TrueSkill\Layers\IteratedTeamDifferencesInnerLayer;
|
||||
use DNW\Skills\TrueSkill\Layers\PlayerPerformancesToTeamPerformancesLayer;
|
||||
use DNW\Skills\TrueSkill\Layers\PlayerPriorValuesToSkillsLayer;
|
||||
|
Reference in New Issue
Block a user