mirror of
https://github.com/furyfire/trueskill.git
synced 2025-01-16 01:47:39 +00:00
Fix a few bugs in GaussianWeightedSumFactor
This commit is contained in:
@ -1,10 +1,13 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace Moserware\Skills\TrueSkill\Factors;
|
namespace Moserware\Skills\TrueSkill\Factors;
|
||||||
|
|
||||||
|
|
||||||
require_once(dirname(__FILE__) . "/GaussianFactor.php");
|
require_once(dirname(__FILE__) . "/GaussianFactor.php");
|
||||||
require_once(dirname(__FILE__) . "/../../FactorGraphs/Message.php");
|
require_once(dirname(__FILE__) . "/../../FactorGraphs/Message.php");
|
||||||
require_once(dirname(__FILE__) . "/../../FactorGraphs/Variable.php");
|
require_once(dirname(__FILE__) . "/../../FactorGraphs/Variable.php");
|
||||||
require_once(dirname(__FILE__) . "/../../Numerics/GaussianDistribution.php");
|
require_once(dirname(__FILE__) . "/../../Numerics/GaussianDistribution.php");
|
||||||
|
require_once(dirname(__FILE__) . "/../../Numerics/BasicMath.php");
|
||||||
|
|
||||||
|
|
||||||
use Moserware\Numerics\GaussianDistribution;
|
use Moserware\Numerics\GaussianDistribution;
|
||||||
use Moserware\Skills\FactorGraphs\Message;
|
use Moserware\Skills\FactorGraphs\Message;
|
||||||
@ -25,7 +28,7 @@ class GaussianWeightedSumFactor extends GaussianFactor
|
|||||||
|
|
||||||
public function __construct(Variable &$sumVariable, array &$variablesToSum, array &$variableWeights = null)
|
public function __construct(Variable &$sumVariable, array &$variablesToSum, array &$variableWeights = null)
|
||||||
{
|
{
|
||||||
parent::__construct($this->createName($sumVariable, $variablesToSum, $variableWeights));
|
parent::__construct(self::createName($sumVariable, $variablesToSum, $variableWeights));
|
||||||
$this->_weights = array();
|
$this->_weights = array();
|
||||||
$this->_weightsSquared = array();
|
$this->_weightsSquared = array();
|
||||||
|
|
||||||
@ -39,7 +42,7 @@ class GaussianWeightedSumFactor extends GaussianFactor
|
|||||||
{
|
{
|
||||||
$weight = $variableWeights[$i];
|
$weight = $variableWeights[$i];
|
||||||
$this->_weights[0][$i] = $weight;
|
$this->_weights[0][$i] = $weight;
|
||||||
$this->_weightsSquared[0][i] = $weight * $weight;
|
$this->_weightsSquared[0][$i] = $weight * $weight;
|
||||||
}
|
}
|
||||||
|
|
||||||
$variablesToSumLength = count($variablesToSum);
|
$variablesToSumLength = count($variablesToSum);
|
||||||
@ -64,14 +67,16 @@ class GaussianWeightedSumFactor extends GaussianFactor
|
|||||||
$variableIndices[] = $weightsIndex;
|
$variableIndices[] = $weightsIndex;
|
||||||
|
|
||||||
$currentWeightsSquared = array();
|
$currentWeightsSquared = array();
|
||||||
$this->_WeightsSquared[$weightsIndex] = $currentWeightsSquared;
|
$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
|
||||||
$currentDestinationWeightIndex = 0;
|
$currentDestinationWeightIndex = 0;
|
||||||
|
|
||||||
|
$variableWeightsLength = count($variableWeights);
|
||||||
|
|
||||||
for ($currentWeightSourceIndex = 0;
|
for ($currentWeightSourceIndex = 0;
|
||||||
$currentWeightSourceIndex < $variableWeights.Length;
|
$currentWeightSourceIndex < $variableWeightsLength;
|
||||||
$currentWeightSourceIndex++)
|
$currentWeightSourceIndex++)
|
||||||
{
|
{
|
||||||
if ($currentWeightSourceIndex == ($weightsIndex - 1))
|
if ($currentWeightSourceIndex == ($weightsIndex - 1))
|
||||||
@ -102,10 +107,10 @@ class GaussianWeightedSumFactor extends GaussianFactor
|
|||||||
// HACK: Getting around division by zero
|
// HACK: Getting around division by zero
|
||||||
$finalWeight = 0;
|
$finalWeight = 0;
|
||||||
}
|
}
|
||||||
$currentWeights[$currentDestinationWeightIndex] = finalWeight;
|
$currentWeights[$currentDestinationWeightIndex] = $finalWeight;
|
||||||
$currentWeightsSquared[currentDestinationWeightIndex] = finalWeight*finalWeight;
|
$currentWeightsSquared[$currentDestinationWeightIndex] = square($finalWeight);
|
||||||
$variableIndices[$variableIndices.Length - 1] = 0;
|
$variableIndices[count($variableIndices) - 1] = 0;
|
||||||
$this->_variableIndexOrdersForWeights[] = $variableIndices;
|
$this->_variableIndexOrdersForWeights[] = &$variableIndices;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->createVariableToMessageBinding($sumVariable);
|
$this->createVariableToMessageBinding($sumVariable);
|
||||||
@ -219,6 +224,11 @@ class GaussianWeightedSumFactor extends GaussianFactor
|
|||||||
$updatedMessages,
|
$updatedMessages,
|
||||||
$updatedVariables);
|
$updatedVariables);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static function createName($sumVariable, $variablesToSum, $variableWeights)
|
||||||
|
{
|
||||||
|
return "TODO";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
Reference in New Issue
Block a user