More debugging and realizing how PHP does references

This commit is contained in:
Jeff Moser 2010-09-25 15:46:23 -04:00
parent e8d444e7da
commit 086d94865f
21 changed files with 77 additions and 72 deletions

@ -36,12 +36,12 @@ abstract class Factor
return count($this->_messages); return count($this->_messages);
} }
protected function getVariables() protected function &getVariables()
{ {
return $this->_variables; return $this->_variables;
} }
protected function getMessages() protected function &getMessages()
{ {
return $this->_messages; return $this->_messages;
} }
@ -77,11 +77,11 @@ abstract class Factor
return $this->sendMessageVariable($message, $variable); return $this->sendMessageVariable($message, $variable);
} }
protected abstract function sendMessageVariable(Message $message, Variable $variable); protected abstract function sendMessageVariable(Message &$message, Variable &$variable);
public abstract function createVariableToMessageBinding(Variable $variable); public abstract function createVariableToMessageBinding(Variable &$variable);
protected function createVariableToMessageBindingWithMessage(Variable $variable, Variable $message) protected function createVariableToMessageBindingWithMessage(Variable &$variable, Variable &$message)
{ {
$index = count($this->_messages); $index = count($this->_messages);
$this->_messages[] = $message; $this->_messages[] = $message;

@ -5,14 +5,14 @@ class FactorGraph
{ {
private $_variableFactory; private $_variableFactory;
public function getVariableFactory() public function &getVariableFactory()
{ {
return $this->_variableFactory; return $this->_variableFactory;
} }
public function setVariableFactory($factory) public function setVariableFactory(&$factory)
{ {
$this->_variableFactory = $factory; $this->_variableFactory = &$factory;
} }
} }
?> ?>

@ -1,6 +1,7 @@
<?php <?php
namespace Moserware\Skills\FactorGraphs; namespace Moserware\Skills\FactorGraphs;
require_once(dirname(__FILE__) . "/FactorGraph.php");
require_once(dirname(__FILE__) . "/Schedule.php"); require_once(dirname(__FILE__) . "/Schedule.php");
abstract class FactorGraphLayer abstract class FactorGraphLayer
@ -10,44 +11,44 @@ abstract class FactorGraphLayer
private $_inputVariablesGroups = array(); private $_inputVariablesGroups = array();
private $_parentFactorGraph; private $_parentFactorGraph;
protected function __construct($parentGraph) protected function __construct(FactorGraph &$parentGraph)
{ {
$this->_parentFactorGraph = $parentGraph; $this->_parentFactorGraph = &$parentGraph;
} }
protected function getInputVariablesGroups() protected function &getInputVariablesGroups()
{ {
return $this->_inputVariablesGroups; return $this->_inputVariablesGroups;
} }
// HACK // HACK
public function getParentFactorGraph() public function &getParentFactorGraph()
{ {
return $this->_parentFactorGraph; return $this->_parentFactorGraph;
} }
public function getOutputVariablesGroups() public function &getOutputVariablesGroups()
{ {
return $this->_outputVariablesGroups; return $this->_outputVariablesGroups;
} }
public function getLocalFactors() public function &getLocalFactors()
{ {
return $this->_localFactors; return $this->_localFactors;
} }
public function setInputVariablesGroups($value) public function &setInputVariablesGroups(&$value)
{ {
$this->_inputVariablesGroups = $value; $this->_inputVariablesGroups = $value;
} }
protected function scheduleSequence($itemsToSequence) protected function scheduleSequence(&$itemsToSequence)
{ {
return new ScheduleSequence("TODO", $itemsToSequence); return new ScheduleSequence("TODO", $itemsToSequence);
} }
protected function addLayerFactor($factor) protected function addLayerFactor(&$factor)
{ {
$this->_localFactors[] = $factor; $this->_localFactors[] = $factor;
} }

@ -49,7 +49,7 @@ class FactorList
return count($this->_list); return count($this->_list);
} }
public function addFactor(Factor $factor) public function addFactor(Factor &$factor)
{ {
$this->_list[] = $factor; $this->_list[] = $factor;
return $factor; return $factor;

@ -14,12 +14,12 @@ class Variable
$this->resetToPrior(); $this->resetToPrior();
} }
public function getValue() public function &getValue()
{ {
return $this->_value; return $this->_value;
} }
public function setValue($value) public function setValue(&$value)
{ {
$this->_value = $value; $this->_value = $value;
} }

