summaryrefslogtreecommitdiff
path: root/src/Rips_complex
diff options
context:
space:
mode:
authorglisse <glisse@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2018-01-31 14:48:07 +0000
committerglisse <glisse@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2018-01-31 14:48:07 +0000
commit7b9b9dcdf26e283232195c9fb3b17f1cc23f0057 (patch)
tree68acd1032d324f7a640df7ca532b4fe44c24f644 /src/Rips_complex
parentc68ef729971d88818ceae9f1aa8e33f62a4dea7a (diff)
test
git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/sparserips-glisse@3196 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 4fbf12d3a2adc56ee85a13fc35571de3963fee70
Diffstat (limited to 'src/Rips_complex')
-rw-r--r--src/Rips_complex/example/example_sparse_rips.cpp6
-rw-r--r--src/Rips_complex/test/test_rips_complex.cpp67
2 files changed, 70 insertions, 3 deletions
diff --git a/src/Rips_complex/example/example_sparse_rips.cpp b/src/Rips_complex/example/example_sparse_rips.cpp
index 49725f0a..94e345ea 100644
--- a/src/Rips_complex/example/example_sparse_rips.cpp
+++ b/src/Rips_complex/example/example_sparse_rips.cpp
@@ -9,7 +9,7 @@ int main() {
using Point = std::vector<double>;
using Simplex_tree = Gudhi::Simplex_tree<Gudhi::Simplex_tree_options_fast_persistence>;
using Filtration_value = Simplex_tree::Filtration_value;
- using Complex = Gudhi::rips_complex::Sparse_rips_complex<Filtration_value>;
+ using Sparse_rips = Gudhi::rips_complex::Sparse_rips_complex<Filtration_value>;
Point points[] = {
{1.0, 1.0},
@@ -24,10 +24,10 @@ int main() {
// Init from Euclidean points
// ----------------------------------------------------------------------------
double epsilon = 2; // very rough, no guarantees
- Complex cpx(points, Gudhi::Euclidean_distance(), epsilon);
+ Sparse_rips sparse_rips(points, Gudhi::Euclidean_distance(), epsilon);
Simplex_tree stree;
- cpx.create_complex(stree, 10);
+ sparse_rips.create_complex(stree, 10);
// ----------------------------------------------------------------------------
// Display information about the complex
diff --git a/src/Rips_complex/test/test_rips_complex.cpp b/src/Rips_complex/test/test_rips_complex.cpp
index 89afbc25..4e7b79d2 100644
--- a/src/Rips_complex/test/test_rips_complex.cpp
+++ b/src/Rips_complex/test/test_rips_complex.cpp
@@ -31,6 +31,7 @@
#include <algorithm> // std::max
#include <gudhi/Rips_complex.h>
+#include <gudhi/Sparse_rips_complex.h>
// to construct Rips_complex from a OFF file of points
#include <gudhi/Points_off_io.h>
#include <gudhi/Simplex_tree.h>
@@ -43,6 +44,7 @@ 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 Sparse_rips_complex = Gudhi::rips_complex::Sparse_rips_complex<Simplex_tree::Filtration_value>;
using Distance_matrix = std::vector<std::vector<Filtration_value>>;
BOOST_AUTO_TEST_CASE(RIPS_DOC_OFF_file) {
@@ -230,6 +232,71 @@ BOOST_AUTO_TEST_CASE(Rips_complex_from_points) {
}
}
+BOOST_AUTO_TEST_CASE(Sparse_rips_complex_from_points) {
+ // This is a clone of the test above
+ // ----------------------------------------------------------------------------
+ // Init of a list of points
+ // ----------------------------------------------------------------------------
+ Vector_of_points points;
+ std::vector<double> coords = { 0.0, 0.0, 0.0, 1.0 };
+ points.push_back(Point(coords.begin(), coords.end()));
+ coords = { 0.0, 0.0, 1.0, 0.0 };
+ points.push_back(Point(coords.begin(), coords.end()));
+ coords = { 0.0, 1.0, 0.0, 0.0 };
+ points.push_back(Point(coords.begin(), coords.end()));
+ coords = { 1.0, 0.0, 0.0, 0.0 };
+ points.push_back(Point(coords.begin(), coords.end()));
+
+ // ----------------------------------------------------------------------------
+ // Init of a Rips complex from the list of points
+ // ----------------------------------------------------------------------------
+ // .001 is small enough that we get a deterministic result matching the exact Rips
+ Sparse_rips_complex sparse_rips(points, Custom_square_euclidean_distance(), .001);
+
+ std::cout << "========== Sparse_rips_complex_from_points ==========" << std::endl;
+ Simplex_tree st;
+ const int DIMENSION = 3;
+ sparse_rips.create_complex(st, DIMENSION);
+
+ // Another way to check num_simplices
+ std::cout << "Iterator on Rips complex simplices in the filtration order, with [filtration value]:" << std::endl;
+ int num_simplices = 0;
+ for (auto f_simplex : st.filtration_simplex_range()) {
+ num_simplices++;
+ std::cout << " ( ";
+ for (auto vertex : st.simplex_vertex_range(f_simplex)) {
+ std::cout << vertex << " ";
+ }
+ std::cout << ") -> " << "[" << st.filtration(f_simplex) << "] ";
+ std::cout << std::endl;
+ }
+ BOOST_CHECK(num_simplices == 15);
+ std::cout << "st.num_simplices()=" << st.num_simplices() << std::endl;
+ BOOST_CHECK(st.num_simplices() == 15);
+
+ std::cout << "st.dimension()=" << st.dimension() << std::endl;
+ BOOST_CHECK(st.dimension() == DIMENSION);
+ std::cout << "st.num_vertices()=" << st.num_vertices() << std::endl;
+ BOOST_CHECK(st.num_vertices() == 4);
+
+ for (auto f_simplex : st.filtration_simplex_range()) {
+ std::cout << "dimension(" << st.dimension(f_simplex) << ") - f = " << st.filtration(f_simplex) << std::endl;
+ switch (st.dimension(f_simplex)) {
+ case 0:
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(st.filtration(f_simplex), 0.0);
+ break;
+ case 1:
+ case 2:
+ case 3:
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(st.filtration(f_simplex), 2.0);
+ break;
+ default:
+ BOOST_CHECK(false); // Shall not happen
+ break;
+ }
+ }
+}
+
BOOST_AUTO_TEST_CASE(Rips_doc_csv_file) {
// ----------------------------------------------------------------------------
//