diff --git a/PHPSkills/TrueSkill/Factors/GaussianWeightedSumFactor.php b/PHPSkills/TrueSkill/Factors/GaussianWeightedSumFactor.php index 6aa657c..c96947e 100644 --- a/PHPSkills/TrueSkill/Factors/GaussianWeightedSumFactor.php +++ b/PHPSkills/TrueSkill/Factors/GaussianWeightedSumFactor.php @@ -93,7 +93,7 @@ class GaussianWeightedSumFactor extends GaussianFactor } $currentWeights[$currentDestinationWeightIndex] = $currentWeight; - $currentWeightsSquared[$currentDestinationWeightIndex] = $currentWeight*currentWeight; + $currentWeightsSquared[$currentDestinationWeightIndex] = $currentWeight*$currentWeight; $variableIndices[$currentDestinationWeightIndex + 1] = $currentWeightSourceIndex + 1; $currentDestinationWeightIndex++; diff --git a/PHPSkills/TrueSkill/Layers/IteratedTeamDifferencesInnerLayer.php b/PHPSkills/TrueSkill/Layers/IteratedTeamDifferencesInnerLayer.php index 6554ea7..1ce6f87 100644 --- a/PHPSkills/TrueSkill/Layers/IteratedTeamDifferencesInnerLayer.php +++ b/PHPSkills/TrueSkill/Layers/IteratedTeamDifferencesInnerLayer.php @@ -29,7 +29,8 @@ class IteratedTeamDifferencesInnerLayer extends TrueSkillFactorGraphLayer public function buildLayer() { - $this->_TeamPerformancesToTeamPerformanceDifferencesLayer->setInputVariablesGroups($this->getInputVariablesGroups()); + $inputVariablesGroups = $this->getInputVariablesGroups(); + $this->_TeamPerformancesToTeamPerformanceDifferencesLayer->setInputVariablesGroups($inputVariablesGroups); $this->_TeamPerformancesToTeamPerformanceDifferencesLayer->buildLayer(); $this->_TeamDifferencesComparisonLayer->setInputVariablesGroups( diff --git a/PHPSkills/TrueSkill/Layers/PlayerPerformancesToTeamPerformancesLayer.php b/PHPSkills/TrueSkill/Layers/PlayerPerformancesToTeamPerformancesLayer.php index 3f50550..7803a03 100644 --- a/PHPSkills/TrueSkill/Layers/PlayerPerformancesToTeamPerformancesLayer.php +++ b/PHPSkills/TrueSkill/Layers/PlayerPerformancesToTeamPerformancesLayer.php @@ -27,12 +27,13 @@ class PlayerPerformancesToTeamPerformancesLayer extends TrueSkillFactorGraphLaye { foreach ($this->getInputVariablesGroups() as $currentTeam) { - $teamPerformance = $this->createOutputVariable($currentTeam); - $this->addLayerFactor($this->createPlayerToTeamSumFactor($currentTeam, $teamPerformance)); + $teamPerformance = &$this->createOutputVariable($currentTeam); + $newSumFactor = $this->createPlayerToTeamSumFactor($currentTeam, $teamPerformance); + $this->addLayerFactor($newSumFactor); // REVIEW: Does it make sense to have groups of one? - $outputVariablesGroups = $this->getOutputVariablesGroups(); - $outputVariablesGroups = $teamPerformance; + $outputVariablesGroups = &$this->getOutputVariablesGroups(); + $outputVariablesGroups[] = array($teamPerformance); } } diff --git a/PHPSkills/TrueSkill/Layers/PlayerSkillsToPerformancesLayer.php b/PHPSkills/TrueSkill/Layers/PlayerSkillsToPerformancesLayer.php index 261fd2b..f9f8b45 100644 --- a/PHPSkills/TrueSkill/Layers/PlayerSkillsToPerformancesLayer.php +++ b/PHPSkills/TrueSkill/Layers/PlayerSkillsToPerformancesLayer.php @@ -27,7 +27,8 @@ class PlayerSkillsToPerformancesLayer extends TrueSkillFactorGraphLayer foreach ($currentTeam as $playerSkillVariable) { $playerPerformance = $this->createOutputVariable($playerSkillVariable->getKey()); - $this->addLayerFactor($this->createLikelihood($playerSkillVariable, $playerPerformance)); + $newLikelihoodFactor = $this->createLikelihood($playerSkillVariable, $playerPerformance); + $this->addLayerFactor($newLikelihoodFactor); $currentTeamPlayerPerformances[] = &$playerPerformance; } diff --git a/PHPSkills/TrueSkill/Layers/TeamPerformancesToTeamPerformanceDifferencesLayer.php b/PHPSkills/TrueSkill/Layers/TeamPerformancesToTeamPerformanceDifferencesLayer.php index 9963224..75803ae 100644 --- a/PHPSkills/TrueSkill/Layers/TeamPerformancesToTeamPerformanceDifferencesLayer.php +++ b/PHPSkills/TrueSkill/Layers/TeamPerformancesToTeamPerformanceDifferencesLayer.php @@ -20,16 +20,17 @@ class TeamPerformancesToTeamPerformanceDifferencesLayer extends TrueSkillFactorG public function buildLayer() { - $inputVariablesGroup = $this->getInputVariablesGroups(); - $inputVariablesGroupCount = count($inputVariablesGroup); + $inputVariablesGroups = &$this->getInputVariablesGroups(); + $inputVariablesGroupsCount = count($inputVariablesGroups); - for ($i = 0; $i < $inputVariablesGroupCount - 1; $i++) + for ($i = 0; $i < $inputVariablesGroupsCount - 1; $i++) { $strongerTeam = $inputVariablesGroups[$i][0]; $weakerTeam = $inputVariablesGroups[$i + 1][0]; $currentDifference = $this->createOutputVariable(); - $this->addLayerFactor($this->createTeamPerformanceToDifferenceFactor($strongerTeam, $weakerTeam, currentDifference)); + $newDifferencesFactor = $this->createTeamPerformanceToDifferenceFactor($strongerTeam, $weakerTeam, $currentDifference); + $this->addLayerFactor($newDifferencesFactor); // REVIEW: Does it make sense to have groups of one? $outputVariablesGroup = $this->getOutputVariablesGroups(); @@ -40,7 +41,9 @@ class TeamPerformancesToTeamPerformanceDifferencesLayer extends TrueSkillFactorG private function createTeamPerformanceToDifferenceFactor( Variable &$strongerTeam, Variable &$weakerTeam, Variable &$output) { - return new GaussianWeightedSumFactor($output, array($strongerTeam, $weakerTeam), array(1.0, -1.0)); + $teams = array($strongerTeam, $weakerTeam); + $weights = array(1.0, -1.0); + return new GaussianWeightedSumFactor($output, $teams, $weights); } private function createOutputVariable()