mirror of
https://github.com/furyfire/trueskill.git
synced 2025-01-16 01:47:39 +00:00
Start of journey to actually give real names to factor graph variables using more PHP style
This commit is contained in:
@ -14,17 +14,17 @@ class VariableFactory
|
|||||||
$this->_variablePriorInitializer = &$variablePriorInitializer;
|
$this->_variablePriorInitializer = &$variablePriorInitializer;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function createBasicVariable()
|
public function createBasicVariable($name)
|
||||||
{
|
{
|
||||||
$initializer = $this->_variablePriorInitializer;
|
$initializer = $this->_variablePriorInitializer;
|
||||||
$newVar = new Variable("variable", $initializer());
|
$newVar = new Variable($name, $initializer());
|
||||||
return $newVar;
|
return $newVar;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function createKeyedVariable($key)
|
public function createKeyedVariable($key, $name)
|
||||||
{
|
{
|
||||||
$initializer = $this->_variablePriorInitializer;
|
$initializer = $this->_variablePriorInitializer;
|
||||||
$newVar = new KeyedVariable($key, "key variable", $initializer());
|
$newVar = new KeyedVariable($key, $name, $initializer());
|
||||||
return $newVar;
|
return $newVar;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -71,7 +71,7 @@ class Player implements ISupportPartialPlay, ISupportPartialUpdate
|
|||||||
{
|
{
|
||||||
if ($this->_Id != null)
|
if ($this->_Id != null)
|
||||||
{
|
{
|
||||||
return $this->_Id;
|
return (string)$this->_Id;
|
||||||
}
|
}
|
||||||
|
|
||||||
return parent::__toString();
|
return parent::__toString();
|
||||||
|
@ -227,9 +227,44 @@ class GaussianWeightedSumFactor extends GaussianFactor
|
|||||||
$updatedVariables);
|
$updatedVariables);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function createName($sumVariable, $variablesToSum, $variableWeights)
|
private static function createName($sumVariable, $variablesToSum, $weights)
|
||||||
{
|
{
|
||||||
return "TODO";
|
// TODO: Perf? Use PHP equivalent of StringBuilder? implode on arrays?
|
||||||
|
$result = (string)$sumVariable;
|
||||||
|
$result .= ' = ';
|
||||||
|
|
||||||
|
$totalVars = count($variablesToSum);
|
||||||
|
for($i = 0; $i < $totalVars; $i++)
|
||||||
|
{
|
||||||
|
$isFirst = ($i == 0);
|
||||||
|
|
||||||
|
if($isFirst && ($weights[$i] < 0))
|
||||||
|
{
|
||||||
|
$result .= '-';
|
||||||
|
}
|
||||||
|
|
||||||
|
$absValue = sprintf("%.2f", \abs($weights[$i])); // 0.00?
|
||||||
|
$result .= $absValue;
|
||||||
|
$result .= "*[";
|
||||||
|
$result .= (string)$variablesToSum[$i];
|
||||||
|
$result .= ']';
|
||||||
|
|
||||||
|
$isLast = ($i == ($totalVars - 1));
|
||||||
|
|
||||||
|
if(!$isLast)
|
||||||
|
{
|
||||||
|
if($weights[$i + 1] >= 0)
|
||||||
|
{
|
||||||
|
$result .= ' + ';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$result .= ' - ';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ class PlayerPerformancesToTeamPerformancesLayer extends TrueSkillFactorGraphLaye
|
|||||||
{
|
{
|
||||||
foreach ($this->getInputVariablesGroups() as $currentTeam)
|
foreach ($this->getInputVariablesGroups() as $currentTeam)
|
||||||
{
|
{
|
||||||
$teamPerformance = &$this->createOutputVariable($currentTeam);
|
$teamPerformance = $this->createOutputVariable($currentTeam);
|
||||||
$newSumFactor = $this->createPlayerToTeamSumFactor($currentTeam, $teamPerformance);
|
$newSumFactor = $this->createPlayerToTeamSumFactor($currentTeam, $teamPerformance);
|
||||||
$this->addLayerFactor($newSumFactor);
|
$this->addLayerFactor($newSumFactor);
|
||||||
|
|
||||||
@ -83,9 +83,14 @@ class PlayerPerformancesToTeamPerformancesLayer extends TrueSkillFactorGraphLaye
|
|||||||
|
|
||||||
private function createOutputVariable(&$team)
|
private function createOutputVariable(&$team)
|
||||||
{
|
{
|
||||||
///$teamMemberNames = String.Join(", ", team.Select(teamMember => teamMember.Key.ToString()).ToArray());
|
$memberNames = \array_map(function ($currentPlayer)
|
||||||
$teamMemberNames = "TODO";
|
{
|
||||||
return $this->getParentFactorGraph()->getVariableFactory()->createBasicVariable("Team[{0}]'s performance", $teamMemberNames);
|
return (string)($currentPlayer->getKey());
|
||||||
|
},
|
||||||
|
$team);
|
||||||
|
|
||||||
|
$teamMemberNames = \join(", ", $memberNames);
|
||||||
|
return $this->getParentFactorGraph()->getVariableFactory()->createBasicVariable("Team[" . $teamMemberNames . "]'s performance");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ class PlayerPriorValuesToSkillsLayer extends TrueSkillFactorGraphLayer
|
|||||||
{
|
{
|
||||||
$parentFactorGraph = $this->getParentFactorGraph();
|
$parentFactorGraph = $this->getParentFactorGraph();
|
||||||
$variableFactory = $parentFactorGraph->getVariableFactory();
|
$variableFactory = $parentFactorGraph->getVariableFactory();
|
||||||
return $variableFactory->createKeyedVariable($key, "{0}'s skill", $key);
|
return $variableFactory->createKeyedVariable($key, $key . "'s skill");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ class PlayerSkillsToPerformancesLayer extends TrueSkillFactorGraphLayer
|
|||||||
|
|
||||||
private function createOutputVariable(&$key)
|
private function createOutputVariable(&$key)
|
||||||
{
|
{
|
||||||
return $this->getParentFactorGraph()->getVariableFactory()->createKeyedVariable($key, "{0}'s performance", $key);
|
return $this->getParentFactorGraph()->getVariableFactory()->createKeyedVariable($key, $key . "'s performance");
|
||||||
}
|
}
|
||||||
|
|
||||||
public function createPriorSchedule()
|
public function createPriorSchedule()
|
||||||
|
Reference in New Issue
Block a user