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,20 +1,9 @@
<?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");
<?php namespace Moserware\Skills\TrueSkill\Layers;
use Moserware\Skills\Numerics\BasicMatch;
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;
@ -33,14 +22,12 @@ class PlayerPriorValuesToSkillsLayer extends TrueSkillFactorGraphLayer
public function buildLayer()
{
$teams = &$this->_teams;
foreach ($teams as &$currentTeam)
{
foreach ($teams as &$currentTeam) {
$localCurrentTeam = &$currentTeam;
$currentTeamSkills = array();
$currentTeamAllPlayers = $localCurrentTeam->getAllPlayers();
foreach ($currentTeamAllPlayers as &$currentTeamPlayer)
{
foreach ($currentTeamAllPlayers as &$currentTeamPlayer) {
$localCurrentTeamPlayer = &$currentTeamPlayer;
$currentTeamPlayerRating = $currentTeam->getRating($localCurrentTeamPlayer);
$playerSkill = &$this->createSkillOutputVariable($localCurrentTeamPlayer);
@ -58,21 +45,22 @@ class PlayerPriorValuesToSkillsLayer extends TrueSkillFactorGraphLayer
{
$localFactors = &$this->getLocalFactors();
return $this->scheduleSequence(
array_map(
function(&$prior)
{
return new ScheduleStep("Prior to Skill Step", $prior, 0);
},
$localFactors),
"All priors");
array_map(
function (&$prior) {
return new ScheduleStep("Prior to Skill Step", $prior, 0);
},
$localFactors),
"All priors");
}
private function createPriorFactor(&$player, Rating &$priorRating, Variable &$skillsVariable)
{
return new GaussianPriorFactor($priorRating->getMean(),
square($priorRating->getStandardDeviation()) +
square($this->getParentFactorGraph()->getGameInfo()->getDynamicsFactor()),
$skillsVariable);
return new GaussianPriorFactor(
$priorRating->getMean(),
BasicMatch::square($priorRating->getStandardDeviation()) +
BasicMatch::square($this->getParentFactorGraph()->getGameInfo()->getDynamicsFactor()),
$skillsVariable
);
}
private function &createSkillOutputVariable(&$key)
@ -82,6 +70,4 @@ class PlayerPriorValuesToSkillsLayer extends TrueSkillFactorGraphLayer
$skillOutputVariable = &$variableFactory->createKeyedVariable($key, $key . "'s skill");
return $skillOutputVariable;
}
}
?>
}