2010-09-18 11:11:44 -04:00
|
|
|
<?php
|
|
|
|
namespace Moserware\Skills\TrueSkill\Layers;
|
|
|
|
|
2010-09-25 19:26:57 -04:00
|
|
|
require_once(dirname(__FILE__) . "/../../PartialPlay.php");
|
2010-09-25 10:15:51 -04:00
|
|
|
require_once(dirname(__FILE__) . "/../../FactorGraphs/Schedule.php");
|
2010-09-25 19:26:57 -04:00
|
|
|
require_once(dirname(__FILE__) . "/../Factors/GaussianWeightedSumFactor.php");
|
2010-09-25 10:15:51 -04:00
|
|
|
require_once(dirname(__FILE__) . "/../TrueSkillFactorGraph.php");
|
|
|
|
require_once(dirname(__FILE__) . "/TrueSkillFactorGraphLayer.php");
|
|
|
|
require_once(dirname(__FILE__) . "/TeamPerformancesToTeamPerformanceDifferencesLayer.php");
|
|
|
|
require_once(dirname(__FILE__) . "/TeamDifferencesComparisonLayer.php");
|
2010-09-18 17:56:57 -04:00
|
|
|
|
2010-09-25 19:26:57 -04:00
|
|
|
use Moserware\Skills\PartialPlay;
|
2010-09-18 17:56:57 -04:00
|
|
|
use Moserware\Skills\FactorGraphs\ScheduleLoop;
|
|
|
|
use Moserware\Skills\FactorGraphs\ScheduleSequence;
|
|
|
|
use Moserware\Skills\FactorGraphs\ScheduleStep;
|
2010-09-25 19:26:57 -04:00
|
|
|
use Moserware\Skills\TrueSkill\Factors\GaussianWeightedSumFactor;
|
2010-09-18 21:19:51 -04:00
|
|
|
use Moserware\Skills\TrueSkill\TrueSkillFactorGraph;
|
2010-09-18 17:56:57 -04:00
|
|
|
|
2010-09-18 11:11:44 -04:00
|
|
|
class PlayerPerformancesToTeamPerformancesLayer 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()
|
|
|
|
{
|
|
|
|
foreach ($this->getInputVariablesGroups() as $currentTeam)
|
|
|
|
{
|
2010-09-26 21:43:17 -04:00
|
|
|
$teamPerformance = $this->createOutputVariable($currentTeam);
|
2010-09-25 22:16:47 -04:00
|
|
|
$newSumFactor = $this->createPlayerToTeamSumFactor($currentTeam, $teamPerformance);
|
|
|
|
$this->addLayerFactor($newSumFactor);
|
2010-09-18 11:11:44 -04:00
|
|
|
|
|
|
|
// REVIEW: Does it make sense to have groups of one?
|
2010-09-25 22:16:47 -04:00
|
|
|
$outputVariablesGroups = &$this->getOutputVariablesGroups();
|
|
|
|
$outputVariablesGroups[] = array($teamPerformance);
|
2010-09-18 11:11:44 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function createPriorSchedule()
|
|
|
|
{
|
|
|
|
return $this->scheduleSequence(
|
|
|
|
array_map(
|
|
|
|
function($weightedSumFactor)
|
|
|
|
{
|
|
|
|
return new ScheduleStep("Perf to Team Perf Step", $weightedSumFactor, 0);
|
|
|
|
},
|
|
|
|
$this->getLocalFactors()),
|
|
|
|
"all player perf to team perf schedule");
|
|
|
|
}
|
|
|
|
|
2010-09-25 15:46:23 -04:00
|
|
|
protected function createPlayerToTeamSumFactor(&$teamMembers, &$sumVariable)
|
2010-09-18 11:11:44 -04:00
|
|
|
{
|
2010-09-25 19:26:57 -04:00
|
|
|
$weights = array_map(
|
2010-09-18 11:11:44 -04:00
|
|
|
function($v)
|
|
|
|
{
|
|
|
|
return PartialPlay::getPartialPlayPercentage($v->getKey());
|
|
|
|
},
|
2010-09-25 19:26:57 -04:00
|
|
|
$teamMembers);
|
|
|
|
|
|
|
|
return new GaussianWeightedSumFactor(
|
|
|
|
$sumVariable,
|
|
|
|
$teamMembers,
|
|
|
|
$weights);
|
2010-09-18 11:11:44 -04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function createPosteriorSchedule()
|
|
|
|
{
|
|
|
|
// BLOG
|
2010-09-18 15:24:36 -04:00
|
|
|
$allFactors = array();
|
|
|
|
foreach($this->getLocalFactors() as $currentFactor)
|
|
|
|
{
|
|
|
|
$numberOfMessages = $currentFactor->getNumberOfMessages();
|
|
|
|
for($currentIteration = 1; $currentIteration < $numberOfMessages; $currentIteration++)
|
|
|
|
{
|
|
|
|
$allFactors[] = new ScheduleStep("team sum perf @" + $currentIteration,
|
|
|
|
$currentFactor, $currentIteration);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $this->scheduleSequence($allFactors, "all of the team's sum iterations");
|
2010-09-18 11:11:44 -04:00
|
|
|
}
|
|
|
|
|
2010-09-25 15:46:23 -04:00
|
|
|
private function createOutputVariable(&$team)
|
2010-09-18 11:11:44 -04:00
|
|
|
{
|
2010-09-26 21:43:17 -04:00
|
|
|
$memberNames = \array_map(function ($currentPlayer)
|
|
|
|
{
|
|
|
|
return (string)($currentPlayer->getKey());
|
|
|
|
},
|
|
|
|
$team);
|
|
|
|
|
|
|
|
$teamMemberNames = \join(", ", $memberNames);
|
|
|
|
return $this->getParentFactorGraph()->getVariableFactory()->createBasicVariable("Team[" . $teamMemberNames . "]'s performance");
|
2010-09-18 11:11:44 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|