mirror of
https://github.com/furyfire/trueskill.git
synced 2025-03-20 16:48:04 +00:00
Another pass at fixing up references
This commit is contained in:
@ -33,8 +33,8 @@ class IteratedTeamDifferencesInnerLayer extends TrueSkillFactorGraphLayer
|
||||
$this->_TeamPerformancesToTeamPerformanceDifferencesLayer->setInputVariablesGroups($inputVariablesGroups);
|
||||
$this->_TeamPerformancesToTeamPerformanceDifferencesLayer->buildLayer();
|
||||
|
||||
$this->_TeamDifferencesComparisonLayer->setInputVariablesGroups(
|
||||
$this->_TeamPerformancesToTeamPerformanceDifferencesLayer->getOutputVariablesGroups());
|
||||
$teamDifferencesOutputVariablesGroups = &$this->_TeamPerformancesToTeamPerformanceDifferencesLayer->getOutputVariablesGroups();
|
||||
$this->_TeamDifferencesComparisonLayer->setInputVariablesGroups($teamDifferencesOutputVariablesGroups);
|
||||
$this->_TeamDifferencesComparisonLayer->buildLayer();
|
||||
}
|
||||
|
||||
@ -65,10 +65,10 @@ class IteratedTeamDifferencesInnerLayer extends TrueSkillFactorGraphLayer
|
||||
$loop,
|
||||
new ScheduleStep(
|
||||
"teamPerformanceToPerformanceDifferenceFactors[0] @ 1",
|
||||
$localFactors[0], 1),
|
||||
&$localFactors[0], 1),
|
||||
new ScheduleStep(
|
||||
sprintf("teamPerformanceToPerformanceDifferenceFactors[teamTeamDifferences = %d - 1] @ 2", $totalTeamDifferences),
|
||||
$localFactors[$totalTeamDifferences - 1], 2)
|
||||
&$localFactors[$totalTeamDifferences - 1], 2)
|
||||
)
|
||||
);
|
||||
|
||||
@ -83,11 +83,11 @@ class IteratedTeamDifferencesInnerLayer extends TrueSkillFactorGraphLayer
|
||||
$itemsToSequence = array(
|
||||
new ScheduleStep(
|
||||
"send team perf to perf differences",
|
||||
$teamPerformancesToTeamPerformanceDifferencesLayerLocalFactors[0],
|
||||
&$teamPerformancesToTeamPerformanceDifferencesLayerLocalFactors[0],
|
||||
0),
|
||||
new ScheduleStep(
|
||||
"send to greater than or within factor",
|
||||
$teamDifferencesComparisonLayerLocalFactors[0],
|
||||
&$teamDifferencesComparisonLayerLocalFactors[0],
|
||||
0)
|
||||
);
|
||||
|
||||
@ -112,16 +112,16 @@ class IteratedTeamDifferencesInnerLayer extends TrueSkillFactorGraphLayer
|
||||
array(
|
||||
new ScheduleStep(
|
||||
sprintf("team perf to perf diff %d", $i),
|
||||
$teamPerformancesToTeamPerformanceDifferencesLayerLocalFactors[$i], 0),
|
||||
&$teamPerformancesToTeamPerformanceDifferencesLayerLocalFactors[$i], 0),
|
||||
new ScheduleStep(
|
||||
sprintf("greater than or within result factor %d", $i),
|
||||
$teamDifferencesComparisonLayerLocalFactors[$i], 0),
|
||||
&$teamDifferencesComparisonLayerLocalFactors[$i], 0),
|
||||
new ScheduleStep(
|
||||
sprintf("team perf to perf diff factors [%d], 2", $i),
|
||||
$teamPerformancesToTeamPerformanceDifferencesLayerLocalFactors[$i], 2)
|
||||
&$teamPerformancesToTeamPerformanceDifferencesLayerLocalFactors[$i], 2)
|
||||
), sprintf("current forward schedule piece %d", $i));
|
||||
|
||||
$forwardScheduleList[] = &$currentForwardSchedulePiece;
|
||||
$forwardScheduleList[] = $currentForwardSchedulePiece;
|
||||
}
|
||||
|
||||
$forwardSchedule = new ScheduleSequence("forward schedule", $forwardScheduleList);
|
||||
@ -133,20 +133,24 @@ class IteratedTeamDifferencesInnerLayer extends TrueSkillFactorGraphLayer
|
||||
$teamPerformancesToTeamPerformanceDifferencesLayerLocalFactors = &$this->_TeamPerformancesToTeamPerformanceDifferencesLayer->getLocalFactors();
|
||||
$teamDifferencesComparisonLayerLocalFactors = &$this->_TeamDifferencesComparisonLayer->getLocalFactors();
|
||||
|
||||
$differencesFactor = &$teamPerformancesToTeamPerformanceDifferencesLayerLocalFactors[$totalTeamDifferences - 1 - $i];
|
||||
$comparisonFactor = &$teamDifferencesComparisonLayerLocalFactors[$totalTeamDifferences - 1 - $i];
|
||||
$performancesToDifferencesFactor = &$teamPerformancesToTeamPerformanceDifferencesLayerLocalFactors[$totalTeamDifferences - 1 - $i];
|
||||
|
||||
$currentBackwardSchedulePiece = new ScheduleSequence(
|
||||
"current backward schedule piece",
|
||||
array(
|
||||
new ScheduleStep(
|
||||
sprintf("teamPerformanceToPerformanceDifferenceFactors[totalTeamDifferences - 1 - %d] @ 0", $i),
|
||||
$teamPerformancesToTeamPerformanceDifferencesLayerLocalFactors[$totalTeamDifferences - 1 - $i], 0),
|
||||
$differencesFactor, 0),
|
||||
new ScheduleStep(
|
||||
sprintf("greaterThanOrWithinResultFactors[totalTeamDifferences - 1 - %d] @ 0", $i),
|
||||
$teamDifferencesComparisonLayerLocalFactors[$totalTeamDifferences - 1 - $i], 0),
|
||||
$comparisonFactor, 0),
|
||||
new ScheduleStep(
|
||||
sprintf("teamPerformanceToPerformanceDifferenceFactors[totalTeamDifferences - 1 - %d] @ 1", $i),
|
||||
$teamPerformancesToTeamPerformanceDifferencesLayerLocalFactors[$totalTeamDifferences - 1 - $i], 1)
|
||||
$performancesToDifferencesFactor, 1)
|
||||
));
|
||||
$backwardScheduleList[] = &$currentBackwardSchedulePiece;
|
||||
$backwardScheduleList[] = $currentBackwardSchedulePiece;
|
||||
}
|
||||
|
||||
$backwardSchedule = new ScheduleSequence("backward schedule", $backwardScheduleList);
|
||||
|
@ -39,14 +39,17 @@ class PlayerPerformancesToTeamPerformancesLayer extends TrueSkillFactorGraphLaye
|
||||
|
||||
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");
|
||||
$localFactors = &$this->getLocalFactors();
|
||||
|
||||
$sequence = &$this->scheduleSequence(
|
||||
array_map(
|
||||
function($weightedSumFactor)
|
||||
{
|
||||
return new ScheduleStep("Perf to Team Perf Step", $weightedSumFactor, 0);
|
||||
},
|
||||
$localFactors),
|
||||
"all player perf to team perf schedule");
|
||||
return $sequence;
|
||||
}
|
||||
|
||||
protected function createPlayerToTeamSumFactor(&$teamMembers, &$sumVariable)
|
||||
@ -69,7 +72,8 @@ class PlayerPerformancesToTeamPerformancesLayer extends TrueSkillFactorGraphLaye
|
||||
{
|
||||
// BLOG
|
||||
$allFactors = array();
|
||||
foreach($this->getLocalFactors() as $currentFactor)
|
||||
$localFactors = &$this->getLocalFactors();
|
||||
foreach($localFactors as &$currentFactor)
|
||||
{
|
||||
$numberOfMessages = $currentFactor->getNumberOfMessages();
|
||||
for($currentIteration = 1; $currentIteration < $numberOfMessages; $currentIteration++)
|
||||
|
@ -1,15 +1,20 @@
|
||||
<?php
|
||||
namespace Moserware\Skills\TrueSkill\Layers;
|
||||
|
||||
require_once(dirname(__FILE__) . "/../../Rating.php");
|
||||
require_once(dirname(__FILE__) . "/../../FactorGraphs/Schedule.php");
|
||||
require_once(dirname(__FILE__) . "/../../FactorGraphs/Variable.php");
|
||||
require_once(dirname(__FILE__) . "/../../Numerics/BasicMath.php");
|
||||
require_once(dirname(__FILE__) . "/../TrueSkillFactorGraph.php");
|
||||
require_once(dirname(__FILE__) . "/../Factors/GaussianPriorFactor.php");
|
||||
require_once(dirname(__FILE__) . "/TrueSkillFactorGraphLayer.php");
|
||||
|
||||
use Moserware\Skills\Rating;
|
||||
use Moserware\Skills\FactorGraphs\ScheduleLoop;
|
||||
use Moserware\Skills\FactorGraphs\ScheduleSequence;
|
||||
use Moserware\Skills\FactorGraphs\ScheduleStep;
|
||||
use Moserware\Skills\FactorGraphs\Variable;
|
||||
use Moserware\Numerics\GaussianDistribution;
|
||||
use Moserware\Skills\TrueSkill\TrueSkillFactorGraph;
|
||||
use Moserware\Skills\TrueSkill\Factors\GaussianPriorFactor;
|
||||
|
||||
@ -27,11 +32,13 @@ class PlayerPriorValuesToSkillsLayer extends TrueSkillFactorGraphLayer
|
||||
|
||||
public function buildLayer()
|
||||
{
|
||||
foreach ($this->_teams as $currentTeam)
|
||||
$teams = &$this->_teams;
|
||||
foreach ($teams as &$currentTeam)
|
||||
{
|
||||
$currentTeamSkills = array();
|
||||
|
||||
foreach ($currentTeam->getAllPlayers() as $currentTeamPlayer)
|
||||
$currentTeamAllPlayers = &$currentTeam->getAllPlayers();
|
||||
foreach ($currentTeamAllPlayers as &$currentTeamPlayer)
|
||||
{
|
||||
$currentTeamPlayerRating = $currentTeam->getRating($currentTeamPlayer);
|
||||
$playerSkill = $this->createSkillOutputVariable($currentTeamPlayer);
|
||||
@ -47,17 +54,18 @@ class PlayerPriorValuesToSkillsLayer extends TrueSkillFactorGraphLayer
|
||||
|
||||
public function createPriorSchedule()
|
||||
{
|
||||
$localFactors = &$this->getLocalFactors();
|
||||
return $this->scheduleSequence(
|
||||
array_map(
|
||||
function($prior)
|
||||
function(&$prior)
|
||||
{
|
||||
return new ScheduleStep("Prior to Skill Step", $prior, 0);
|
||||
},
|
||||
$this->getLocalFactors()),
|
||||
$localFactors),
|
||||
"All priors");
|
||||
}
|
||||
|
||||
private function createPriorFactor(&$player, &$priorRating, &$skillsVariable)
|
||||
private function createPriorFactor(&$player, Rating &$priorRating, Variable &$skillsVariable)
|
||||
{
|
||||
return new GaussianPriorFactor($priorRating->getMean(),
|
||||
square($priorRating->getStandardDeviation()) +
|
||||
@ -67,8 +75,8 @@ class PlayerPriorValuesToSkillsLayer extends TrueSkillFactorGraphLayer
|
||||
|
||||
private function createSkillOutputVariable($key)
|
||||
{
|
||||
$parentFactorGraph = $this->getParentFactorGraph();
|
||||
$variableFactory = $parentFactorGraph->getVariableFactory();
|
||||
$parentFactorGraph = &$this->getParentFactorGraph();
|
||||
$variableFactory = &$parentFactorGraph->getVariableFactory();
|
||||
return $variableFactory->createKeyedVariable($key, $key . "'s skill");
|
||||
}
|
||||
}
|
||||
|
@ -2,12 +2,14 @@
|
||||
namespace Moserware\Skills\TrueSkill\Layers;
|
||||
|
||||
require_once(dirname(__FILE__) . "/../../FactorGraphs/Schedule.php");
|
||||
require_once(dirname(__FILE__) . "/../../FactorGraphs/Variable.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");
|
||||
|
||||
use Moserware\Skills\FactorGraphs\ScheduleStep;
|
||||
use Moserware\Skills\FactorGraphs\KeyedVariable;
|
||||
use Moserware\Skills\TrueSkill\TrueSkillFactorGraph;
|
||||
use Moserware\Skills\TrueSkill\Factors\GaussianLikelihoodFactor;
|
||||
|
||||
@ -20,7 +22,10 @@ class PlayerSkillsToPerformancesLayer extends TrueSkillFactorGraphLayer
|
||||
|
||||
public function buildLayer()
|
||||
{
|
||||
foreach ($this->getInputVariablesGroups() as $currentTeam)
|
||||
$inputVariablesGroups = &$this->getInputVariablesGroups();
|
||||
$outputVariablesGroups = &$this->getOutputVariablesGroups();
|
||||
|
||||
foreach ($inputVariablesGroups as &$currentTeam)
|
||||
{
|
||||
$currentTeamPlayerPerformances = array();
|
||||
|
||||
@ -30,14 +35,13 @@ class PlayerSkillsToPerformancesLayer extends TrueSkillFactorGraphLayer
|
||||
$newLikelihoodFactor = $this->createLikelihood($playerSkillVariable, $playerPerformance);
|
||||
$this->addLayerFactor($newLikelihoodFactor);
|
||||
$currentTeamPlayerPerformances[] = $playerPerformance;
|
||||
}
|
||||
}
|
||||
|
||||
$outputVariablesGroups = &$this->getOutputVariablesGroups();
|
||||
$outputVariablesGroups[] = $currentTeamPlayerPerformances;
|
||||
}
|
||||
}
|
||||
|
||||
private function createLikelihood(&$playerSkill, &$playerPerformance)
|
||||
private function createLikelihood(KeyedVariable &$playerSkill, KeyedVariable &$playerPerformance)
|
||||
{
|
||||
return new GaussianLikelihoodFactor(square($this->getParentFactorGraph()->getGameInfo()->getBeta()), $playerPerformance, $playerSkill);
|
||||
}
|
||||
@ -49,25 +53,27 @@ class PlayerSkillsToPerformancesLayer extends TrueSkillFactorGraphLayer
|
||||
|
||||
public function createPriorSchedule()
|
||||
{
|
||||
$localFactors = &$this->getLocalFactors();
|
||||
return $this->scheduleSequence(
|
||||
array_map(
|
||||
function($likelihood)
|
||||
{
|
||||
return new ScheduleStep("Skill to Perf step", $likelihood, 0);
|
||||
},
|
||||
$this->getLocalFactors()),
|
||||
$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);
|
||||
},
|
||||
$this->getLocalFactors()),
|
||||
$localFactors),
|
||||
"All skill to performance sending");
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ class TeamDifferencesComparisonLayer extends TrueSkillFactorGraphLayer
|
||||
{
|
||||
parent::__construct($parentGraph);
|
||||
$this->_teamRanks = $teamRanks;
|
||||
$gameInfo = $this->getParentFactorGraph()->getGameInfo();
|
||||
$gameInfo = &$this->getParentFactorGraph()->getGameInfo();
|
||||
$this->_epsilon = DrawMargin::getDrawMarginFromDrawProbability($gameInfo->getDrawProbability(), $gameInfo->getBeta());
|
||||
}
|
||||
|
||||
@ -33,7 +33,7 @@ class TeamDifferencesComparisonLayer extends TrueSkillFactorGraphLayer
|
||||
for ($i = 0; $i < $inputVarGroupsCount; $i++)
|
||||
{
|
||||
$isDraw = ($this->_teamRanks[$i] == $this->_teamRanks[$i + 1]);
|
||||
$teamDifference = $inputVarGroups[$i][0];
|
||||
$teamDifference = &$inputVarGroups[$i][0];
|
||||
|
||||
$factor =
|
||||
$isDraw
|
||||
|
@ -22,18 +22,18 @@ class TeamPerformancesToTeamPerformanceDifferencesLayer extends TrueSkillFactorG
|
||||
{
|
||||
$inputVariablesGroups = &$this->getInputVariablesGroups();
|
||||
$inputVariablesGroupsCount = count($inputVariablesGroups);
|
||||
$outputVariablesGroup = &$this->getOutputVariablesGroups();
|
||||
|
||||
for ($i = 0; $i < $inputVariablesGroupsCount - 1; $i++)
|
||||
{
|
||||
$strongerTeam = $inputVariablesGroups[$i][0];
|
||||
$weakerTeam = $inputVariablesGroups[$i + 1][0];
|
||||
$strongerTeam = &$inputVariablesGroups[$i][0];
|
||||
$weakerTeam = &$inputVariablesGroups[$i + 1][0];
|
||||
|
||||
$currentDifference = &$this->createOutputVariable();
|
||||
$newDifferencesFactor = $this->createTeamPerformanceToDifferenceFactor($strongerTeam, $weakerTeam, $currentDifference);
|
||||
$this->addLayerFactor($newDifferencesFactor);
|
||||
|
||||
// REVIEW: Does it make sense to have groups of one?
|
||||
$outputVariablesGroup = &$this->getOutputVariablesGroups();
|
||||
// REVIEW: Does it make sense to have groups of one?
|
||||
$outputVariablesGroup[] = array($currentDifference);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user