Cleanup in src/, adding namespaces, removing php closing tag and general code cleanup

This commit is contained in:
Alexander Liljengård
2016-05-24 14:10:39 +02:00
parent 9f97eb1653
commit 5694a2fb30
64 changed files with 891 additions and 1328 deletions

View File

@ -1,22 +1,5 @@
<?php
namespace Moserware\Skills\TrueSkill;
<?php namespace Moserware\Skills\TrueSkill;
require_once(dirname(__FILE__) . '/../GameInfo.php');
require_once(dirname(__FILE__) . '/../Rating.php');
require_once(dirname(__FILE__) . '/../RatingContainer.php');
require_once(dirname(__FILE__) . '/../FactorGraphs/FactorGraph.php');
require_once(dirname(__FILE__) . '/../FactorGraphs/FactorList.php');
require_once(dirname(__FILE__) . '/../FactorGraphs/Schedule.php');
require_once(dirname(__FILE__) . '/../FactorGraphs/VariableFactory.php');
require_once(dirname(__FILE__) . '/../Numerics/GaussianDistribution.php');
require_once(dirname(__FILE__) . '/Layers/IteratedTeamDifferencesInnerLayer.php');
require_once(dirname(__FILE__) . '/Layers/PlayerPerformancesToTeamPerformancesLayer.php');
require_once(dirname(__FILE__) . '/Layers/PlayerPriorValuesToSkillsLayer.php');
require_once(dirname(__FILE__) . '/Layers/PlayerSkillsToPerformancesLayer.php');
require_once(dirname(__FILE__) . '/Layers/TeamDifferencesComparisonLayer.php');
require_once(dirname(__FILE__) . '/Layers/TeamPerformancesToTeamPerformanceDifferencesLayer.php');
use Moserware\Numerics\GaussianDistribution;
use Moserware\Skills\GameInfo;
use Moserware\Skills\Rating;
use Moserware\Skills\RatingContainer;
@ -35,28 +18,27 @@ class TrueSkillFactorGraph extends FactorGraph
{
private $_gameInfo;
private $_layers;
private $_priorLayer;
private $_priorLayer;
public function __construct(GameInfo &$gameInfo, array &$teams, array $teamRanks)
{
$this->_priorLayer = new PlayerPriorValuesToSkillsLayer($this, $teams);
$this->_gameInfo = $gameInfo;
$newFactory = new VariableFactory(
function()
{
return GaussianDistribution::fromPrecisionMean(0, 0);
});
function () {
return GaussianDistribution::fromPrecisionMean(0, 0);
});
$this->setVariableFactory($newFactory);
$this->_layers = array(
$this->_priorLayer,
new PlayerSkillsToPerformancesLayer($this),
new PlayerPerformancesToTeamPerformancesLayer($this),
new IteratedTeamDifferencesInnerLayer(
$this,
new TeamPerformancesToTeamPerformanceDifferencesLayer($this),
new TeamDifferencesComparisonLayer($this, $teamRanks))
);
$this->_priorLayer,
new PlayerSkillsToPerformancesLayer($this),
new PlayerPerformancesToTeamPerformancesLayer($this),
new IteratedTeamDifferencesInnerLayer(
$this,
new TeamPerformancesToTeamPerformanceDifferencesLayer($this),
new TeamDifferencesComparisonLayer($this, $teamRanks))
);
}
public function getGameInfo()
@ -69,16 +51,14 @@ class TrueSkillFactorGraph extends FactorGraph
$lastOutput = null;
$layers = &$this->_layers;
foreach ($layers as &$currentLayer)
{
if ($lastOutput != null)
{
foreach ($layers as &$currentLayer) {
if ($lastOutput != null) {
$currentLayer->setInputVariablesGroups($lastOutput);
}
$currentLayer->buildLayer();
$lastOutput = &$currentLayer->getOutputVariablesGroups();
$lastOutput = &$currentLayer->getOutputVariablesGroups();
}
}
@ -93,11 +73,9 @@ class TrueSkillFactorGraph extends FactorGraph
$factorList = new FactorList();
$layers = &$this->_layers;
foreach ($layers as &$currentLayer)
{
foreach ($layers as &$currentLayer) {
$localFactors = &$currentLayer->getLocalFactors();
foreach ($localFactors as &$currentFactor)
{
foreach ($localFactors as &$currentFactor) {
$localCurrentFactor = &$currentFactor;
$factorList->addFactor($localCurrentFactor);
}
@ -112,22 +90,18 @@ class TrueSkillFactorGraph extends FactorGraph
$fullSchedule = array();
$layers = &$this->_layers;
foreach ($layers as &$currentLayer)
{
foreach ($layers as &$currentLayer) {
$currentPriorSchedule = $currentLayer->createPriorSchedule();
if ($currentPriorSchedule != null)
{
if ($currentPriorSchedule != null) {
$fullSchedule[] = $currentPriorSchedule;
}
}
$allLayersReverse = \array_reverse($this->_layers);
foreach ($allLayersReverse as &$currentLayer)
{
foreach ($allLayersReverse as &$currentLayer) {
$currentPosteriorSchedule = $currentLayer->createPosteriorSchedule();
if ($currentPosteriorSchedule != null)
{
if ($currentPosteriorSchedule != null) {
$fullSchedule[] = $currentPosteriorSchedule;
}
}
@ -140,13 +114,11 @@ class TrueSkillFactorGraph extends FactorGraph
$result = new RatingContainer();
$priorLayerOutputVariablesGroups = &$this->_priorLayer->getOutputVariablesGroups();
foreach ($priorLayerOutputVariablesGroups as &$currentTeam)
{
foreach ($currentTeam as &$currentPlayer)
{
$localCurrentPlayer = &$currentPlayer->getKey();
foreach ($priorLayerOutputVariablesGroups as &$currentTeam) {
foreach ($currentTeam as &$currentPlayer) {
$localCurrentPlayer = &$currentPlayer->getKey();
$newRating = new Rating($currentPlayer->getValue()->getMean(),
$currentPlayer->getValue()->getStandardDeviation());
$currentPlayer->getValue()->getStandardDeviation());
$result->setRating($localCurrentPlayer, $newRating);
}
@ -154,6 +126,4 @@ class TrueSkillFactorGraph extends FactorGraph
return $result;
}
}
?>
}