You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_Median.hpp 3.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. ///-------------------------------------------------------------------------------------------------
  2. ///
  3. /// \file test_Median.hpp
  4. /// \brief Tests for Median Functions.
  5. /// \author Thibaut Monseigne (Inria).
  6. /// \version 1.0.
  7. /// \date 29/07/2020.
  8. /// \copyright <a href="https://choosealicense.com/licenses/agpl-3.0/">GNU Affero General Public License v3.0</a>.
  9. /// \remarks We use the EEglab Matlab plugin to compare result for validation
  10. ///
  11. ///-------------------------------------------------------------------------------------------------
  12. #pragma once
  13. #include "gtest/gtest.h"
  14. #include "init.hpp"
  15. #include "misc.hpp"
  16. #include <geometry/Basics.hpp>
  17. #include <geometry/Median.hpp>
  18. //---------------------------------------------------------------------------------------------------
  19. class Tests_Median : public testing::Test
  20. {
  21. protected:
  22. std::vector<Eigen::MatrixXd> m_dataSet;
  23. void SetUp() override { m_dataSet = Geometry::Vector2DTo1D(InitCovariance::LWF::Reference()); }
  24. };
  25. //---------------------------------------------------------------------------------------------------
  26. //---------------------------------------------------------------------------------------------------
  27. TEST_F(Tests_Median, Simple_Median)
  28. {
  29. std::vector<double> v{ 5, 6, 4, 3, 2, 6, 7, 9, 3 };
  30. double calc = Geometry::Median(v);
  31. EXPECT_EQ(calc, 5);
  32. v.pop_back();
  33. calc = Geometry::Median(v);
  34. EXPECT_EQ(calc, 5.5);
  35. Eigen::MatrixXd m(3, 3);
  36. m << 5, 6, 4, 3, 2, 6, 7, 9, 3;
  37. calc = Geometry::Median(m);
  38. EXPECT_EQ(calc, 5);
  39. }
  40. //---------------------------------------------------------------------------------------------------
  41. //---------------------------------------------------------------------------------------------------
  42. TEST_F(Tests_Median, Euclidian)
  43. {
  44. Eigen::MatrixXd calc;
  45. Eigen::MatrixXd ref(3, 3);
  46. ref << 1.749537973777478, 0.002960131606861, 0.020507254841909,
  47. 0.002960131606861, 1.754563395557952, 0.043042786354499,
  48. 0.020507254841909, 0.043042786354499, 1.057672472691352;
  49. EXPECT_TRUE(Geometry::Median(m_dataSet, calc, 0.0001, 50, Geometry::EMetric::Euclidian)) << "Error During Median Computing";
  50. EXPECT_TRUE(isAlmostEqual(ref, calc)) << ErrorMsg("Euclidian Median of Dataset", ref, calc);
  51. }
  52. //---------------------------------------------------------------------------------------------------
  53. //---------------------------------------------------------------------------------------------------
  54. TEST_F(Tests_Median, Riemann)
  55. {
  56. Eigen::MatrixXd calc;
  57. Eigen::MatrixXd ref(3, 3);
  58. ref << 1.851330747504982, 0.002002346316770, 0.022122030618131,
  59. 0.002002346316770, 1.644242996651016, 0.033655563302757,
  60. 0.022122030618131, 0.033655563302757, 0.851184143800763;
  61. EXPECT_TRUE(Geometry::Median(m_dataSet, calc, 0.0001, 50, Geometry::EMetric::Riemann)) << "Error During Median Computes";
  62. EXPECT_TRUE(isAlmostEqual(ref, calc)) << ErrorMsg("Riemann Median of Dataset", ref, calc);
  63. }
  64. //---------------------------------------------------------------------------------------------------
  65. //---------------------------------------------------------------------------------------------------
  66. TEST_F(Tests_Median, Identity)
  67. {
  68. const Eigen::MatrixXd ref = InitMeans::Identity::Reference();
  69. Eigen::MatrixXd calc;
  70. EXPECT_TRUE(Geometry::Median(m_dataSet, calc, 0.0001, 50, Geometry::EMetric::Identity)) << "Error During Median Computes";
  71. EXPECT_TRUE(isAlmostEqual(ref, calc)) << ErrorMsg("Identity Median of Dataset", ref, calc);
  72. }
  73. //---------------------------------------------------------------------------------------------------