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_Covariance.hpp 6.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. ///-------------------------------------------------------------------------------------------------
  2. ///
  3. /// \file test_Covariance.hpp
  4. /// \brief Tests for Covariance Matrix 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/Covariance.hpp>
  16. //---------------------------------------------------------------------------------------------------
  17. class Tests_Covariances : public testing::Test
  18. {
  19. protected:
  20. std::vector<std::vector<Eigen::MatrixXd>> m_dataSet;
  21. void SetUp() override { m_dataSet = InitDataset::Dataset(); }
  22. };
  23. //---------------------------------------------------------------------------------------------------
  24. //---------------------------------------------------------------------------------------------------
  25. TEST_F(Tests_Covariances, Covariance_Matrix_COR)
  26. {
  27. std::vector<std::vector<Eigen::MatrixXd>> calc, ref = InitCovariance::COR::Dataset();
  28. calc.resize(m_dataSet.size());
  29. for (size_t k = 0; k < m_dataSet.size(); ++k)
  30. {
  31. calc[k].resize(m_dataSet[k].size());
  32. for (size_t i = 0; i < m_dataSet[k].size(); ++i)
  33. {
  34. CovarianceMatrix(m_dataSet[k][i], calc[k][i], Geometry::EEstimator::COR, Geometry::EStandardization::None);
  35. const std::string title = "Covariance Matrix COR Sample [" + std::to_string(k) + "][" + std::to_string(i) + "]";
  36. EXPECT_TRUE(isAlmostEqual(ref[k][i], calc[k][i])) << ErrorMsg(title, ref[k][i], calc[k][i]);
  37. }
  38. }
  39. }
  40. //---------------------------------------------------------------------------------------------------
  41. //---------------------------------------------------------------------------------------------------
  42. TEST_F(Tests_Covariances, Covariance_Matrix_COV)
  43. {
  44. std::vector<std::vector<Eigen::MatrixXd>> calc, ref = InitCovariance::COV::Dataset();
  45. calc.resize(m_dataSet.size());
  46. for (size_t k = 0; k < m_dataSet.size(); ++k)
  47. {
  48. calc[k].resize(m_dataSet[k].size());
  49. for (size_t i = 0; i < m_dataSet[k].size(); ++i)
  50. {
  51. CovarianceMatrix(m_dataSet[k][i], calc[k][i], Geometry::EEstimator::COV, Geometry::EStandardization::None);
  52. const std::string title = "Covariance Matrix COV Sample [" + std::to_string(k) + "][" + std::to_string(i) + "]";
  53. EXPECT_TRUE(isAlmostEqual(ref[k][i], calc[k][i])) << ErrorMsg(title, ref[k][i], calc[k][i]);
  54. }
  55. }
  56. }
  57. //---------------------------------------------------------------------------------------------------
  58. //---------------------------------------------------------------------------------------------------
  59. TEST_F(Tests_Covariances, Covariance_Matrix_LWF)
  60. {
  61. std::vector<std::vector<Eigen::MatrixXd>> calc, ref = InitCovariance::LWF::Reference();
  62. calc.resize(m_dataSet.size());
  63. for (size_t k = 0; k < m_dataSet.size(); ++k)
  64. {
  65. calc[k].resize(m_dataSet[k].size());
  66. for (size_t i = 0; i < m_dataSet[k].size(); ++i)
  67. {
  68. CovarianceMatrix(m_dataSet[k][i], calc[k][i], Geometry::EEstimator::LWF, Geometry::EStandardization::Center);
  69. const std::string title = "Covariance Matrix LWF Sample [" + std::to_string(k) + "][" + std::to_string(i) + "]";
  70. EXPECT_TRUE(isAlmostEqual(ref[k][i], calc[k][i])) << ErrorMsg(title, ref[k][i], calc[k][i]);
  71. }
  72. }
  73. }
  74. //---------------------------------------------------------------------------------------------------
  75. //---------------------------------------------------------------------------------------------------
  76. TEST_F(Tests_Covariances, Covariance_Matrix_MCD)
  77. {
  78. std::cout << "Not implemented" << std::endl;
  79. std::vector<std::vector<Eigen::MatrixXd>> calc;
  80. //std::vector<std::vector<Eigen::MatrixXd>> ref = InitCovariance::MCD::Reference();
  81. calc.resize(m_dataSet.size());
  82. for (size_t k = 0; k < m_dataSet.size(); ++k)
  83. {
  84. calc[k].resize(m_dataSet[k].size());
  85. for (size_t i = 0; i < m_dataSet[k].size(); ++i)
  86. {
  87. CovarianceMatrix(m_dataSet[k][i], calc[k][i], Geometry::EEstimator::MCD, Geometry::EStandardization::Center);
  88. //const std::string title = "Covariance Matrix MCD Sample [" + std::to_string(k) + "][" + std::to_string(i) + "]";
  89. //EXPECT_TRUE(isAlmostEqual(ref[k][i], calc[k][i])) << ErrorMsg(title, ref[k][i], calc[k][i]);
  90. }
  91. }
  92. }
  93. //---------------------------------------------------------------------------------------------------
  94. //---------------------------------------------------------------------------------------------------
  95. TEST_F(Tests_Covariances, Covariance_Matrix_OAS)
  96. {
  97. std::vector<std::vector<Eigen::MatrixXd>> calc, ref = InitCovariance::OAS::Reference();
  98. calc.resize(m_dataSet.size());
  99. for (size_t k = 0; k < m_dataSet.size(); ++k)
  100. {
  101. calc[k].resize(m_dataSet[k].size());
  102. for (size_t i = 0; i < m_dataSet[k].size(); ++i)
  103. {
  104. CovarianceMatrix(m_dataSet[k][i], calc[k][i], Geometry::EEstimator::OAS, Geometry::EStandardization::Center);
  105. const std::string title = "Covariance Matrix OAS Sample [" + std::to_string(k) + "][" + std::to_string(i) + "]";
  106. EXPECT_TRUE(isAlmostEqual(ref[k][i], calc[k][i])) << ErrorMsg(title, ref[k][i], calc[k][i]);
  107. }
  108. }
  109. }
  110. //---------------------------------------------------------------------------------------------------
  111. //---------------------------------------------------------------------------------------------------
  112. TEST_F(Tests_Covariances, Covariance_Matrix_SCM)
  113. {
  114. std::vector<std::vector<Eigen::MatrixXd>> calc, ref = InitCovariance::SCM::Reference();
  115. calc.resize(m_dataSet.size());
  116. for (size_t k = 0; k < m_dataSet.size(); ++k)
  117. {
  118. calc[k].resize(m_dataSet[k].size());
  119. for (size_t i = 0; i < m_dataSet[k].size(); ++i)
  120. {
  121. CovarianceMatrix(m_dataSet[k][i], calc[k][i], Geometry::EEstimator::SCM, Geometry::EStandardization::None);
  122. const std::string title = "Covariance Matrix SCM Sample [" + std::to_string(k) + "][" + std::to_string(i) + "]";
  123. EXPECT_TRUE(isAlmostEqual(ref[k][i], calc[k][i])) << ErrorMsg(title, ref[k][i], calc[k][i]);
  124. }
  125. }
  126. }
  127. //---------------------------------------------------------------------------------------------------
  128. //---------------------------------------------------------------------------------------------------
  129. TEST_F(Tests_Covariances, Covariance_Matrix_IDE)
  130. {
  131. std::vector<std::vector<Eigen::MatrixXd>> calc;
  132. const Eigen::MatrixXd ref = Eigen::MatrixXd::Identity(NB_CHAN, NB_CHAN);
  133. calc.resize(m_dataSet.size());
  134. for (size_t k = 0; k < m_dataSet.size(); ++k)
  135. {
  136. calc[k].resize(m_dataSet[k].size());
  137. for (size_t i = 0; i < m_dataSet[k].size(); ++i)
  138. {
  139. CovarianceMatrix(m_dataSet[k][i], calc[k][i], Geometry::EEstimator::IDE, Geometry::EStandardization::None);
  140. const std::string title = "Covariance Matrix IDE Sample [" + std::to_string(k) + "][" + std::to_string(i) + "]";
  141. EXPECT_TRUE(isAlmostEqual(ref, calc[k][i])) << ErrorMsg(title, ref, calc[k][i]);
  142. }
  143. }
  144. }
  145. //---------------------------------------------------------------------------------------------------