mirror of
https://github.com/furyfire/trueskill.git
synced 2025-04-15 02:24:28 +00:00
45 lines
1.6 KiB
PHP
45 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace DNW\Skills\TrueSkill\Layers;
|
|
|
|
use DNW\Skills\FactorGraphs\Variable;
|
|
use DNW\Skills\TrueSkill\Factors\GaussianWeightedSumFactor;
|
|
|
|
class TeamPerformancesToTeamPerformanceDifferencesLayer extends TrueSkillFactorGraphLayer
|
|
{
|
|
public function buildLayer(): void
|
|
{
|
|
$inputVariablesGroups = $this->getInputVariablesGroups();
|
|
$inputVariablesGroupsCount = is_countable($inputVariablesGroups) ? count($inputVariablesGroups) : 0;
|
|
$outputVariablesGroup = &$this->getOutputVariablesGroups();
|
|
|
|
for ($i = 0; $i < $inputVariablesGroupsCount - 1; $i++) {
|
|
$strongerTeam = $inputVariablesGroups[$i][0];
|
|
$weakerTeam = $inputVariablesGroups[$i + 1][0];
|
|
|
|
$currentDifference = $this->createOutputVariable();
|
|
$newDifferencesFactor = $this->createTeamPerformanceToDifferenceFactor($strongerTeam, $weakerTeam, $currentDifference);
|
|
$this->addLayerFactor($newDifferencesFactor);
|
|
|
|
// REVIEW: Does it make sense to have groups of one?
|
|
$outputVariablesGroup[] = [$currentDifference];
|
|
}
|
|
}
|
|
|
|
private function createTeamPerformanceToDifferenceFactor(
|
|
Variable $strongerTeam,
|
|
Variable $weakerTeam,
|
|
Variable $output
|
|
): GaussianWeightedSumFactor {
|
|
$teams = [$strongerTeam, $weakerTeam];
|
|
$weights = [1.0, -1.0];
|
|
|
|
return new GaussianWeightedSumFactor($output, $teams, $weights);
|
|
}
|
|
|
|
private function createOutputVariable(): Variable
|
|
{
|
|
return $this->getParentFactorGraph()->getVariableFactory()->createBasicVariable('Team performance difference');
|
|
}
|
|
}
|