rector: codingStyle

This commit is contained in:
2024-02-21 13:48:37 +00:00
parent f3e5912ebb
commit 0184d0432b
24 changed files with 86 additions and 76 deletions

View File

@ -29,6 +29,7 @@ class FactorGraphTrueSkillCalculator extends SkillCalculator
{
parent::__construct(SkillCalculatorSupportedOptions::PARTIAL_PLAY | SkillCalculatorSupportedOptions::PARTIAL_UPDATE, TeamsRange::atLeast(2), PlayersRange::atLeast(1));
}
/**
* {@inheritdoc}
*/
@ -51,6 +52,7 @@ class FactorGraphTrueSkillCalculator extends SkillCalculator
return $factorGraph->getUpdatedRatings();
}
/**
* {@inheritdoc}
*/
@ -104,7 +106,7 @@ class FactorGraphTrueSkillCalculator extends SkillCalculator
return new Vector(
self::getPlayerRatingValues(
$teamAssignmentsList,
fn (Rating $rating): float => $rating->getMean()
static fn(Rating $rating): float => $rating->getMean()
)
);
}
@ -119,7 +121,7 @@ class FactorGraphTrueSkillCalculator extends SkillCalculator
return new DiagonalMatrix(
self::getPlayerRatingValues(
$teamAssignmentsList,
fn (Rating $rating): float => BasicMath::square($rating->getStandardDeviation())
static fn(Rating $rating): float => BasicMath::square($rating->getStandardDeviation())
)
);
}
@ -171,7 +173,7 @@ class FactorGraphTrueSkillCalculator extends SkillCalculator
$currentColumn = 0;
for ($i = 0; $i < count($teamAssignmentsList) - 1; $i++) {
for ($i = 0; $i < count($teamAssignmentsList) - 1; ++$i) {
$currentTeam = $teamAssignmentsList[$i];
// Need to add in 0's for all the previous players, since they're not
@ -181,7 +183,7 @@ class FactorGraphTrueSkillCalculator extends SkillCalculator
foreach ($currentTeam->getAllPlayers() as $currentPlayer) {
$playerAssignments[$currentColumn][] = PartialPlay::getPartialPlayPercentage($currentPlayer);
// indicates the player is on the team
$totalPreviousPlayers++;
++$totalPreviousPlayers;
}
$rowsRemaining = $totalPlayers - $totalPreviousPlayers;
@ -190,15 +192,15 @@ class FactorGraphTrueSkillCalculator extends SkillCalculator
foreach ($nextTeam->getAllPlayers() as $nextTeamPlayer) {
// Add a -1 * playing time to represent the difference
$playerAssignments[$currentColumn][] = -1 * PartialPlay::getPartialPlayPercentage($nextTeamPlayer);
$rowsRemaining--;
--$rowsRemaining;
}
for ($ixAdditionalRow = 0; $ixAdditionalRow < $rowsRemaining; $ixAdditionalRow++) {
for ($ixAdditionalRow = 0; $ixAdditionalRow < $rowsRemaining; ++$ixAdditionalRow) {
// Pad with zeros
$playerAssignments[$currentColumn][] = 0;
}
$currentColumn++;
++$currentColumn;
}
return Matrix::fromColumnValues($totalPlayers, count($teamAssignmentsList) - 1, $playerAssignments);

View File

@ -30,6 +30,7 @@ class GaussianWeightedSumFactor extends GaussianFactor
* @var array<float[]> $weights
*/
private array $weights = [];
/**
* @var array<float[]> $weightsSquared
*/
@ -48,7 +49,7 @@ class GaussianWeightedSumFactor extends GaussianFactor
$variableWeightsLength = count($variableWeights);
$this->weights[0] = array_fill(0, count($variableWeights), 0);
for ($i = 0; $i < $variableWeightsLength; $i++) {
for ($i = 0; $i < $variableWeightsLength; ++$i) {
$weight = &$variableWeights[$i];
$this->weights[0][$i] = $weight;
$this->weightsSquared[0][$i] = BasicMath::square($weight);
@ -58,7 +59,7 @@ class GaussianWeightedSumFactor extends GaussianFactor
// 0..n-1
$this->variableIndexOrdersForWeights[0] = [];
for ($i = 0; $i < ($variablesToSumLength + 1); $i++) {
for ($i = 0; $i < ($variablesToSumLength + 1); ++$i) {
$this->variableIndexOrdersForWeights[0][] = $i;
}
@ -70,7 +71,7 @@ class GaussianWeightedSumFactor extends GaussianFactor
// By convention, we'll put the v_0 term at the end
$weightsLength = $variableWeightsLength + 1;
for ($weightsIndex = 1; $weightsIndex < $weightsLength; $weightsIndex++) {
for ($weightsIndex = 1; $weightsIndex < $weightsLength; ++$weightsIndex) {
$currentWeights = \array_fill(0, $variableWeightsLength, 0);
$variableIndices = \array_fill(0, $variableWeightsLength + 1, 0);
@ -82,7 +83,7 @@ class GaussianWeightedSumFactor extends GaussianFactor
// This is helpful since we skip over one of the spots
$currentDestinationWeightIndex = 0;
for ($currentWeightSourceIndex = 0; $currentWeightSourceIndex < $variableWeightsLength; $currentWeightSourceIndex++) {
for ($currentWeightSourceIndex = 0; $currentWeightSourceIndex < $variableWeightsLength; ++$currentWeightSourceIndex) {
if ($currentWeightSourceIndex === $weightsIndex - 1) {
continue;
}
@ -98,7 +99,7 @@ class GaussianWeightedSumFactor extends GaussianFactor
$currentWeightsSquared[$currentDestinationWeightIndex] = $currentWeight * $currentWeight;
$variableIndices[$currentDestinationWeightIndex + 1] = $currentWeightSourceIndex + 1;
$currentDestinationWeightIndex++;
++$currentDestinationWeightIndex;
}
// And the final one
@ -108,6 +109,7 @@ class GaussianWeightedSumFactor extends GaussianFactor
// HACK: Getting around division by zero
$finalWeight = 0;
}
$currentWeights[$currentDestinationWeightIndex] = $finalWeight;
$currentWeightsSquared[$currentDestinationWeightIndex] = BasicMath::square($finalWeight);
$variableIndices[count($variableWeights)] = 0;
@ -135,7 +137,7 @@ class GaussianWeightedSumFactor extends GaussianFactor
$counter = count($vars);
// We start at 1 since offset 0 has the sum
for ($i = 1; $i < $counter; $i++) {
for ($i = 1; $i < $counter; ++$i) {
$result += GaussianDistribution::logRatioNormalization($vars[$i]->getValue(), $messages[$i]->getValue());
}
@ -164,7 +166,7 @@ class GaussianWeightedSumFactor extends GaussianFactor
$weightsSquaredLength = count($weightsSquared);
for ($i = 0; $i < $weightsSquaredLength; $i++) {
for ($i = 0; $i < $weightsSquaredLength; ++$i) {
// These flow directly from the paper
$inverseOfNewPrecisionSum += $weightsSquared[$i] /
@ -221,7 +223,7 @@ class GaussianWeightedSumFactor extends GaussianFactor
// The tricky part here is that we have to put the messages and variables in the same
// order as the weights. Thankfully, the weights and messages share the same index numbers,
// so we just need to make sure they're consistent
for ($i = 0; $i < $counter; $i++) {
for ($i = 0; $i < $counter; ++$i) {
$updatedMessages[] = $allMessages[$indicesToUse[$i]];
$updatedVariables[] = $allVariables[$indicesToUse[$i]];
}
@ -245,7 +247,7 @@ class GaussianWeightedSumFactor extends GaussianFactor
$result .= ' = ';
$totalVars = count($variablesToSum);
for ($i = 0; $i < $totalVars; $i++) {
for ($i = 0; $i < $totalVars; ++$i) {
$isFirst = ($i == 0);
if ($isFirst && ($weights[$i] < 0)) {

View File

@ -113,7 +113,7 @@ class IteratedTeamDifferencesInnerLayer extends TrueSkillFactorGraphLayer
$forwardScheduleList = [];
for ($i = 0; $i < $totalTeamDifferences - 1; $i++) {
for ($i = 0; $i < $totalTeamDifferences - 1; ++$i) {
$teamPerformancesToTeamPerformanceDifferencesLayerLocalFactors = $this->TeamPerformancesToTeamPerformanceDifferencesLayer->getLocalFactors();
$teamDifferencesComparisonLayerLocalFactors = $this->TeamDifferencesComparisonLayer->getLocalFactors();
@ -149,7 +149,7 @@ class IteratedTeamDifferencesInnerLayer extends TrueSkillFactorGraphLayer
$backwardScheduleList = [];
for ($i = 0; $i < $totalTeamDifferences - 1; $i++) {
for ($i = 0; $i < $totalTeamDifferences - 1; ++$i) {
$teamPerformancesToTeamPerformanceDifferencesLayerLocalFactors = $this->TeamPerformancesToTeamPerformanceDifferencesLayer->getLocalFactors();
$teamDifferencesComparisonLayerLocalFactors = $this->TeamDifferencesComparisonLayer->getLocalFactors();

View File

@ -37,7 +37,7 @@ class PlayerPerformancesToTeamPerformancesLayer extends TrueSkillFactorGraphLaye
return $this->scheduleSequence(
array_map(
fn ($weightedSumFactor): ScheduleStep => new ScheduleStep('Perf to Team Perf Step', $weightedSumFactor, 0),
static fn($weightedSumFactor): ScheduleStep => new ScheduleStep('Perf to Team Perf Step', $weightedSumFactor, 0),
$localFactors
),
'all player perf to team perf schedule'
@ -50,9 +50,8 @@ class PlayerPerformancesToTeamPerformancesLayer extends TrueSkillFactorGraphLaye
protected function createPlayerToTeamSumFactor(array $teamMembers, Variable $sumVariable): GaussianWeightedSumFactor
{
$weights = array_map(
function ($v): float {
static function ($v): float {
$player = $v->getKey();
return PartialPlay::getPartialPlayPercentage($player);
},
$teamMembers
@ -72,7 +71,7 @@ class PlayerPerformancesToTeamPerformancesLayer extends TrueSkillFactorGraphLaye
foreach ($localFactors as $currentFactor) {
$localCurrentFactor = $currentFactor;
$numberOfMessages = $localCurrentFactor->getNumberOfMessages();
for ($currentIteration = 1; $currentIteration < $numberOfMessages; $currentIteration++) {
for ($currentIteration = 1; $currentIteration < $numberOfMessages; ++$currentIteration) {
$allFactors[] = new ScheduleStep(
'team sum perf @' . $currentIteration,
$localCurrentFactor,
@ -89,7 +88,7 @@ class PlayerPerformancesToTeamPerformancesLayer extends TrueSkillFactorGraphLaye
*/
private function createOutputVariable(array $team): Variable
{
$memberNames = array_map(fn ($currentPlayer): string => (string)($currentPlayer->getKey()), $team);
$memberNames = array_map(static fn($currentPlayer): string => (string)($currentPlayer->getKey()), $team);
$teamMemberNames = \implode(', ', $memberNames);

View File

@ -55,7 +55,7 @@ class PlayerPriorValuesToSkillsLayer extends TrueSkillFactorGraphLayer
return $this->scheduleSequence(
array_map(
fn ($prior): ScheduleStep => new ScheduleStep('Prior to Skill Step', $prior, 0),
static fn($prior): ScheduleStep => new ScheduleStep('Prior to Skill Step', $prior, 0),
$localFactors
),
'All priors'

View File

@ -53,7 +53,7 @@ class PlayerSkillsToPerformancesLayer extends TrueSkillFactorGraphLayer
return $this->scheduleSequence(
array_map(
fn ($likelihood): ScheduleStep => new ScheduleStep('Skill to Perf step', $likelihood, 0),
static fn($likelihood): ScheduleStep => new ScheduleStep('Skill to Perf step', $likelihood, 0),
$localFactors
),
'All skill to performance sending'
@ -66,7 +66,7 @@ class PlayerSkillsToPerformancesLayer extends TrueSkillFactorGraphLayer
return $this->scheduleSequence(
array_map(
fn ($likelihood): ScheduleStep => new ScheduleStep('name', $likelihood, 1),
static fn($likelihood): ScheduleStep => new ScheduleStep('name', $likelihood, 1),
$localFactors
),
'All skill to performance sending'

View File

@ -28,7 +28,7 @@ class TeamDifferencesComparisonLayer extends TrueSkillFactorGraphLayer
$inputVarGroups = $this->getInputVariablesGroups();
$inputVarGroupsCount = count($inputVarGroups);
for ($i = 0; $i < $inputVarGroupsCount; $i++) {
for ($i = 0; $i < $inputVarGroupsCount; ++$i) {
$isDraw = ($this->teamRanks[$i] == $this->teamRanks[$i + 1]);
$teamDifference = $inputVarGroups[$i][0];

View File

@ -15,7 +15,7 @@ class TeamPerformancesToTeamPerformanceDifferencesLayer extends TrueSkillFactorG
$inputVariablesGroupsCount = count($inputVariablesGroups);
$outputVariablesGroup = &$this->getOutputVariablesGroups();
for ($i = 0; $i < $inputVariablesGroupsCount - 1; $i++) {
for ($i = 0; $i < $inputVariablesGroupsCount - 1; ++$i) {
$strongerTeam = $inputVariablesGroups[$i][0];
$weakerTeam = $inputVariablesGroups[$i + 1][0];

View File

@ -39,7 +39,7 @@ class TrueSkillFactorGraph extends FactorGraph
{
$this->priorLayer = new PlayerPriorValuesToSkillsLayer($this, $teams);
$newFactory = new VariableFactory(
fn (): GaussianDistribution => GaussianDistribution::fromPrecisionMean(0, 0)
static fn(): GaussianDistribution => GaussianDistribution::fromPrecisionMean(0, 0)
);
$this->setVariableFactory($newFactory);

View File

@ -28,6 +28,7 @@ class TwoTeamTrueSkillCalculator extends SkillCalculator
{
parent::__construct(SkillCalculatorSupportedOptions::NONE, TeamsRange::exactly(2), PlayersRange::atLeast(1));
}
/**
* {@inheritdoc}
*/
@ -82,12 +83,12 @@ class TwoTeamTrueSkillCalculator extends SkillCalculator
$totalPlayers = $selfTeam->count() + $otherTeam->count();
$meanGetter = fn (Rating $currentRating): float => $currentRating->getMean();
$meanGetter = static fn(Rating $currentRating): float => $currentRating->getMean();
$selfMeanSum = BasicMath::sum($selfTeam->getAllRatings(), $meanGetter);
$otherTeamMeanSum = BasicMath::sum($otherTeam->getAllRatings(), $meanGetter);
$varianceGetter = fn (Rating $currentRating): float => BasicMath::square($currentRating->getStandardDeviation());
$varianceGetter = static fn(Rating $currentRating): float => BasicMath::square($currentRating->getStandardDeviation());
$c = sqrt(
BasicMath::sum($selfTeam->getAllRatings(), $varianceGetter)
@ -163,9 +164,9 @@ class TwoTeamTrueSkillCalculator extends SkillCalculator
$betaSquared = BasicMath::square($gameInfo->getBeta());
$meanGetter = fn (Rating $currentRating): float => $currentRating->getMean();
$meanGetter = static fn(Rating $currentRating): float => $currentRating->getMean();
$varianceGetter = fn (Rating $currentRating): float => BasicMath::square($currentRating->getStandardDeviation());
$varianceGetter = static fn(Rating $currentRating): float => BasicMath::square($currentRating->getStandardDeviation());
$team1MeanSum = BasicMath::sum($team1Ratings, $meanGetter);
$team1StdDevSquared = BasicMath::sum($team1Ratings, $varianceGetter);