Permalink
Browse files

Another pass at fixing up references

  • Loading branch information...
moserware committed Sep 30, 2010
1 parent 5368f75 commit 803a0816a84879ebfa651ec975664c6ba2f7b93f
Showing with 168 additions and 103 deletions.
  1. +1 −1 PHPSkills/Elo/FideEloCalculator.php
  2. +9 −8 PHPSkills/FactorGraphs/Factor.php
  3. +5 −2 PHPSkills/FactorGraphs/FactorGraph.php
  4. +11 −6 PHPSkills/FactorGraphs/FactorGraphLayer.php
  5. +4 −3 PHPSkills/FactorGraphs/FactorList.php
  6. +3 −2 PHPSkills/FactorGraphs/Message.php
  7. +7 −4 PHPSkills/FactorGraphs/Schedule.php
  8. +6 −5 PHPSkills/FactorGraphs/Variable.php
  9. +2 −2 PHPSkills/FactorGraphs/VariableFactory.php
  10. +3 −2 PHPSkills/HashMap.php
  11. +1 −1 PHPSkills/Numerics/BasicMath.php
  12. +19 −2 PHPSkills/Numerics/GaussianDistribution.php
  13. +2 −1 PHPSkills/Player.php
  14. +3 −2 PHPSkills/RatingContainer.php
  15. +2 −2 PHPSkills/Team.php
  16. +1 −1 PHPSkills/Teams.php
  17. +3 −2 PHPSkills/TrueSkill/Factors/GaussianFactor.php
  18. +2 −2 PHPSkills/TrueSkill/Factors/GaussianLikelihoodFactor.php
  19. +1 −1 PHPSkills/TrueSkill/Factors/GaussianWeightedSumFactor.php
  20. +18 −14 PHPSkills/TrueSkill/Layers/IteratedTeamDifferencesInnerLayer.php
  21. +13 −9 PHPSkills/TrueSkill/Layers/PlayerPerformancesToTeamPerformancesLayer.php
  22. +15 −7 PHPSkills/TrueSkill/Layers/PlayerPriorValuesToSkillsLayer.php
  23. +12 −6 PHPSkills/TrueSkill/Layers/PlayerSkillsToPerformancesLayer.php
  24. +2 −2 PHPSkills/TrueSkill/Layers/TeamDifferencesComparisonLayer.php
  25. +4 −4 PHPSkills/TrueSkill/Layers/TeamPerformancesToTeamPerformanceDifferencesLayer.php
  26. +12 −7 PHPSkills/TrueSkill/TrueSkillFactorGraph.php
  27. +5 −3 PHPSkills/TrueSkill/TwoPlayerTrueSkillCalculator.php
  28. +2 −2 PHPSkills/TrueSkill/TwoTeamTrueSkillCalculator.php
