2022-07-05 15:33:34 +02:00
|
|
|
<?php namespace DNW\Skills\TrueSkill\Layers;
|
2010-09-18 21:19:51 -04:00
|
|
|
|
2022-07-05 15:33:34 +02:00
|
|
|
use DNW\Skills\TrueSkill\DrawMargin;
|
|
|
|
use DNW\Skills\TrueSkill\TrueSkillFactorGraph;
|
|
|
|
use DNW\Skills\TrueSkill\Factors\GaussianGreaterThanFactor;
|
|
|
|
use DNW\Skills\TrueSkill\Factors\GaussianWithinFactor;
|
2010-09-18 21:19:51 -04:00
|
|
|
|
2010-09-18 11:11:44 -04:00
|
|
|
class TeamDifferencesComparisonLayer extends TrueSkillFactorGraphLayer
|
|
|
|
{
|
|
|
|
private $_epsilon;
|
|
|
|
private $_teamRanks;
|
|
|
|
|
2016-05-24 16:31:21 +02:00
|
|
|
public function __construct(TrueSkillFactorGraph $parentGraph, array $teamRanks)
|
2010-09-18 11:11:44 -04:00
|
|
|
{
|
|
|
|
parent::__construct($parentGraph);
|
|
|
|
$this->_teamRanks = $teamRanks;
|
2016-05-24 16:31:21 +02:00
|
|
|
$gameInfo = $this->getParentFactorGraph()->getGameInfo();
|
2010-09-18 11:11:44 -04:00
|
|
|
$this->_epsilon = DrawMargin::getDrawMarginFromDrawProbability($gameInfo->getDrawProbability(), $gameInfo->getBeta());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function buildLayer()
|
|
|
|
{
|
2016-05-24 16:31:21 +02:00
|
|
|
$inputVarGroups = $this->getInputVariablesGroups();
|
2010-09-18 11:11:44 -04:00
|
|
|
$inputVarGroupsCount = count($inputVarGroups);
|
|
|
|
|
2016-05-24 14:10:39 +02:00
|
|
|
for ($i = 0; $i < $inputVarGroupsCount; $i++) {
|
2010-09-18 11:11:44 -04:00
|
|
|
$isDraw = ($this->_teamRanks[$i] == $this->_teamRanks[$i + 1]);
|
2016-05-24 16:31:21 +02:00
|
|
|
$teamDifference = $inputVarGroups[$i][0];
|
2010-09-18 11:11:44 -04:00
|
|
|
|
|
|
|
$factor =
|
|
|
|
$isDraw
|
|
|
|
? new GaussianWithinFactor($this->_epsilon, $teamDifference)
|
|
|
|
: new GaussianGreaterThanFactor($this->_epsilon, $teamDifference);
|
|
|
|
|
|
|
|
$this->addLayerFactor($factor);
|
|
|
|
}
|
|
|
|
}
|
2016-05-24 14:10:39 +02:00
|
|
|
}
|