mirror of
https://github.com/furyfire/trueskill.git
synced 2025-01-16 01:47:39 +00:00
Fixed an array size issue because of ignored 0 value
This commit is contained in:
@ -63,7 +63,7 @@ abstract class Factor
|
|||||||
public function resetMarginals()
|
public function resetMarginals()
|
||||||
{
|
{
|
||||||
$allValues = &$this->_messageToVariableBinding->getAllValues();
|
$allValues = &$this->_messageToVariableBinding->getAllValues();
|
||||||
foreach ($allValues as $currentVariable)
|
foreach ($allValues as &$currentVariable)
|
||||||
{
|
{
|
||||||
$currentVariable->resetToPrior();
|
$currentVariable->resetToPrior();
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,8 @@ class ScheduleSequence extends Schedule
|
|||||||
$schedules = &$this->_schedules;
|
$schedules = &$this->_schedules;
|
||||||
foreach ($schedules as &$currentSchedule)
|
foreach ($schedules as &$currentSchedule)
|
||||||
{
|
{
|
||||||
$maxDelta = max($currentSchedule->visit($depth + 1, $maxDepth), $maxDelta);
|
$currentVisit = $currentSchedule->visit($depth + 1, $maxDepth);
|
||||||
|
$maxDelta = max($currentVisit, $maxDelta);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $maxDelta;
|
return $maxDelta;
|
||||||
|
@ -34,10 +34,9 @@ class GaussianWeightedSumFactor extends GaussianFactor
|
|||||||
|
|
||||||
// The first weights are a straightforward copy
|
// The first weights are a straightforward copy
|
||||||
// v_0 = a_1*v_1 + a_2*v_2 + ... + a_n * v_n
|
// v_0 = a_1*v_1 + a_2*v_2 + ... + a_n * v_n
|
||||||
$this->_weights[0] = array();
|
|
||||||
|
|
||||||
$variableWeightsLength = count($variableWeights);
|
$variableWeightsLength = count($variableWeights);
|
||||||
|
$this->_weights[0] = \array_fill(0, count($variableWeights), 0);
|
||||||
|
|
||||||
for($i = 0; $i < $variableWeightsLength; $i++)
|
for($i = 0; $i < $variableWeightsLength; $i++)
|
||||||
{
|
{
|
||||||
$weight = &$variableWeights[$i];
|
$weight = &$variableWeights[$i];
|
||||||
@ -53,7 +52,9 @@ class GaussianWeightedSumFactor extends GaussianFactor
|
|||||||
{
|
{
|
||||||
$this->_variableIndexOrdersForWeights[0][] = $i;
|
$this->_variableIndexOrdersForWeights[0][] = $i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$variableWeightsLength = count($variableWeights);
|
||||||
|
|
||||||
// The rest move the variables around and divide out the constant.
|
// The rest move the variables around and divide out the constant.
|
||||||
// For example:
|
// For example:
|
||||||
// v_1 = (-a_2 / a_1) * v_2 + (-a3/a1) * v_3 + ... + (1.0 / a_1) * v_0
|
// v_1 = (-a_2 / a_1) * v_2 + (-a3/a1) * v_3 + ... + (1.0 / a_1) * v_0
|
||||||
@ -61,19 +62,17 @@ class GaussianWeightedSumFactor extends GaussianFactor
|
|||||||
|
|
||||||
$weightsLength = $variableWeightsLength + 1;
|
$weightsLength = $variableWeightsLength + 1;
|
||||||
for ($weightsIndex = 1; $weightsIndex < $weightsLength; $weightsIndex++)
|
for ($weightsIndex = 1; $weightsIndex < $weightsLength; $weightsIndex++)
|
||||||
{
|
{
|
||||||
$currentWeights = array();
|
$currentWeights = \array_fill(0, $variableWeightsLength, 0);
|
||||||
|
|
||||||
$variableIndices = array();
|
$variableIndices = \array_fill(0, $variableWeightsLength + 1, 0);
|
||||||
$variableIndices[0] = $weightsIndex;
|
$variableIndices[0] = $weightsIndex;
|
||||||
|
|
||||||
$currentWeightsSquared = array();
|
$currentWeightsSquared = \array_fill(0, $variableWeightsLength, 0);
|
||||||
|
|
||||||
// keep a single variable to keep track of where we are in the array.
|
// keep a single variable to keep track of where we are in the array.
|
||||||
// This is helpful since we skip over one of the spots
|
// This is helpful since we skip over one of the spots
|
||||||
$currentDestinationWeightIndex = 0;
|
$currentDestinationWeightIndex = 0;
|
||||||
|
|
||||||
$variableWeightsLength = count($variableWeights);
|
|
||||||
|
|
||||||
for ($currentWeightSourceIndex = 0;
|
for ($currentWeightSourceIndex = 0;
|
||||||
$currentWeightSourceIndex < $variableWeightsLength;
|
$currentWeightSourceIndex < $variableWeightsLength;
|
||||||
|
@ -59,16 +59,19 @@ class IteratedTeamDifferencesInnerLayer extends TrueSkillFactorGraphLayer
|
|||||||
$totalTeams = $totalTeamDifferences + 1;
|
$totalTeams = $totalTeamDifferences + 1;
|
||||||
|
|
||||||
$localFactors = &$this->_TeamPerformancesToTeamPerformanceDifferencesLayer->getLocalFactors();
|
$localFactors = &$this->_TeamPerformancesToTeamPerformanceDifferencesLayer->getLocalFactors();
|
||||||
|
|
||||||
|
$firstDifferencesFactor = &$localFactors[0];
|
||||||
|
$lastDifferencesFactor = &$localFactors[$totalTeamDifferences - 1];
|
||||||
$innerSchedule = new ScheduleSequence(
|
$innerSchedule = new ScheduleSequence(
|
||||||
"inner schedule",
|
"inner schedule",
|
||||||
array(
|
array(
|
||||||
$loop,
|
$loop,
|
||||||
new ScheduleStep(
|
new ScheduleStep(
|
||||||
"teamPerformanceToPerformanceDifferenceFactors[0] @ 1",
|
"teamPerformanceToPerformanceDifferenceFactors[0] @ 1",
|
||||||
&$localFactors[0], 1),
|
$firstDifferencesFactor, 1),
|
||||||
new ScheduleStep(
|
new ScheduleStep(
|
||||||
sprintf("teamPerformanceToPerformanceDifferenceFactors[teamTeamDifferences = %d - 1] @ 2", $totalTeamDifferences),
|
sprintf("teamPerformanceToPerformanceDifferenceFactors[teamTeamDifferences = %d - 1] @ 2", $totalTeamDifferences),
|
||||||
&$localFactors[$totalTeamDifferences - 1], 2)
|
$lastDifferencesFactor, 2)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -25,9 +25,10 @@ class PlayerPerformancesToTeamPerformancesLayer extends TrueSkillFactorGraphLaye
|
|||||||
|
|
||||||
public function buildLayer()
|
public function buildLayer()
|
||||||
{
|
{
|
||||||
foreach ($this->getInputVariablesGroups() as $currentTeam)
|
$inputVariablesGroups = &$this->getInputVariablesGroups();
|
||||||
|
foreach ($inputVariablesGroups 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);
|
||||||
|
|
||||||
|
@ -29,9 +29,10 @@ class PlayerSkillsToPerformancesLayer extends TrueSkillFactorGraphLayer
|
|||||||
{
|
{
|
||||||
$currentTeamPlayerPerformances = array();
|
$currentTeamPlayerPerformances = array();
|
||||||
|
|
||||||
foreach ($currentTeam as $playerSkillVariable)
|
foreach ($currentTeam as &$playerSkillVariable)
|
||||||
{
|
{
|
||||||
$playerPerformance = $this->createOutputVariable($playerSkillVariable->getKey());
|
$currentPlayer = &$playerSkillVariable->getKey();
|
||||||
|
$playerPerformance = $this->createOutputVariable($currentPlayer);
|
||||||
$newLikelihoodFactor = $this->createLikelihood($playerSkillVariable, $playerPerformance);
|
$newLikelihoodFactor = $this->createLikelihood($playerSkillVariable, $playerPerformance);
|
||||||
$this->addLayerFactor($newLikelihoodFactor);
|
$this->addLayerFactor($newLikelihoodFactor);
|
||||||
$currentTeamPlayerPerformances[] = $playerPerformance;
|
$currentTeamPlayerPerformances[] = $playerPerformance;
|
||||||
|
@ -78,7 +78,7 @@ class TrueSkillFactorGraph extends FactorGraph
|
|||||||
|
|
||||||
$currentLayer->buildLayer();
|
$currentLayer->buildLayer();
|
||||||
|
|
||||||
$lastOutput = &$currentLayer->getOutputVariablesGroups();
|
$lastOutput = &$currentLayer->getOutputVariablesGroups();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user