mirror of
https://github.com/furyfire/trueskill.git
synced 2025-01-15 17:37:39 +00:00
Added/converted a file I missed earlier (TrueSkillFactorGraph) and started adding using's and require_once's
This commit is contained in:
@ -2,6 +2,16 @@
|
||||
|
||||
namespace Moserware\Skills\TrueSkill\Factors;
|
||||
|
||||
require_once(dirname(__FILE__) . "../../FactorGraphs/Factor.php");
|
||||
require_once(dirname(__FILE__) . "../../FactorGraphs/Message.php");
|
||||
require_once(dirname(__FILE__) . "../../FactorGraphs/Variable.php");
|
||||
require_once(dirname(__FILE__) . "../../Numerics/GaussianDistribution.php");
|
||||
|
||||
use Moserware\Numerics\GaussianDistribution;
|
||||
use Moserware\Skills\FactorGraphs\Factor;
|
||||
use Moserware\Skills\FactorGraphs\Message;
|
||||
use Moserware\Skills\FactorGraphs\Variable;
|
||||
|
||||
abstract class GaussianFactor extends Factor
|
||||
{
|
||||
protected function __construct($name)
|
||||
@ -28,5 +38,4 @@ abstract class GaussianFactor extends Factor
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
|
@ -1,6 +1,17 @@
|
||||
<?php
|
||||
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/Variable.php");
|
||||
require_once(dirname(__FILE__) . "../../Numerics/GaussianDistribution.php");
|
||||
|
||||
use Moserware\Numerics\GaussianDistribution;
|
||||
use Moserware\Skills\TrueSkill\TruncatedGaussianCorrectionFunctions;
|
||||
use Moserware\Skills\FactorGraphs\Message;
|
||||
use Moserware\Skills\FactorGraphs\Variable;
|
||||
|
||||
/// <summary>
|
||||
/// Factor representing a team difference that has exceeded the draw margin.
|
||||
/// </summary>
|
||||
|
@ -1,7 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace Moserware\Skills\TrueSkill\Factors;
|
||||
|
||||
require_once(dirname(__FILE__) . "GaussianFactor.php");
|
||||
require_once(dirname(__FILE__) . "../../FactorGraphs/Message.php");
|
||||
require_once(dirname(__FILE__) . "../../FactorGraphs/Variable.php");
|
||||
require_once(dirname(__FILE__) . "../../Numerics/GaussianDistribution.php");
|
||||
|
||||
use Moserware\Numerics\GaussianDistribution;
|
||||
use Moserware\Skills\FactorGraphs\Message;
|
||||
use Moserware\Skills\FactorGraphs\Variable;
|
||||
|
||||
/// <summary>
|
||||
/// Connects two variables and adds uncertainty.
|
||||
/// </summary>
|
||||
|
@ -1,7 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace Moserware\Skills\TrueSkill\Factors;
|
||||
|
||||
require_once(dirname(__FILE__) . "GaussianFactor.php");
|
||||
require_once(dirname(__FILE__) . "../../FactorGraphs/Message.php");
|
||||
require_once(dirname(__FILE__) . "../../FactorGraphs/Variable.php");
|
||||
require_once(dirname(__FILE__) . "../../Numerics/GaussianDistribution.php");
|
||||
|
||||
use Moserware\Numerics\GaussianDistribution;
|
||||
use Moserware\Skills\FactorGraphs\Message;
|
||||
use Moserware\Skills\FactorGraphs\Variable;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Supplies the factor graph with prior information.
|
||||
/// </summary>
|
||||
@ -36,5 +45,4 @@ class GaussianPriorFactor extends GaussianFactor
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
|
@ -1,7 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace Moserware\Skills\TrueSkill\Factors;
|
||||
|
||||
require_once(dirname(__FILE__) . "GaussianFactor.php");
|
||||
require_once(dirname(__FILE__) . "../../FactorGraphs/Message.php");
|
||||
require_once(dirname(__FILE__) . "../../FactorGraphs/Variable.php");
|
||||
require_once(dirname(__FILE__) . "../../Numerics/GaussianDistribution.php");
|
||||
|
||||
use Moserware\Numerics\GaussianDistribution;
|
||||
use Moserware\Skills\FactorGraphs\Message;
|
||||
use Moserware\Skills\FactorGraphs\Variable;
|
||||
|
||||
/// <summary>
|
||||
/// Factor that sums together multiple Gaussians.
|
||||
/// </summary>
|
||||
|
@ -1,7 +1,17 @@
|
||||
<?php
|
||||
|
||||
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/Variable.php");
|
||||
require_once(dirname(__FILE__) . "../../Numerics/GaussianDistribution.php");
|
||||
|
||||
use Moserware\Numerics\GaussianDistribution;
|
||||
use Moserware\Skills\TrueSkill\TruncatedGaussianCorrectionFunctions;
|
||||
use Moserware\Skills\FactorGraphs\Message;
|
||||
use Moserware\Skills\FactorGraphs\Variable;
|
||||
|
||||
/// <summary>
|
||||
/// Factor representing a team difference that has not exceeded the draw margin.
|
||||
/// </summary>
|
||||
|
@ -1,7 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace Moserware\Skills\TrueSkill\Layers;
|
||||
|
||||
require_once(dirname(__FILE__) . "TrueSkillFactorGraphLayer.php");
|
||||
require_once(dirname(__FILE__) . "TeamPerformancesToTeamPerformanceDifferencesLayer.php");
|
||||
require_once(dirname(__FILE__) . "TeamDifferencesComparisonLayer.php");
|
||||
require_once(dirname(__FILE__) . "../../FactorGraphs/Schedule.php");
|
||||
|
||||
use Moserware\Skills\FactorGraphs\ScheduleLoop;
|
||||
use Moserware\Skills\FactorGraphs\ScheduleSequence;
|
||||
use Moserware\Skills\FactorGraphs\ScheduleStep;
|
||||
|
||||
// The whole purpose of this is to do a loop on the bottom
|
||||
class IteratedTeamDifferencesInnerLayer extends TrueSkillFactorGraphLayer
|
||||
{
|
||||
|
@ -1,7 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace Moserware\Skills\TrueSkill\Layers;
|
||||
|
||||
require_once(dirname(__FILE__) . "TrueSkillFactorGraphLayer.php");
|
||||
require_once(dirname(__FILE__) . "TeamPerformancesToTeamPerformanceDifferencesLayer.php");
|
||||
require_once(dirname(__FILE__) . "TeamDifferencesComparisonLayer.php");
|
||||
require_once(dirname(__FILE__) . "../../FactorGraphs/Schedule.php");
|
||||
|
||||
use Moserware\Skills\FactorGraphs\ScheduleLoop;
|
||||
use Moserware\Skills\FactorGraphs\ScheduleSequence;
|
||||
use Moserware\Skills\FactorGraphs\ScheduleStep;
|
||||
|
||||
class PlayerPerformancesToTeamPerformancesLayer extends TrueSkillFactorGraphLayer
|
||||
{
|
||||
public function __construct(TrueSkillFactorGraph $parentGraph)
|
||||
|
141
PHPSkills/TrueSkill/TrueSkillFactorGraph.php
Normal file
141
PHPSkills/TrueSkill/TrueSkillFactorGraph.php
Normal file
@ -0,0 +1,141 @@
|
||||
<?php
|
||||
namespace Moserware\Skills\TrueSkill;
|
||||
|
||||
require_once(dirname(__FILE__) . '../Rating.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/PlayerPriorValuesToSkillsLayer.php');
|
||||
require_once(dirname(__FILE__) . '/Layers/PlayerSkillsToPerformancesLayer.php');
|
||||
require_once(dirname(__FILE__) . '/Layers/IteratedTeamDifferencesInnerLayer.php');
|
||||
require_once(dirname(__FILE__) . '/Layers/TeamPerformancesToTeamPerformanceDifferencesLayer.php');
|
||||
require_once(dirname(__FILE__) . '/Layers/TeamDifferencesComparisonLayer.php');
|
||||
|
||||
use Moserware\Skills\Rating;
|
||||
use Moserware\Skills\FactorGraphs\FactorList;
|
||||
use Moserware\Skills\FactorGraphs\ScheduleSequence;
|
||||
use Moserware\Skills\FactorGraphs\VariableFactory;
|
||||
use Moserware\Skills\TrueSkill\Layers\PlayerPriorValuesToSkillsLayer;
|
||||
use Moserware\Skills\TrueSkill\Layers\PlayerSkillsToPerformancesLayer;
|
||||
use Moserware\Skills\TrueSkill\Layers\IteratedTeamDifferencesInnerLayer;
|
||||
use Moserware\Skills\TrueSkill\Layers\TeamPerformancesToTeamPerformanceDifferencesLayer;
|
||||
use Moserware\Skills\TrueSkill\Layers\TeamDifferencesComparisonLayer;
|
||||
|
||||
class TrueSkillFactorGraph extends FactorGraph
|
||||
{
|
||||
private $_gameInfo;
|
||||
private $_layers;
|
||||
private $_priorLayer;
|
||||
private $_variableFactory;
|
||||
|
||||
public function __construct(GameInfo $gameInfo, $teams, array $teamRanks)
|
||||
{
|
||||
$this->_priorLayer = new PlayerPriorValuesToSkillsLayer($this, $teams);
|
||||
$this->_gameInfo = $gameInfo;
|
||||
$this->_variableFactory = new VariableFactory(
|
||||
function()
|
||||
{
|
||||
return GaussianDistribution::fromPrecisionMean(0, 0);
|
||||
});
|
||||
|
||||
$this->_layers = array(
|
||||
$this->_priorLayer,
|
||||
new PlayerSkillsToPerformancesLayer($this),
|
||||
new PlayerPerformancesToTeamPerformancesLayer($this),
|
||||
new IteratedTeamDifferencesInnerLayer(
|
||||
$this,
|
||||
new TeamPerformancesToTeamPerformanceDifferencesLayer($this),
|
||||
new TeamDifferencesComparisonLayer($this, $teamRanks))
|
||||
);
|
||||
}
|
||||
|
||||
public function getGameInfo()
|
||||
{
|
||||
return $this->_gameInfo;
|
||||
}
|
||||
|
||||
public function buildGraph()
|
||||
{
|
||||
$lastOutput = null;
|
||||
|
||||
foreach ($this->_layers as $currentLayer)
|
||||
{
|
||||
if ($lastOutput != null)
|
||||
{
|
||||
$currentLayer->setInputVariablesGroups($lastOutput);
|
||||
}
|
||||
|
||||
$currentLayer->buildLayer();
|
||||
|
||||
$lastOutput = $currentLayer->getOutputVariablesGroups();
|
||||
}
|
||||
}
|
||||
|
||||
public function runSchedule()
|
||||
{
|
||||
$fullSchedule = $this->createFullSchedule();
|
||||
$fullScheduleDelta = $fullSchedule->visit();
|
||||
}
|
||||
|
||||
public function getProbabilityOfRanking()
|
||||
{
|
||||
$factorList = new FactorList();
|
||||
|
||||
foreach ($this->_layers as $currentLayer)
|
||||
{
|
||||
foreach ($currentLayer->getFactors() as $currentFactor)
|
||||
{
|
||||
$factorList->addFactor($currentFactor);
|
||||
}
|
||||
}
|
||||
|
||||
$logZ = $factorList->getLogNormalization();
|
||||
return exp($logZ);
|
||||
}
|
||||
|
||||
private function createFullSchedule()
|
||||
{
|
||||
$fullSchedule = array();
|
||||
|
||||
foreach ($this->_layers as $currentLayer)
|
||||
{
|
||||
$currentPriorSchedule = $currentLayer->createPriorSchedule();
|
||||
if ($currentPriorSchedule != null)
|
||||
{
|
||||
$fullSchedule->add($currentPriorSchedule);
|
||||
}
|
||||
}
|
||||
|
||||
$allLayersReverse = \array_reverse($this->_layers);
|
||||
|
||||
foreach ($allLayersReverse as $currentLayer)
|
||||
{
|
||||
$currentPosteriorSchedule = $currentLayer->createPosteriorSchedule();
|
||||
if ($currentPosteriorSchedule != null)
|
||||
{
|
||||
$fullSchedule->add($currentPosteriorSchedule);
|
||||
}
|
||||
}
|
||||
|
||||
return new ScheduleSequence("Full schedule", $fullSchedule);
|
||||
}
|
||||
|
||||
public function getUpdatedRatings()
|
||||
{
|
||||
$result = array();
|
||||
|
||||
foreach ($this->_priorLayer->getOutputVariablesGroups() as $currentTeam)
|
||||
{
|
||||
foreach ($currentTeam as $currentPlayer)
|
||||
{
|
||||
$result[$currentPlayer->getKey()] = new Rating($currentPlayer->getValue()->getMean(),
|
||||
$currentPlayer->getValue()->getStandardDeviation());
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
Reference in New Issue
Block a user