mirror of
				https://github.com/furyfire/trueskill.git
				synced 2025-11-04 02:02:29 +01:00 
			
		
		
		
	This commit is contained in:
		@@ -10,7 +10,7 @@ abstract class FactorGraph
 | 
			
		||||
 | 
			
		||||
    protected function __construct()
 | 
			
		||||
    {
 | 
			
		||||
        $this->variableFactory = new VariableFactory(fn () => NULL);
 | 
			
		||||
        $this->variableFactory = new VariableFactory(static fn(): null => NULL);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function getVariableFactory(): VariableFactory
 | 
			
		||||
 
 | 
			
		||||
@@ -15,12 +15,12 @@ abstract class FactorGraphLayer
 | 
			
		||||
    private array $localFactors = [];
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @var array<int,array<int,object>>
 | 
			
		||||
     * @var array<int,array<int,Variable>>
 | 
			
		||||
     */
 | 
			
		||||
    private array $outputVariablesGroups = [];
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @var array<int,array<int,object>>
 | 
			
		||||
     * @var array<int,array<int,Variable>>
 | 
			
		||||
     */
 | 
			
		||||
    private array $inputVariablesGroups = [];
 | 
			
		||||
 | 
			
		||||
@@ -29,7 +29,7 @@ abstract class FactorGraphLayer
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @return array<int,array<int,object>>
 | 
			
		||||
     * @return array<int,array<int,Variable>>
 | 
			
		||||
     */
 | 
			
		||||
    protected function getInputVariablesGroups(): array
 | 
			
		||||
    {
 | 
			
		||||
@@ -44,7 +44,7 @@ abstract class FactorGraphLayer
 | 
			
		||||
    /**
 | 
			
		||||
     * This reference is still needed
 | 
			
		||||
     *
 | 
			
		||||
     * @return array<int,array<int,object>>
 | 
			
		||||
     * @return array<int,array<int,Variable>>
 | 
			
		||||
     */
 | 
			
		||||
    public function &getOutputVariablesGroups(): array
 | 
			
		||||
    {
 | 
			
		||||
@@ -60,7 +60,7 @@ abstract class FactorGraphLayer
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param array<int,array<int,object>> $value
 | 
			
		||||
     * @param array<int,array<int,Variable>> $value
 | 
			
		||||
     */
 | 
			
		||||
    public function setInputVariablesGroups(array $value): void
 | 
			
		||||
    {
 | 
			
		||||
 
 | 
			
		||||
@@ -13,13 +13,6 @@ use Exception;
 | 
			
		||||
 */
 | 
			
		||||
class Guard
 | 
			
		||||
{
 | 
			
		||||
    public static function argumentNotNull(mixed $value, string $parameterName): void
 | 
			
		||||
    {
 | 
			
		||||
        if ($value == NULL) {
 | 
			
		||||
            throw new Exception($parameterName . ' can not be null');
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static function argumentIsValidIndex(int $index, int $count, string $parameterName): void
 | 
			
		||||
    {
 | 
			
		||||
        if (($index < 0) || ($index >= $count)) {
 | 
			
		||||
 
 | 
			
		||||
@@ -39,7 +39,6 @@ class FactorGraphTrueSkillCalculator extends SkillCalculator
 | 
			
		||||
        array $teamRanks
 | 
			
		||||
    ): RatingContainer
 | 
			
		||||
    {
 | 
			
		||||
        Guard::argumentNotNull($gameInfo, 'gameInfo');
 | 
			
		||||
        $this->validateTeamCountAndPlayersCountPerTeam($teams);
 | 
			
		||||
 | 
			
		||||
        RankSorter::sort($teams, $teamRanks);
 | 
			
		||||
 
 | 
			
		||||
@@ -5,6 +5,7 @@ declare(strict_types=1);
 | 
			
		||||
namespace DNW\Skills\TrueSkill\Layers;
 | 
			
		||||
 | 
			
		||||
use DNW\Skills\FactorGraphs\KeyedVariable;
 | 
			
		||||
use DNW\Skills\FactorGraphs\Variable;
 | 
			
		||||
use DNW\Skills\FactorGraphs\ScheduleStep;
 | 
			
		||||
use DNW\Skills\Numerics\BasicMath;
 | 
			
		||||
use DNW\Skills\TrueSkill\Factors\GaussianLikelihoodFactor;
 | 
			
		||||
@@ -20,9 +21,12 @@ class PlayerSkillsToPerformancesLayer extends TrueSkillFactorGraphLayer
 | 
			
		||||
        foreach ($inputVariablesGroups as $currentTeam) {
 | 
			
		||||
            $currentTeamPlayerPerformances = [];
 | 
			
		||||
 | 
			
		||||
            /**
 | 
			
		||||
             * @var Variable $playerSkillVariable
 | 
			
		||||
             */
 | 
			
		||||
            foreach ($currentTeam as $playerSkillVariable) {
 | 
			
		||||
                $localPlayerSkillVariable = $playerSkillVariable;
 | 
			
		||||
                $currentPlayer = $localPlayerSkillVariable->getKey();
 | 
			
		||||
                $currentPlayer = ($localPlayerSkillVariable instanceof KeyedVariable) ? $localPlayerSkillVariable->getKey() : "";
 | 
			
		||||
                $playerPerformance = $this->createOutputVariable($currentPlayer);
 | 
			
		||||
                $newLikelihoodFactor = $this->createLikelihood($localPlayerSkillVariable, $playerPerformance);
 | 
			
		||||
                $this->addLayerFactor($newLikelihoodFactor);
 | 
			
		||||
@@ -33,7 +37,7 @@ class PlayerSkillsToPerformancesLayer extends TrueSkillFactorGraphLayer
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private function createLikelihood(KeyedVariable $playerSkill, KeyedVariable $playerPerformance): GaussianLikelihoodFactor
 | 
			
		||||
    private function createLikelihood(Variable $playerSkill, Variable $playerPerformance): GaussianLikelihoodFactor
 | 
			
		||||
    {
 | 
			
		||||
        return new GaussianLikelihoodFactor(
 | 
			
		||||
            BasicMath::square($this->getParentFactorGraph()->getGameInfo()->getBeta()),
 | 
			
		||||
 
 | 
			
		||||
@@ -12,8 +12,10 @@ use DNW\Skills\GameInfo;
 | 
			
		||||
use DNW\Skills\Numerics\GaussianDistribution;
 | 
			
		||||
use DNW\Skills\Rating;
 | 
			
		||||
use DNW\Skills\Team;
 | 
			
		||||
use DNW\Skills\Player;
 | 
			
		||||
use DNW\Skills\RatingContainer;
 | 
			
		||||
use DNW\Skills\FactorGraphs\FactorGraphLayer;
 | 
			
		||||
use DNW\Skills\FactorGraphs\KeyedVariable;
 | 
			
		||||
use DNW\Skills\TrueSkill\Layers\IteratedTeamDifferencesInnerLayer;
 | 
			
		||||
use DNW\Skills\TrueSkill\Layers\PlayerPerformancesToTeamPerformancesLayer;
 | 
			
		||||
use DNW\Skills\TrueSkill\Layers\PlayerPriorValuesToSkillsLayer;
 | 
			
		||||
@@ -132,7 +134,7 @@ class TrueSkillFactorGraph extends FactorGraph
 | 
			
		||||
        $priorLayerOutputVariablesGroups = $this->priorLayer->getOutputVariablesGroups();
 | 
			
		||||
        foreach ($priorLayerOutputVariablesGroups as $currentTeam) {
 | 
			
		||||
            foreach ($currentTeam as $currentPlayer) {
 | 
			
		||||
                $localCurrentPlayer = $currentPlayer->getKey();
 | 
			
		||||
                $localCurrentPlayer = ($currentPlayer instanceof KeyedVariable) ? $currentPlayer->getKey() : new Player("");
 | 
			
		||||
                $newRating = new Rating(
 | 
			
		||||
                    $currentPlayer->getValue()->getMean(),
 | 
			
		||||
                    $currentPlayer->getValue()->getStandardDeviation()
 | 
			
		||||
 
 | 
			
		||||
@@ -40,7 +40,6 @@ class TwoPlayerTrueSkillCalculator extends SkillCalculator
 | 
			
		||||
    ): RatingContainer
 | 
			
		||||
    {
 | 
			
		||||
        // Basic argument checking
 | 
			
		||||
        Guard::argumentNotNull($gameInfo, 'gameInfo');
 | 
			
		||||
        $this->validateTeamCountAndPlayersCountPerTeam($teams);
 | 
			
		||||
 | 
			
		||||
        // Make sure things are in order
 | 
			
		||||
@@ -143,7 +142,6 @@ class TwoPlayerTrueSkillCalculator extends SkillCalculator
 | 
			
		||||
     */
 | 
			
		||||
    public function calculateMatchQuality(GameInfo $gameInfo, array $teams): float
 | 
			
		||||
    {
 | 
			
		||||
        Guard::argumentNotNull($gameInfo, 'gameInfo');
 | 
			
		||||
        $this->validateTeamCountAndPlayersCountPerTeam($teams);
 | 
			
		||||
 | 
			
		||||
        $team1 = $teams[0];
 | 
			
		||||
 
 | 
			
		||||
@@ -34,7 +34,6 @@ class TwoTeamTrueSkillCalculator extends SkillCalculator
 | 
			
		||||
     */
 | 
			
		||||
    public function calculateNewRatings(GameInfo $gameInfo, array $teams, array $teamRanks): RatingContainer
 | 
			
		||||
    {
 | 
			
		||||
        Guard::argumentNotNull($gameInfo, 'gameInfo');
 | 
			
		||||
        $this->validateTeamCountAndPlayersCountPerTeam($teams);
 | 
			
		||||
 | 
			
		||||
        RankSorter::sort($teams, $teamRanks);
 | 
			
		||||
@@ -150,7 +149,6 @@ class TwoTeamTrueSkillCalculator extends SkillCalculator
 | 
			
		||||
     */
 | 
			
		||||
    public function calculateMatchQuality(GameInfo $gameInfo, array $teams): float
 | 
			
		||||
    {
 | 
			
		||||
        Guard::argumentNotNull($gameInfo, 'gameInfo');
 | 
			
		||||
        $this->validateTeamCountAndPlayersCountPerTeam($teams);
 | 
			
		||||
 | 
			
		||||
        // We've verified that there's just two teams
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user