2010-09-18 11:11:44 -04:00
|
|
|
<?php
|
|
|
|
namespace Moserware\Skills\TrueSkill\Layers;
|
|
|
|
|
2010-09-25 10:15:51 -04:00
|
|
|
require_once(dirname(__FILE__) . "/../../FactorGraphs/Variable.php");
|
|
|
|
require_once(dirname(__FILE__) . "/../TrueSkillFactorGraph.php");
|
|
|
|
require_once(dirname(__FILE__) . "/../Factors/GaussianWeightedSumFactor.php");
|
|
|
|
require_once(dirname(__FILE__) . "/TrueSkillFactorGraphLayer.php");
|
2010-09-18 21:19:51 -04:00
|
|
|
|
|
|
|
use Moserware\Skills\FactorGraphs\Variable;
|
|
|
|
use Moserware\Skills\TrueSkill\DrawMargin;
|
|
|
|
use Moserware\Skills\TrueSkill\TrueSkillFactorGraph;
|
|
|
|
use Moserware\Skills\TrueSkill\Factors\GaussianWeightedSumFactor;
|
|
|
|
|
2010-09-18 11:11:44 -04:00
|
|
|
class TeamPerformancesToTeamPerformanceDifferencesLayer extends TrueSkillFactorGraphLayer
|
|
|
|
{
|
2010-09-25 15:46:23 -04:00
|
|
|
public function __construct(TrueSkillFactorGraph &$parentGraph)
|
2010-09-18 11:11:44 -04:00
|
|
|
{
|
|
|
|
parent::__construct($parentGraph);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function buildLayer()
|
|
|
|
{
|
2010-09-25 22:16:47 -04:00
|
|
|
$inputVariablesGroups = &$this->getInputVariablesGroups();
|
|
|
|
$inputVariablesGroupsCount = count($inputVariablesGroups);
|
2010-09-30 08:25:31 -04:00
|
|
|
$outputVariablesGroup = &$this->getOutputVariablesGroups();
|
2010-09-18 11:11:44 -04:00
|
|
|
|
2010-09-25 22:16:47 -04:00
|
|
|
for ($i = 0; $i < $inputVariablesGroupsCount - 1; $i++)
|
2010-09-18 11:11:44 -04:00
|
|
|
{
|
2010-09-30 08:25:31 -04:00
|
|
|
$strongerTeam = &$inputVariablesGroups[$i][0];
|
|
|
|
$weakerTeam = &$inputVariablesGroups[$i + 1][0];
|
2010-09-18 11:11:44 -04:00
|
|
|
|
2010-09-25 22:40:56 -04: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
|
|
|
|
2010-09-30 08:25:31 -04:00
|
|
|
// REVIEW: Does it make sense to have groups of one?
|
2010-09-25 22:40:56 -04:00
|
|
|
$outputVariablesGroup[] = array($currentDifference);
|
2010-09-18 11:11:44 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private function createTeamPerformanceToDifferenceFactor(
|
2010-09-25 15:46:23 -04:00
|
|
|
Variable &$strongerTeam, Variable &$weakerTeam, Variable &$output)
|
2010-09-18 11:11:44 -04:00
|
|
|
{
|
2010-09-25 22:16:47 -04:00
|
|
|
$teams = array($strongerTeam, $weakerTeam);
|
|
|
|
$weights = array(1.0, -1.0);
|
|
|
|
return new GaussianWeightedSumFactor($output, $teams, $weights);
|
2010-09-18 11:11:44 -04:00
|
|
|
}
|
|
|
|
|
2010-10-02 21:15:47 -04:00
|
|
|
private function &createOutputVariable()
|
2010-09-18 11:11:44 -04:00
|
|
|
{
|
2010-10-02 21:15:47 -04:00
|
|
|
$outputVariable = &$this->getParentFactorGraph()->getVariableFactory()->createBasicVariable("Team performance difference");
|
|
|
|
return $outputVariable;
|
2010-09-18 11:11:44 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|