32 #include <Eigen/Geometry> 34 #include <gtest/gtest.h> 38 TEST(NormalLiklihood, Normality)
40 for (
double sigma = 1.0; sigma <= 3.0; sigma += 1.0)
44 const double likelihood0 = 1.0 / sqrtf(M_PI * 2.0 * sigma * sigma);
45 ASSERT_NEAR(nl(0.0), likelihood0, 1e-6);
46 ASSERT_NEAR(nl(sigma), likelihood0 * 0.60653066, 1e-6);
47 ASSERT_NEAR(nl(-sigma), likelihood0 * 0.60653066, 1e-6);
48 ASSERT_NEAR(nl(3.0 * sigma), likelihood0 * 0.011108997, 1e-6);
49 ASSERT_NEAR(nl(-3.0 * sigma), likelihood0 * 0.011108997, 1e-6);
53 const double step = 0.1;
54 for (
double i = -100.0; i < 100.0; i += step)
58 ASSERT_NEAR(sum, 1.0, 1e-6);
62 TEST(NormalLiklihood, NormalityNd)
64 for (
double sigma = 1.0; sigma <= 3.0; sigma += 1.0)
68 NormalLikelihood2d::Matrix cov;
71 NormalLikelihood2d nl(cov);
73 const double likelihood0 = 1.0 / (M_PI * 2.0 *
sqrt(cov.determinant()));
75 nl(NormalLikelihood2d::Vector(0.0, 0.0)), likelihood0, 1e-6);
79 NormalLikelihood2d::Vector(sigma, 0.0).transpose() *
81 NormalLikelihood2d::Vector(sigma, 0.0));
84 NormalLikelihood2d::Vector(0.0, sigma).transpose() *
86 NormalLikelihood2d::Vector(0.0, sigma));
88 nl(NormalLikelihood2d::Vector(sigma, 0.0)), likelihood0 * e1a, 1e-6);
90 nl(NormalLikelihood2d::Vector(-sigma, 0.0)), likelihood0 * e1a, 1e-6);
92 nl(NormalLikelihood2d::Vector(0.0, sigma)), likelihood0 * e1b, 1e-6);
94 nl(NormalLikelihood2d::Vector(0.0, -sigma)), likelihood0 * e1b, 1e-6);
98 NormalLikelihood2d::Vector(3.0 * sigma, 0.0).transpose() *
100 NormalLikelihood2d::Vector(3.0 * sigma, 0.0));
103 NormalLikelihood2d::Vector(0.0, 3.0 * sigma).transpose() *
105 NormalLikelihood2d::Vector(0.0, 3.0 * sigma));
107 nl(NormalLikelihood2d::Vector(3.0 * sigma, 0.0)), likelihood0 * e2a, 1e-6);
109 nl(NormalLikelihood2d::Vector(-3.0 * sigma, 0.0)), likelihood0 * e2a, 1e-6);
111 nl(NormalLikelihood2d::Vector(0.0, 3.0 * sigma)), likelihood0 * e2b, 1e-6);
113 nl(NormalLikelihood2d::Vector(0.0, -3.0 * sigma)), likelihood0 * e2b, 1e-6);
117 const double step = 0.1;
118 const double step_sq = step * step;
119 for (
double i = -100.0; i < 100.0; i += step)
121 for (
double j = -100.0; j < 100.0; j += step)
123 sum += nl(NormalLikelihood2d::Vector(i, j)) * step_sq;
126 ASSERT_NEAR(sum, 1.0, 1e-6);
128 for (
double sigma = 1.0; sigma <= 3.0; sigma += 1.0)
132 NormalLikelihood2d::Matrix cov;
135 NormalLikelihood2d nl(cov);
137 const double likelihood0 = 1.0 / (M_PI * 2.0 *
sqrt(cov.determinant()));
140 NormalLikelihood2d::Vector(sigma, 0.0).transpose() *
142 NormalLikelihood2d::Vector(sigma, 0.0));
145 NormalLikelihood2d::Vector(3.0 * sigma, 0.0).transpose() *
147 NormalLikelihood2d::Vector(3.0 * sigma, 0.0));
148 for (
double r = 0; r < M_PI * 2; r += M_PI / 6)
151 Eigen::Rotation2D<double>(r) *
152 NormalLikelihood2d::Vector(sigma, 0.0);
153 ASSERT_NEAR(nl(v1), likelihood0 * e1, 1e-6);
155 Eigen::Rotation2D<double>(r) *
156 NormalLikelihood2d::Vector(3.0 * sigma, 0.0);
157 ASSERT_NEAR(nl(v2), likelihood0 * e2, 1e-6);
162 int main(
int argc,
char** argv)
164 testing::InitGoogleTest(&argc, argv);
166 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)