First time was able to debug w/o file errors. Still lots to go

This commit is contained in:
Jeff Moser 2010-09-25 10:15:51 -04:00
parent f081a6a70a
commit c4c6128c57
21 changed files with 85 additions and 76 deletions

@ -1,12 +1,15 @@
<?php <?php
namespace Moserware\Skills\FactorGraphs; namespace Moserware\Skills\FactorGraphs;
require_once(dirname(__FILE__) . "./../Guard.php"); require_once(dirname(__FILE__) . "/../Guard.php");
require_once(dirname(__FILE__) . "./../HashMap.php"); require_once(dirname(__FILE__) . "/../HashMap.php");
require_once(dirname(__FILE__) . "/Message.php");
require_once(dirname(__FILE__) . "/Variable.php");
use Moserware\Skills\Guard; use Moserware\Skills\Guard;
use Moserware\Skills\HashMap; use Moserware\Skills\HashMap;
abstract class Factor abstract class Factor
{ {
private $_messages = array(); private $_messages = array();
@ -50,7 +53,7 @@ abstract class Factor
return $this->updateMessageVariable($this->_messages[$messageIndex], $this->_messageToVariableBinding->getValue($messageIndex)); return $this->updateMessageVariable($this->_messages[$messageIndex], $this->_messageToVariableBinding->getValue($messageIndex));
} }
protected function updateMessageVariable($message, $variable) protected function updateMessageVariable(Message $message, Variable $variable)
{ {
throw new Exception(); throw new Exception();
} }
@ -74,11 +77,11 @@ abstract class Factor
return $this->sendMessageVariable($message, $variable); return $this->sendMessageVariable($message, $variable);
} }
protected abstract function sendMessageVariable($message, $variable); protected abstract function sendMessageVariable(Message $message, Variable $variable);
public abstract function createVariableToMessageBinding($variable); public abstract function createVariableToMessageBinding(Variable $variable);
protected function createVariableToMessageBindingWithMessage($variable, $message) protected function createVariableToMessageBindingWithMessage(Variable $variable, Variable $message)
{ {
$index = count($this->_messages); $index = count($this->_messages);
$this->_messages[] = $message; $this->_messages[] = $message;

@ -1,7 +1,7 @@
<?php <?php
namespace Moserware\Skills\FactorGraphs; namespace Moserware\Skills\FactorGraphs;
require_once(dirname(__FILE__) . "Schedule.php"); require_once(dirname(__FILE__) . "/Schedule.php");
abstract class FactorGraphLayer abstract class FactorGraphLayer
{ {

@ -2,7 +2,7 @@
namespace Moserware\Skills\FactorGraphs; namespace Moserware\Skills\FactorGraphs;
require_once(dirname(__FILE__) . "./Factor.php"); require_once(dirname(__FILE__) . "/Factor.php");
/// <summary> /// <summary>
/// Helper class for computing the factor graph's normalization constant. /// Helper class for computing the factor graph's normalization constant.

@ -2,7 +2,7 @@
namespace Moserware\Skills\FactorGraphs; namespace Moserware\Skills\FactorGraphs;
require_once(dirname(__FILE__) . "Variable.php"); require_once(dirname(__FILE__) . "/Variable.php");
class VariableFactory class VariableFactory
{ {

@ -1,6 +1,10 @@
<?php <?php
namespace Moserware\Skills; namespace Moserware\Skills;
require_once(dirname(__FILE__) . "/GameInfo.php");
require_once(dirname(__FILE__) . "/PlayersRange.php");
require_once(dirname(__FILE__) . "/TeamsRange.php");
/** /**
* Base class for all skill calculator implementations. * Base class for all skill calculator implementations.
*/ */
@ -25,7 +29,7 @@ abstract class SkillCalculator
/// <param name="teams">A mapping of team players and their ratings.</param> /// <param name="teams">A mapping of team players and their ratings.</param>
/// <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> /// <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> /// <returns>All the players and their new ratings.</returns>
public abstract function calculateNewRatings($gameInfo, public abstract function calculateNewRatings(GameInfo $gameInfo,
array $teamsOfPlayerToRatings, array $teamsOfPlayerToRatings,
array $teamRanks); array $teamRanks);
@ -36,7 +40,7 @@ abstract class SkillCalculator
/// <param name="gameInfo">Parameters for the game.</param> /// <param name="gameInfo">Parameters for the game.</param>
/// <param name="teams">A mapping of team players and their ratings.</param> /// <param name="teams">A mapping of team players and their ratings.</param>
/// <returns>The quality of the match between the teams as a percentage (0% = bad, 100% = well matched).</returns> /// <returns>The quality of the match between the teams as a percentage (0% = bad, 100% = well matched).</returns>
public abstract function calculateMatchQuality($gameInfo, public abstract function calculateMatchQuality(GameInfo $gameInfo,
array $teamsOfPlayerToRatings); array $teamsOfPlayerToRatings);
public function isSupported($option) public function isSupported($option)

@ -40,7 +40,7 @@ class FactorGraphTrueSkillCalculator extends SkillCalculator
parent::__construct(SkillCalculatorSupportedOptions::PARTIAL_PLAY | SkillCalculatorSupportedOptions::PARTIAL_UPDATE, TeamsRange::atLeast(2), PlayersRange::atLeast(1)); parent::__construct(SkillCalculatorSupportedOptions::PARTIAL_PLAY | SkillCalculatorSupportedOptions::PARTIAL_UPDATE, TeamsRange::atLeast(2), PlayersRange::atLeast(1));
} }
public function CalculateNewRatings(GameInfo $gameInfo, public function calculateNewRatings(GameInfo $gameInfo,
array $teams, array $teams,
array $teamRanks) array $teamRanks)
{ {

@ -2,10 +2,10 @@
namespace Moserware\Skills\TrueSkill\Factors; namespace Moserware\Skills\TrueSkill\Factors;
require_once(dirname(__FILE__) . "../../FactorGraphs/Factor.php"); require_once(dirname(__FILE__) . "/../../FactorGraphs/Factor.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");
use Moserware\Numerics\GaussianDistribution; use Moserware\Numerics\GaussianDistribution;
use Moserware\Skills\FactorGraphs\Factor; use Moserware\Skills\FactorGraphs\Factor;

@ -1,11 +1,11 @@
<?php <?php
namespace Moserware\Skills\TrueSkill\Factors; namespace Moserware\Skills\TrueSkill\Factors;
require_once(dirname(__FILE__) . "GaussianFactor.php"); 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");
use Moserware\Numerics\GaussianDistribution; use Moserware\Numerics\GaussianDistribution;
use Moserware\Skills\TrueSkill\TruncatedGaussianCorrectionFunctions; use Moserware\Skills\TrueSkill\TruncatedGaussianCorrectionFunctions;

@ -1,10 +1,10 @@
<?php <?php
namespace Moserware\Skills\TrueSkill\Factors; namespace Moserware\Skills\TrueSkill\Factors;
require_once(dirname(__FILE__) . "GaussianFactor.php"); 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");
use Moserware\Numerics\GaussianDistribution; use Moserware\Numerics\GaussianDistribution;
use Moserware\Skills\FactorGraphs\Message; use Moserware\Skills\FactorGraphs\Message;

@ -1,10 +1,10 @@
<?php <?php
namespace Moserware\Skills\TrueSkill\Factors; namespace Moserware\Skills\TrueSkill\Factors;
require_once(dirname(__FILE__) . "GaussianFactor.php"); 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");
use Moserware\Numerics\GaussianDistribution; use Moserware\Numerics\GaussianDistribution;
use Moserware\Skills\FactorGraphs\Message; use Moserware\Skills\FactorGraphs\Message;

@ -1,10 +1,10 @@
<?php <?php
namespace Moserware\Skills\TrueSkill\Factors; namespace Moserware\Skills\TrueSkill\Factors;
require_once(dirname(__FILE__) . "GaussianFactor.php"); 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");
use Moserware\Numerics\GaussianDistribution; use Moserware\Numerics\GaussianDistribution;
use Moserware\Skills\FactorGraphs\Message; use Moserware\Skills\FactorGraphs\Message;

@ -1,11 +1,11 @@
<?php <?php
namespace Moserware\Skills\TrueSkill\Factors; namespace Moserware\Skills\TrueSkill\Factors;
require_once(dirname(__FILE__) . "GaussianFactor.php"); 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");
use Moserware\Numerics\GaussianDistribution; use Moserware\Numerics\GaussianDistribution;
use Moserware\Skills\TrueSkill\TruncatedGaussianCorrectionFunctions; use Moserware\Skills\TrueSkill\TruncatedGaussianCorrectionFunctions;

@ -1,11 +1,11 @@
<?php <?php
namespace Moserware\Skills\TrueSkill\Layers; namespace Moserware\Skills\TrueSkill\Layers;
require_once(dirname(__FILE__) . "../../FactorGraphs/Schedule.php"); require_once(dirname(__FILE__) . "/../../FactorGraphs/Schedule.php");
require_once(dirname(__FILE__) . "../TrueSkillFactorGraph.php"); require_once(dirname(__FILE__) . "/../TrueSkillFactorGraph.php");
require_once(dirname(__FILE__) . "TrueSkillFactorGraphLayer.php"); require_once(dirname(__FILE__) . "/TrueSkillFactorGraphLayer.php");
require_once(dirname(__FILE__) . "TeamPerformancesToTeamPerformanceDifferencesLayer.php"); require_once(dirname(__FILE__) . "/TeamPerformancesToTeamPerformanceDifferencesLayer.php");
require_once(dirname(__FILE__) . "TeamDifferencesComparisonLayer.php"); require_once(dirname(__FILE__) . "/TeamDifferencesComparisonLayer.php");
use Moserware\Skills\FactorGraphs\ScheduleLoop; use Moserware\Skills\FactorGraphs\ScheduleLoop;
use Moserware\Skills\FactorGraphs\ScheduleSequence; use Moserware\Skills\FactorGraphs\ScheduleSequence;

@ -1,11 +1,11 @@
<?php <?php
namespace Moserware\Skills\TrueSkill\Layers; namespace Moserware\Skills\TrueSkill\Layers;
require_once(dirname(__FILE__) . "../../FactorGraphs/Schedule.php"); require_once(dirname(__FILE__) . "/../../FactorGraphs/Schedule.php");
require_once(dirname(__FILE__) . "../TrueSkillFactorGraph.php"); require_once(dirname(__FILE__) . "/../TrueSkillFactorGraph.php");
require_once(dirname(__FILE__) . "TrueSkillFactorGraphLayer.php"); require_once(dirname(__FILE__) . "/TrueSkillFactorGraphLayer.php");
require_once(dirname(__FILE__) . "TeamPerformancesToTeamPerformanceDifferencesLayer.php"); require_once(dirname(__FILE__) . "/TeamPerformancesToTeamPerformanceDifferencesLayer.php");
require_once(dirname(__FILE__) . "TeamDifferencesComparisonLayer.php"); require_once(dirname(__FILE__) . "/TeamDifferencesComparisonLayer.php");
use Moserware\Skills\FactorGraphs\ScheduleLoop; use Moserware\Skills\FactorGraphs\ScheduleLoop;
use Moserware\Skills\FactorGraphs\ScheduleSequence; use Moserware\Skills\FactorGraphs\ScheduleSequence;

@ -1,11 +1,11 @@
<?php <?php
namespace Moserware\Skills\TrueSkill\Layers; namespace Moserware\Skills\TrueSkill\Layers;
require_once(dirname(__FILE__) . "../../FactorGraphs/Schedule.php"); require_once(dirname(__FILE__) . "/../../FactorGraphs/Schedule.php");
require_once(dirname(__FILE__) . "../../Numerics/BasicMath.php"); require_once(dirname(__FILE__) . "/../../Numerics/BasicMath.php");
require_once(dirname(__FILE__) . "../TrueSkillFactorGraph.php"); require_once(dirname(__FILE__) . "/../TrueSkillFactorGraph.php");
require_once(dirname(__FILE__) . "../Factors/GaussianPriorFactor.php"); require_once(dirname(__FILE__) . "/../Factors/GaussianPriorFactor.php");
require_once(dirname(__FILE__) . "TrueSkillFactorGraphLayer.php"); require_once(dirname(__FILE__) . "/TrueSkillFactorGraphLayer.php");
use Moserware\Skills\FactorGraphs\ScheduleLoop; use Moserware\Skills\FactorGraphs\ScheduleLoop;
use Moserware\Skills\FactorGraphs\ScheduleSequence; use Moserware\Skills\FactorGraphs\ScheduleSequence;
@ -14,6 +14,7 @@ use Moserware\Skills\TrueSkill\TrueSkillFactorGraph;
use Moserware\Skills\TrueSkill\Factors\GaussianPriorFactor; use Moserware\Skills\TrueSkill\Factors\GaussianPriorFactor;
// We intentionally have no Posterior schedule since the only purpose here is to // We intentionally have no Posterior schedule since the only purpose here is to
// start the process.
class PlayerPriorValuesToSkillsLayer extends TrueSkillFactorGraphLayer class PlayerPriorValuesToSkillsLayer extends TrueSkillFactorGraphLayer
{ {
private $_teams; private $_teams;

@ -1,11 +1,11 @@
<?php <?php
namespace Moserware\Skills\TrueSkill\Layers; namespace Moserware\Skills\TrueSkill\Layers;
require_once(dirname(__FILE__) . "../../FactorGraphs/Schedule.php"); require_once(dirname(__FILE__) . "/../../FactorGraphs/Schedule.php");
require_once(dirname(__FILE__) . "../../Numerics/BasicMath.php"); require_once(dirname(__FILE__) . "/../../Numerics/BasicMath.php");
require_once(dirname(__FILE__) . "../TrueSkillFactorGraph.php"); require_once(dirname(__FILE__) . "/../TrueSkillFactorGraph.php");
require_once(dirname(__FILE__) . "../Factors/GaussianLikelihoodFactor.php"); require_once(dirname(__FILE__) . "/../Factors/GaussianLikelihoodFactor.php");
require_once(dirname(__FILE__) . "TrueSkillFactorGraphLayer.php"); require_once(dirname(__FILE__) . "/TrueSkillFactorGraphLayer.php");
use Moserware\Skills\FactorGraphs\ScheduleStep; use Moserware\Skills\FactorGraphs\ScheduleStep;
use Moserware\Skills\TrueSkill\TrueSkillFactorGraph; use Moserware\Skills\TrueSkill\TrueSkillFactorGraph;

@ -1,11 +1,11 @@
<?php <?php
namespace Moserware\Skills\TrueSkill\Layers; namespace Moserware\Skills\TrueSkill\Layers;
require_once(dirname(__FILE__) . "../DrawMargin.php"); require_once(dirname(__FILE__) . "/../DrawMargin.php");
require_once(dirname(__FILE__) . "../TrueSkillFactorGraph.php"); require_once(dirname(__FILE__) . "/../TrueSkillFactorGraph.php");
require_once(dirname(__FILE__) . "../Factors/GaussianGreaterThanFactor.php"); require_once(dirname(__FILE__) . "/../Factors/GaussianGreaterThanFactor.php");
require_once(dirname(__FILE__) . "../Factors/GaussianWithinFactor.php"); require_once(dirname(__FILE__) . "/../Factors/GaussianWithinFactor.php");
require_once(dirname(__FILE__) . "TrueSkillFactorGraphLayer.php"); require_once(dirname(__FILE__) . "/TrueSkillFactorGraphLayer.php");
use Moserware\Skills\TrueSkill\DrawMargin; use Moserware\Skills\TrueSkill\DrawMargin;
use Moserware\Skills\TrueSkill\TrueSkillFactorGraph; use Moserware\Skills\TrueSkill\TrueSkillFactorGraph;

@ -1,10 +1,10 @@
<?php <?php
namespace Moserware\Skills\TrueSkill\Layers; namespace Moserware\Skills\TrueSkill\Layers;
require_once(dirname(__FILE__) . "../../FactorGraphs/Variable.php"); require_once(dirname(__FILE__) . "/../../FactorGraphs/Variable.php");
require_once(dirname(__FILE__) . "../TrueSkillFactorGraph.php"); require_once(dirname(__FILE__) . "/../TrueSkillFactorGraph.php");
require_once(dirname(__FILE__) . "../Factors/GaussianWeightedSumFactor.php"); require_once(dirname(__FILE__) . "/../Factors/GaussianWeightedSumFactor.php");
require_once(dirname(__FILE__) . "TrueSkillFactorGraphLayer.php"); require_once(dirname(__FILE__) . "/TrueSkillFactorGraphLayer.php");
use Moserware\Skills\FactorGraphs\Variable; use Moserware\Skills\FactorGraphs\Variable;
use Moserware\Skills\TrueSkill\DrawMargin; use Moserware\Skills\TrueSkill\DrawMargin;

@ -1,7 +1,7 @@
<?php <?php
namespace Moserware\Skills\TrueSkill\Layers; namespace Moserware\Skills\TrueSkill\Layers;
require_once(dirname(__FILE__) . "../../FactorGraphs/FactorGraphLayer.php"); require_once(dirname(__FILE__) . "/../../FactorGraphs/FactorGraphLayer.php");
use Moserware\Skills\FactorGraphs\FactorGraphLayer; use Moserware\Skills\FactorGraphs\FactorGraphLayer;

@ -1,11 +1,12 @@
<?php <?php
namespace Moserware\Skills\TrueSkill; namespace Moserware\Skills\TrueSkill;
require_once(dirname(__FILE__) . './../Rating.php'); require_once(dirname(__FILE__) . '/../Rating.php');
require_once(dirname(__FILE__) . './../FactorGraphs/FactorList.php'); require_once(dirname(__FILE__) . '/../FactorGraphs/FactorGraph.php');
require_once(dirname(__FILE__) . './../FactorGraphs/Schedule.php'); require_once(dirname(__FILE__) . '/../FactorGraphs/FactorList.php');
require_once(dirname(__FILE__) . './../FactorGraphs/VariableFactory.php'); require_once(dirname(__FILE__) . '/../FactorGraphs/Schedule.php');
require_once(dirname(__FILE__) . './../Numerics/GaussianDistribution.php'); require_once(dirname(__FILE__) . '/../FactorGraphs/VariableFactory.php');
require_once(dirname(__FILE__) . '/../Numerics/GaussianDistribution.php');
require_once(dirname(__FILE__) . '/Layers/PlayerPriorValuesToSkillsLayer.php'); require_once(dirname(__FILE__) . '/Layers/PlayerPriorValuesToSkillsLayer.php');
require_once(dirname(__FILE__) . '/Layers/PlayerSkillsToPerformancesLayer.php'); require_once(dirname(__FILE__) . '/Layers/PlayerSkillsToPerformancesLayer.php');
require_once(dirname(__FILE__) . '/Layers/IteratedTeamDifferencesInnerLayer.php'); require_once(dirname(__FILE__) . '/Layers/IteratedTeamDifferencesInnerLayer.php');
@ -13,6 +14,7 @@ require_once(dirname(__FILE__) . '/Layers/TeamPerformancesToTeamPerformanceDiffe
require_once(dirname(__FILE__) . '/Layers/TeamDifferencesComparisonLayer.php'); require_once(dirname(__FILE__) . '/Layers/TeamDifferencesComparisonLayer.php');
use Moserware\Skills\Rating; use Moserware\Skills\Rating;
use Moserware\Skills\FactorGraphs\FactorGraph;
use Moserware\Skills\FactorGraphs\FactorList; use Moserware\Skills\FactorGraphs\FactorList;
use Moserware\Skills\FactorGraphs\ScheduleSequence; use Moserware\Skills\FactorGraphs\ScheduleSequence;
use Moserware\Skills\FactorGraphs\VariableFactory; use Moserware\Skills\FactorGraphs\VariableFactory;

@ -13,15 +13,14 @@ class FactorGraphTrueSkillCalculatorTest extends PHPUnit_Framework_TestCase
public function testFactorGraphTrueSkillCalculator() public function testFactorGraphTrueSkillCalculator()
{ {
$calculator = new FactorGraphTrueSkillCalculator(); $calculator = new FactorGraphTrueSkillCalculator();
// We only support two players
TrueSkillCalculatorTests::testAllTwoPlayerScenarios($this, $calculator); TrueSkillCalculatorTests::testAllTwoPlayerScenarios($this, $calculator);
TrueSkillCalculatorTests::testAllTwoTeamScenarios($this, $calculator); TrueSkillCalculatorTests::testAllTwoTeamScenarios($this, $calculator);
} }
} }
$testSuite = new \PHPUnit_Framework_TestSuite(); $testSuite = new \PHPUnit_Framework_TestSuite();
$testSuite->addTest( new TwoTeamTrueSkillCalculatorTest("testFactorGraphTrueSkillCalculator")); $testSuite->addTest( new FactorGraphTrueSkillCalculatorTest("testFactorGraphTrueSkillCalculator"));
\PHPUnit_TextUI_TestRunner::run($testSuite); \PHPUnit_TextUI_TestRunner::run($testSuite);
?> ?>