mirror of
				https://github.com/furyfire/trueskill.git
				synced 2025-11-04 10:12:28 +01:00 
			
		
		
		
	Initial pass at getting up to GaussianWeightedSum running
This commit is contained in:
		@@ -16,7 +16,8 @@ class VariableFactory
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    public function createBasicVariable()
 | 
					    public function createBasicVariable()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $newVar = new Variable($this->_variablePriorInitializer());
 | 
					        $initializer = $this->_variablePriorInitializer;
 | 
				
			||||||
 | 
					        $newVar = new Variable("variable", $initializer());
 | 
				
			||||||
        return $newVar;
 | 
					        return $newVar;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -14,7 +14,7 @@ class PartialPlay
 | 
				
			|||||||
            return 1.0;
 | 
					            return 1.0;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $partialPlayPercentage = $partialPlay->getPartialPlayPercentage();
 | 
					        $partialPlayPercentage = $player->getPartialPlayPercentage();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // HACK to get around bug near 0
 | 
					        // HACK to get around bug near 0
 | 
				
			||||||
        $smallestPercentage = 0.0001;
 | 
					        $smallestPercentage = 0.0001;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,15 +1,19 @@
 | 
				
			|||||||
<?php
 | 
					<?php
 | 
				
			||||||
namespace Moserware\Skills\TrueSkill\Layers;
 | 
					namespace Moserware\Skills\TrueSkill\Layers;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					require_once(dirname(__FILE__) . "/../../PartialPlay.php");
 | 
				
			||||||
require_once(dirname(__FILE__) . "/../../FactorGraphs/Schedule.php");
 | 
					require_once(dirname(__FILE__) . "/../../FactorGraphs/Schedule.php");
 | 
				
			||||||
 | 
					require_once(dirname(__FILE__) . "/../Factors/GaussianWeightedSumFactor.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\PartialPlay;
 | 
				
			||||||
use Moserware\Skills\FactorGraphs\ScheduleLoop;
 | 
					use Moserware\Skills\FactorGraphs\ScheduleLoop;
 | 
				
			||||||
use Moserware\Skills\FactorGraphs\ScheduleSequence;
 | 
					use Moserware\Skills\FactorGraphs\ScheduleSequence;
 | 
				
			||||||
use Moserware\Skills\FactorGraphs\ScheduleStep;
 | 
					use Moserware\Skills\FactorGraphs\ScheduleStep;
 | 
				
			||||||
 | 
					use Moserware\Skills\TrueSkill\Factors\GaussianWeightedSumFactor;
 | 
				
			||||||
use Moserware\Skills\TrueSkill\TrueSkillFactorGraph;
 | 
					use Moserware\Skills\TrueSkill\TrueSkillFactorGraph;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class PlayerPerformancesToTeamPerformancesLayer extends TrueSkillFactorGraphLayer
 | 
					class PlayerPerformancesToTeamPerformancesLayer extends TrueSkillFactorGraphLayer
 | 
				
			||||||
@@ -46,15 +50,17 @@ class PlayerPerformancesToTeamPerformancesLayer extends TrueSkillFactorGraphLaye
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    protected function createPlayerToTeamSumFactor(&$teamMembers, &$sumVariable)
 | 
					    protected function createPlayerToTeamSumFactor(&$teamMembers, &$sumVariable)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        return new GaussianWeightedSumFactor(
 | 
					        $weights = array_map(
 | 
				
			||||||
                $sumVariable,
 | 
					 | 
				
			||||||
                $teamMembers,
 | 
					 | 
				
			||||||
                array_map(
 | 
					 | 
				
			||||||
                        function($v)
 | 
					                        function($v)
 | 
				
			||||||
                        {
 | 
					                        {
 | 
				
			||||||
                            return PartialPlay::getPartialPlayPercentage($v->getKey());
 | 
					                            return PartialPlay::getPartialPlayPercentage($v->getKey());
 | 
				
			||||||
                        },
 | 
					                        },
 | 
				
			||||||
                        $teamMembers));
 | 
					                        $teamMembers);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return new GaussianWeightedSumFactor(
 | 
				
			||||||
 | 
					                $sumVariable,
 | 
				
			||||||
 | 
					                $teamMembers,
 | 
				
			||||||
 | 
					                $weights);
 | 
				
			||||||
                                                 
 | 
					                                                 
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -28,11 +28,11 @@ class PlayerSkillsToPerformancesLayer extends TrueSkillFactorGraphLayer
 | 
				
			|||||||
            {
 | 
					            {
 | 
				
			||||||
                $playerPerformance = $this->createOutputVariable($playerSkillVariable->getKey());
 | 
					                $playerPerformance = $this->createOutputVariable($playerSkillVariable->getKey());
 | 
				
			||||||
                $this->addLayerFactor($this->createLikelihood($playerSkillVariable, $playerPerformance));
 | 
					                $this->addLayerFactor($this->createLikelihood($playerSkillVariable, $playerPerformance));
 | 
				
			||||||
                $currentTeamPlayerPerformances[] = $playerPerformance;
 | 
					                $currentTeamPlayerPerformances[] = &$playerPerformance;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            
 | 
					            
 | 
				
			||||||
            $outputVariablesGroups = $this->getOutputVariablesGroups();
 | 
					            $outputVariablesGroups = &$this->getOutputVariablesGroups();
 | 
				
			||||||
            $outputVariablesGroups[] = $currentTeamPlayerPerformances;
 | 
					            $outputVariablesGroups[] = &$currentTeamPlayerPerformances;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -75,7 +75,7 @@ class TrueSkillFactorGraph extends FactorGraph
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            $currentLayer->buildLayer();
 | 
					            $currentLayer->buildLayer();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            $lastOutput = $currentLayer->getOutputVariablesGroups();
 | 
					            $lastOutput = &$currentLayer->getOutputVariablesGroups();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user