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/Schedule.php");
|
|
|
|
require_once(dirname(__FILE__) . "/../../Numerics/BasicMath.php");
|
|
|
|
require_once(dirname(__FILE__) . "/../TrueSkillFactorGraph.php");
|
|
|
|
require_once(dirname(__FILE__) . "/../Factors/GaussianLikelihoodFactor.php");
|
|
|
|
require_once(dirname(__FILE__) . "/TrueSkillFactorGraphLayer.php");
|
2010-09-18 21:19:51 -04:00
|
|
|
|
|
|
|
use Moserware\Skills\FactorGraphs\ScheduleStep;
|
|
|
|
use Moserware\Skills\TrueSkill\TrueSkillFactorGraph;
|
|
|
|
use Moserware\Skills\TrueSkill\Factors\GaussianLikelihoodFactor;
|
|
|
|
|
2010-09-18 11:11:44 -04:00
|
|
|
class PlayerSkillsToPerformancesLayer 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)
|
|
|
|
{
|
|
|
|
$currentTeamPlayerPerformances = array();
|
|
|
|
|
|
|
|
foreach ($currentTeam as $playerSkillVariable)
|
|
|
|
{
|
|
|
|
$playerPerformance = $this->createOutputVariable($playerSkillVariable->getKey());
|
2010-09-25 22:16:47 -04:00
|
|
|
$newLikelihoodFactor = $this->createLikelihood($playerSkillVariable, $playerPerformance);
|
|
|
|
$this->addLayerFactor($newLikelihoodFactor);
|
2010-09-25 19:26:57 -04:00
|
|
|
$currentTeamPlayerPerformances[] = &$playerPerformance;
|
2010-09-18 11:11:44 -04:00
|
|
|
}
|
2010-09-18 15:24:36 -04:00
|
|
|
|
2010-09-25 19:26:57 -04:00
|
|
|
$outputVariablesGroups = &$this->getOutputVariablesGroups();
|
|
|
|
$outputVariablesGroups[] = &$currentTeamPlayerPerformances;
|
2010-09-18 11:11:44 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-25 15:46:23 -04:00
|
|
|
private function createLikelihood(&$playerSkill, &$playerPerformance)
|
2010-09-18 11:11:44 -04:00
|
|
|
{
|
|
|
|
return new GaussianLikelihoodFactor(square($this->getParentFactorGraph()->getGameInfo()->getBeta()), $playerPerformance, $playerSkill);
|
|
|
|
}
|
|
|
|
|
2010-09-25 15:46:23 -04:00
|
|
|
private function createOutputVariable(&$key)
|
2010-09-18 11:11:44 -04:00
|
|
|
{
|
2010-09-26 21:43:17 -04:00
|
|
|
return $this->getParentFactorGraph()->getVariableFactory()->createKeyedVariable($key, $key . "'s performance");
|
2010-09-18 11:11:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function createPriorSchedule()
|
|
|
|
{
|
|
|
|
return $this->scheduleSequence(
|
|
|
|
array_map(
|
|
|
|
function($likelihood)
|
|
|
|
{
|
2010-09-25 18:25:56 -04:00
|
|
|
return new ScheduleStep("Skill to Perf step", $likelihood, 0);
|
2010-09-18 11:11:44 -04:00
|
|
|
},
|
|
|
|
$this->getLocalFactors()),
|
|
|
|
"All skill to performance sending");
|
|
|
|
}
|
|
|
|
|
|
|
|
public function createPosteriorSchedule()
|
|
|
|
{
|
|
|
|
return $this->scheduleSequence(
|
|
|
|
array_map(
|
|
|
|
function($likelihood)
|
|
|
|
{
|
|
|
|
return new ScheduleStep("name", $likelihood, 1);
|
|
|
|
},
|
|
|
|
$this->getLocalFactors()),
|
|
|
|
"All skill to performance sending");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|