Some minor documentation cleanup (e.g. converted C# comments to PHPDocumentor comments)

This commit is contained in:
Jeff Moser 2010-10-08 21:44:36 -04:00
parent f863e150d4
commit d2fc7dc5c7
22 changed files with 174 additions and 159 deletions

@ -2,8 +2,8 @@
namespace Moserware\Skills\Elo; namespace Moserware\Skills\Elo;
require_once(dirname(__FILE__) . "/TwoPlayerEloCalculator.php");
require_once(dirname(__FILE__) . "/FideKFactor.php"); require_once(dirname(__FILE__) . "/FideKFactor.php");
require_once(dirname(__FILE__) . "/TwoPlayerEloCalculator.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 * See http://en.wikipedia.org/wiki/Elo_rating_system#Theory

@ -23,13 +23,17 @@ abstract class Factor
$this->_messageToVariableBinding = new HashMap(); $this->_messageToVariableBinding = new HashMap();
} }
/// Returns the log-normalization constant of that factor /**
* @return The log-normalization constant of that factor
*/
public function getLogNormalization() public function getLogNormalization()
{ {
return 0; return 0;
} }
/// Returns the number of messages that the factor has /**
* @return The number of messages that the factor has
*/
public function getNumberOfMessages() public function getNumberOfMessages()
{ {
return count($this->_messages); return count($this->_messages);
@ -45,7 +49,9 @@ abstract class Factor
return $this->_messages; return $this->_messages;
} }
/// Update the message and marginal of the i-th variable that the factor is connected to /**
* Update the message and marginal of the i-th variable that the factor is connected to
*/
public function updateMessageIndex($messageIndex) public function updateMessageIndex($messageIndex)
{ {
Guard::argumentIsValidIndex($messageIndex, count($this->_messages), "messageIndex"); Guard::argumentIsValidIndex($messageIndex, count($this->_messages), "messageIndex");
@ -59,7 +65,9 @@ abstract class Factor
throw new Exception(); throw new Exception();
} }
/// Resets the marginal of the variables a factor is connected to /**
* Resets the marginal of the variables a factor is connected to
*/
public function resetMarginals() public function resetMarginals()
{ {
$allValues = &$this->_messageToVariableBinding->getAllValues(); $allValues = &$this->_messageToVariableBinding->getAllValues();
@ -69,7 +77,9 @@ abstract class Factor
} }
} }
/// Sends the ith message to the marginal and returns the log-normalization constant /**
* Sends the ith message to the marginal and returns the log-normalization constant
*/
public function sendMessageIndex($messageIndex) public function sendMessageIndex($messageIndex)
{ {
Guard::argumentIsValidIndex($messageIndex, count($this->_messages), "messageIndex"); Guard::argumentIsValidIndex($messageIndex, count($this->_messages), "messageIndex");

@ -4,9 +4,9 @@ namespace Moserware\Skills\FactorGraphs;
require_once(dirname(__FILE__) . "/Factor.php"); require_once(dirname(__FILE__) . "/Factor.php");
/// <summary> /**
/// Helper class for computing the factor graph's normalization constant. * Helper class for computing the factor graph's normalization constant.
/// </summary> */
class FactorList class FactorList
{ {
private $_list = array(); private $_list = array();

@ -1,11 +1,11 @@
<?php <?php
namespace Moserware\Skills; namespace Moserware\Skills;
/// <summary> /**
/// Verifies argument contracts. * Verifies argument contracts.
/// </summary> *
/// <remarks>These are used until .NET 4.0 ships with Contracts. For more information, * @see http://www.moserware.com/2008/01/borrowing-ideas-from-3-interesting.html
/// see http://www.moserware.com/2008/01/borrowing-ideas-from-3-interesting.html</remarks> */
class Guard class Guard
{ {
public static function argumentNotNull($value, $parameterName) public static function argumentNotNull($value, $parameterName)

@ -2,6 +2,9 @@
namespace Moserware\Skills; namespace Moserware\Skills;
/**
* Basic hashmap that supports object keys.
*/
class HashMap class HashMap
{ {
private $_hashToValue = array(); private $_hashToValue = array();

@ -2,22 +2,30 @@
/** /**
* Basic math functions. * Basic math functions.
* *
* PHP version 5
*
* @category Math
* @package PHPSkills * @package PHPSkills
* @author Jeff Moser <jeff@moserware.com> * @author Jeff Moser <jeff@moserware.com>
* @copyright 2010 Jeff Moser * @copyright 2010 Jeff Moser
*/ */
/**
* Squares the input (x^2 = x * x)
* @param number $x Value to square (x)
* @return number The squared value (x^2)
*/
function square($x) function square($x)
{ {
return $x * $x; return $x * $x;
} }
function sum(array $itemsToSum, $funcName ) /**
* Sums the items in $itemsToSum
* @param array $itemsToSum The items to sum,
* @param callback $callback The function to apply to each array element before summing.
* @return number The sum.
*/
function sum(array $itemsToSum, $callback )
{ {
$mappedItems = array_map($funcName, $itemsToSum); $mappedItems = array_map($callback, $itemsToSum);
return array_sum($mappedItems); return array_sum($mappedItems);
} }

@ -1,25 +1,22 @@
<?php <?php
/**
* Computes Gaussian values.
*
* PHP version 5
*
* @category Math
* @package PHPSkills
* @author Jeff Moser <jeff@moserware.com>
* @copyright 2010 Jeff Moser
*/
namespace Moserware\Numerics; namespace Moserware\Numerics;
require_once(dirname(__FILE__) . "/basicmath.php"); require_once(dirname(__FILE__) . "/basicmath.php");
/**
* Computes Gaussian (bell curve) values.
*
* @package PHPSkills
* @author Jeff Moser <jeff@moserware.com>
* @copyright 2010 Jeff Moser
*/
class GaussianDistribution class GaussianDistribution
{ {
private $_mean; private $_mean;
private $_standardDeviation; private $_standardDeviation;
// Precision and PrecisionMean are used because they make multiplying and dividing simpler // precision and precisionMean are used because they make multiplying and dividing simpler
// (the the accompanying math paper for more details) // (the the accompanying math paper for more details)
private $_precision; private $_precision;
private $_precisionMean; private $_precisionMean;

@ -5,9 +5,9 @@ require_once(dirname(__FILE__) . "/Guard.php");
require_once(dirname(__FILE__) . "/ISupportPartialPlay.php"); require_once(dirname(__FILE__) . "/ISupportPartialPlay.php");
require_once(dirname(__FILE__) . "/ISupportPartialUpdate.php"); require_once(dirname(__FILE__) . "/ISupportPartialUpdate.php");
/// <summary> /**
/// Represents a player who has a <see cref="Rating"/>. * Represents a player who has a Rating.
/// </summary> */
class Player implements ISupportPartialPlay, ISupportPartialUpdate class Player implements ISupportPartialPlay, ISupportPartialUpdate
{ {
const DEFAULT_PARTIAL_PLAY_PERCENTAGE = 1.0; // = 100% play time const DEFAULT_PARTIAL_PLAY_PERCENTAGE = 1.0; // = 100% play time
@ -17,12 +17,13 @@ class Player implements ISupportPartialPlay, ISupportPartialUpdate
private $_PartialPlayPercentage; private $_PartialPlayPercentage;
private $_PartialUpdatePercentage; private $_PartialUpdatePercentage;
/// <summary> /**
/// Constructs a player. * Constructs a player.
/// </summary> *
/// <param name="id">The identifier for the player, such as a name.</param> * @param mixed $id The identifier for the player, such as a name.
/// <param name="partialPlayPercentage">The weight percentage to give this player when calculating a new rank.</param> * @param number $partialPlayPercentage The weight percentage to give this player when calculating a new rank.
/// <param name="partialUpdatePercentage">/// Indicated how much of a skill update a player should receive where 0 represents no update and 1.0 represents 100% of the update.</param> * @param number $partialUpdatePercentage Indicated how much of a skill update a player should receive where 0 represents no update and 1.0 represents 100% of the update.
*/
public function __construct($id, public function __construct($id,
$partialPlayPercentage = self::DEFAULT_PARTIAL_PLAY_PERCENTAGE, $partialPlayPercentage = self::DEFAULT_PARTIAL_PLAY_PERCENTAGE,
$partialUpdatePercentage = self::DEFAULT_PARTIAL_UPDATE_PERCENTAGE) $partialUpdatePercentage = self::DEFAULT_PARTIAL_UPDATE_PERCENTAGE)
@ -35,39 +36,31 @@ class Player implements ISupportPartialPlay, ISupportPartialUpdate
$this->_PartialUpdatePercentage = $partialUpdatePercentage; $this->_PartialUpdatePercentage = $partialUpdatePercentage;
} }
/// <summary> /**
/// The identifier for the player, such as a name. * The identifier for the player, such as a name.
/// </summary> */
public function &getId() public function &getId()
{ {
$id = &$this->_Id; $id = &$this->_Id;
return $this->_Id; return $this->_Id;
} }
#region ISupportPartialPlay Members /**
* Indicates the percent of the time the player should be weighted where 0.0 indicates the player didn't play and 1.0 indicates the player played 100% of the time.
/// <summary> */
/// Indicates the percent of the time the player should be weighted where 0.0 indicates the player didn't play and 1.0 indicates the player played 100% of the time.
/// </summary>
public function getPartialPlayPercentage() public function getPartialPlayPercentage()
{ {
return $this->_PartialPlayPercentage; return $this->_PartialPlayPercentage;
} }
#endregion /**
* Indicated how much of a skill update a player should receive where 0.0 represents no update and 1.0 represents 100% of the update.
#region ISupportPartialUpdate Members */
/// <summary>
/// Indicated how much of a skill update a player should receive where 0.0 represents no update and 1.0 represents 100% of the update.
/// </summary>
public function getPartialUpdatePercentage() public function getPartialUpdatePercentage()
{ {
return $this->_PartialUpdatePercentage; return $this->_PartialUpdatePercentage;
} }
#endregion
public function __toString() public function __toString()
{ {
if ($this->_Id != null) if ($this->_Id != null)

@ -2,17 +2,17 @@
namespace Moserware\Skills; namespace Moserware\Skills;
/// <summary> /**
/// Helper class to sort ranks in non-decreasing order. * Helper class to sort ranks in non-decreasing order.
/// </summary> */
class RankSorter class RankSorter
{ {
/// <summary> /**
/// Performs an in-place sort of the <paramref name="items"/> in according to the <paramref name="ranks"/> in non-decreasing order. * Performs an in-place sort of the items in according to the ranks in non-decreasing order.
/// </summary> *
/// <typeparam name="T">The types of items to sort.</typeparam> * @param $items The items to sort according to the order specified by ranks.
/// <param name="items">The items to sort according to the order specified by <paramref name="ranks"/>.</param> * @param $ranks The ranks for each item where 1 is first place.
/// <param name="ranks">The ranks for each item where 1 is first place.</param> */
public static function sort(array &$teams, array &$teamRanks) public static function sort(array &$teams, array &$teamRanks)
{ {
array_multisort($teamRanks, $teams); array_multisort($teamRanks, $teams);

@ -21,25 +21,24 @@ abstract class SkillCalculator
$this->_playersPerTeamAllowed = $playerPerTeamAllowed; $this->_playersPerTeamAllowed = $playerPerTeamAllowed;
} }
/// <summary> /**
/// Calculates new ratings based on the prior ratings and team ranks. * Calculates new ratings based on the prior ratings and team ranks.
/// </summary> * @param $gameInfo Parameters for the game.
/// <typeparam name="TPlayer">The underlying type of the player.</typeparam> * @param $teams A mapping of team players and their ratings.
/// <param name="gameInfo">Parameters for the game.</param> * @param $teamRanks The ranks of the teams where 1 is first place. For a tie, repeat the number (e.g. 1, 2, 2).
/// <param name="teams">A mapping of team players and their ratings.</param> * @return All the players and their new ratings.
/// <param name="teamRanks">The ranks of the teams where 1 is first place. For a tie, repeat the number (e.g. 1, 2, 2)</param> */
/// <returns>All the players and their new ratings.</returns>
public abstract function calculateNewRatings(GameInfo &$gameInfo, public abstract function calculateNewRatings(GameInfo &$gameInfo,
array $teamsOfPlayerToRatings, array $teamsOfPlayerToRatings,
array $teamRanks); array $teamRanks);
/// <summary> /**
/// Calculates the match quality as the likelihood of all teams drawing. * Calculates the match quality as the likelihood of all teams drawing.
/// </summary> *
/// <typeparam name="TPlayer">The underlying type of the player.</typeparam> * @param $gameInfo Parameters for the game.
/// <param name="gameInfo">Parameters for the game.</param> * @param $teams A mapping of team players and their ratings.
/// <param name="teams">A mapping of team players and their ratings.</param> * @return The quality of the match between the teams as a percentage (0% = bad, 100% = well matched).
/// <returns>The quality of the match between the teams as a percentage (0% = bad, 100% = well matched).</returns> */
public abstract function calculateMatchQuality(GameInfo &$gameInfo, public abstract function calculateMatchQuality(GameInfo &$gameInfo,
array &$teamsOfPlayerToRatings); array &$teamsOfPlayerToRatings);

@ -30,9 +30,9 @@ use Moserware\Skills\SkillCalculator;
use Moserware\Skills\SkillCalculatorSupportedOptions; use Moserware\Skills\SkillCalculatorSupportedOptions;
use Moserware\Skills\TeamsRange; use Moserware\Skills\TeamsRange;
/// <summary> /**
/// Calculates TrueSkill using a full factor graph. * Calculates TrueSkill using a full factor graph.
/// </summary> */
class FactorGraphTrueSkillCalculator extends SkillCalculator class FactorGraphTrueSkillCalculator extends SkillCalculator
{ {
public function __construct() public function __construct()

@ -19,7 +19,9 @@ abstract class GaussianFactor extends Factor
parent::__construct($name); parent::__construct($name);
} }
/// Sends the factor-graph message with and returns the log-normalization constant /**
* Sends the factor-graph message with and returns the log-normalization constant.
*/
protected function sendMessageVariable(Message &$message, Variable &$variable) protected function sendMessageVariable(Message &$message, Variable &$variable)
{ {
$marginal = &$variable->getValue(); $marginal = &$variable->getValue();

@ -1,21 +1,22 @@
<?php <?php
namespace Moserware\Skills\TrueSkill\Factors; namespace Moserware\Skills\TrueSkill\Factors;
require_once(dirname(__FILE__) . "/GaussianFactor.php");
require_once(dirname(__FILE__) . "/../TruncatedGaussianCorrectionFunctions.php");
require_once(dirname(__FILE__) . "/../../FactorGraphs/Message.php"); require_once(dirname(__FILE__) . "/../../FactorGraphs/Message.php");
require_once(dirname(__FILE__) . "/../../FactorGraphs/Variable.php"); require_once(dirname(__FILE__) . "/../../FactorGraphs/Variable.php");
require_once(dirname(__FILE__) . "/../../Numerics/GaussianDistribution.php"); require_once(dirname(__FILE__) . "/../../Numerics/GaussianDistribution.php");
require_once(dirname(__FILE__) . "/../TruncatedGaussianCorrectionFunctions.php");
require_once(dirname(__FILE__) . "/GaussianFactor.php");
use Moserware\Numerics\GaussianDistribution; use Moserware\Numerics\GaussianDistribution;
use Moserware\Skills\TrueSkill\TruncatedGaussianCorrectionFunctions; use Moserware\Skills\TrueSkill\TruncatedGaussianCorrectionFunctions;
use Moserware\Skills\FactorGraphs\Message; use Moserware\Skills\FactorGraphs\Message;
use Moserware\Skills\FactorGraphs\Variable; use Moserware\Skills\FactorGraphs\Variable;
/// <summary> /**
/// Factor representing a team difference that has exceeded the draw margin. * Factor representing a team difference that has exceeded the draw margin.
/// </summary> *
/// <remarks>See the accompanying math paper for more details.</remarks> * See the accompanying math paper for more details.
*/
class GaussianGreaterThanFactor extends GaussianFactor class GaussianGreaterThanFactor extends GaussianFactor
{ {
private $_epsilon; private $_epsilon;
@ -72,12 +73,12 @@ class GaussianGreaterThanFactor extends GaussianFactor
GaussianDistribution::multiply($oldMessage, $newMarginal), GaussianDistribution::multiply($oldMessage, $newMarginal),
$oldMarginal); $oldMarginal);
/// Update the message and marginal // Update the message and marginal
$message->setValue($newMessage); $message->setValue($newMessage);
$variable->setValue($newMarginal); $variable->setValue($newMarginal);
/// Return the difference in the new marginal // Return the difference in the new marginal
return GaussianDistribution::subtract($newMarginal, $oldMarginal); return GaussianDistribution::subtract($newMarginal, $oldMarginal);
} }
} }

@ -1,19 +1,20 @@
<?php <?php
namespace Moserware\Skills\TrueSkill\Factors; namespace Moserware\Skills\TrueSkill\Factors;
require_once(dirname(__FILE__) . "/GaussianFactor.php");
require_once(dirname(__FILE__) . "/../../FactorGraphs/Message.php"); require_once(dirname(__FILE__) . "/../../FactorGraphs/Message.php");
require_once(dirname(__FILE__) . "/../../FactorGraphs/Variable.php"); require_once(dirname(__FILE__) . "/../../FactorGraphs/Variable.php");
require_once(dirname(__FILE__) . "/../../Numerics/GaussianDistribution.php"); require_once(dirname(__FILE__) . "/../../Numerics/GaussianDistribution.php");
require_once(dirname(__FILE__) . "/GaussianFactor.php");
use Moserware\Numerics\GaussianDistribution; use Moserware\Numerics\GaussianDistribution;
use Moserware\Skills\FactorGraphs\Message; use Moserware\Skills\FactorGraphs\Message;
use Moserware\Skills\FactorGraphs\Variable; use Moserware\Skills\FactorGraphs\Variable;
/// <summary> /**
/// Connects two variables and adds uncertainty. * Connects two variables and adds uncertainty.
/// </summary> *
/// <remarks>See the accompanying math paper for more details.</remarks> * See the accompanying math paper for more details.
*/
class GaussianLikelihoodFactor extends GaussianFactor class GaussianLikelihoodFactor extends GaussianFactor
{ {
private $_precision; private $_precision;
@ -55,12 +56,12 @@ class GaussianLikelihoodFactor extends GaussianFactor
$newMarginal = GaussianDistribution::multiply($oldMarginalWithoutMessage, $newMessage); $newMarginal = GaussianDistribution::multiply($oldMarginalWithoutMessage, $newMessage);
/// Update the message and marginal // Update the message and marginal
$message1->setValue($newMessage); $message1->setValue($newMessage);
$variable1->setValue($newMarginal); $variable1->setValue($newMarginal);
/// Return the difference in the new marginal // Return the difference in the new marginal
return GaussianDistribution::subtract($newMarginal, $marginal1); return GaussianDistribution::subtract($newMarginal, $marginal1);
} }

@ -1,20 +1,20 @@
<?php <?php
namespace Moserware\Skills\TrueSkill\Factors; namespace Moserware\Skills\TrueSkill\Factors;
require_once(dirname(__FILE__) . "/GaussianFactor.php");
require_once(dirname(__FILE__) . "/../../FactorGraphs/Message.php"); require_once(dirname(__FILE__) . "/../../FactorGraphs/Message.php");
require_once(dirname(__FILE__) . "/../../FactorGraphs/Variable.php"); require_once(dirname(__FILE__) . "/../../FactorGraphs/Variable.php");
require_once(dirname(__FILE__) . "/../../Numerics/GaussianDistribution.php"); require_once(dirname(__FILE__) . "/../../Numerics/GaussianDistribution.php");
require_once(dirname(__FILE__) . "/GaussianFactor.php");
use Moserware\Numerics\GaussianDistribution; use Moserware\Numerics\GaussianDistribution;
use Moserware\Skills\FactorGraphs\Message; use Moserware\Skills\FactorGraphs\Message;
use Moserware\Skills\FactorGraphs\Variable; use Moserware\Skills\FactorGraphs\Variable;
/**
/// <summary> * Supplies the factor graph with prior information.
/// Supplies the factor graph with prior information. *
/// </summary> * See the accompanying math paper for more details.
/// <remarks>See the accompanying math paper for more details.</remarks> */
class GaussianPriorFactor extends GaussianFactor class GaussianPriorFactor extends GaussianFactor
{ {
private $_newMessage; private $_newMessage;

@ -1,22 +1,23 @@
<?php <?php
namespace Moserware\Skills\TrueSkill\Factors; namespace Moserware\Skills\TrueSkill\Factors;
require_once(dirname(__FILE__) . "/GaussianFactor.php");
require_once(dirname(__FILE__) . "/../../Guard.php"); require_once(dirname(__FILE__) . "/../../Guard.php");
require_once(dirname(__FILE__) . "/../../FactorGraphs/Message.php"); require_once(dirname(__FILE__) . "/../../FactorGraphs/Message.php");
require_once(dirname(__FILE__) . "/../../FactorGraphs/Variable.php"); require_once(dirname(__FILE__) . "/../../FactorGraphs/Variable.php");
require_once(dirname(__FILE__) . "/../../Numerics/GaussianDistribution.php"); require_once(dirname(__FILE__) . "/../../Numerics/GaussianDistribution.php");
require_once(dirname(__FILE__) . "/../../Numerics/BasicMath.php"); require_once(dirname(__FILE__) . "/../../Numerics/BasicMath.php");
require_once(dirname(__FILE__) . "/GaussianFactor.php");
use Moserware\Numerics\GaussianDistribution; use Moserware\Numerics\GaussianDistribution;
use Moserware\Skills\Guard; use Moserware\Skills\Guard;
use Moserware\Skills\FactorGraphs\Message; use Moserware\Skills\FactorGraphs\Message;
use Moserware\Skills\FactorGraphs\Variable; use Moserware\Skills\FactorGraphs\Variable;
/// <summary> /**
/// Factor that sums together multiple Gaussians. * Factor that sums together multiple Gaussians.
/// </summary> *
/// <remarks>See the accompanying math paper for more details.</remarks> * See the accompanying math paper for more details.s
*/
class GaussianWeightedSumFactor extends GaussianFactor class GaussianWeightedSumFactor extends GaussianFactor
{ {
private $_variableIndexOrdersForWeights = array(); private $_variableIndexOrdersForWeights = array();
@ -189,12 +190,12 @@ class GaussianWeightedSumFactor extends GaussianFactor
$newMarginal = GaussianDistribution::multiply($oldMarginalWithoutMessage, $newMessage); $newMarginal = GaussianDistribution::multiply($oldMarginalWithoutMessage, $newMessage);
/// Update the message and marginal // Update the message and marginal
$messages[0]->setValue($newMessage); $messages[0]->setValue($newMessage);
$variables[0]->setValue($newMarginal); $variables[0]->setValue($newMarginal);
/// Return the difference in the new marginal // Return the difference in the new marginal
$finalDiff = GaussianDistribution::subtract($newMarginal, $marginal0); $finalDiff = GaussianDistribution::subtract($newMarginal, $marginal0);
return $finalDiff; return $finalDiff;
} }

@ -1,21 +1,22 @@
<?php <?php
namespace Moserware\Skills\TrueSkill\Factors; namespace Moserware\Skills\TrueSkill\Factors;
require_once(dirname(__FILE__) . "/GaussianFactor.php");
require_once(dirname(__FILE__) . "/../TruncatedGaussianCorrectionFunctions.php"); require_once(dirname(__FILE__) . "/../TruncatedGaussianCorrectionFunctions.php");
require_once(dirname(__FILE__) . "/../../FactorGraphs/Message.php"); require_once(dirname(__FILE__) . "/../../FactorGraphs/Message.php");
require_once(dirname(__FILE__) . "/../../FactorGraphs/Variable.php"); require_once(dirname(__FILE__) . "/../../FactorGraphs/Variable.php");
require_once(dirname(__FILE__) . "/../../Numerics/GaussianDistribution.php"); require_once(dirname(__FILE__) . "/../../Numerics/GaussianDistribution.php");
require_once(dirname(__FILE__) . "/GaussianFactor.php");
use Moserware\Numerics\GaussianDistribution; use Moserware\Numerics\GaussianDistribution;
use Moserware\Skills\TrueSkill\TruncatedGaussianCorrectionFunctions; use Moserware\Skills\TrueSkill\TruncatedGaussianCorrectionFunctions;
use Moserware\Skills\FactorGraphs\Message; use Moserware\Skills\FactorGraphs\Message;
use Moserware\Skills\FactorGraphs\Variable; use Moserware\Skills\FactorGraphs\Variable;
/// <summary> /**
/// Factor representing a team difference that has not exceeded the draw margin. * Factor representing a team difference that has not exceeded the draw margin.
/// </summary> *
/// <remarks>See the accompanying math paper for more details.</remarks> * See the accompanying math paper for more details.
*/
class GaussianWithinFactor extends GaussianFactor class GaussianWithinFactor extends GaussianFactor
{ {
private $_epsilon; private $_epsilon;
@ -71,11 +72,11 @@ class GaussianWithinFactor extends GaussianFactor
GaussianDistribution::multiply($oldMessage, $newMarginal), GaussianDistribution::multiply($oldMessage, $newMarginal),
$oldMarginal); $oldMarginal);
/// Update the message and marginal // Update the message and marginal
$message->setValue($newMessage); $message->setValue($newMessage);
$variable->setValue($newMarginal); $variable->setValue($newMarginal);
/// Return the difference in the new marginal // Return the difference in the new marginal
return GaussianDistribution::subtract($newMarginal, $oldMarginal); return GaussianDistribution::subtract($newMarginal, $oldMarginal);
} }
} }

@ -48,7 +48,6 @@ class IteratedTeamDifferencesInnerLayer extends TrueSkillFactorGraphLayer
public function createPriorSchedule() public function createPriorSchedule()
{ {
// BLOG about $loop
switch (count($this->getInputVariablesGroups())) switch (count($this->getInputVariablesGroups()))
{ {
case 0: case 0:

@ -74,7 +74,6 @@ class PlayerPerformancesToTeamPerformancesLayer extends TrueSkillFactorGraphLaye
public function createPosteriorSchedule() public function createPosteriorSchedule()
{ {
// BLOG
$allFactors = array(); $allFactors = array();
$localFactors = &$this->getLocalFactors(); $localFactors = &$this->getLocalFactors();
foreach($localFactors as &$currentFactor) foreach($localFactors as &$currentFactor)

@ -9,14 +9,14 @@ class TruncatedGaussianCorrectionFunctions
{ {
// These functions from the bottom of page 4 of the TrueSkill paper. // These functions from the bottom of page 4 of the TrueSkill paper.
/// <summary> /**
/// The "V" function where the team performance difference is greater than the draw margin. * The "V" function where the team performance difference is greater than the draw margin.
/// </summary> *
/// <remarks>In the reference F# implementation, this is referred to as "the additive * In the reference F# implementation, this is referred to as "the additive
/// correction of a single-sided truncated Gaussian with unit variance."</remarks> * correction of a single-sided truncated Gaussian with unit variance."
/// <param name="teamPerformanceDifference"></param> *
/// <param name="drawMargin">In the paper, it's referred to as just "ε".</param> * @param number $drawMargin In the paper, it's referred to as just "ε".
/// <returns></returns> */
public static function vExceedsMarginScaled($teamPerformanceDifference, $drawMargin, $c) public static function vExceedsMarginScaled($teamPerformanceDifference, $drawMargin, $c)
{ {
return self::vExceedsMargin($teamPerformanceDifference/$c, $drawMargin/$c); return self::vExceedsMargin($teamPerformanceDifference/$c, $drawMargin/$c);
@ -34,15 +34,13 @@ class TruncatedGaussianCorrectionFunctions
return GaussianDistribution::at($teamPerformanceDifference - $drawMargin)/$denominator; return GaussianDistribution::at($teamPerformanceDifference - $drawMargin)/$denominator;
} }
/// <summary> /**
/// The "W" function where the team performance difference is greater than the draw margin. * The "W" function where the team performance difference is greater than the draw margin.
/// </summary> *
/// <remarks>In the reference F# implementation, this is referred to as "the multiplicative * In the reference F# implementation, this is referred to as "the multiplicative
/// correction of a single-sided truncated Gaussian with unit variance."</remarks> * correction of a single-sided truncated Gaussian with unit variance."
/// <param name="teamPerformanceDifference"></param> */
/// <param name="drawMargin"></param>
/// <param name="c"></param>
/// <returns></returns>
public static function wExceedsMarginScaled($teamPerformanceDifference, $drawMargin, $c) public static function wExceedsMarginScaled($teamPerformanceDifference, $drawMargin, $c)
{ {
return self::wExceedsMargin($teamPerformanceDifference/$c, $drawMargin/$c); return self::wExceedsMargin($teamPerformanceDifference/$c, $drawMargin/$c);

@ -30,13 +30,13 @@ use Moserware\Skills\SkillCalculatorSupportedOptions;
use Moserware\Skills\PlayersRange; use Moserware\Skills\PlayersRange;
use Moserware\Skills\TeamsRange; use Moserware\Skills\TeamsRange;
/// <summary> /**
/// Calculates the new ratings for only two players. * Calculates the new ratings for only two players.
/// </summary> *
/// <remarks> * When you only have two players, a lot of the math simplifies. The main purpose of this class
/// When you only have two players, a lot of the math simplifies. The main purpose of this class * is to show the bare minimum of what a TrueSkill implementation should have.
/// is to show the bare minimum of what a TrueSkill implementation should have. */
/// </remarks>
class TwoPlayerTrueSkillCalculator extends SkillCalculator class TwoPlayerTrueSkillCalculator extends SkillCalculator
{ {
public function __construct() public function __construct()
@ -139,7 +139,9 @@ class TwoPlayerTrueSkillCalculator extends SkillCalculator
return new Rating($newMean, $newStdDev); return new Rating($newMean, $newStdDev);
} }
/// <inheritdoc/> /**
* {@inheritdoc }
*/
public function calculateMatchQuality(GameInfo &$gameInfo, array &$teams) public function calculateMatchQuality(GameInfo &$gameInfo, array &$teams)
{ {
Guard::argumentNotNull($gameInfo, "gameInfo"); Guard::argumentNotNull($gameInfo, "gameInfo");

@ -34,12 +34,11 @@ use Moserware\Skills\TeamsRange;
use Moserware\Skills\Team; use Moserware\Skills\Team;
/// <summary> /**
/// Calculates new ratings for only two teams where each team has 1 or more players. * Calculates new ratings for only two teams where each team has 1 or more players.
/// </summary> *
/// <remarks> * When you only have two teams, the math is still simple: no factor graphs are used yet.
/// When you only have two teams, the math is still simple: no factor graphs are used yet. */
/// </remarks>
class TwoTeamTrueSkillCalculator extends SkillCalculator class TwoTeamTrueSkillCalculator extends SkillCalculator
{ {
public function __construct() public function __construct()
@ -165,7 +164,9 @@ class TwoTeamTrueSkillCalculator extends SkillCalculator
} }
} }
/// <inheritdoc/> /**
* {@inheritdoc }
*/
public function calculateMatchQuality(GameInfo &$gameInfo, public function calculateMatchQuality(GameInfo &$gameInfo,
array &$teams) array &$teams)
{ {