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/Factor.php");
|
|
|
|
require_once(dirname(__FILE__) . "/../../FactorGraphs/Message.php");
|
|
|
|
require_once(dirname(__FILE__) . "/../../FactorGraphs/Variable.php");
|
|
|
|
require_once(dirname(__FILE__) . "/../../Numerics/GaussianDistribution.php");
|
2010-09-18 17:56:57 -04:00
|
|
|
|
|
|
|
use Moserware\Numerics\GaussianDistribution;
|
|
|
|
use Moserware\Skills\FactorGraphs\Factor;
|
|
|
|
use Moserware\Skills\FactorGraphs\Message;
|
|
|
|
use Moserware\Skills\FactorGraphs\Variable;
|
|
|
|
|
2010-09-18 11:11:44 -04:00
|
|
|
abstract class GaussianFactor extends Factor
|
|
|
|
{
|
|
|
|
protected function __construct($name)
|
|
|
|
{
|
|
|
|
parent::__construct($name);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Sends the factor-graph message with and returns the log-normalization constant
|
2010-09-25 15:46:23 -04:00
|
|
|
protected function sendMessageVariable(Message &$message, Variable &$variable)
|
2010-09-18 11:11:44 -04:00
|
|
|
{
|
2010-09-25 22:40:56 -04:00
|
|
|
$marginal = &$variable->getValue();
|
|
|
|
$messageValue = &$message->getValue();
|
2010-09-18 11:11:44 -04:00
|
|
|
$logZ = GaussianDistribution::logProductNormalization($marginal, $messageValue);
|
2010-09-28 08:12:06 -04:00
|
|
|
$variable->setValue(GaussianDistribution::multiply($marginal, $messageValue));
|
2010-09-18 11:11:44 -04:00
|
|
|
return $logZ;
|
|
|
|
}
|
|
|
|
|
2010-09-30 08:25:31 -04:00
|
|
|
public function &createVariableToMessageBinding(Variable &$variable)
|
2010-09-18 11:11:44 -04:00
|
|
|
{
|
2010-10-02 21:15:47 -04:00
|
|
|
$newDistribution = GaussianDistribution::fromPrecisionMean(0, 0);
|
2010-09-30 08:25:31 -04:00
|
|
|
$binding = &parent::createVariableToMessageBindingWithMessage($variable,
|
2010-09-18 11:11:44 -04:00
|
|
|
new Message(
|
2010-10-02 21:15:47 -04:00
|
|
|
$newDistribution,
|
2010-09-27 08:00:22 -04:00
|
|
|
sprintf("message from %s to %s", $this, $variable)));
|
2010-09-30 08:25:31 -04:00
|
|
|
return $binding;
|
2010-09-18 11:11:44 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|