diff --git a/PHPSkills/TrueSkill/Factors/GaussianFactor.php b/PHPSkills/TrueSkill/Factors/GaussianFactor.php index 267246c..e868f97 100644 --- a/PHPSkills/TrueSkill/Factors/GaussianFactor.php +++ b/PHPSkills/TrueSkill/Factors/GaussianFactor.php @@ -2,6 +2,16 @@ namespace Moserware\Skills\TrueSkill\Factors; +require_once(dirname(__FILE__) . "../../FactorGraphs/Factor.php"); +require_once(dirname(__FILE__) . "../../FactorGraphs/Message.php"); +require_once(dirname(__FILE__) . "../../FactorGraphs/Variable.php"); +require_once(dirname(__FILE__) . "../../Numerics/GaussianDistribution.php"); + +use Moserware\Numerics\GaussianDistribution; +use Moserware\Skills\FactorGraphs\Factor; +use Moserware\Skills\FactorGraphs\Message; +use Moserware\Skills\FactorGraphs\Variable; + abstract class GaussianFactor extends Factor { protected function __construct($name) @@ -28,5 +38,4 @@ abstract class GaussianFactor extends Factor } } - ?> diff --git a/PHPSkills/TrueSkill/Factors/GaussianGreaterThanFactor.php b/PHPSkills/TrueSkill/Factors/GaussianGreaterThanFactor.php index 8f332a8..b767451 100644 --- a/PHPSkills/TrueSkill/Factors/GaussianGreaterThanFactor.php +++ b/PHPSkills/TrueSkill/Factors/GaussianGreaterThanFactor.php @@ -1,6 +1,17 @@ /// Factor representing a team difference that has exceeded the draw margin. /// diff --git a/PHPSkills/TrueSkill/Factors/GaussianLikelihoodFactor.php b/PHPSkills/TrueSkill/Factors/GaussianLikelihoodFactor.php index 7927254..a71104f 100644 --- a/PHPSkills/TrueSkill/Factors/GaussianLikelihoodFactor.php +++ b/PHPSkills/TrueSkill/Factors/GaussianLikelihoodFactor.php @@ -1,7 +1,15 @@ /// Connects two variables and adds uncertainty. /// diff --git a/PHPSkills/TrueSkill/Factors/GaussianPriorFactor.php b/PHPSkills/TrueSkill/Factors/GaussianPriorFactor.php index e4500b9..0276af0 100644 --- a/PHPSkills/TrueSkill/Factors/GaussianPriorFactor.php +++ b/PHPSkills/TrueSkill/Factors/GaussianPriorFactor.php @@ -1,7 +1,16 @@ /// Supplies the factor graph with prior information. /// @@ -36,5 +45,4 @@ class GaussianPriorFactor extends GaussianFactor } } - ?> diff --git a/PHPSkills/TrueSkill/Factors/GaussianWeightedSumFactor.php b/PHPSkills/TrueSkill/Factors/GaussianWeightedSumFactor.php index e4a3e53..08e365a 100644 --- a/PHPSkills/TrueSkill/Factors/GaussianWeightedSumFactor.php +++ b/PHPSkills/TrueSkill/Factors/GaussianWeightedSumFactor.php @@ -1,7 +1,15 @@ /// Factor that sums together multiple Gaussians. /// diff --git a/PHPSkills/TrueSkill/Factors/GaussianWithinFactor.php b/PHPSkills/TrueSkill/Factors/GaussianWithinFactor.php index 28a6822..23d661e 100644 --- a/PHPSkills/TrueSkill/Factors/GaussianWithinFactor.php +++ b/PHPSkills/TrueSkill/Factors/GaussianWithinFactor.php @@ -1,7 +1,17 @@ /// Factor representing a team difference that has not exceeded the draw margin. /// diff --git a/PHPSkills/TrueSkill/Layers/IteratedTeamDifferencesInnerLayer.php b/PHPSkills/TrueSkill/Layers/IteratedTeamDifferencesInnerLayer.php index df64058..b427617 100644 --- a/PHPSkills/TrueSkill/Layers/IteratedTeamDifferencesInnerLayer.php +++ b/PHPSkills/TrueSkill/Layers/IteratedTeamDifferencesInnerLayer.php @@ -1,7 +1,15 @@ _priorLayer = new PlayerPriorValuesToSkillsLayer($this, $teams); + $this->_gameInfo = $gameInfo; + $this->_variableFactory = new VariableFactory( + function() + { + return GaussianDistribution::fromPrecisionMean(0, 0); + }); + + $this->_layers = array( + $this->_priorLayer, + new PlayerSkillsToPerformancesLayer($this), + new PlayerPerformancesToTeamPerformancesLayer($this), + new IteratedTeamDifferencesInnerLayer( + $this, + new TeamPerformancesToTeamPerformanceDifferencesLayer($this), + new TeamDifferencesComparisonLayer($this, $teamRanks)) + ); + } + + public function getGameInfo() + { + return $this->_gameInfo; + } + + public function buildGraph() + { + $lastOutput = null; + + foreach ($this->_layers as $currentLayer) + { + if ($lastOutput != null) + { + $currentLayer->setInputVariablesGroups($lastOutput); + } + + $currentLayer->buildLayer(); + + $lastOutput = $currentLayer->getOutputVariablesGroups(); + } + } + + public function runSchedule() + { + $fullSchedule = $this->createFullSchedule(); + $fullScheduleDelta = $fullSchedule->visit(); + } + + public function getProbabilityOfRanking() + { + $factorList = new FactorList(); + + foreach ($this->_layers as $currentLayer) + { + foreach ($currentLayer->getFactors() as $currentFactor) + { + $factorList->addFactor($currentFactor); + } + } + + $logZ = $factorList->getLogNormalization(); + return exp($logZ); + } + + private function createFullSchedule() + { + $fullSchedule = array(); + + foreach ($this->_layers as $currentLayer) + { + $currentPriorSchedule = $currentLayer->createPriorSchedule(); + if ($currentPriorSchedule != null) + { + $fullSchedule->add($currentPriorSchedule); + } + } + + $allLayersReverse = \array_reverse($this->_layers); + + foreach ($allLayersReverse as $currentLayer) + { + $currentPosteriorSchedule = $currentLayer->createPosteriorSchedule(); + if ($currentPosteriorSchedule != null) + { + $fullSchedule->add($currentPosteriorSchedule); + } + } + + return new ScheduleSequence("Full schedule", $fullSchedule); + } + + public function getUpdatedRatings() + { + $result = array(); + + foreach ($this->_priorLayer->getOutputVariablesGroups() as $currentTeam) + { + foreach ($currentTeam as $currentPlayer) + { + $result[$currentPlayer->getKey()] = new Rating($currentPlayer->getValue()->getMean(), + $currentPlayer->getValue()->getStandardDeviation()); + } + } + + return $result; + } +} + +?>