mirror of
https://github.com/furyfire/trueskill.git
synced 2025-04-18 20:04:28 +00:00
Cleanup in src/, adding namespaces, removing php closing tag and general code cleanup
This commit is contained in:
@ -1,18 +1,13 @@
|
||||
<?php
|
||||
namespace Moserware\Skills\TrueSkill\Factors;
|
||||
<?php namespace Moserware\Skills\TrueSkill\Factors;
|
||||
|
||||
require_once(dirname(__FILE__) . "/../../FactorGraphs/Message.php");
|
||||
require_once(dirname(__FILE__) . "/../../FactorGraphs/Variable.php");
|
||||
require_once(dirname(__FILE__) . "/../../Numerics/GaussianDistribution.php");
|
||||
require_once(dirname(__FILE__) . "/GaussianFactor.php");
|
||||
|
||||
use Moserware\Numerics\GaussianDistribution;
|
||||
use Exception;
|
||||
use Moserware\Skills\FactorGraphs\Message;
|
||||
use Moserware\Skills\FactorGraphs\Variable;
|
||||
use Moserware\Skills\Numerics\GaussianDistribution;
|
||||
|
||||
/**
|
||||
* Connects two variables and adds uncertainty.
|
||||
*
|
||||
*
|
||||
* See the accompanying math paper for more details.
|
||||
*/
|
||||
class GaussianLikelihoodFactor extends GaussianFactor
|
||||
@ -22,7 +17,7 @@ class GaussianLikelihoodFactor extends GaussianFactor
|
||||
public function __construct($betaSquared, Variable &$variable1, Variable &$variable2)
|
||||
{
|
||||
parent::__construct(sprintf("Likelihood of %s going to %s", $variable2, $variable1));
|
||||
$this->_precision = 1.0/$betaSquared;
|
||||
$this->_precision = 1.0 / $betaSquared;
|
||||
$this->createVariableToMessageBinding($variable1);
|
||||
$this->createVariableToMessageBinding($variable2);
|
||||
}
|
||||
@ -33,24 +28,24 @@ class GaussianLikelihoodFactor extends GaussianFactor
|
||||
$messages = &$this->getMessages();
|
||||
|
||||
return GaussianDistribution::logRatioNormalization(
|
||||
$vars[0]->getValue(),
|
||||
$messages[0]->getValue());
|
||||
$vars[0]->getValue(),
|
||||
$messages[0]->getValue());
|
||||
}
|
||||
|
||||
private function updateHelper(Message &$message1, Message &$message2,
|
||||
Variable &$variable1, Variable &$variable2)
|
||||
{
|
||||
{
|
||||
$message1Value = clone $message1->getValue();
|
||||
$message2Value = clone $message2->getValue();
|
||||
|
||||
$message2Value = clone $message2->getValue();
|
||||
|
||||
$marginal1 = clone $variable1->getValue();
|
||||
$marginal2 = clone $variable2->getValue();
|
||||
|
||||
$a = $this->_precision/($this->_precision + $marginal2->getPrecision() - $message2Value->getPrecision());
|
||||
$a = $this->_precision / ($this->_precision + $marginal2->getPrecision() - $message2Value->getPrecision());
|
||||
|
||||
$newMessage = GaussianDistribution::fromPrecisionMean(
|
||||
$a*($marginal2->getPrecisionMean() - $message2Value->getPrecisionMean()),
|
||||
$a*($marginal2->getPrecision() - $message2Value->getPrecision()));
|
||||
$a * ($marginal2->getPrecisionMean() - $message2Value->getPrecisionMean()),
|
||||
$a * ($marginal2->getPrecision() - $message2Value->getPrecision()));
|
||||
|
||||
$oldMarginalWithoutMessage = GaussianDistribution::divide($marginal1, $message1Value);
|
||||
|
||||
@ -68,20 +63,17 @@ class GaussianLikelihoodFactor extends GaussianFactor
|
||||
public function updateMessageIndex($messageIndex)
|
||||
{
|
||||
$messages = &$this->getMessages();
|
||||
$vars = &$this->getVariables();
|
||||
$vars = &$this->getVariables();
|
||||
|
||||
switch ($messageIndex)
|
||||
{
|
||||
switch ($messageIndex) {
|
||||
case 0:
|
||||
return $this->updateHelper($messages[0], $messages[1],
|
||||
$vars[0], $vars[1]);
|
||||
$vars[0], $vars[1]);
|
||||
case 1:
|
||||
return $this->updateHelper($messages[1], $messages[0],
|
||||
$vars[1], $vars[0]);
|
||||
$vars[1], $vars[0]);
|
||||
default:
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
}
|
Reference in New Issue
Block a user