Fixed some debugging messages on factors

This commit is contained in:
Jeff Moser 2010-09-27 08:00:22 -04:00
parent 5cb1919c21
commit f816a766d7
6 changed files with 10 additions and 12 deletions

@ -3,14 +3,12 @@ namespace Moserware\Skills\FactorGraphs;
class Message
{
private $_nameFormat;
private $_nameFormatArgs;
private $_name;
private $_value;
public function __construct($value = null, $nameFormat = null, $args = null)
public function __construct($value = null, $name = null)
{
$this->_nameFormat = $nameFormat;
$this->_nameFormatArgs = $args;
$this->_name = $name;
$this->_value = $value;
}
@ -21,7 +19,7 @@ class Message
public function __toString()
{
return $this->_nameFormat; //return (_NameFormat == null) ? base.ToString() : String.Format(_NameFormat, _NameFormatArgs);
return $this->_name;
}
}

@ -34,7 +34,7 @@ abstract class GaussianFactor extends Factor
return parent::createVariableToMessageBindingWithMessage($variable,
new Message(
GaussianDistribution::fromPrecisionMean(0, 0),
"message from {0} to {1}", $this));
sprintf("message from %s to %s", $this, $variable)));
}
}

@ -22,7 +22,7 @@ class GaussianGreaterThanFactor extends GaussianFactor
public function __construct($epsilon, Variable &$variable)
{
parent::__construct("{0} > {1:0.000}");
parent::__construct(\sprintf("%s > %.2f", $variable, $epsilon));
$this->_epsilon = $epsilon;
$this->createVariableToMessageBinding($variable);
}

@ -20,7 +20,7 @@ class GaussianLikelihoodFactor extends GaussianFactor
public function __construct($betaSquared, Variable &$variable1, Variable &$variable2)
{
parent::__construct("Likelihood of {0} going to {1}");
parent::__construct(sprintf("Likelihood of %s going to %s", $variable2, $variable1));
$this->_precision = 1.0/$betaSquared;
$this->createVariableToMessageBinding($variable1);
$this->createVariableToMessageBinding($variable2);

@ -21,11 +21,10 @@ class GaussianPriorFactor extends GaussianFactor
public function __construct($mean, $variance, Variable &$variable)
{
parent::__construct("Prior value going to {0}");
parent::__construct(sprintf("Prior value going to %s", $variable));
$this->_newMessage = new GaussianDistribution($mean, sqrt($variance));
$newMessage = new Message(GaussianDistribution::fromPrecisionMean(0, 0),
"message from {0} to {1}",
$this, $variable);
sprintf("message from %s to %s", $this, $variable));
$this->createVariableToMessageBindingWithMessage($variable, $newMessage);
}

@ -22,6 +22,7 @@ class GaussianWithinFactor extends GaussianFactor
public function __construct($epsilon, Variable &$variable)
{
parent::__construct(sprintf("%s <= %.2f", $variable, $epsilon));
$this->_epsilon = $epsilon;
$this->createVariableToMessageBinding($variable);
}