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_Mean.hpp 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. ///-------------------------------------------------------------------------------------------------
  2. ///
  3. /// \file test_Mean.hpp
  4. /// \brief Tests for Mean 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/Mean.hpp>
  16. //---------------------------------------------------------------------------------------------------
  17. class Tests_Means : 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_Means, BadInput)
  26. {
  27. std::vector<Eigen::MatrixXd> bad;
  28. Eigen::MatrixXd calc;
  29. EXPECT_FALSE(Mean(bad, calc, Geometry::EMetric::Riemann));
  30. bad.emplace_back(Eigen::MatrixXd::Zero(1, 2));
  31. bad.emplace_back(Eigen::MatrixXd::Zero(1, 2));
  32. EXPECT_FALSE(Mean(bad, calc, Geometry::EMetric::Riemann));
  33. bad.emplace_back(Eigen::MatrixXd::Zero(2, 2));
  34. EXPECT_FALSE(Mean(bad, calc, Geometry::EMetric::Riemann));
  35. }
  36. //---------------------------------------------------------------------------------------------------
  37. //---------------------------------------------------------------------------------------------------
  38. TEST_F(Tests_Means, Euclidian)
  39. {
  40. const Eigen::MatrixXd ref = InitMeans::Euclidian::Reference();
  41. Eigen::MatrixXd calc;
  42. Mean(m_dataSet, calc, Geometry::EMetric::Euclidian);
  43. EXPECT_TRUE(isAlmostEqual(ref, calc)) << ErrorMsg("Mean Matrix Euclidian", ref, calc);
  44. }
  45. //---------------------------------------------------------------------------------------------------
  46. //---------------------------------------------------------------------------------------------------
  47. TEST_F(Tests_Means, LogEuclidian)
  48. {
  49. const Eigen::MatrixXd ref = InitMeans::LogEuclidian::Reference();
  50. Eigen::MatrixXd calc;
  51. Mean(m_dataSet, calc, Geometry::EMetric::LogEuclidian);
  52. EXPECT_TRUE(isAlmostEqual(ref, calc)) << ErrorMsg("Mean Matrix LogEuclidian", ref, calc);
  53. }
  54. //---------------------------------------------------------------------------------------------------
  55. //---------------------------------------------------------------------------------------------------
  56. TEST_F(Tests_Means, Riemann)
  57. {
  58. const Eigen::MatrixXd ref = InitMeans::Riemann::Reference();
  59. Eigen::MatrixXd calc;
  60. Mean(m_dataSet, calc, Geometry::EMetric::Riemann);
  61. EXPECT_TRUE(isAlmostEqual(ref, calc)) << ErrorMsg("Mean Matrix Riemann", ref, calc);
  62. }
  63. //---------------------------------------------------------------------------------------------------
  64. //---------------------------------------------------------------------------------------------------
  65. TEST_F(Tests_Means, LogDet)
  66. {
  67. const Eigen::MatrixXd ref = InitMeans::LogDeterminant::Reference();
  68. Eigen::MatrixXd calc;
  69. Mean(m_dataSet, calc, Geometry::EMetric::LogDet);
  70. EXPECT_TRUE(isAlmostEqual(ref, calc)) << ErrorMsg("Mean Matrix LogDet", ref, calc);
  71. }
  72. //---------------------------------------------------------------------------------------------------
  73. //---------------------------------------------------------------------------------------------------
  74. TEST_F(Tests_Means, Kullback)
  75. {
  76. const Eigen::MatrixXd ref = InitMeans::Kullback::Reference();
  77. Eigen::MatrixXd calc;
  78. Mean(m_dataSet, calc, Geometry::EMetric::Kullback);
  79. EXPECT_TRUE(isAlmostEqual(ref, calc)) << ErrorMsg("Mean Matrix Kullback", ref, calc);
  80. }
  81. //---------------------------------------------------------------------------------------------------
  82. //---------------------------------------------------------------------------------------------------
  83. TEST_F(Tests_Means, Wasserstein)
  84. {
  85. std::cout << "Precision Error" << std::endl;
  86. Eigen::MatrixXd calc;
  87. Mean(m_dataSet, calc, Geometry::EMetric::Wasserstein);
  88. //const Eigen::MatrixXd ref = InitMeans::Wasserstein::Reference();
  89. //EXPECT_TRUE(isAlmostEqual(ref, calc)) << ErrorMsg("Mean Matrix Wasserstein", ref, calc);
  90. }
  91. //---------------------------------------------------------------------------------------------------
  92. //---------------------------------------------------------------------------------------------------
  93. TEST_F(Tests_Means, ALE)
  94. {
  95. std::cout << "Not implemented" << std::endl;
  96. Eigen::MatrixXd calc;
  97. Mean(m_dataSet, calc, Geometry::EMetric::ALE);
  98. //const Eigen::MatrixXd ref = InitMeans::ALE::Reference();
  99. //EXPECT_TRUE(isAlmostEqual(ref, calc)) << ErrorMsg("Mean Matrix ALE", ref, calc);
  100. }
  101. //---------------------------------------------------------------------------------------------------
  102. //---------------------------------------------------------------------------------------------------
  103. TEST_F(Tests_Means, Harmonic)
  104. {
  105. const Eigen::MatrixXd ref = InitMeans::Harmonic::Reference();
  106. Eigen::MatrixXd calc;
  107. Mean(m_dataSet, calc, Geometry::EMetric::Harmonic);
  108. EXPECT_TRUE(isAlmostEqual(ref, calc)) << ErrorMsg("Mean Matrix Harmonic", ref, calc);
  109. }
  110. //---------------------------------------------------------------------------------------------------
  111. //---------------------------------------------------------------------------------------------------
  112. TEST_F(Tests_Means, Identity)
  113. {
  114. const Eigen::MatrixXd ref = InitMeans::Identity::Reference();
  115. Eigen::MatrixXd calc;
  116. Mean(m_dataSet, calc, Geometry::EMetric::Identity);
  117. EXPECT_TRUE(isAlmostEqual(ref, calc)) << ErrorMsg("Mean Matrix Identity", ref, calc);
  118. }
  119. //---------------------------------------------------------------------------------------------------