mirror of
https://github.com/furyfire/trueskill.git
synced 2025-01-16 01:47:39 +00:00
Sub 200 warnings on static analysis
This commit is contained in:
@ -9,7 +9,7 @@ class ScheduleStep extends Schedule
|
|||||||
parent::__construct($name);
|
parent::__construct($name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function visit($depth = -1, $maxDepth = 0)
|
public function visit(int $depth = -1, int $maxDepth = 0)
|
||||||
{
|
{
|
||||||
$currentFactor = $this->_factor;
|
$currentFactor = $this->_factor;
|
||||||
|
|
||||||
|
@ -30,11 +30,11 @@ abstract class SkillCalculator
|
|||||||
*
|
*
|
||||||
* @param GameInfo $gameInfo Parameters for the game.
|
* @param GameInfo $gameInfo Parameters for the game.
|
||||||
* @param array $teamsOfPlayerToRatings A mapping of team players and their ratings.
|
* @param array $teamsOfPlayerToRatings A mapping of team players and their ratings.
|
||||||
* @return The quality of the match between the teams as a percentage (0% = bad, 100% = well matched).
|
* @return float The quality of the match between the teams as a percentage (0% = bad, 100% = well matched).
|
||||||
*/
|
*/
|
||||||
abstract public function calculateMatchQuality(GameInfo $gameInfo, array $teamsOfPlayerToRatings);
|
abstract public function calculateMatchQuality(GameInfo $gameInfo, array $teamsOfPlayerToRatings): float;
|
||||||
|
|
||||||
public function isSupported($option)
|
public function isSupported($option): bool
|
||||||
{
|
{
|
||||||
return ($this->_supportedOptions & $option) == $option;
|
return ($this->_supportedOptions & $option) == $option;
|
||||||
}
|
}
|
||||||
@ -46,11 +46,10 @@ abstract class SkillCalculator
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array<\DNW\Skills\Team> $teams
|
* @param array<\DNW\Skills\Team> $teams
|
||||||
* @return void
|
|
||||||
*
|
*
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
private static function validateTeamCountAndPlayersCountPerTeamWithRanges(array $teams, TeamsRange $totalTeams, PlayersRange $playersPerTeam)
|
private static function validateTeamCountAndPlayersCountPerTeamWithRanges(array $teams, TeamsRange $totalTeams, PlayersRange $playersPerTeam): void
|
||||||
{
|
{
|
||||||
$countOfTeams = 0;
|
$countOfTeams = 0;
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ class FactorGraphTrueSkillCalculator extends SkillCalculator
|
|||||||
return $factorGraph->getUpdatedRatings();
|
return $factorGraph->getUpdatedRatings();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function calculateMatchQuality(GameInfo $gameInfo, array $teams)
|
public function calculateMatchQuality(GameInfo $gameInfo, array $teams): float
|
||||||
{
|
{
|
||||||
// We need to create the A matrix which is the player team assigments.
|
// We need to create the A matrix which is the player team assigments.
|
||||||
$teamAssignmentsList = $teams;
|
$teamAssignmentsList = $teams;
|
||||||
|
@ -25,7 +25,7 @@ class GaussianLikelihoodFactor extends GaussianFactor
|
|||||||
$this->createVariableToMessageBinding($variable2);
|
$this->createVariableToMessageBinding($variable2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getLogNormalization()
|
public function getLogNormalization(): float
|
||||||
{
|
{
|
||||||
/** @var KeyedVariable[]|mixed $vars */
|
/** @var KeyedVariable[]|mixed $vars */
|
||||||
$vars = $this->getVariables();
|
$vars = $this->getVariables();
|
||||||
|
@ -15,7 +15,7 @@ class GaussianPriorFactor extends GaussianFactor
|
|||||||
{
|
{
|
||||||
private $_newMessage;
|
private $_newMessage;
|
||||||
|
|
||||||
public function __construct($mean, $variance, Variable $variable)
|
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', $variable));
|
||||||
$this->_newMessage = new GaussianDistribution($mean, sqrt($variance));
|
$this->_newMessage = new GaussianDistribution($mean, sqrt($variance));
|
||||||
@ -25,7 +25,7 @@ class GaussianPriorFactor extends GaussianFactor
|
|||||||
$this->createVariableToMessageBindingWithMessage($variable, $newMessage);
|
$this->createVariableToMessageBindingWithMessage($variable, $newMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function updateMessageVariable(Message $message, Variable $variable)
|
protected function updateMessageVariable(Message $message, Variable $variable): float
|
||||||
{
|
{
|
||||||
$oldMarginal = clone $variable->getValue();
|
$oldMarginal = clone $variable->getValue();
|
||||||
$oldMessage = $message;
|
$oldMessage = $message;
|
||||||
|
@ -127,7 +127,7 @@ class GaussianWeightedSumFactor extends GaussianFactor
|
|||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function updateHelper(array $weights, array $weightsSquared, array $messages, array $variables)
|
private function updateHelper(array $weights, array $weightsSquared, array $messages, array $variables): float
|
||||||
{
|
{
|
||||||
// Potentially look at http://mathworld.wolfram.com/NormalSumDistribution.html for clues as
|
// Potentially look at http://mathworld.wolfram.com/NormalSumDistribution.html for clues as
|
||||||
// to what it's doing
|
// to what it's doing
|
||||||
@ -182,7 +182,7 @@ class GaussianWeightedSumFactor extends GaussianFactor
|
|||||||
return $finalDiff;
|
return $finalDiff;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updateMessageIndex($messageIndex)
|
public function updateMessageIndex(int $messageIndex): float
|
||||||
{
|
{
|
||||||
$allMessages = $this->getMessages();
|
$allMessages = $this->getMessages();
|
||||||
$allVariables = $this->getVariables();
|
$allVariables = $this->getVariables();
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
namespace DNW\Skills\TrueSkill\Layers;
|
namespace DNW\Skills\TrueSkill\Layers;
|
||||||
|
|
||||||
use DNW\Skills\FactorGraphs\ScheduleStep;
|
use DNW\Skills\FactorGraphs\ScheduleStep;
|
||||||
|
use DNW\Skills\FactorGraphs\ScheduleSequence;
|
||||||
use DNW\Skills\PartialPlay;
|
use DNW\Skills\PartialPlay;
|
||||||
use DNW\Skills\TrueSkill\Factors\GaussianWeightedSumFactor;
|
use DNW\Skills\TrueSkill\Factors\GaussianWeightedSumFactor;
|
||||||
|
|
||||||
@ -24,7 +25,7 @@ class PlayerPerformancesToTeamPerformancesLayer extends TrueSkillFactorGraphLaye
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function createPriorSchedule()
|
public function createPriorSchedule(): ScheduleSequence
|
||||||
{
|
{
|
||||||
$localFactors = $this->getLocalFactors();
|
$localFactors = $this->getLocalFactors();
|
||||||
|
|
||||||
@ -35,7 +36,7 @@ class PlayerPerformancesToTeamPerformancesLayer extends TrueSkillFactorGraphLaye
|
|||||||
'all player perf to team perf schedule');
|
'all player perf to team perf schedule');
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function createPlayerToTeamSumFactor($teamMembers, $sumVariable)
|
protected function createPlayerToTeamSumFactor($teamMembers, $sumVariable): GaussianWeightedSumFactor
|
||||||
{
|
{
|
||||||
$weights = array_map(
|
$weights = array_map(
|
||||||
function ($v) {
|
function ($v) {
|
||||||
@ -51,7 +52,7 @@ class PlayerPerformancesToTeamPerformancesLayer extends TrueSkillFactorGraphLaye
|
|||||||
$weights);
|
$weights);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function createPosteriorSchedule()
|
public function createPosteriorSchedule(): ScheduleSequence
|
||||||
{
|
{
|
||||||
$allFactors = [];
|
$allFactors = [];
|
||||||
$localFactors = $this->getLocalFactors();
|
$localFactors = $this->getLocalFactors();
|
||||||
|
@ -46,7 +46,7 @@ class TrueSkillFactorGraph extends FactorGraph
|
|||||||
return $this->_gameInfo;
|
return $this->_gameInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function buildGraph()
|
public function buildGraph(): void
|
||||||
{
|
{
|
||||||
$lastOutput = null;
|
$lastOutput = null;
|
||||||
|
|
||||||
@ -62,13 +62,13 @@ class TrueSkillFactorGraph extends FactorGraph
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function runSchedule()
|
public function runSchedule(): void
|
||||||
{
|
{
|
||||||
$fullSchedule = $this->createFullSchedule();
|
$fullSchedule = $this->createFullSchedule();
|
||||||
$fullSchedule->visit();
|
$fullSchedule->visit();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getProbabilityOfRanking()
|
public function getProbabilityOfRanking(): float
|
||||||
{
|
{
|
||||||
$factorList = new FactorList();
|
$factorList = new FactorList();
|
||||||
|
|
||||||
@ -86,7 +86,7 @@ class TrueSkillFactorGraph extends FactorGraph
|
|||||||
return exp($logZ);
|
return exp($logZ);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function createFullSchedule()
|
private function createFullSchedule(): ScheduleSequence
|
||||||
{
|
{
|
||||||
$fullSchedule = [];
|
$fullSchedule = [];
|
||||||
|
|
||||||
|
@ -123,7 +123,7 @@ class TwoPlayerTrueSkillCalculator extends SkillCalculator
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function calculateMatchQuality(GameInfo $gameInfo, array $teams)
|
public function calculateMatchQuality(GameInfo $gameInfo, array $teams): float
|
||||||
{
|
{
|
||||||
Guard::argumentNotNull($gameInfo, 'gameInfo');
|
Guard::argumentNotNull($gameInfo, 'gameInfo');
|
||||||
$this->validateTeamCountAndPlayersCountPerTeam($teams);
|
$this->validateTeamCountAndPlayersCountPerTeam($teams);
|
||||||
|
Reference in New Issue
Block a user