1
0
mirror of https://github.com/furyfire/trueskill.git synced 2025-03-26 11:08:01 +00:00

Another pass at fixing up references

This commit is contained in:
Jeff Moser
2010-09-30 08:25:31 -04:00
parent 5368f7528e
commit 803a0816a8
28 changed files with 168 additions and 103 deletions

@ -29,12 +29,13 @@ abstract class GaussianFactor extends Factor
return $logZ;
}
public function createVariableToMessageBinding(Variable &$variable)
public function &createVariableToMessageBinding(Variable &$variable)
{
return parent::createVariableToMessageBindingWithMessage($variable,
$binding = &parent::createVariableToMessageBindingWithMessage($variable,
new Message(
GaussianDistribution::fromPrecisionMean(0, 0),
sprintf("message from %s to %s", $this, $variable)));
return $binding;
}
}

@ -28,8 +28,8 @@ class GaussianLikelihoodFactor extends GaussianFactor
public function getLogNormalization()
{
$vars = $this->getVariables();
$messages = $this->getMessages();
$vars = &$this->getVariables();
$messages = &$this->getMessages();
return GaussianDistribution::logRatioNormalization(
$vars[0]->getValue(),

@ -118,7 +118,7 @@ class GaussianWeightedSumFactor extends GaussianFactor
$this->createVariableToMessageBinding($sumVariable);
foreach ($variablesToSum as $currentVariable)
foreach ($variablesToSum as &$currentVariable)
{
$this->createVariableToMessageBinding($currentVariable);
}

@ -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);
}
}

@ -68,7 +68,8 @@ class TrueSkillFactorGraph extends FactorGraph
{
$lastOutput = null;
foreach ($this->_layers as $currentLayer)
$layers = &$this->_layers;
foreach ($layers as &$currentLayer)
{
if ($lastOutput != null)
{
@ -91,9 +92,11 @@ class TrueSkillFactorGraph extends FactorGraph
{
$factorList = new FactorList();
foreach ($this->_layers as $currentLayer)
$layers = &$this->_layers;
foreach ($layers as &$currentLayer)
{
foreach ($currentLayer->getLocalFactors() as $currentFactor)
$localFactors = &$currentLayer->getLocalFactors();
foreach ($localFactors as &$currentFactor)
{
$factorList->addFactor($currentFactor);
}
@ -107,7 +110,8 @@ class TrueSkillFactorGraph extends FactorGraph
{
$fullSchedule = array();
foreach ($this->_layers as $currentLayer)
$layers = &$this->_layers;
foreach ($layers as &$currentLayer)
{
$currentPriorSchedule = $currentLayer->createPriorSchedule();
if ($currentPriorSchedule != null)
@ -118,7 +122,7 @@ class TrueSkillFactorGraph extends FactorGraph
$allLayersReverse = \array_reverse($this->_layers);
foreach ($allLayersReverse as $currentLayer)
foreach ($allLayersReverse as &$currentLayer)
{
$currentPosteriorSchedule = $currentLayer->createPosteriorSchedule();
if ($currentPosteriorSchedule != null)
@ -134,9 +138,10 @@ class TrueSkillFactorGraph extends FactorGraph
{
$result = new RatingContainer();
foreach ($this->_priorLayer->getOutputVariablesGroups() as $currentTeam)
$priorLayerOutputVariablesGroups = &$this->_priorLayer->getOutputVariablesGroups();
foreach ($priorLayerOutputVariablesGroups as &$currentTeam)
{
foreach ($currentTeam as $currentPlayer)
foreach ($currentTeam as &$currentPlayer)
{
$newRating = new Rating($currentPlayer->getValue()->getMean(),
$currentPlayer->getValue()->getStandardDeviation());

@ -2,6 +2,7 @@
namespace Moserware\Skills\TrueSkill;
require_once(dirname(__FILE__) . "/../GameInfo.php");
require_once(dirname(__FILE__) . "/../Guard.php");
require_once(dirname(__FILE__) . "/../PairwiseComparison.php");
require_once(dirname(__FILE__) . "/../RankSorter.php");
@ -17,6 +18,7 @@ require_once(dirname(__FILE__) . "/../Numerics/BasicMath.php");
require_once(dirname(__FILE__) . "/DrawMargin.php");
require_once(dirname(__FILE__) . "/TruncatedGaussianCorrectionFunctions.php");
use Moserware\Skills\GameInfo;
use Moserware\Skills\Guard;
use Moserware\Skills\PairwiseComparison;
use Moserware\Skills\RankSorter;
@ -42,7 +44,7 @@ class TwoPlayerTrueSkillCalculator extends SkillCalculator
parent::__construct(SkillCalculatorSupportedOptions::NONE, TeamsRange::exactly(2), PlayersRange::exactly(1));
}
public function calculateNewRatings($gameInfo,
public function calculateNewRatings(GameInfo &$gameInfo,
array $teams,
array $teamRanks)
{
@ -82,7 +84,7 @@ class TwoPlayerTrueSkillCalculator extends SkillCalculator
return $results;
}
private static function calculateNewRating($gameInfo, $selfRating, $opponentRating, $comparison)
private static function calculateNewRating(GameInfo $gameInfo, Rating $selfRating, Rating $opponentRating, $comparison)
{
$drawMargin = DrawMargin::getDrawMarginFromDrawProbability($gameInfo->getDrawProbability(),
$gameInfo->getBeta());
@ -138,7 +140,7 @@ class TwoPlayerTrueSkillCalculator extends SkillCalculator
}
/// <inheritdoc/>
public function calculateMatchQuality($gameInfo, array $teams)
public function calculateMatchQuality(GameInfo $gameInfo, array $teams)
{
Guard::argumentNotNull($gameInfo, "gameInfo");
$this->validateTeamCountAndPlayersCountPerTeam($teams);

@ -47,7 +47,7 @@ class TwoTeamTrueSkillCalculator extends SkillCalculator
parent::__construct(SkillCalculatorSupportedOptions::NONE, TeamsRange::exactly(2), PlayersRange::atLeast(1));
}
public function calculateNewRatings($gameInfo,
public function calculateNewRatings(GameInfo $gameInfo,
array $teams,
array $teamRanks)
{
@ -164,7 +164,7 @@ class TwoTeamTrueSkillCalculator extends SkillCalculator
}
/// <inheritdoc/>
public function calculateMatchQuality($gameInfo, array $teams)
public function calculateMatchQuality(GameInfo $gameInfo, array $teams)
{
Guard::argumentNotNull($gameInfo, "gameInfo");
$this->validateTeamCountAndPlayersCountPerTeam($teams);