2022-07-05 15:55:47 +02:00
|
|
|
<?php
|
|
|
|
|
2024-02-02 14:53:38 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2022-07-05 15:55:47 +02:00
|
|
|
namespace DNW\Skills\TrueSkill\Layers;
|
2010-09-18 21:19:51 -04:00
|
|
|
|
2022-07-05 15:33:34 +02:00
|
|
|
use DNW\Skills\FactorGraphs\Variable;
|
|
|
|
use DNW\Skills\TrueSkill\Factors\GaussianWeightedSumFactor;
|
2010-09-18 21:19:51 -04:00
|
|
|
|
2010-09-18 11:11:44 -04:00
|
|
|
class TeamPerformancesToTeamPerformanceDifferencesLayer extends TrueSkillFactorGraphLayer
|
|
|
|
{
|
2023-08-02 10:10:57 +00:00
|
|
|
public function buildLayer(): void
|
2010-09-18 11:11:44 -04:00
|
|
|
{
|
2016-05-24 16:31:21 +02:00
|
|
|
$inputVariablesGroups = $this->getInputVariablesGroups();
|
2023-08-03 13:08:04 +00:00
|
|
|
$inputVariablesGroupsCount = count($inputVariablesGroups);
|
2010-09-30 08:25:31 -04:00
|
|
|
$outputVariablesGroup = &$this->getOutputVariablesGroups();
|
2010-09-18 11:11:44 -04:00
|
|
|
|
2024-02-21 13:48:37 +00:00
|
|
|
for ($i = 0; $i < $inputVariablesGroupsCount - 1; ++$i) {
|
2016-05-24 16:31:21 +02:00
|
|
|
$strongerTeam = $inputVariablesGroups[$i][0];
|
|
|
|
$weakerTeam = $inputVariablesGroups[$i + 1][0];
|
2010-09-18 11:11:44 -04:00
|
|
|
|
2016-05-24 16:31:21 +02:00
|
|
|
$currentDifference = $this->createOutputVariable();
|
2010-09-28 22:40:54 -04:00
|
|
|
$newDifferencesFactor = $this->createTeamPerformanceToDifferenceFactor($strongerTeam, $weakerTeam, $currentDifference);
|
2010-09-25 22:16:47 -04:00
|
|
|
$this->addLayerFactor($newDifferencesFactor);
|
2010-09-18 11:11:44 -04:00
|
|
|
|
2022-07-05 15:33:34 +02:00
|
|
|
// REVIEW: Does it make sense to have groups of one?
|
2022-07-05 15:55:47 +02:00
|
|
|
$outputVariablesGroup[] = [$currentDifference];
|
2010-09-18 11:11:44 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-01 13:53:19 +00:00
|
|
|
private function createTeamPerformanceToDifferenceFactor(
|
|
|
|
Variable $strongerTeam,
|
|
|
|
Variable $weakerTeam,
|
|
|
|
Variable $output
|
2024-02-02 15:16:11 +00:00
|
|
|
): GaussianWeightedSumFactor
|
|
|
|
{
|
2022-07-05 15:55:47 +02:00
|
|
|
$teams = [$strongerTeam, $weakerTeam];
|
|
|
|
$weights = [1.0, -1.0];
|
|
|
|
|
2010-09-25 22:16:47 -04:00
|
|
|
return new GaussianWeightedSumFactor($output, $teams, $weights);
|
2010-09-18 11:11:44 -04:00
|
|
|
}
|
|
|
|
|
2023-08-02 10:10:57 +00:00
|
|
|
private function createOutputVariable(): Variable
|
2010-09-18 11:11:44 -04:00
|
|
|
{
|
2022-07-05 16:21:06 +02:00
|
|
|
return $this->getParentFactorGraph()->getVariableFactory()->createBasicVariable('Team performance difference');
|
2010-09-18 11:11:44 -04:00
|
|
|
}
|
2022-07-05 15:55:47 +02:00
|
|
|
}
|