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_Distance.hpp 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. ///-------------------------------------------------------------------------------------------------
  2. ///
  3. /// \file test_Distance.hpp
  4. /// \brief Tests for Distance Functions.
  5. /// \author Thibaut Monseigne (Inria).
  6. /// \version 1.0.
  7. /// \date 09/01/2019.
  8. /// \copyright <a href="https://choosealicense.com/licenses/agpl-3.0/">GNU Affero General Public License v3.0</a>.
  9. ///
  10. ///-------------------------------------------------------------------------------------------------
  11. #pragma once
  12. #include "gtest/gtest.h"
  13. #include "misc.hpp"
  14. #include "init.hpp"
  15. #include <geometry/Distance.hpp>
  16. //---------------------------------------------------------------------------------------------------
  17. class Tests_Distances : public testing::Test
  18. {
  19. protected:
  20. std::vector<Eigen::MatrixXd> m_dataSet;
  21. void SetUp() override { m_dataSet = Geometry::Vector2DTo1D(InitCovariance::LWF::Reference()); }
  22. };
  23. //---------------------------------------------------------------------------------------------------
  24. //---------------------------------------------------------------------------------------------------
  25. TEST_F(Tests_Distances, Euclidian)
  26. {
  27. const std::vector<double> ref = InitDistance::Euclidian::Reference();
  28. const Eigen::MatrixXd mean = InitMeans::Euclidian::Reference();
  29. for (size_t i = 0; i < m_dataSet.size(); ++i)
  30. {
  31. const double calc = Distance(mean, m_dataSet[i], Geometry::EMetric::Euclidian);
  32. EXPECT_TRUE(isAlmostEqual(ref[i], calc)) << ErrorMsg("Distance Euclidian Sample [" + std::to_string(i) + "]", ref[i], calc);
  33. }
  34. }
  35. //---------------------------------------------------------------------------------------------------
  36. //---------------------------------------------------------------------------------------------------
  37. TEST_F(Tests_Distances, LogEuclidian)
  38. {
  39. const std::vector<double> ref = InitDistance::LogEuclidian::Reference();
  40. const Eigen::MatrixXd mean = InitMeans::LogEuclidian::Reference();
  41. for (size_t i = 0; i < m_dataSet.size(); ++i)
  42. {
  43. const double calc = Distance(mean, m_dataSet[i], Geometry::EMetric::LogEuclidian);
  44. EXPECT_TRUE(isAlmostEqual(ref[i], calc)) << ErrorMsg("Distance LogEuclidian Sample [" + std::to_string(i) + "]", ref[i], calc);
  45. }
  46. }
  47. //---------------------------------------------------------------------------------------------------
  48. //---------------------------------------------------------------------------------------------------
  49. TEST_F(Tests_Distances, Riemann)
  50. {
  51. const std::vector<double> ref = InitDistance::Riemann::Reference();
  52. const Eigen::MatrixXd mean = InitMeans::Riemann::Reference();
  53. for (size_t i = 0; i < m_dataSet.size(); ++i)
  54. {
  55. const double calc = Distance(mean, m_dataSet[i], Geometry::EMetric::Riemann);
  56. EXPECT_TRUE(isAlmostEqual(ref[i], calc)) << ErrorMsg("Distance Riemann Sample [" + std::to_string(i) + "]", ref[i], calc);
  57. }
  58. }
  59. //---------------------------------------------------------------------------------------------------
  60. //---------------------------------------------------------------------------------------------------
  61. TEST_F(Tests_Distances, LogDet)
  62. {
  63. const std::vector<double> ref = InitDistance::LogDeterminant::Reference();
  64. const Eigen::MatrixXd mean = InitMeans::LogDeterminant::Reference();
  65. for (size_t i = 0; i < m_dataSet.size(); ++i)
  66. {
  67. const double calc = Distance(mean, m_dataSet[i], Geometry::EMetric::LogDet);
  68. EXPECT_TRUE(isAlmostEqual(ref[i], calc)) << ErrorMsg("Distance LogDet Sample [" + std::to_string(i) + "]", ref[i], calc);
  69. }
  70. }
  71. //---------------------------------------------------------------------------------------------------
  72. //---------------------------------------------------------------------------------------------------
  73. TEST_F(Tests_Distances, Kullback)
  74. {
  75. const std::vector<double> ref = InitDistance::Kullback::Reference();
  76. const Eigen::MatrixXd mean = InitMeans::Kullback::Reference();
  77. for (size_t i = 0; i < m_dataSet.size(); ++i)
  78. {
  79. const double calc = Distance(mean, m_dataSet[i], Geometry::EMetric::Kullback);
  80. EXPECT_TRUE(isAlmostEqual(ref[i], calc)) << ErrorMsg("Distance Kullback Sample [" + std::to_string(i) + "]", ref[i], calc);
  81. }
  82. }
  83. //---------------------------------------------------------------------------------------------------
  84. //---------------------------------------------------------------------------------------------------
  85. TEST_F(Tests_Distances, Wasserstein)
  86. {
  87. const std::vector<double> ref = InitDistance::Wasserstein::Reference();
  88. const Eigen::MatrixXd mean = InitMeans::Wasserstein::Reference();
  89. for (size_t i = 0; i < m_dataSet.size(); ++i)
  90. {
  91. const double calc = Distance(mean, m_dataSet[i], Geometry::EMetric::Wasserstein);
  92. EXPECT_TRUE(isAlmostEqual(ref[i], calc)) << ErrorMsg("Distance Wasserstein Sample [" + std::to_string(i) + "]", ref[i], calc);
  93. }
  94. }
  95. //---------------------------------------------------------------------------------------------------
  96. //---------------------------------------------------------------------------------------------------
  97. TEST_F(Tests_Distances, Identity)
  98. {
  99. const Eigen::MatrixXd mean = InitMeans::Wasserstein::Reference();
  100. for (size_t i = 0; i < m_dataSet.size(); ++i)
  101. {
  102. const double calc = Distance(mean, m_dataSet[i], Geometry::EMetric::Identity);
  103. EXPECT_TRUE(isAlmostEqual(1, calc)) << ErrorMsg("Distance Wasserstein Sample [" + std::to_string(i) + "]", 1, calc);
  104. }
  105. }
  106. //---------------------------------------------------------------------------------------------------