Fix sign issue and added test
parent
b7fbe3f6a7
commit
28658490e8
|
|
@ -122,7 +122,7 @@ namespace gtsam {
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
double GaussianBayesNet::evaluate(const VectorValues& x) const {
|
double GaussianBayesNet::evaluate(const VectorValues& x) const {
|
||||||
return exp(-logProbability(x));
|
return exp(logProbability(x));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
|
|
|
||||||
|
|
@ -78,9 +78,13 @@ TEST(GaussianBayesNet, Evaluate1) {
|
||||||
// which at the mean is 1.0! So, the only thing we need to calculate is
|
// 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 normalization constant 1.0/sqrt((2*pi*Sigma).det()).
|
||||||
// The covariance matrix inv(Sigma) = R'*R, so the determinant is
|
// 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);
|
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.
|
// Check the evaluate with non-unit noise.
|
||||||
|
|
@ -89,9 +93,9 @@ TEST(GaussianBayesNet, Evaluate2) {
|
||||||
const VectorValues mean = noisyBayesNet.optimize();
|
const VectorValues mean = noisyBayesNet.optimize();
|
||||||
const Matrix R = noisyBayesNet.matrix().first;
|
const Matrix R = noisyBayesNet.matrix().first;
|
||||||
const Matrix invSigma = R.transpose() * R;
|
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);
|
const double actual = noisyBayesNet.evaluate(mean);
|
||||||
EXPECT_DOUBLES_EQUAL(expected, actual, 1e-9);
|
EXPECT_DOUBLES_EQUAL(constant, actual, 1e-9);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue