33 #include <Eigen/Geometry> 35 #include <gtest/gtest.h> 39 TEST(NormalLiklihood, Normality)
41 for (
double sigma = 1.0; sigma <= 3.0; sigma += 1.0)
45 const double likelihood0 = 1.0 / std::sqrt(M_PI * 2.0 * sigma * sigma);
46 ASSERT_NEAR(nl(0.0), likelihood0, 1e-6);
47 ASSERT_NEAR(nl(sigma), likelihood0 * 0.60653066, 1e-6);
48 ASSERT_NEAR(nl(-sigma), likelihood0 * 0.60653066, 1e-6);
49 ASSERT_NEAR(nl(3.0 * sigma), likelihood0 * 0.011108997, 1e-6);
50 ASSERT_NEAR(nl(-3.0 * sigma), likelihood0 * 0.011108997, 1e-6);
54 const double step = 0.1;
55 for (
double i = -100.0; i < 100.0; i += step)
59 ASSERT_NEAR(sum, 1.0, 1e-6);
63 TEST(NormalLiklihood, NormalityNd)
65 for (
double sigma = 1.0; sigma <= 3.0; sigma += 1.0)
69 NormalLikelihood2d::Matrix cov;
72 NormalLikelihood2d nl(cov);
74 const double likelihood0 = 1.0 / (M_PI * 2.0 *
sqrt(cov.determinant()));
76 nl(NormalLikelihood2d::Vector(0.0, 0.0)), likelihood0, 1e-6);
80 NormalLikelihood2d::Vector(sigma, 0.0).transpose() *
82 NormalLikelihood2d::Vector(sigma, 0.0));
85 NormalLikelihood2d::Vector(0.0, sigma).transpose() *
87 NormalLikelihood2d::Vector(0.0, sigma));
89 nl(NormalLikelihood2d::Vector(sigma, 0.0)), likelihood0 * e1a, 1e-6);
91 nl(NormalLikelihood2d::Vector(-sigma, 0.0)), likelihood0 * e1a, 1e-6);
93 nl(NormalLikelihood2d::Vector(0.0, sigma)), likelihood0 * e1b, 1e-6);
95 nl(NormalLikelihood2d::Vector(0.0, -sigma)), likelihood0 * e1b, 1e-6);
99 NormalLikelihood2d::Vector(3.0 * sigma, 0.0).transpose() *
101 NormalLikelihood2d::Vector(3.0 * sigma, 0.0));
104 NormalLikelihood2d::Vector(0.0, 3.0 * sigma).transpose() *
106 NormalLikelihood2d::Vector(0.0, 3.0 * sigma));
108 nl(NormalLikelihood2d::Vector(3.0 * sigma, 0.0)), likelihood0 * e2a, 1e-6);
110 nl(NormalLikelihood2d::Vector(-3.0 * sigma, 0.0)), likelihood0 * e2a, 1e-6);
112 nl(NormalLikelihood2d::Vector(0.0, 3.0 * sigma)), likelihood0 * e2b, 1e-6);
114 nl(NormalLikelihood2d::Vector(0.0, -3.0 * sigma)), likelihood0 * e2b, 1e-6);
118 const double step = 0.1;
119 const double step_sq = step * step;
120 for (
double i = -100.0; i < 100.0; i += step)
122 for (
double j = -100.0; j < 100.0; j += step)
124 sum += nl(NormalLikelihood2d::Vector(i, j)) * step_sq;
127 ASSERT_NEAR(sum, 1.0, 1e-6);
129 for (
double sigma = 1.0; sigma <= 3.0; sigma += 1.0)
133 NormalLikelihood2d::Matrix cov;
136 NormalLikelihood2d nl(cov);
138 const double likelihood0 = 1.0 / (M_PI * 2.0 *
sqrt(cov.determinant()));
141 NormalLikelihood2d::Vector(sigma, 0.0).transpose() *
143 NormalLikelihood2d::Vector(sigma, 0.0));
146 NormalLikelihood2d::Vector(3.0 * sigma, 0.0).transpose() *
148 NormalLikelihood2d::Vector(3.0 * sigma, 0.0));
149 for (
double r = 0; r < M_PI * 2; r += M_PI / 6)
152 Eigen::Rotation2D<double>(r) *
153 NormalLikelihood2d::Vector(sigma, 0.0);
154 ASSERT_NEAR(nl(v1), likelihood0 * e1, 1e-6);
156 Eigen::Rotation2D<double>(r) *
157 NormalLikelihood2d::Vector(3.0 * sigma, 0.0);
158 ASSERT_NEAR(nl(v2), likelihood0 * e2, 1e-6);
163 int main(
int argc,
char** argv)
165 testing::InitGoogleTest(&argc, argv);
167 return RUN_ALL_TESTS();
int main(int argc, char **argv)
INLINE Rall1d< T, V, S > sqrt(const Rall1d< T, V, S > &arg)
INLINE Rall1d< T, V, S > exp(const Rall1d< T, V, S > &arg)
TEST(NormalLiklihood, Normality)