mirror of
https://github.com/furyfire/trueskill.git
synced 2025-04-18 20:04:28 +00:00
Pint applied for formatting
This commit is contained in:
@ -1,15 +1,18 @@
|
||||
<?php namespace DNW\Skills\TrueSkill\Layers;
|
||||
<?php
|
||||
|
||||
namespace DNW\Skills\TrueSkill\Layers;
|
||||
|
||||
use Exception;
|
||||
use DNW\Skills\FactorGraphs\ScheduleLoop;
|
||||
use DNW\Skills\FactorGraphs\ScheduleSequence;
|
||||
use DNW\Skills\FactorGraphs\ScheduleStep;
|
||||
use DNW\Skills\TrueSkill\TrueSkillFactorGraph;
|
||||
use Exception;
|
||||
|
||||
// The whole purpose of this is to do a loop on the bottom
|
||||
class IteratedTeamDifferencesInnerLayer extends TrueSkillFactorGraphLayer
|
||||
{
|
||||
private $_TeamDifferencesComparisonLayer;
|
||||
|
||||
private $_TeamPerformancesToTeamPerformanceDifferencesLayer;
|
||||
|
||||
public function __construct(TrueSkillFactorGraph $parentGraph,
|
||||
@ -65,16 +68,16 @@ class IteratedTeamDifferencesInnerLayer extends TrueSkillFactorGraphLayer
|
||||
$lastDifferencesFactor = $localFactors[$totalTeamDifferences - 1];
|
||||
|
||||
$innerSchedule = new ScheduleSequence(
|
||||
"inner schedule",
|
||||
array(
|
||||
'inner schedule',
|
||||
[
|
||||
$loop,
|
||||
new ScheduleStep(
|
||||
"teamPerformanceToPerformanceDifferenceFactors[0] @ 1",
|
||||
'teamPerformanceToPerformanceDifferenceFactors[0] @ 1',
|
||||
$firstDifferencesFactor, 1),
|
||||
new ScheduleStep(
|
||||
sprintf("teamPerformanceToPerformanceDifferenceFactors[teamTeamDifferences = %d - 1] @ 2", $totalTeamDifferences),
|
||||
$lastDifferencesFactor, 2)
|
||||
)
|
||||
sprintf('teamPerformanceToPerformanceDifferenceFactors[teamTeamDifferences = %d - 1] @ 2', $totalTeamDifferences),
|
||||
$lastDifferencesFactor, 2),
|
||||
]
|
||||
);
|
||||
|
||||
return $innerSchedule;
|
||||
@ -87,27 +90,27 @@ class IteratedTeamDifferencesInnerLayer extends TrueSkillFactorGraphLayer
|
||||
|
||||
$firstPerfToTeamDiff = $teamPerformancesToTeamPerformanceDifferencesLayerLocalFactors[0];
|
||||
$firstTeamDiffComparison = $teamDifferencesComparisonLayerLocalFactors[0];
|
||||
$itemsToSequence = array(
|
||||
$itemsToSequence = [
|
||||
new ScheduleStep(
|
||||
"send team perf to perf differences",
|
||||
'send team perf to perf differences',
|
||||
$firstPerfToTeamDiff,
|
||||
0),
|
||||
new ScheduleStep(
|
||||
"send to greater than or within factor",
|
||||
'send to greater than or within factor',
|
||||
$firstTeamDiffComparison,
|
||||
0)
|
||||
);
|
||||
0),
|
||||
];
|
||||
|
||||
return $this->scheduleSequence(
|
||||
$itemsToSequence,
|
||||
"loop of just two teams inner sequence");
|
||||
'loop of just two teams inner sequence');
|
||||
}
|
||||
|
||||
private function createMultipleTeamInnerPriorLoopSchedule()
|
||||
{
|
||||
$totalTeamDifferences = count($this->_TeamPerformancesToTeamPerformanceDifferencesLayer->getLocalFactors());
|
||||
|
||||
$forwardScheduleList = array();
|
||||
$forwardScheduleList = [];
|
||||
|
||||
for ($i = 0; $i < $totalTeamDifferences - 1; $i++) {
|
||||
$teamPerformancesToTeamPerformanceDifferencesLayerLocalFactors = $this->_TeamPerformancesToTeamPerformanceDifferencesLayer->getLocalFactors();
|
||||
@ -118,24 +121,24 @@ class IteratedTeamDifferencesInnerLayer extends TrueSkillFactorGraphLayer
|
||||
|
||||
$currentForwardSchedulePiece =
|
||||
$this->scheduleSequence(
|
||||
array(
|
||||
[
|
||||
new ScheduleStep(
|
||||
sprintf("team perf to perf diff %d", $i),
|
||||
sprintf('team perf to perf diff %d', $i),
|
||||
$currentTeamPerfToTeamPerfDiff, 0),
|
||||
new ScheduleStep(
|
||||
sprintf("greater than or within result factor %d", $i),
|
||||
sprintf('greater than or within result factor %d', $i),
|
||||
$currentTeamDiffComparison, 0),
|
||||
new ScheduleStep(
|
||||
sprintf("team perf to perf diff factors [%d], 2", $i),
|
||||
$currentTeamPerfToTeamPerfDiff, 2)
|
||||
), sprintf("current forward schedule piece %d", $i));
|
||||
sprintf('team perf to perf diff factors [%d], 2', $i),
|
||||
$currentTeamPerfToTeamPerfDiff, 2),
|
||||
], sprintf('current forward schedule piece %d', $i));
|
||||
|
||||
$forwardScheduleList[] = $currentForwardSchedulePiece;
|
||||
}
|
||||
|
||||
$forwardSchedule = new ScheduleSequence("forward schedule", $forwardScheduleList);
|
||||
$forwardSchedule = new ScheduleSequence('forward schedule', $forwardScheduleList);
|
||||
|
||||
$backwardScheduleList = array();
|
||||
$backwardScheduleList = [];
|
||||
|
||||
for ($i = 0; $i < $totalTeamDifferences - 1; $i++) {
|
||||
$teamPerformancesToTeamPerformanceDifferencesLayerLocalFactors = $this->_TeamPerformancesToTeamPerformanceDifferencesLayer->getLocalFactors();
|
||||
@ -146,35 +149,35 @@ class IteratedTeamDifferencesInnerLayer extends TrueSkillFactorGraphLayer
|
||||
$performancesToDifferencesFactor = $teamPerformancesToTeamPerformanceDifferencesLayerLocalFactors[$totalTeamDifferences - 1 - $i];
|
||||
|
||||
$currentBackwardSchedulePiece = new ScheduleSequence(
|
||||
"current backward schedule piece",
|
||||
array(
|
||||
'current backward schedule piece',
|
||||
[
|
||||
new ScheduleStep(
|
||||
sprintf("teamPerformanceToPerformanceDifferenceFactors[totalTeamDifferences - 1 - %d] @ 0", $i),
|
||||
sprintf('teamPerformanceToPerformanceDifferenceFactors[totalTeamDifferences - 1 - %d] @ 0', $i),
|
||||
$differencesFactor, 0),
|
||||
new ScheduleStep(
|
||||
sprintf("greaterThanOrWithinResultFactors[totalTeamDifferences - 1 - %d] @ 0", $i),
|
||||
sprintf('greaterThanOrWithinResultFactors[totalTeamDifferences - 1 - %d] @ 0', $i),
|
||||
$comparisonFactor, 0),
|
||||
new ScheduleStep(
|
||||
sprintf("teamPerformanceToPerformanceDifferenceFactors[totalTeamDifferences - 1 - %d] @ 1", $i),
|
||||
$performancesToDifferencesFactor, 1)
|
||||
));
|
||||
sprintf('teamPerformanceToPerformanceDifferenceFactors[totalTeamDifferences - 1 - %d] @ 1', $i),
|
||||
$performancesToDifferencesFactor, 1),
|
||||
]);
|
||||
$backwardScheduleList[] = $currentBackwardSchedulePiece;
|
||||
}
|
||||
|
||||
$backwardSchedule = new ScheduleSequence("backward schedule", $backwardScheduleList);
|
||||
$backwardSchedule = new ScheduleSequence('backward schedule', $backwardScheduleList);
|
||||
|
||||
$forwardBackwardScheduleToLoop =
|
||||
new ScheduleSequence(
|
||||
"forward Backward Schedule To Loop",
|
||||
array($forwardSchedule, $backwardSchedule));
|
||||
'forward Backward Schedule To Loop',
|
||||
[$forwardSchedule, $backwardSchedule]);
|
||||
|
||||
$initialMaxDelta = 0.0001;
|
||||
|
||||
$loop = new ScheduleLoop(
|
||||
sprintf("loop with max delta of %f", $initialMaxDelta),
|
||||
sprintf('loop with max delta of %f', $initialMaxDelta),
|
||||
$forwardBackwardScheduleToLoop,
|
||||
$initialMaxDelta);
|
||||
|
||||
return $loop;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
<?php namespace DNW\Skills\TrueSkill\Layers;
|
||||
<?php
|
||||
|
||||
namespace DNW\Skills\TrueSkill\Layers;
|
||||
|
||||
use DNW\Skills\PartialPlay;
|
||||
use DNW\Skills\FactorGraphs\ScheduleLoop;
|
||||
use DNW\Skills\FactorGraphs\ScheduleSequence;
|
||||
use DNW\Skills\FactorGraphs\ScheduleStep;
|
||||
use DNW\Skills\PartialPlay;
|
||||
use DNW\Skills\TrueSkill\Factors\GaussianWeightedSumFactor;
|
||||
use DNW\Skills\TrueSkill\TrueSkillFactorGraph;
|
||||
|
||||
@ -26,7 +26,7 @@ class PlayerPerformancesToTeamPerformancesLayer extends TrueSkillFactorGraphLaye
|
||||
|
||||
// REVIEW: Does it make sense to have groups of one?
|
||||
$outputVariablesGroups = &$this->getOutputVariablesGroups();
|
||||
$outputVariablesGroups[] = array($teamPerformance);
|
||||
$outputVariablesGroups[] = [$teamPerformance];
|
||||
}
|
||||
}
|
||||
|
||||
@ -37,10 +37,11 @@ class PlayerPerformancesToTeamPerformancesLayer extends TrueSkillFactorGraphLaye
|
||||
$sequence = $this->scheduleSequence(
|
||||
array_map(
|
||||
function ($weightedSumFactor) {
|
||||
return new ScheduleStep("Perf to Team Perf Step", $weightedSumFactor, 0);
|
||||
return new ScheduleStep('Perf to Team Perf Step', $weightedSumFactor, 0);
|
||||
},
|
||||
$localFactors),
|
||||
"all player perf to team perf schedule");
|
||||
'all player perf to team perf schedule');
|
||||
|
||||
return $sequence;
|
||||
}
|
||||
|
||||
@ -49,6 +50,7 @@ class PlayerPerformancesToTeamPerformancesLayer extends TrueSkillFactorGraphLaye
|
||||
$weights = array_map(
|
||||
function ($v) {
|
||||
$player = $v->getKey();
|
||||
|
||||
return PartialPlay::getPartialPlayPercentage($player);
|
||||
},
|
||||
$teamMembers);
|
||||
@ -57,32 +59,33 @@ class PlayerPerformancesToTeamPerformancesLayer extends TrueSkillFactorGraphLaye
|
||||
$sumVariable,
|
||||
$teamMembers,
|
||||
$weights);
|
||||
|
||||
}
|
||||
|
||||
public function createPosteriorSchedule()
|
||||
{
|
||||
$allFactors = array();
|
||||
$allFactors = [];
|
||||
$localFactors = $this->getLocalFactors();
|
||||
foreach ($localFactors as $currentFactor) {
|
||||
$localCurrentFactor = $currentFactor;
|
||||
$numberOfMessages = $localCurrentFactor->getNumberOfMessages();
|
||||
for ($currentIteration = 1; $currentIteration < $numberOfMessages; $currentIteration++) {
|
||||
$allFactors[] = new ScheduleStep("team sum perf @" . $currentIteration,
|
||||
$allFactors[] = new ScheduleStep('team sum perf @'.$currentIteration,
|
||||
$localCurrentFactor, $currentIteration);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->scheduleSequence($allFactors, "all of the team's sum iterations");
|
||||
}
|
||||
|
||||
private function createOutputVariable($team)
|
||||
{
|
||||
$memberNames = array_map(function ($currentPlayer) {
|
||||
return (string)($currentPlayer->getKey());
|
||||
return (string) ($currentPlayer->getKey());
|
||||
}, $team);
|
||||
|
||||
$teamMemberNames = \join(", ", $memberNames);
|
||||
$outputVariable = $this->getParentFactorGraph()->getVariableFactory()->createBasicVariable("Team[" . $teamMemberNames . "]'s performance");
|
||||
$teamMemberNames = \implode(', ', $memberNames);
|
||||
$outputVariable = $this->getParentFactorGraph()->getVariableFactory()->createBasicVariable('Team['.$teamMemberNames."]'s performance");
|
||||
|
||||
return $outputVariable;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,13 @@
|
||||
<?php namespace DNW\Skills\TrueSkill\Layers;
|
||||
<?php
|
||||
|
||||
namespace DNW\Skills\TrueSkill\Layers;
|
||||
|
||||
use DNW\Skills\Numerics\BasicMath;
|
||||
use DNW\Skills\Rating;
|
||||
use DNW\Skills\FactorGraphs\ScheduleStep;
|
||||
use DNW\Skills\FactorGraphs\Variable;
|
||||
use DNW\Skills\TrueSkill\TrueSkillFactorGraph;
|
||||
use DNW\Skills\Numerics\BasicMath;
|
||||
use DNW\Skills\Rating;
|
||||
use DNW\Skills\TrueSkill\Factors\GaussianPriorFactor;
|
||||
use DNW\Skills\TrueSkill\TrueSkillFactorGraph;
|
||||
|
||||
// We intentionally have no Posterior schedule since the only purpose here is to
|
||||
// start the process.
|
||||
@ -24,7 +26,7 @@ class PlayerPriorValuesToSkillsLayer extends TrueSkillFactorGraphLayer
|
||||
$teams = $this->_teams;
|
||||
foreach ($teams as $currentTeam) {
|
||||
$localCurrentTeam = $currentTeam;
|
||||
$currentTeamSkills = array();
|
||||
$currentTeamSkills = [];
|
||||
|
||||
$currentTeamAllPlayers = $localCurrentTeam->getAllPlayers();
|
||||
foreach ($currentTeamAllPlayers as $currentTeamPlayer) {
|
||||
@ -44,13 +46,14 @@ class PlayerPriorValuesToSkillsLayer extends TrueSkillFactorGraphLayer
|
||||
public function createPriorSchedule()
|
||||
{
|
||||
$localFactors = $this->getLocalFactors();
|
||||
|
||||
return $this->scheduleSequence(
|
||||
array_map(
|
||||
function ($prior) {
|
||||
return new ScheduleStep("Prior to Skill Step", $prior, 0);
|
||||
return new ScheduleStep('Prior to Skill Step', $prior, 0);
|
||||
},
|
||||
$localFactors),
|
||||
"All priors");
|
||||
'All priors');
|
||||
}
|
||||
|
||||
private function createPriorFactor($player, Rating $priorRating, Variable $skillsVariable)
|
||||
@ -67,7 +70,8 @@ class PlayerPriorValuesToSkillsLayer extends TrueSkillFactorGraphLayer
|
||||
{
|
||||
$parentFactorGraph = $this->getParentFactorGraph();
|
||||
$variableFactory = $parentFactorGraph->getVariableFactory();
|
||||
$skillOutputVariable = $variableFactory->createKeyedVariable($key, $key . "'s skill");
|
||||
$skillOutputVariable = $variableFactory->createKeyedVariable($key, $key."'s skill");
|
||||
|
||||
return $skillOutputVariable;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,12 @@
|
||||
<?php namespace DNW\Skills\TrueSkill\Layers;
|
||||
<?php
|
||||
|
||||
namespace DNW\Skills\TrueSkill\Layers;
|
||||
|
||||
use DNW\Skills\FactorGraphs\ScheduleStep;
|
||||
use DNW\Skills\FactorGraphs\KeyedVariable;
|
||||
use DNW\Skills\FactorGraphs\ScheduleStep;
|
||||
use DNW\Skills\Numerics\BasicMath;
|
||||
use DNW\Skills\TrueSkill\TrueSkillFactorGraph;
|
||||
use DNW\Skills\TrueSkill\Factors\GaussianLikelihoodFactor;
|
||||
use DNW\Skills\TrueSkill\TrueSkillFactorGraph;
|
||||
|
||||
class PlayerSkillsToPerformancesLayer extends TrueSkillFactorGraphLayer
|
||||
{
|
||||
@ -19,7 +21,7 @@ class PlayerSkillsToPerformancesLayer extends TrueSkillFactorGraphLayer
|
||||
$outputVariablesGroups = &$this->getOutputVariablesGroups();
|
||||
|
||||
foreach ($inputVariablesGroups as $currentTeam) {
|
||||
$currentTeamPlayerPerformances = array();
|
||||
$currentTeamPlayerPerformances = [];
|
||||
|
||||
foreach ($currentTeam as $playerSkillVariable) {
|
||||
$localPlayerSkillVariable = $playerSkillVariable;
|
||||
@ -45,31 +47,34 @@ class PlayerSkillsToPerformancesLayer extends TrueSkillFactorGraphLayer
|
||||
|
||||
private function createOutputVariable($key)
|
||||
{
|
||||
$outputVariable = $this->getParentFactorGraph()->getVariableFactory()->createKeyedVariable($key, $key . "'s performance");
|
||||
$outputVariable = $this->getParentFactorGraph()->getVariableFactory()->createKeyedVariable($key, $key."'s performance");
|
||||
|
||||
return $outputVariable;
|
||||
}
|
||||
|
||||
public function createPriorSchedule()
|
||||
{
|
||||
$localFactors = $this->getLocalFactors();
|
||||
|
||||
return $this->scheduleSequence(
|
||||
array_map(
|
||||
function ($likelihood) {
|
||||
return new ScheduleStep("Skill to Perf step", $likelihood, 0);
|
||||
return new ScheduleStep('Skill to Perf step', $likelihood, 0);
|
||||
},
|
||||
$localFactors),
|
||||
"All skill to performance sending");
|
||||
'All skill to performance sending');
|
||||
}
|
||||
|
||||
public function createPosteriorSchedule()
|
||||
{
|
||||
$localFactors = $this->getLocalFactors();
|
||||
|
||||
return $this->scheduleSequence(
|
||||
array_map(
|
||||
function ($likelihood) {
|
||||
return new ScheduleStep("name", $likelihood, 1);
|
||||
return new ScheduleStep('name', $likelihood, 1);
|
||||
},
|
||||
$localFactors),
|
||||
"All skill to performance sending");
|
||||
'All skill to performance sending');
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,16 @@
|
||||
<?php namespace DNW\Skills\TrueSkill\Layers;
|
||||
<?php
|
||||
|
||||
namespace DNW\Skills\TrueSkill\Layers;
|
||||
|
||||
use DNW\Skills\TrueSkill\DrawMargin;
|
||||
use DNW\Skills\TrueSkill\TrueSkillFactorGraph;
|
||||
use DNW\Skills\TrueSkill\Factors\GaussianGreaterThanFactor;
|
||||
use DNW\Skills\TrueSkill\Factors\GaussianWithinFactor;
|
||||
use DNW\Skills\TrueSkill\TrueSkillFactorGraph;
|
||||
|
||||
class TeamDifferencesComparisonLayer extends TrueSkillFactorGraphLayer
|
||||
{
|
||||
private $_epsilon;
|
||||
|
||||
private $_teamRanks;
|
||||
|
||||
public function __construct(TrueSkillFactorGraph $parentGraph, array $teamRanks)
|
||||
@ -35,4 +38,4 @@ class TeamDifferencesComparisonLayer extends TrueSkillFactorGraphLayer
|
||||
$this->addLayerFactor($factor);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,10 @@
|
||||
<?php namespace DNW\Skills\TrueSkill\Layers;
|
||||
<?php
|
||||
|
||||
namespace DNW\Skills\TrueSkill\Layers;
|
||||
|
||||
use DNW\Skills\FactorGraphs\Variable;
|
||||
use DNW\Skills\TrueSkill\TrueSkillFactorGraph;
|
||||
use DNW\Skills\TrueSkill\Factors\GaussianWeightedSumFactor;
|
||||
use DNW\Skills\TrueSkill\TrueSkillFactorGraph;
|
||||
|
||||
class TeamPerformancesToTeamPerformanceDifferencesLayer extends TrueSkillFactorGraphLayer
|
||||
{
|
||||
@ -17,8 +19,7 @@ class TeamPerformancesToTeamPerformanceDifferencesLayer extends TrueSkillFactorG
|
||||
$inputVariablesGroupsCount = count($inputVariablesGroups);
|
||||
$outputVariablesGroup = &$this->getOutputVariablesGroups();
|
||||
|
||||
for ($i = 0; $i < $inputVariablesGroupsCount - 1; $i++)
|
||||
{
|
||||
for ($i = 0; $i < $inputVariablesGroupsCount - 1; $i++) {
|
||||
$strongerTeam = $inputVariablesGroups[$i][0];
|
||||
$weakerTeam = $inputVariablesGroups[$i + 1][0];
|
||||
|
||||
@ -27,7 +28,7 @@ class TeamPerformancesToTeamPerformanceDifferencesLayer extends TrueSkillFactorG
|
||||
$this->addLayerFactor($newDifferencesFactor);
|
||||
|
||||
// REVIEW: Does it make sense to have groups of one?
|
||||
$outputVariablesGroup[] = array($currentDifference);
|
||||
$outputVariablesGroup[] = [$currentDifference];
|
||||
}
|
||||
}
|
||||
|
||||
@ -35,14 +36,16 @@ class TeamPerformancesToTeamPerformanceDifferencesLayer extends TrueSkillFactorG
|
||||
Variable $weakerTeam,
|
||||
Variable $output)
|
||||
{
|
||||
$teams = array($strongerTeam, $weakerTeam);
|
||||
$weights = array(1.0, -1.0);
|
||||
$teams = [$strongerTeam, $weakerTeam];
|
||||
$weights = [1.0, -1.0];
|
||||
|
||||
return new GaussianWeightedSumFactor($output, $teams, $weights);
|
||||
}
|
||||
|
||||
private function createOutputVariable()
|
||||
{
|
||||
$outputVariable = $this->getParentFactorGraph()->getVariableFactory()->createBasicVariable("Team performance difference");
|
||||
$outputVariable = $this->getParentFactorGraph()->getVariableFactory()->createBasicVariable('Team performance difference');
|
||||
|
||||
return $outputVariable;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,6 @@
|
||||
<?php namespace DNW\Skills\TrueSkill\Layers;
|
||||
<?php
|
||||
|
||||
namespace DNW\Skills\TrueSkill\Layers;
|
||||
|
||||
use DNW\Skills\FactorGraphs\FactorGraphLayer;
|
||||
use DNW\Skills\TrueSkill\TrueSkillFactorGraph;
|
||||
@ -9,4 +11,4 @@ abstract class TrueSkillFactorGraphLayer extends FactorGraphLayer
|
||||
{
|
||||
parent::__construct($parentGraph);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user