@ -14,7 +14,7 @@ abstract class SkillCalculator
private $_playersPerTeamAllowed; private $_playersPerTeamAllowed;
private $_totalTeamsAllowed; private $_totalTeamsAllowed;
protected function __construct($supportedOptions, TeamsRange $totalTeamsAllowed, PlayersRange $playerPerTeamAllowed) protected function __construct($supportedOptions, TeamsRange &$totalTeamsAllowed, PlayersRange &$playerPerTeamAllowed)
{ {
$this->_supportedOptions = $supportedOptions; $this->_supportedOptions = $supportedOptions;
$this->_totalTeamsAllowed = $totalTeamsAllowed; $this->_totalTeamsAllowed = $totalTeamsAllowed;
@ -29,7 +29,7 @@ abstract class SkillCalculator
/// <param name="teams">A mapping of team players and their ratings.</param> /// <param name="teams">A mapping of team players and their ratings.</param>
/// <param name="teamRanks">The ranks of the teams where 1 is first place. For a tie, repeat the number (e.g. 1, 2, 2)</param> /// <param name="teamRanks">The ranks of the teams where 1 is first place. For a tie, repeat the number (e.g. 1, 2, 2)</param>
/// <returns>All the players and their new ratings.</returns> /// <returns>All the players and their new ratings.</returns>
public abstract function calculateNewRatings(GameInfo $gameInfo, public abstract function calculateNewRatings(GameInfo &$gameInfo,
array $teamsOfPlayerToRatings, array $teamsOfPlayerToRatings,
array $teamRanks); array $teamRanks);
@ -40,23 +40,23 @@ abstract class SkillCalculator
/// <param name="gameInfo">Parameters for the game.</param> /// <param name="gameInfo">Parameters for the game.</param>
/// <param name="teams">A mapping of team players and their ratings.</param> /// <param name="teams">A mapping of team players and their ratings.</param>
/// <returns>The quality of the match between the teams as a percentage (0% = bad, 100% = well matched).</returns> /// <returns>The quality of the match between the teams as a percentage (0% = bad, 100% = well matched).</returns>
public abstract function calculateMatchQuality(GameInfo $gameInfo, public abstract function calculateMatchQuality(GameInfo &$gameInfo,
array $teamsOfPlayerToRatings); array &$teamsOfPlayerToRatings);
public function isSupported($option) public function isSupported($option)
{ {
return ($this->_supportedOptions & $option) == $option; return ($this->_supportedOptions & $option) == $option;
} }
protected function validateTeamCountAndPlayersCountPerTeam(array $teamsOfPlayerToRatings) protected function validateTeamCountAndPlayersCountPerTeam(array &$teamsOfPlayerToRatings)
{ {
self::validateTeamCountAndPlayersCountPerTeamWithRanges($teamsOfPlayerToRatings, $this->_totalTeamsAllowed, $this->_playersPerTeamAllowed); self::validateTeamCountAndPlayersCountPerTeamWithRanges($teamsOfPlayerToRatings, $this->_totalTeamsAllowed, $this->_playersPerTeamAllowed);
} }
private static function validateTeamCountAndPlayersCountPerTeamWithRanges( private static function validateTeamCountAndPlayersCountPerTeamWithRanges(
array $teams, array &$teams,
TeamsRange $totalTeams, TeamsRange &$totalTeams,
PlayersRange $playersPerTeam) PlayersRange &$playersPerTeam)
{ {
$countOfTeams = 0; $countOfTeams = 0;

@ -40,7 +40,7 @@ class FactorGraphTrueSkillCalculator extends SkillCalculator
parent::__construct(SkillCalculatorSupportedOptions::PARTIAL_PLAY | SkillCalculatorSupportedOptions::PARTIAL_UPDATE, TeamsRange::atLeast(2), PlayersRange::atLeast(1)); parent::__construct(SkillCalculatorSupportedOptions::PARTIAL_PLAY | SkillCalculatorSupportedOptions::PARTIAL_UPDATE, TeamsRange::atLeast(2), PlayersRange::atLeast(1));
} }
public function calculateNewRatings(GameInfo $gameInfo, public function calculateNewRatings(GameInfo &$gameInfo,
array $teams, array $teams,
array $teamRanks) array $teamRanks)
{ {
@ -58,8 +58,8 @@ class FactorGraphTrueSkillCalculator extends SkillCalculator
return $factorGraph->getUpdatedRatings(); return $factorGraph->getUpdatedRatings();
} }
public function calculateMatchQuality(GameInfo $gameInfo, public function calculateMatchQuality(GameInfo &$gameInfo,
array $teams) array &$teams)
{ {
// We need to create the A matrix which is the player team assigments. // We need to create the A matrix which is the player team assigments.
$teamAssignmentsList = $teams; $teamAssignmentsList = $teams;
@ -100,7 +100,7 @@ class FactorGraphTrueSkillCalculator extends SkillCalculator
return $result; return $result;
} }
private static function getPlayerMeansVector(array $teamAssignmentsList) private static function getPlayerMeansVector(array &$teamAssignmentsList)
{ {
// A simple vector of all the player means. // A simple vector of all the player means.
return new Vector($this->getPlayerRatingValues($teamAssignmentsList, return new Vector($this->getPlayerRatingValues($teamAssignmentsList,
@ -110,7 +110,7 @@ class FactorGraphTrueSkillCalculator extends SkillCalculator
})); }));
} }
private static function getPlayerCovarianceMatrix(array $teamAssignmentsList) private static function getPlayerCovarianceMatrix(array &$teamAssignmentsList)
{ {
// This is a square matrix whose diagonal values represent the variance (square of standard deviation) of all // This is a square matrix whose diagonal values represent the variance (square of standard deviation) of all
// players. // players.
@ -123,7 +123,7 @@ class FactorGraphTrueSkillCalculator extends SkillCalculator
} }
// Helper function that gets a list of values for all player ratings // Helper function that gets a list of values for all player ratings
private static function getPlayerRatingValues(array $teamAssignmentsList, private static function getPlayerRatingValues(array &$teamAssignmentsList,
$playerRatingFunction) $playerRatingFunction)
{ {
$playerRatingValues = array(); $playerRatingValues = array();
@ -139,7 +139,7 @@ class FactorGraphTrueSkillCalculator extends SkillCalculator
return $playerRatingValues; return $playerRatingValues;
} }
private static function createPlayerTeamAssignmentMatrix($teamAssignmentsList, $totalPlayers) private static function createPlayerTeamAssignmentMatrix(&$teamAssignmentsList, &$totalPlayers)
{ {
// The team assignment matrix is often referred to as the "A" matrix. It's a matrix whose rows represent the players // The team assignment matrix is often referred to as the "A" matrix. It's a matrix whose rows represent the players
// and the columns represent teams. At Matrix[row, column] represents that player[row] is on team[col] // and the columns represent teams. At Matrix[row, column] represents that player[row] is on team[col]

@ -20,7 +20,7 @@ abstract class GaussianFactor extends Factor
} }
/// Sends the factor-graph message with and returns the log-normalization constant /// Sends the factor-graph message with and returns the log-normalization constant
protected function sendMessageVariable(Message $message, Variable $variable) protected function sendMessageVariable(Message &$message, Variable &$variable)
{ {
$marginal = $variable->getValue(); $marginal = $variable->getValue();
$messageValue = $message->getValue(); $messageValue = $message->getValue();
@ -29,7 +29,7 @@ abstract class GaussianFactor extends Factor
return $logZ; return $logZ;
} }
public function createVariableToMessageBinding(Variable $variable) public function createVariableToMessageBinding(Variable &$variable)
{ {
return parent::createVariableToMessageBinding($variable, return parent::createVariableToMessageBinding($variable,
new Message( new Message(

@ -20,7 +20,7 @@ class GaussianGreaterThanFactor extends GaussianFactor
{ {
private $_epsilon; private $_epsilon;
public function __construct($epsilon, Variable $variable) public function __construct($epsilon, Variable &$variable)
{ {
parent::_construct("{0} > {1:0.000}"); parent::_construct("{0} > {1:0.000}");
$this->_epsilon = $epsilon; $this->_epsilon = $epsilon;
@ -42,7 +42,7 @@ class GaussianGreaterThanFactor extends GaussianFactor
} }
protected function updateMessageVariable(Message $message, Variable $variable) protected function updateMessageVariable(Message &$message, Variable &$variable)
{ {
$oldMarginal = clone $variable->getValue(); $oldMarginal = clone $variable->getValue();
$oldMessage = clone $message->getValue(); $oldMessage = clone $message->getValue();

@ -18,7 +18,7 @@ class GaussianLikelihoodFactor extends GaussianFactor
{ {
private $_precision; private $_precision;
public function __construct($betaSquared, Variable $variable1, Variable $variable2) public function __construct($betaSquared, Variable &$variable1, Variable &$variable2)
{ {
parent::__construct("Likelihood of {0} going to {1}"); parent::__construct("Likelihood of {0} going to {1}");
$this->_precision = 1.0/$betaSquared; $this->_precision = 1.0/$betaSquared;
@ -36,8 +36,8 @@ class GaussianLikelihoodFactor extends GaussianFactor
$messages[0]->getValue()); $messages[0]->getValue());
} }
private function updateHelper(Message $message1, Message $message2, private function updateHelper(Message &$message1, Message &$message2,
Variable $variable1, Variable $variable2) Variable &$variable1, Variable &$variable2)
{ {
$message1Value = clone $message1->getValue(); $message1Value = clone $message1->getValue();
$message2Value = clone $message2->getValue(); $message2Value = clone $message2->getValue();

@ -19,7 +19,7 @@ class GaussianPriorFactor extends GaussianFactor
{ {
private $_newMessage; private $_newMessage;
public function __construct($mean, $variance, Variable $variable) public function __construct($mean, $variance, Variable &$variable)
{ {
parent::__construct("Prior value going to {0}"); parent::__construct("Prior value going to {0}");
$this->_newMessage = new GaussianDistribution($mean, sqrt($variance)); $this->_newMessage = new GaussianDistribution($mean, sqrt($variance));
@ -27,10 +27,10 @@ class GaussianPriorFactor extends GaussianFactor
new Message( new Message(
GaussianDistribution::fromPrecisionMean(0, 0), GaussianDistribution::fromPrecisionMean(0, 0),
"message from {0} to {1}", "message from {0} to {1}",
this, variable)); $this, variable));
} }
protected function updateMessageVariable(Message $message, Variable $variable) protected function updateMessageVariable(Message &$message, Variable &$variable)
{ {
$oldMarginal = clone $variable->getValue(); $oldMarginal = clone $variable->getValue();
$oldMessage = $message; $oldMessage = $message;

@ -23,7 +23,7 @@ class GaussianWeightedSumFactor extends GaussianFactor
private $_weights; private $_weights;
private $_weightsSquared; private $_weightsSquared;
public function __construct(Variable $sumVariable, array $variablesToSum, array $variableWeights = null) public function __construct(Variable &$sumVariable, array &$variablesToSum, array &$variableWeights = null)
{ {
parent::__construct($this->createName($sumVariable, $variablesToSum, $variableWeights)); parent::__construct($this->createName($sumVariable, $variablesToSum, $variableWeights));
$this->_weights = array(); $this->_weights = array();
@ -133,9 +133,9 @@ class GaussianWeightedSumFactor extends GaussianFactor
return $result; return $result;
} }
private function updateHelper(array $weights, array $weightsSquared, private function updateHelper(array &$weights, array &$weightsSquared,
array $messages, array &$messages,
array $variables) array &$variables)
{ {
// Potentially look at http://mathworld.wolfram.com/NormalSumDistribution.html for clues as // Potentially look at http://mathworld.wolfram.com/NormalSumDistribution.html for clues as
// to what it's doing // to what it's doing

@ -20,7 +20,7 @@ class GaussianWithinFactor extends GaussianFactor
{ {
private $_epsilon; private $_epsilon;
public function __construct($epsilon, Variable $variable) public function __construct($epsilon, Variable &$variable)
{ {
$this->_epsilon = $epsilon; $this->_epsilon = $epsilon;
$this->createVariableToMessageBinding($variable); $this->createVariableToMessageBinding($variable);
@ -43,7 +43,7 @@ class GaussianWithinFactor extends GaussianFactor
return -GaussianDistribution::logProductNormalization($messageFromVariable, $message) + log($z); return -GaussianDistribution::logProductNormalization($messageFromVariable, $message) + log($z);
} }
protected function updateMessage(Message $message, Variable $variable) protected function updateMessage(Message &$message, Variable &$variable)
{ {
$oldMarginal = clone $variable->getValue(); $oldMarginal = clone $variable->getValue();
$oldMessage = clone $message->getValue(); $oldMessage = clone $message->getValue();

@ -18,9 +18,9 @@ class IteratedTeamDifferencesInnerLayer extends TrueSkillFactorGraphLayer
private $_TeamDifferencesComparisonLayer; private $_TeamDifferencesComparisonLayer;
private $_TeamPerformancesToTeamPerformanceDifferencesLayer; private $_TeamPerformancesToTeamPerformanceDifferencesLayer;
public function __construct(TrueSkillFactorGraph $parentGraph, public function __construct(TrueSkillFactorGraph &$parentGraph,
TeamPerformancesToTeamPerformanceDifferencesLayer $teamPerformancesToPerformanceDifferences, TeamPerformancesToTeamPerformanceDifferencesLayer &$teamPerformancesToPerformanceDifferences,
TeamDifferencesComparisonLayer $teamDifferencesComparisonLayer) TeamDifferencesComparisonLayer &$teamDifferencesComparisonLayer)
{ {
parent::__construct($parentGraph); parent::__construct($parentGraph);
$this->_TeamPerformancesToTeamPerformanceDifferencesLayer = $teamPerformancesToPerformanceDifferences; $this->_TeamPerformancesToTeamPerformanceDifferencesLayer = $teamPerformancesToPerformanceDifferences;

@ -14,7 +14,7 @@ use Moserware\Skills\TrueSkill\TrueSkillFactorGraph;
class PlayerPerformancesToTeamPerformancesLayer extends TrueSkillFactorGraphLayer class PlayerPerformancesToTeamPerformancesLayer extends TrueSkillFactorGraphLayer
{ {
public function __construct(TrueSkillFactorGraph $parentGraph) public function __construct(TrueSkillFactorGraph &$parentGraph)
{ {
parent::__construct($parentGraph); parent::__construct($parentGraph);
} }
@ -44,7 +44,7 @@ class PlayerPerformancesToTeamPerformancesLayer extends TrueSkillFactorGraphLaye
"all player perf to team perf schedule"); "all player perf to team perf schedule");
} }
protected function createPlayerToTeamSumFactor($teamMembers, $sumVariable) protected function createPlayerToTeamSumFactor(&$teamMembers, &$sumVariable)
{ {
return new GaussianWeightedSumFactor( return new GaussianWeightedSumFactor(
$sumVariable, $sumVariable,
@ -74,7 +74,7 @@ class PlayerPerformancesToTeamPerformancesLayer extends TrueSkillFactorGraphLaye
return $this->scheduleSequence($allFactors, "all of the team's sum iterations"); return $this->scheduleSequence($allFactors, "all of the team's sum iterations");
} }
private function createOutputVariable($team) private function createOutputVariable(&$team)
{ {
///$teamMemberNames = String.Join(", ", team.Select(teamMember => teamMember.Key.ToString()).ToArray()); ///$teamMemberNames = String.Join(", ", team.Select(teamMember => teamMember.Key.ToString()).ToArray());
$teamMemberNames = "TODO"; $teamMemberNames = "TODO";

@ -19,7 +19,7 @@ class PlayerPriorValuesToSkillsLayer extends TrueSkillFactorGraphLayer
{ {
private $_teams; private $_teams;
public function __construct(TrueSkillFactorGraph $parentGraph, $teams) public function __construct(TrueSkillFactorGraph &$parentGraph, &$teams)
{ {
parent::__construct($parentGraph); parent::__construct($parentGraph);
$this->_teams = $teams; $this->_teams = $teams;
@ -31,10 +31,11 @@ class PlayerPriorValuesToSkillsLayer extends TrueSkillFactorGraphLayer
{ {
$currentTeamSkills = array(); $currentTeamSkills = array();
foreach ($currentTeam as $currentTeamPlayer) foreach ($currentTeam->getAllPlayers() as $currentTeamPlayer)
{ {
$playerSkill = $this->createSkillOutputVariable($currentTeamPlayer.Key); $currentTeamPlayerRating = $currentTeam->getRating($currentTeamPlayer);
$this->addLayerFactor($this->createPriorFactor($currentTeamPlayer.Key, $currentTeamPlayer.Value, $playerSkill)); $playerSkill = $this->createSkillOutputVariable($currentTeamPlayer);
$this->addLayerFactor($this->createPriorFactor($currentTeamPlayer, $currentTeamPlayerRating, $playerSkill));
$currentTeamSkills[] = $playerSkill; $currentTeamSkills[] = $playerSkill;
} }
@ -55,7 +56,7 @@ class PlayerPriorValuesToSkillsLayer extends TrueSkillFactorGraphLayer
"All priors"); "All priors");
} }
private function createPriorFactor($player, $priorRating, $skillsVariable) private function createPriorFactor(&$player, &$priorRating, &$skillsVariable)
{ {
return new GaussianPriorFactor($priorRating->getMean(), return new GaussianPriorFactor($priorRating->getMean(),
square($priorRating->getStandardDeviation()) + square($priorRating->getStandardDeviation()) +
@ -65,7 +66,9 @@ class PlayerPriorValuesToSkillsLayer extends TrueSkillFactorGraphLayer
private function createSkillOutputVariable($key) private function createSkillOutputVariable($key)
{ {
return $this->getParentFactorGraph()->getVariableFactory()->createKeyedVariable($key, "{0}'s skill", $key); $parentFactorGraph = $this->getParentFactorGraph();
$variableFactory = $parentFactorGraph->getVariableFactory();
return $variableFactory->createKeyedVariable($key, "{0}'s skill", $key);
} }
} }

@ -13,7 +13,7 @@ use Moserware\Skills\TrueSkill\Factors\GaussianLikelihoodFactor;
class PlayerSkillsToPerformancesLayer extends TrueSkillFactorGraphLayer class PlayerSkillsToPerformancesLayer extends TrueSkillFactorGraphLayer
{ {
public function __construct(TrueSkillFactorGraph $parentGraph) public function __construct(TrueSkillFactorGraph &$parentGraph)
{ {
parent::__construct($parentGraph); parent::__construct($parentGraph);
} }
@ -36,12 +36,12 @@ class PlayerSkillsToPerformancesLayer extends TrueSkillFactorGraphLayer
} }
} }
private function createLikelihood($playerSkill, $playerPerformance) private function createLikelihood(&$playerSkill, &$playerPerformance)
{ {
return new GaussianLikelihoodFactor(square($this->getParentFactorGraph()->getGameInfo()->getBeta()), $playerPerformance, $playerSkill); return new GaussianLikelihoodFactor(square($this->getParentFactorGraph()->getGameInfo()->getBeta()), $playerPerformance, $playerSkill);
} }
private function createOutputVariable($key) private function createOutputVariable(&$key)
{ {
return $this->getParentFactorGraph()->getVariableFactory()->createKeyedVariable($key, "{0}'s performance", $key); return $this->getParentFactorGraph()->getVariableFactory()->createKeyedVariable($key, "{0}'s performance", $key);
} }

@ -17,7 +17,7 @@ class TeamDifferencesComparisonLayer extends TrueSkillFactorGraphLayer
private $_epsilon; private $_epsilon;
private $_teamRanks; private $_teamRanks;
public function __construct(TrueSkillFactorGraph $parentGraph, array $teamRanks) public function __construct(TrueSkillFactorGraph &$parentGraph, array &$teamRanks)
{ {
parent::__construct($parentGraph); parent::__construct($parentGraph);
$this->_teamRanks = $teamRanks; $this->_teamRanks = $teamRanks;

@ -13,7 +13,7 @@ use Moserware\Skills\TrueSkill\Factors\GaussianWeightedSumFactor;
class TeamPerformancesToTeamPerformanceDifferencesLayer extends TrueSkillFactorGraphLayer class TeamPerformancesToTeamPerformanceDifferencesLayer extends TrueSkillFactorGraphLayer
{ {
public function __construct(TrueSkillFactorGraph $parentGraph) public function __construct(TrueSkillFactorGraph &$parentGraph)
{ {
parent::__construct($parentGraph); parent::__construct($parentGraph);
} }
@ -38,7 +38,7 @@ class TeamPerformancesToTeamPerformanceDifferencesLayer extends TrueSkillFactorG
} }
private function createTeamPerformanceToDifferenceFactor( private function createTeamPerformanceToDifferenceFactor(
Variable $strongerTeam, Variable $weakerTeam, Variable $output) Variable &$strongerTeam, Variable &$weakerTeam, Variable &$output)
{ {
return new GaussianWeightedSumFactor($output, array($strongerTeam, $weakerTeam), array(1.0, -1.0)); return new GaussianWeightedSumFactor($output, array($strongerTeam, $weakerTeam), array(1.0, -1.0));
} }

@ -9,7 +9,7 @@ use Moserware\Skills\TrueSkill\TrueSkillFactorGraph;
abstract class TrueSkillFactorGraphLayer extends FactorGraphLayer abstract class TrueSkillFactorGraphLayer extends FactorGraphLayer
{ {
public function __construct(TrueSkillFactorGraph $parentGraph) public function __construct(TrueSkillFactorGraph &$parentGraph)
{ {
parent::__construct($parentGraph); parent::__construct($parentGraph);
} }

@ -35,15 +35,16 @@ class TrueSkillFactorGraph extends FactorGraph
private $_priorLayer; private $_priorLayer;
private $_variableFactory; private $_variableFactory;
public function __construct(GameInfo $gameInfo, $teams, array $teamRanks) public function __construct(GameInfo &$gameInfo, &$teams, array $teamRanks)
{ {
$this->_priorLayer = new PlayerPriorValuesToSkillsLayer($this, $teams); $this->_priorLayer = new PlayerPriorValuesToSkillsLayer($this, $teams);
$this->_gameInfo = $gameInfo; $this->_gameInfo = $gameInfo;
$this->_variableFactory = new VariableFactory( $newFactory = new VariableFactory(
function() function()
{ {
return GaussianDistribution::fromPrecisionMean(0, 0); return GaussianDistribution::fromPrecisionMean(0, 0);
}); });
$this->setVariableFactory($newFactory);
$this->_layers = array( $this->_layers = array(
$this->_priorLayer, $this->_priorLayer,