Slight tweaks based off references and need for a RatingContainer

This commit is contained in:
Jeff Moser 2010-09-28 22:40:54 -04:00
parent a45a1c47da
commit 4c7cfef8d6
3 changed files with 13 additions and 8 deletions

@ -63,13 +63,11 @@ class GaussianWeightedSumFactor extends GaussianFactor
for ($weightsIndex = 1; $weightsIndex < $weightsLength; $weightsIndex++) for ($weightsIndex = 1; $weightsIndex < $weightsLength; $weightsIndex++)
{ {
$currentWeights = array(); $currentWeights = array();
$this->_weights[$weightsIndex] = &$currentWeights;
$variableIndices = array(); $variableIndices = array();
$variableIndices[0] = $weightsIndex; $variableIndices[0] = $weightsIndex;
$currentWeightsSquared = array(); $currentWeightsSquared = array();
$this->_weightsSquared[$weightsIndex] = &$currentWeightsSquared;
// 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
@ -112,7 +110,10 @@ class GaussianWeightedSumFactor extends GaussianFactor
$currentWeights[$currentDestinationWeightIndex] = $finalWeight; $currentWeights[$currentDestinationWeightIndex] = $finalWeight;
$currentWeightsSquared[$currentDestinationWeightIndex] = square($finalWeight); $currentWeightsSquared[$currentDestinationWeightIndex] = square($finalWeight);
$variableIndices[count($variableWeights)] = 0; $variableIndices[count($variableWeights)] = 0;
$this->_variableIndexOrdersForWeights[] = &$variableIndices; $this->_variableIndexOrdersForWeights[] = $variableIndices;
$this->_weights[$weightsIndex] = $currentWeights;
$this->_weightsSquared[$weightsIndex] = $currentWeightsSquared;
} }
$this->createVariableToMessageBinding($sumVariable); $this->createVariableToMessageBinding($sumVariable);

@ -29,7 +29,7 @@ class TeamPerformancesToTeamPerformanceDifferencesLayer extends TrueSkillFactorG
$weakerTeam = $inputVariablesGroups[$i + 1][0]; $weakerTeam = $inputVariablesGroups[$i + 1][0];
$currentDifference = &$this->createOutputVariable(); $currentDifference = &$this->createOutputVariable();
$newDifferencesFactor = &$this->createTeamPerformanceToDifferenceFactor($strongerTeam, $weakerTeam, $currentDifference); $newDifferencesFactor = $this->createTeamPerformanceToDifferenceFactor($strongerTeam, $weakerTeam, $currentDifference);
$this->addLayerFactor($newDifferencesFactor); $this->addLayerFactor($newDifferencesFactor);
// REVIEW: Does it make sense to have groups of one? // REVIEW: Does it make sense to have groups of one?

@ -3,6 +3,7 @@ namespace Moserware\Skills\TrueSkill;
require_once(dirname(__FILE__) . '/../GameInfo.php'); require_once(dirname(__FILE__) . '/../GameInfo.php');
require_once(dirname(__FILE__) . '/../Rating.php'); require_once(dirname(__FILE__) . '/../Rating.php');
require_once(dirname(__FILE__) . '/../RatingContainer.php');
require_once(dirname(__FILE__) . '/../FactorGraphs/FactorGraph.php'); require_once(dirname(__FILE__) . '/../FactorGraphs/FactorGraph.php');
require_once(dirname(__FILE__) . '/../FactorGraphs/FactorList.php'); require_once(dirname(__FILE__) . '/../FactorGraphs/FactorList.php');
require_once(dirname(__FILE__) . '/../FactorGraphs/Schedule.php'); require_once(dirname(__FILE__) . '/../FactorGraphs/Schedule.php');
@ -18,6 +19,7 @@ require_once(dirname(__FILE__) . '/Layers/TeamPerformancesToTeamPerformanceDiffe
use Moserware\Numerics\GaussianDistribution; use Moserware\Numerics\GaussianDistribution;
use Moserware\Skills\GameInfo; use Moserware\Skills\GameInfo;
use Moserware\Skills\Rating; use Moserware\Skills\Rating;
use Moserware\Skills\RatingContainer;
use Moserware\Skills\FactorGraphs\FactorGraph; use Moserware\Skills\FactorGraphs\FactorGraph;
use Moserware\Skills\FactorGraphs\FactorList; use Moserware\Skills\FactorGraphs\FactorList;
use Moserware\Skills\FactorGraphs\ScheduleSequence; use Moserware\Skills\FactorGraphs\ScheduleSequence;
@ -130,14 +132,16 @@ class TrueSkillFactorGraph extends FactorGraph
public function getUpdatedRatings() public function getUpdatedRatings()
{ {
$result = array(); $result = new RatingContainer();
foreach ($this->_priorLayer->getOutputVariablesGroups() as $currentTeam) foreach ($this->_priorLayer->getOutputVariablesGroups() as $currentTeam)
{ {
foreach ($currentTeam as $currentPlayer) foreach ($currentTeam as $currentPlayer)
{ {
$result[$currentPlayer->getKey()] = new Rating($currentPlayer->getValue()->getMean(), $newRating = new Rating($currentPlayer->getValue()->getMean(),
$currentPlayer->getValue()->getStandardDeviation()); $currentPlayer->getValue()->getStandardDeviation());
$result->setRating($currentPlayer, $newRating);
} }
} }