2022-07-05 15:55:47 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace DNW\Skills\TrueSkill\Factors;
|
2010-09-18 11:11:44 -04:00
|
|
|
|
2022-07-05 15:33:34 +02:00
|
|
|
use DNW\Skills\FactorGraphs\Factor;
|
|
|
|
use DNW\Skills\FactorGraphs\Message;
|
|
|
|
use DNW\Skills\FactorGraphs\Variable;
|
|
|
|
use DNW\Skills\Numerics\GaussianDistribution;
|
2010-09-18 17:56:57 -04:00
|
|
|
|
2010-09-18 11:11:44 -04:00
|
|
|
abstract class GaussianFactor extends Factor
|
|
|
|
{
|
2010-10-08 21:44:36 -04:00
|
|
|
/**
|
|
|
|
* Sends the factor-graph message with and returns the log-normalization constant.
|
|
|
|
*/
|
2022-07-05 16:21:06 +02:00
|
|
|
protected function sendMessageVariable(Message $message, Variable $variable): float|int
|
2010-09-18 11:11:44 -04:00
|
|
|
{
|
2016-05-24 16:31:21 +02: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));
|
2022-07-05 15:55:47 +02:00
|
|
|
|
2010-09-18 11:11:44 -04:00
|
|
|
return $logZ;
|
|
|
|
}
|
|
|
|
|
2023-08-01 12:56:37 +00:00
|
|
|
public function createVariableToMessageBinding(Variable $variable): Message
|
2010-09-18 11:11:44 -04:00
|
|
|
{
|
2010-10-02 21:15:47 -04:00
|
|
|
$newDistribution = GaussianDistribution::fromPrecisionMean(0, 0);
|
2022-07-05 16:21:06 +02:00
|
|
|
|
2023-08-01 13:53:19 +00:00
|
|
|
return parent::createVariableToMessageBindingWithMessage(
|
|
|
|
$variable,
|
2016-05-24 14:10:39 +02:00
|
|
|
new Message(
|
|
|
|
$newDistribution,
|
2023-08-08 07:00:51 +00:00
|
|
|
sprintf('message from %s to %s', (string)$this, (string)$variable)
|
2023-08-01 13:53:19 +00:00
|
|
|
)
|
|
|
|
);
|
2010-09-18 11:11:44 -04:00
|
|
|
}
|
2022-07-05 15:55:47 +02:00
|
|
|
}
|