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_ASR.hpp 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. ///-------------------------------------------------------------------------------------------------
  2. ///
  3. /// \file test_ASR.hpp
  4. /// \brief Tests for Artifact Subspace Reconstruction.
  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/artifacts/CASR.hpp>
  17. #include <geometry/Basics.hpp>
  18. //---------------------------------------------------------------------------------------------------
  19. class Tests_ASR : public testing::Test
  20. {
  21. protected:
  22. std::vector<Eigen::MatrixXd> m_dataset;
  23. void SetUp() override { m_dataset = Geometry::Vector2DTo1D(InitDataset::Dataset()); }
  24. };
  25. //---------------------------------------------------------------------------------------------------
  26. //---------------------------------------------------------------------------------------------------
  27. TEST_F(Tests_ASR, Train_Euclidian)
  28. {
  29. const Geometry::CASR ref = InitASR::Euclidian::Reference();
  30. const Geometry::CASR calc(Geometry::EMetric::Euclidian, m_dataset);
  31. EXPECT_TRUE(calc == ref) << ErrorMsg("Train ASR in Euclidian metric", ref, calc);
  32. }
  33. //---------------------------------------------------------------------------------------------------
  34. //---------------------------------------------------------------------------------------------------
  35. TEST_F(Tests_ASR, Train_Riemann)
  36. {
  37. std::cout << "Riemannian Eigen Value isn't implemented, so result is same as Euclidian metric." << std::endl;
  38. const Geometry::CASR ref = InitASR::Riemann::Reference();
  39. const Geometry::CASR calc(Geometry::EMetric::Riemann, m_dataset);
  40. EXPECT_TRUE(calc == ref) << ErrorMsg("Train ASR in Riemann metric", ref, calc);
  41. }
  42. //---------------------------------------------------------------------------------------------------
  43. //---------------------------------------------------------------------------------------------------
  44. TEST_F(Tests_ASR, Process)
  45. {
  46. m_dataset = InitDataset::FirstClassDataset();
  47. Geometry::CASR calc(Geometry::EMetric::Euclidian, m_dataset);
  48. std::vector<Eigen::MatrixXd> testset = InitDataset::SecondClassDataset();
  49. std::vector<Eigen::MatrixXd> result(testset.size());
  50. for (size_t i = 0; i < testset.size(); ++i)
  51. {
  52. testset[i] *= 2;
  53. EXPECT_TRUE(calc.process(testset[i], result[i])) << "ASR Process fail for sample " + std::to_string(i) + ".\n";
  54. }
  55. for (size_t i = 1; i < testset.size(); ++i)
  56. {
  57. EXPECT_FALSE(isAlmostEqual(result[i], testset[i])) << "the sample " + std::to_string(i) + " wasn't reconstructed.\n";
  58. }
  59. }
  60. //---------------------------------------------------------------------------------------------------
  61. //---------------------------------------------------------------------------------------------------
  62. TEST_F(Tests_ASR, Save)
  63. {
  64. Geometry::CASR calc;
  65. const Geometry::CASR ref = InitASR::Euclidian::Reference();
  66. EXPECT_TRUE(ref.saveXML("test_ASR_Save.xml")) << "Error during Saving : " << std::endl << ref << std::endl;
  67. EXPECT_TRUE(calc.loadXML("test_ASR_Save.xml")) << "Error during Loading : " << std::endl << calc << std::endl;
  68. EXPECT_TRUE(ref == calc) << ErrorMsg("ASR Save", ref, calc);
  69. }
  70. //---------------------------------------------------------------------------------------------------