summaryrefslogtreecommitdiff
path: root/src/Rips_complex/test/test_rips_complex.cpp
diff options
context:
space:
mode:
authorvrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2016-11-22 14:22:16 +0000
committervrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2016-11-22 14:22:16 +0000
commit759b7d6fd92fa8666c41fb3acdb3158d744134c3 (patch)
treec10d9ff567c7069d36dd29ef0b9308ee15631f24 /src/Rips_complex/test/test_rips_complex.cpp
parent71f9bed6df48dedc0d4e8ef620496af9c494eccc (diff)
Add distance matrix Unitary test
git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/distance_matrix_in_rips_module@1768 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 566a69cf00976360c07084ce5df48fcc02f6653f
Diffstat (limited to 'src/Rips_complex/test/test_rips_complex.cpp')
-rw-r--r--src/Rips_complex/test/test_rips_complex.cpp97
1 files changed, 97 insertions, 0 deletions
diff --git a/src/Rips_complex/test/test_rips_complex.cpp b/src/Rips_complex/test/test_rips_complex.cpp
index f8be9748..faedbf4a 100644
--- a/src/Rips_complex/test/test_rips_complex.cpp
+++ b/src/Rips_complex/test/test_rips_complex.cpp
@@ -36,12 +36,14 @@
// to construct a simplex_tree from rips complex
#include <gudhi/Simplex_tree.h>
#include <gudhi/distance_functions.h>
+#include <gudhi/reader_utils.h>
// Type definitions
using Point = std::vector<double>;
using Simplex_tree = Gudhi::Simplex_tree<>;
using Filtration_value = Simplex_tree::Filtration_value;
using Rips_complex = Gudhi::rips_complex::Rips_complex<Simplex_tree::Filtration_value>;
+using Distance_matrix = std::vector<std::vector<Filtration_value>>;
bool are_almost_the_same(float a, float b) {
return std::fabs(a - b) < std::numeric_limits<float>::epsilon();
@@ -231,3 +233,98 @@ BOOST_AUTO_TEST_CASE(Rips_complex_from_points) {
}
}
}
+
+BOOST_AUTO_TEST_CASE(Rips_doc_csv_file) {
+ // ----------------------------------------------------------------------------
+ //
+ // Init of a rips complex from a OFF file
+ //
+ // ----------------------------------------------------------------------------
+ std::string csv_file_name("full_square_distance_matrix.csv");
+ double rips_threshold = 12.0;
+ std::cout << "========== CSV FILE NAME = " << csv_file_name << " - rips threshold=" <<
+ rips_threshold << "==========" << std::endl;
+
+ Distance_matrix distances = read_lower_triangular_matrix_from_csv_file<Filtration_value>(csv_file_name);
+ Rips_complex rips_complex_from_file(distances, rips_threshold);
+
+ const int DIMENSION_1 = 1;
+ Simplex_tree st;
+ BOOST_CHECK(rips_complex_from_file.create_complex(st, DIMENSION_1));
+ std::cout << "st.dimension()=" << st.dimension() << std::endl;
+ BOOST_CHECK(st.dimension() == DIMENSION_1);
+
+ const int NUMBER_OF_VERTICES = 7;
+ std::cout << "st.num_vertices()=" << st.num_vertices() << std::endl;
+ BOOST_CHECK(st.num_vertices() == NUMBER_OF_VERTICES);
+
+ std::cout << "st.num_simplices()=" << st.num_simplices() << std::endl;
+ BOOST_CHECK(st.num_simplices() == 18);
+
+ // Check filtration values of vertices is 0.0
+ for (auto f_simplex : st.skeleton_simplex_range(0)) {
+ BOOST_CHECK(st.filtration(f_simplex) == 0.0);
+ }
+
+ // Check filtration values of edges
+ for (auto f_simplex : st.skeleton_simplex_range(DIMENSION_1)) {
+ if (DIMENSION_1 == st.dimension(f_simplex)) {
+ std::vector<Simplex_tree::Vertex_handle> vvh;
+ std::cout << "vertex = (";
+ for (auto vertex : st.simplex_vertex_range(f_simplex)) {
+ std::cout << vertex << ",";
+ vvh.push_back(vertex);
+ }
+ std::cout << ") - filtration =" << st.filtration(f_simplex) << std::endl;
+ BOOST_CHECK(vvh.size() == 2);
+ BOOST_CHECK(are_almost_the_same(st.filtration(f_simplex), distances[vvh.at(0)][vvh.at(1)]));
+ }
+ }
+
+ const int DIMENSION_2 = 2;
+ Simplex_tree st2;
+ BOOST_CHECK(rips_complex_from_file.create_complex(st2, DIMENSION_2));
+ std::cout << "st2.dimension()=" << st2.dimension() << std::endl;
+ BOOST_CHECK(st2.dimension() == DIMENSION_2);
+
+ std::cout << "st2.num_vertices()=" << st2.num_vertices() << std::endl;
+ BOOST_CHECK(st2.num_vertices() == NUMBER_OF_VERTICES);
+
+ std::cout << "st2.num_simplices()=" << st2.num_simplices() << std::endl;
+ BOOST_CHECK(st2.num_simplices() == 23);
+
+ Simplex_tree::Filtration_value f01 = st2.filtration(st2.find({0, 1}));
+ Simplex_tree::Filtration_value f02 = st2.filtration(st2.find({0, 2}));
+ Simplex_tree::Filtration_value f12 = st2.filtration(st2.find({1, 2}));
+ Simplex_tree::Filtration_value f012 = st2.filtration(st2.find({0, 1, 2}));
+ std::cout << "f012= " << f012 << " | f01= " << f01 << " - f02= " << f02 << " - f12= " << f12 << std::endl;
+ BOOST_CHECK(are_almost_the_same(f012, std::max(f01, std::max(f02,f12))));
+
+ Simplex_tree::Filtration_value f45 = st2.filtration(st2.find({4, 5}));
+ Simplex_tree::Filtration_value f56 = st2.filtration(st2.find({5, 6}));
+ Simplex_tree::Filtration_value f46 = st2.filtration(st2.find({4, 6}));
+ Simplex_tree::Filtration_value f456 = st2.filtration(st2.find({4, 5, 6}));
+ std::cout << "f456= " << f456 << " | f45= " << f45 << " - f56= " << f56 << " - f46= " << f46 << std::endl;
+ BOOST_CHECK(are_almost_the_same(f456, std::max(f45, std::max(f56,f46))));
+
+ const int DIMENSION_3 = 3;
+ Simplex_tree st3;
+ BOOST_CHECK(rips_complex_from_file.create_complex(st3, DIMENSION_3));
+ std::cout << "st3.dimension()=" << st3.dimension() << std::endl;
+ BOOST_CHECK(st3.dimension() == DIMENSION_3);
+
+ std::cout << "st3.num_vertices()=" << st3.num_vertices() << std::endl;
+ BOOST_CHECK(st3.num_vertices() == NUMBER_OF_VERTICES);
+
+ std::cout << "st3.num_simplices()=" << st3.num_simplices() << std::endl;
+ BOOST_CHECK(st3.num_simplices() == 24);
+
+ Simplex_tree::Filtration_value f123 = st3.filtration(st3.find({1, 2, 3}));
+ Simplex_tree::Filtration_value f013 = st3.filtration(st3.find({0, 1, 3}));
+ Simplex_tree::Filtration_value f023 = st3.filtration(st3.find({0, 2, 3}));
+ Simplex_tree::Filtration_value f0123 = st3.filtration(st3.find({0, 1, 2, 3}));
+ std::cout << "f0123= " << f0123 << " | f012= " << f012 << " - f123= " << f123 << " - f013= " << f013 <<
+ " - f023= " << f023 << std::endl;
+ BOOST_CHECK(are_almost_the_same(f0123, std::max(f012, std::max(f123, std::max(f013, f023)))));
+
+} \ No newline at end of file