Files
trueskill/src/TrueSkill/Layers/TeamPerformancesToTeamPerformanceDifferencesLayer.php

48 lines
1.8 KiB
PHP
Raw Normal View History

2022-07-05 15:33:34 +02:00
<?php namespace DNW\Skills\TrueSkill\Layers;
2022-07-05 15:33:34 +02:00
use DNW\Skills\FactorGraphs\Variable;
use DNW\Skills\TrueSkill\TrueSkillFactorGraph;
use DNW\Skills\TrueSkill\Factors\GaussianWeightedSumFactor;
class TeamPerformancesToTeamPerformanceDifferencesLayer extends TrueSkillFactorGraphLayer
{
public function __construct(TrueSkillFactorGraph $parentGraph)
{
parent::__construct($parentGraph);
}
public function buildLayer()
{
$inputVariablesGroups = $this->getInputVariablesGroups();
$inputVariablesGroupsCount = count($inputVariablesGroups);
2010-09-30 08:25:31 -04:00
$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);
2022-07-05 15:33:34 +02:00
// REVIEW: Does it make sense to have groups of one?
$outputVariablesGroup[] = array($currentDifference);
}
}
private function createTeamPerformanceToDifferenceFactor(Variable $strongerTeam,
Variable $weakerTeam,
Variable $output)
{
$teams = array($strongerTeam, $weakerTeam);
$weights = array(1.0, -1.0);
return new GaussianWeightedSumFactor($output, $teams, $weights);
}
private function createOutputVariable()
{
$outputVariable = $this->getParentFactorGraph()->getVariableFactory()->createBasicVariable("Team performance difference");
return $outputVariable;
}
}