trueskill/src/TrueSkill/Layers/PlayerSkillsToPerformancesLayer.php

76 lines
2.6 KiB
PHP
Raw Normal View History

2022-07-05 15:33:34 +02:00
<?php namespace DNW\Skills\TrueSkill\Layers;
2022-07-05 15:33:34 +02:00
use DNW\Skills\FactorGraphs\ScheduleStep;
use DNW\Skills\FactorGraphs\KeyedVariable;
use DNW\Skills\Numerics\BasicMath;
use DNW\Skills\TrueSkill\TrueSkillFactorGraph;
use DNW\Skills\TrueSkill\Factors\GaussianLikelihoodFactor;
class PlayerSkillsToPerformancesLayer extends TrueSkillFactorGraphLayer
{
public function __construct(TrueSkillFactorGraph $parentGraph)
{
parent::__construct($parentGraph);
}
public function buildLayer()
{
$inputVariablesGroups = $this->getInputVariablesGroups();
2010-09-30 08:25:31 -04:00
$outputVariablesGroups = &$this->getOutputVariablesGroups();
foreach ($inputVariablesGroups as $currentTeam) {
$currentTeamPlayerPerformances = array();
foreach ($currentTeam as $playerSkillVariable) {
$localPlayerSkillVariable = $playerSkillVariable;
$currentPlayer = $localPlayerSkillVariable->getKey();
$playerPerformance = $this->createOutputVariable($currentPlayer);
$newLikelihoodFactor = $this->createLikelihood($localPlayerSkillVariable, $playerPerformance);
$this->addLayerFactor($newLikelihoodFactor);
$currentTeamPlayerPerformances[] = $playerPerformance;
}
$outputVariablesGroups[] = $currentTeamPlayerPerformances;
}
}
private function createLikelihood(KeyedVariable $playerSkill, KeyedVariable $playerPerformance)
{
return new GaussianLikelihoodFactor(
2016-05-24 15:12:29 +02:00
BasicMath::square($this->getParentFactorGraph()->getGameInfo()->getBeta()),
$playerPerformance,
$playerSkill
);
}
private function createOutputVariable($key)
{
$outputVariable = $this->getParentFactorGraph()->getVariableFactory()->createKeyedVariable($key, $key . "'s performance");
return $outputVariable;
}
public function createPriorSchedule()
{
$localFactors = $this->getLocalFactors();
return $this->scheduleSequence(
array_map(
function ($likelihood) {
return new ScheduleStep("Skill to Perf step", $likelihood, 0);
},
$localFactors),
"All skill to performance sending");
}
public function createPosteriorSchedule()
{
$localFactors = $this->getLocalFactors();
return $this->scheduleSequence(
array_map(
function ($likelihood) {
return new ScheduleStep("name", $likelihood, 1);
},
$localFactors),
"All skill to performance sending");
}
}