Fix sign issue and added test

release/4.3a0
Frank Dellaert 2023-01-10 14:36:58 -08:00
parent b7fbe3f6a7
commit 28658490e8
2 changed files with 9 additions and 5 deletions

View File

@ -122,7 +122,7 @@ namespace gtsam {
/* ************************************************************************* */
double GaussianBayesNet::evaluate(const VectorValues& x) const {
return exp(-logProbability(x));
return exp(logProbability(x));
}
/* ************************************************************************* */

View File

@ -78,9 +78,13 @@ TEST(GaussianBayesNet, Evaluate1) {
// which at the mean is 1.0! So, the only thing we need to calculate is
// the normalization constant 1.0/sqrt((2*pi*Sigma).det()).
// The covariance matrix inv(Sigma) = R'*R, so the determinant is
const double expected = sqrt((invSigma / (2 * M_PI)).determinant());
const double constant = sqrt((invSigma / (2 * M_PI)).determinant());
EXPECT_DOUBLES_EQUAL(log(constant),
smallBayesNet.at(0)->logNormalizationConstant() +
smallBayesNet.at(1)->logNormalizationConstant(),
1e-9);
const double actual = smallBayesNet.evaluate(mean);
EXPECT_DOUBLES_EQUAL(expected, actual, 1e-9);
EXPECT_DOUBLES_EQUAL(constant, actual, 1e-9);
}
// Check the evaluate with non-unit noise.
@ -89,9 +93,9 @@ TEST(GaussianBayesNet, Evaluate2) {
const VectorValues mean = noisyBayesNet.optimize();
const Matrix R = noisyBayesNet.matrix().first;
const Matrix invSigma = R.transpose() * R;
const double expected = sqrt((invSigma / (2 * M_PI)).determinant());
const double constant = sqrt((invSigma / (2 * M_PI)).determinant());
const double actual = noisyBayesNet.evaluate(mean);
EXPECT_DOUBLES_EQUAL(expected, actual, 1e-9);
EXPECT_DOUBLES_EQUAL(constant, actual, 1e-9);
}
/* ************************************************************************* */