@@ -5,7 +5,7 @@
require_once(dirname(__FILE__) . "/TwoPlayerEloCalculator.php");
require_once(dirname(__FILE__) . "/FideKFactor.php");
/** Including ELO's scheme as a simple comparison.
/** Including Elo's scheme as a simple comparison.
* See http://en.wikipedia.org/wiki/Elo_rating_system#Theory
* for more details
*/
@@ -50,7 +50,7 @@ public function updateMessageIndex($messageIndex)
{
Guard::argumentIsValidIndex($messageIndex, count($this->_messages), "messageIndex");
$message = &$this->_messages[$messageIndex];
$variable = &$this->_messageToVariableBinding->getValue($this->_messages[$messageIndex]);
$variable = &$this->_messageToVariableBinding->getValue($message);
return $this->updateMessageVariable($message, $variable);
}
@@ -62,7 +62,8 @@ protected function updateMessageVariable(Message $message, Variable $variable)
/// Resets the marginal of the variables a factor is connected to
public function resetMarginals()
{
foreach ($this->_messageToVariableBinding->getAllValues() as $currentVariable)
$allValues = &$this->_messageToVariableBinding->getAllValues();
foreach ($allValues as $currentVariable)
{
$currentVariable->resetToPrior();
}
@@ -73,21 +74,21 @@ public function sendMessageIndex($messageIndex)
{
Guard::argumentIsValidIndex($messageIndex, count($this->_messages), "messageIndex");
$message = $this->_messages[$messageIndex];
$variable = $this->_messageToVariableBinding->getValue($message);
$message = &$this->_messages[$messageIndex];
$variable = &$this->_messageToVariableBinding->getValue($message);
return $this->sendMessageVariable($message, $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, Message &$message)
protected function &createVariableToMessageBindingWithMessage(Variable &$variable, Message &$message)
{
$index = count($this->_messages);
$this->_messages[] = $message;
$this->_messages[] = &$message;
$this->_messageToVariableBinding->setValue($message, $variable);
$this->_variables[] = $variable;
$this->_variables[] = &$variable;
return $message;
}
@@ -1,16 +1,19 @@
<?php
namespace Moserware\Skills\FactorGraphs;
require_once(dirname(__FILE__) . "/VariableFactory.php");
class FactorGraph
{
private $_variableFactory;
public function &getVariableFactory()
{
return $this->_variableFactory;
$factory = &$this->_variableFactory;
return $factory;
}
public function setVariableFactory(&$factory)
public function setVariableFactory(VariableFactory &$factory)
{
$this->_variableFactory = &$factory;
}
@@ -1,6 +1,7 @@
<?php
namespace Moserware\Skills\FactorGraphs;
require_once(dirname(__FILE__) . "/Factor.php");
require_once(dirname(__FILE__) . "/FactorGraph.php");
require_once(dirname(__FILE__) . "/Schedule.php");
@@ -18,37 +19,41 @@ protected function __construct(FactorGraph &$parentGraph)
protected function &getInputVariablesGroups()
{
return $this->_inputVariablesGroups;
$inputVariablesGroups = &$this->_inputVariablesGroups;
return $inputVariablesGroups;
}
// HACK
public function &getParentFactorGraph()
{
return $this->_parentFactorGraph;
$parentFactorGraph = &$this->_parentFactorGraph;
return $parentFactorGraph;
}
public function &getOutputVariablesGroups()
{
return $this->_outputVariablesGroups;
$outputVariablesGroups = &$this->_outputVariablesGroups;
return $outputVariablesGroups;
}
public function &getLocalFactors()
{
return $this->_localFactors;
$localFactors = &$this->_localFactors;
return $localFactors;
}
public function setInputVariablesGroups(&$value)
{
$this->_inputVariablesGroups = $value;
}
protected function scheduleSequence($itemsToSequence, $name)
protected function scheduleSequence(array $itemsToSequence, $name)
{
return new ScheduleSequence($name, $itemsToSequence);
}
protected function addLayerFactor(&$factor)
protected function addLayerFactor(Factor &$factor)
{
$this->_localFactors[] = $factor;
}
@@ -13,7 +13,8 @@ class FactorList
public function getLogNormalization()
{
foreach($this->_list as $currentFactor)
$list = &$this->_list;
foreach($list as &$currentFactor)
{
$currentFactor->resetMarginals();
}
@@ -36,7 +37,7 @@ public function getLogNormalization()
$sumLogS = 0;
foreach($this->_list as $currentFactor)
foreach($list as &$currentFactor)
{
$sumLogS = $sumLogS + $currentFactor->getLogNormalization();
}
@@ -49,7 +50,7 @@ public function count()
return count($this->_list);
}
public function addFactor(Factor &$factor)
public function &addFactor(Factor &$factor)
{
$this->_list[] = $factor;
return $factor;
@@ -6,15 +6,16 @@ class Message
private $_name;
private $_value;
public function __construct($value = null, $name = null)
public function __construct(&$value = null, $name = null)
{
$this->_name = $name;
$this->_value = $value;
}
public function& getValue()
{
return $this->_value;
$value = &$this->_value;
return $value;
}
public function setValue(&$value)
@@ -1,6 +1,8 @@
<?php
namespace Moserware\Skills\FactorGraphs;
require_once(dirname(__FILE__) . "/Factor.php");
abstract class Schedule
{
private $_name;
@@ -23,7 +25,7 @@ class ScheduleStep extends Schedule
private $_factor;
private $_index;
public function __construct($name, $factor, $index)
public function __construct($name, Factor &$factor, $index)
{
parent::__construct($name);
$this->_factor = $factor;
@@ -41,7 +43,7 @@ class ScheduleSequence extends Schedule
{
private $_schedules;
public function __construct($name, $schedules)
public function __construct($name, array $schedules)
{
parent::__construct($name);
$this->_schedules = $schedules;
@@ -51,7 +53,8 @@ public function visit($depth = -1, $maxDepth = 0)
{
$maxDelta = 0;
foreach ($this->_schedules as $currentSchedule)
$schedules = &$this->_schedules;
foreach ($schedules as &$currentSchedule)
{
$maxDelta = max($currentSchedule->visit($depth + 1, $maxDepth), $maxDelta);
}
@@ -65,7 +68,7 @@ class ScheduleLoop extends Schedule
private $_maxDelta;
private $_scheduleToLoop;
public function __construct($name, Schedule $scheduleToLoop, $maxDelta)
public function __construct($name, Schedule &$scheduleToLoop, $maxDelta)
{
parent::__construct($name);
$this->_scheduleToLoop = $scheduleToLoop;
@@ -7,7 +7,7 @@ class Variable
private $_prior;
private $_value;
public function __construct($name, $prior)
public function __construct($name, &$prior)
{
$this->_name = "Variable[" . $name . "]";
$this->_prior = $prior;
@@ -16,7 +16,8 @@ public function __construct($name, $prior)
public function &getValue()
{
return $this->_value;
$value = &$this->_value;
return $value;
}
public function setValue(&$value)
@@ -42,12 +43,12 @@ public function __construct()
parent::__construct("Default", null);
}
public function getValue()
public function &getValue()
{
return null;
}
public function setValue($value)
public function setValue(&$value)
{
throw new Exception();
}
@@ -56,7 +57,7 @@ public function setValue($value)
class KeyedVariable extends Variable
{
private $_key;
public function __construct($key, $name, $prior)
public function __construct($key, $name, &$prior)
{
parent::__construct($name, $prior);
$this->_key = $key;
@@ -14,14 +14,14 @@ public function __construct($variablePriorInitializer)
$this->_variablePriorInitializer = &$variablePriorInitializer;
}
public function createBasicVariable($name)
public function &createBasicVariable($name)
{
$initializer = $this->_variablePriorInitializer;
$newVar = new Variable($name, $initializer());
return $newVar;
}
public function createKeyedVariable($key, $name)
public function &createKeyedVariable(&$key, $name)
{
$initializer = $this->_variablePriorInitializer;
$newVar = new KeyedVariable($key, $name, $initializer());
@@ -7,10 +7,11 @@ class HashMap
private $_hashToValue = array();
private $_hashToKey = array();
public function getValue($key)
public function &getValue($key)
{
$hash = self::getHash($key);
return $this->_hashToValue[$hash];
$hashValue = &$this->_hashToValue[$hash];
return $hashValue;
}
public function setValue($key, $value)
@@ -15,7 +15,7 @@ function square($x)
return $x * $x;
}
function sum($itemsToSum, $funcName )
function sum(array $itemsToSum, $funcName )
{
$mappedItems = array_map($funcName, $itemsToSum);
return array_sum($mappedItems);
@@ -30,8 +30,25 @@ function __construct($mean = 0.0, $standardDeviation = 1.0)
$this->_mean = $mean;
$this->_standardDeviation = $standardDeviation;
$this->_variance = square($standardDeviation);
$this->_precision = 1.0/$this->_variance;
$this->_precisionMean = $this->_precision*$this->_mean;
if($this->_variance != 0)
{
$this->_precision = 1.0/$this->_variance;
$this->_precisionMean = $this->_precision*$this->_mean;
}
else
{
$this->_precision = \INF;
if($this->_mean == 0)
{
$this->_precisionMean = 0;
}
else
{
$this->_precisionMean = \INF;
}
}
}
public function getMean()
@@ -38,8 +38,9 @@ public function __construct($id,
/// <summary>
/// The identifier for the player, such as a name.
/// </summary>
public function getId()
public function &getId()
{
$id = &$this->_Id;
return $this->_Id;
}
@@ -12,9 +12,10 @@ public function __construct()
$this->_playerToRating = new HashMap();
}
public function getRating($player)
public function &getRating($player)
{
return $this->_playerToRating->getValue($player);
$rating = &$this->_playerToRating->getValue($player);
return $rating;
}
public function setRating($player, $rating)
@@ -5,7 +5,7 @@
class Team extends RatingContainer
{
public function __construct($player = null, $rating = null)
public function __construct(&$player = null, &$rating = null)
{
parent::__construct();
@@ -15,7 +15,7 @@ public function __construct($player = null, $rating = null)
}
}
public function addPlayer($player, $rating)
public function addPlayer(&$player, &$rating)
{
$this->setRating($player, $rating);
return $this;
@@ -8,7 +8,7 @@ public static function concat(/*variable arguments*/)
$args = \func_get_args();
$result = array();
foreach ($args as $currentTeam) {
foreach ($args as &$currentTeam) {
$result[] = $currentTeam;
}
Oops, something went wrong.

0 comments on commit 803a081

Please sign in to comment.