我尝试使用似乎是为这项工作设计的:BOOST_CHECK_CLOSE
,所以我有以下测试:
BOOST_AUTO_TEST_CASE( MultivariateNormalDensityTest )
{
double TOLLERANCE=1e-14;
Eigen::Vector3d mu(0.0, 1.0, 2.0);
Eigen::Matrix3d sigma;
sigma << 2.0, 1.0, 0.5,
1.0, 2.3, 0.7,
0.5, 0.7, 1.7;
MultivariateNormalDensity<3> mnd(mu, sigma);
BOOST_CHECK_CLOSE(0.027671392189542814988, mnd(Eigen::Vector3d(0.0, 1.0, 2.0)), TOLLERANCE);
BOOST_CHECK_CLOSE(0.0027063822550173750707, mnd(Eigen::Vector3d(2.0, 1.0, 0.5)), TOLLERANCE);
BOOST_CHECK_CLOSE(0.024708597088231143424, mnd(Eigen::Vector3d(0.5, 1.5, 2.5)), TOLLERANCE);
BOOST_CHECK_CLOSE(0.026554587643995836849, mnd(Eigen::Vector3d(-0.3, 0.6, 1.8)), TOLLERANCE);
//examples calculated using R
}
但是,第一次检查失败并出现以下错误:
/home/ga1009/PhD/cpp/grzesLib/test/multivariatenormaltests.cpp(36): error in "MultivariateNormalDensityTest": difference{3.76141e-14%} between 0.027671392189542814988{0.027671392189542815} and mnd(Eigen::Vector3d(0.0, 1.0, 2.0)){0.027671392189542805} exceeds 1e-14%
当我做数学时,我得到:
(0.027671392189542815-0.027671392189542805)/0.027671392189542805=0.00000000000000036138406
小于 1e-14。我在这里做错了什么?