2010-09-18 11:11:44 -04:00
|
|
|
<?php
|
|
|
|
namespace Moserware\Skills\TrueSkill\Factors;
|
|
|
|
|
2010-09-25 10:15:51 -04:00
|
|
|
require_once(dirname(__FILE__) . "/../../FactorGraphs/Message.php");
|
|
|
|
require_once(dirname(__FILE__) . "/../../FactorGraphs/Variable.php");
|
|
|
|
require_once(dirname(__FILE__) . "/../../Numerics/GaussianDistribution.php");
|
2010-10-08 21:44:36 -04:00
|
|
|
require_once(dirname(__FILE__) . "/GaussianFactor.php");
|
2010-09-18 17:56:57 -04:00
|
|
|
|
|
|
|
use Moserware\Numerics\GaussianDistribution;
|
|
|
|
use Moserware\Skills\FactorGraphs\Message;
|
|
|
|
use Moserware\Skills\FactorGraphs\Variable;
|
|
|
|
|
2010-10-08 21:44:36 -04:00
|
|
|
/**
|
|
|
|
* Supplies the factor graph with prior information.
|
|
|
|
*
|
|
|
|
* See the accompanying math paper for more details.
|
|
|
|
*/
|
2010-09-18 11:11:44 -04:00
|
|
|
class GaussianPriorFactor extends GaussianFactor
|
|
|
|
{
|
|
|
|
private $_newMessage;
|
|
|
|
|
2010-09-25 15:46:23 -04:00
|
|
|
public function __construct($mean, $variance, Variable &$variable)
|
2010-09-18 11:11:44 -04:00
|
|
|
{
|
2010-09-27 08:00:22 -04:00
|
|
|
parent::__construct(sprintf("Prior value going to %s", $variable));
|
2010-09-18 11:11:44 -04:00
|
|
|
$this->_newMessage = new GaussianDistribution($mean, sqrt($variance));
|
2010-09-25 18:25:56 -04:00
|
|
|
$newMessage = new Message(GaussianDistribution::fromPrecisionMean(0, 0),
|
2010-09-27 08:00:22 -04:00
|
|
|
sprintf("message from %s to %s", $this, $variable));
|
2010-09-25 18:25:56 -04:00
|
|
|
|
|
|
|
$this->createVariableToMessageBindingWithMessage($variable, $newMessage);
|
2010-09-18 11:11:44 -04:00
|
|
|
}
|
|
|
|
|
2010-09-25 15:46:23 -04:00
|
|
|
protected function updateMessageVariable(Message &$message, Variable &$variable)
|
2010-09-18 11:11:44 -04:00
|
|
|
{
|
|
|
|
$oldMarginal = clone $variable->getValue();
|
|
|
|
$oldMessage = $message;
|
|
|
|
$newMarginal =
|
|
|
|
GaussianDistribution::fromPrecisionMean(
|
|
|
|
$oldMarginal->getPrecisionMean() + $this->_newMessage->getPrecisionMean() - $oldMessage->getValue()->getPrecisionMean(),
|
|
|
|
$oldMarginal->getPrecision() + $this->_newMessage->getPrecision() - $oldMessage->getValue()->getPrecision());
|
|
|
|
|
|
|
|
$variable->setValue($newMarginal);
|
2010-10-02 21:15:47 -04:00
|
|
|
$newMessage = &$this->_newMessage;
|
|
|
|
$message->setValue($newMessage);
|
2010-09-18 11:11:44 -04:00
|
|
|
return GaussianDistribution::subtract($oldMarginal, $newMarginal);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|