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");
|
2010-09-30 08:25:31 -04:00
|
|
|
require_once(dirname(__FILE__) . "/../../FactorGraphs/Variable.php");
|
2010-09-25 10:15:51 -04:00
|
|
|
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;
|
2010-09-30 08:25:31 -04:00
|
|
|
use Moserware\Skills\FactorGraphs\KeyedVariable;
|
2010-09-18 21:19:51 -04:00
|
|
|
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()
|
|
|
|
{
|
2010-09-30 08:25:31 -04:00
|
|
|
$inputVariablesGroups = &$this->getInputVariablesGroups();
|
|
|
|
$outputVariablesGroups = &$this->getOutputVariablesGroups();
|
|
|
|
|
|
|
|
foreach ($inputVariablesGroups as &$currentTeam)
|
2010-09-18 11:11:44 -04:00
|
|
|
{
|
|
|
|
$currentTeamPlayerPerformances = array();
|
|
|
|
|
2010-10-02 14:17:48 -04:00
|
|
|
foreach ($currentTeam as &$playerSkillVariable)
|
2010-09-18 11:11:44 -04:00
|
|
|
{
|
2010-10-02 14:17:48 -04:00
|
|
|
$currentPlayer = &$playerSkillVariable->getKey();
|
|
|
|
$playerPerformance = $this->createOutputVariable($currentPlayer);
|
2010-09-25 22:16:47 -04:00
|
|
|
$newLikelihoodFactor = $this->createLikelihood($playerSkillVariable, $playerPerformance);
|
|
|
|
$this->addLayerFactor($newLikelihoodFactor);
|
2010-09-27 22:26:28 -04:00
|
|
|
$currentTeamPlayerPerformances[] = $playerPerformance;
|
2010-09-30 08:25:31 -04:00
|
|
|
}
|
2010-09-18 15:24:36 -04:00
|
|
|
|
2010-09-27 22:26:28 -04:00
|
|
|
$outputVariablesGroups[] = $currentTeamPlayerPerformances;
|
2010-09-18 11:11:44 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-30 08:25:31 -04:00
|
|
|
private function createLikelihood(KeyedVariable &$playerSkill, KeyedVariable &$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()
|
|
|
|
{
|
2010-09-30 08:25:31 -04:00
|
|
|
$localFactors = &$this->getLocalFactors();
|
2010-09-18 11:11:44 -04:00
|
|
|
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
|
|
|
},
|
2010-09-30 08:25:31 -04:00
|
|
|
$localFactors),
|
2010-09-18 11:11:44 -04:00
|
|
|
"All skill to performance sending");
|
|
|
|
}
|
|
|
|
|
|
|
|
public function createPosteriorSchedule()
|
|
|
|
{
|
2010-09-30 08:25:31 -04:00
|
|
|
$localFactors = &$this->getLocalFactors();
|
2010-09-18 11:11:44 -04:00
|
|
|
return $this->scheduleSequence(
|
|
|
|
array_map(
|
|
|
|
function($likelihood)
|
|
|
|
{
|
|
|
|
return new ScheduleStep("name", $likelihood, 1);
|
|
|
|
},
|
2010-09-30 08:25:31 -04:00
|
|
|
$localFactors),
|
2010-09-18 11:11:44 -04:00
|
|
|
"All skill to performance sending");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|