From ca6b3d72f2114cdd2d0899fd44dba19303dd3bb2 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Wed, 28 Sep 2016 11:15:34 +0000 Subject: Add rips complex module and first modification step git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/rips_complex_module@1577 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: fc949570c6cffa4756f84a15c41fadc8c45b2af2 --- src/common/include/gudhi/distance_functions.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/common/include/gudhi/distance_functions.h') diff --git a/src/common/include/gudhi/distance_functions.h b/src/common/include/gudhi/distance_functions.h index cd518581..b2726ba8 100644 --- a/src/common/include/gudhi/distance_functions.h +++ b/src/common/include/gudhi/distance_functions.h @@ -29,7 +29,7 @@ * by a range of coordinates. The points are assumed to have * the same dimension. */ template< typename Point > -double euclidean_distance(Point &p1, Point &p2) { +double euclidean_distance(const Point &p1,const Point &p2) { double dist = 0.; auto it1 = p1.begin(); auto it2 = p2.begin(); -- cgit v1.2.3 From 5ce7c7c8ec1378439cdc02dc94ac2a7e14e9ca04 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Mon, 3 Oct 2016 15:17:04 +0000 Subject: Fix euclidean distance for rips git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/rips_complex_module@1610 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: a07dfd4ffe3f17bf242ffb5b57058e99171a8016 --- src/GudhUI/utils/Persistence_compute.h | 2 +- .../benchmark/performance_rips_persistence.cpp | 4 ++-- .../example/rips_multifield_persistence.cpp | 4 ++-- src/Persistent_cohomology/example/rips_persistence.cpp | 4 ++-- .../example/rips_persistence_via_boundary_matrix.cpp | 2 +- .../example/example_one_skeleton_rips_from_points.cpp | 9 +++++---- src/Rips_complex/example/example_rips_complex_from_off_file.cpp | 5 +++-- src/Rips_complex/test/test_rips_complex.cpp | 8 +++++--- .../include/gudhi/Landmark_choice_by_furthest_point.h | 2 +- .../include/gudhi/Landmark_choice_by_random_point.h | 2 +- src/common/include/gudhi/distance_functions.h | 8 ++++---- 11 files changed, 27 insertions(+), 23 deletions(-) (limited to 'src/common/include/gudhi/distance_functions.h') diff --git a/src/GudhUI/utils/Persistence_compute.h b/src/GudhUI/utils/Persistence_compute.h index fa5bafc1..f7048c28 100644 --- a/src/GudhUI/utils/Persistence_compute.h +++ b/src/GudhUI/utils/Persistence_compute.h @@ -76,7 +76,7 @@ template class Persistence_compute { using Field_Zp = Gudhi::persistent_cohomology::Field_Zp; using Persistent_cohomology = Gudhi::persistent_cohomology::Persistent_cohomology; - Rips_complex rips_complex(points, params.threshold, euclidean_distance); + Rips_complex rips_complex(points, params.threshold, euclidean_distance); Simplex_tree st; if (rips_complex.create_complex(st, params.max_dim)) { diff --git a/src/Persistent_cohomology/benchmark/performance_rips_persistence.cpp b/src/Persistent_cohomology/benchmark/performance_rips_persistence.cpp index 99fcad41..a9eab5dd 100644 --- a/src/Persistent_cohomology/benchmark/performance_rips_persistence.cpp +++ b/src/Persistent_cohomology/benchmark/performance_rips_persistence.cpp @@ -33,7 +33,7 @@ #include // Types definition -using Simplex_tree = Gudhi::Simplex_tree; +using Simplex_tree = Gudhi::Simplex_tree; using Filtration_value = Simplex_tree::Filtration_value; using Rips_complex = Gudhi::rips_complex::Rips_complex; using Field_Zp = Gudhi::persistent_cohomology::Field_Zp; @@ -84,7 +84,7 @@ int main(int argc, char * argv[]) { // Compute the proximity graph of the points start = std::chrono::system_clock::now(); Rips_complex rips_complex_from_file(off_reader.get_point_cloud(), threshold, - euclidean_distance); + euclidean_distance); end = std::chrono::system_clock::now(); elapsed_sec = std::chrono::duration_cast(end - start).count(); std::cout << "Compute Rips graph in " << elapsed_sec << " ms.\n"; diff --git a/src/Persistent_cohomology/example/rips_multifield_persistence.cpp b/src/Persistent_cohomology/example/rips_multifield_persistence.cpp index f4adc7a9..8e5c83a1 100644 --- a/src/Persistent_cohomology/example/rips_multifield_persistence.cpp +++ b/src/Persistent_cohomology/example/rips_multifield_persistence.cpp @@ -33,7 +33,7 @@ #include // Types definition -using Simplex_tree = Gudhi::Simplex_tree; +using Simplex_tree = Gudhi::Simplex_tree; using Filtration_value = Simplex_tree::Filtration_value; using Rips_complex = Gudhi::rips_complex::Rips_complex; using Multi_field = Gudhi::persistent_cohomology::Multi_field; @@ -63,7 +63,7 @@ int main(int argc, char * argv[]) { Points_off_reader off_reader(off_file_points); Rips_complex rips_complex_from_file(off_reader.get_point_cloud(), threshold, - euclidean_distance); + euclidean_distance); // Construct the Rips complex in a Simplex Tree Simplex_tree simplex_tree; diff --git a/src/Persistent_cohomology/example/rips_persistence.cpp b/src/Persistent_cohomology/example/rips_persistence.cpp index 97bab14c..b74d0094 100644 --- a/src/Persistent_cohomology/example/rips_persistence.cpp +++ b/src/Persistent_cohomology/example/rips_persistence.cpp @@ -34,7 +34,7 @@ #include // infinity // Types definition -using Simplex_tree = Gudhi::Simplex_tree; +using Simplex_tree = Gudhi::Simplex_tree; using Filtration_value = Simplex_tree::Filtration_value; using Rips_complex = Gudhi::rips_complex::Rips_complex; using Field_Zp = Gudhi::persistent_cohomology::Field_Zp; @@ -62,7 +62,7 @@ int main(int argc, char * argv[]) { Points_off_reader off_reader(off_file_points); Rips_complex rips_complex_from_file(off_reader.get_point_cloud(), threshold, - euclidean_distance); + euclidean_distance); // Construct the Rips complex in a Simplex Tree Simplex_tree simplex_tree; diff --git a/src/Persistent_cohomology/example/rips_persistence_via_boundary_matrix.cpp b/src/Persistent_cohomology/example/rips_persistence_via_boundary_matrix.cpp index 991ed4f0..ee6577f4 100644 --- a/src/Persistent_cohomology/example/rips_persistence_via_boundary_matrix.cpp +++ b/src/Persistent_cohomology/example/rips_persistence_via_boundary_matrix.cpp @@ -72,7 +72,7 @@ int main(int argc, char * argv[]) { Points_off_reader off_reader(off_file_points); Rips_complex rips_complex_from_file(off_reader.get_point_cloud(), threshold, - euclidean_distance); + euclidean_distance); // Construct the Rips complex in a Simplex Tree Simplex_tree& st = *new Simplex_tree; diff --git a/src/Rips_complex/example/example_one_skeleton_rips_from_points.cpp b/src/Rips_complex/example/example_one_skeleton_rips_from_points.cpp index db41b425..2e63d9a6 100644 --- a/src/Rips_complex/example/example_one_skeleton_rips_from_points.cpp +++ b/src/Rips_complex/example/example_one_skeleton_rips_from_points.cpp @@ -23,8 +23,9 @@ int main(int argc, char **argv) { // Type definitions using Point = std::vector; - using Simplex_tree = Gudhi::Simplex_tree<>; - using Rips_complex = Gudhi::rips_complex::Rips_complex; + using Simplex_tree = Gudhi::Simplex_tree; + using Filtration_value = Simplex_tree::Filtration_value; + using Rips_complex = Gudhi::rips_complex::Rips_complex; std::vector points; points.push_back({1.0, 1.0}); @@ -38,10 +39,10 @@ int main(int argc, char **argv) { // ---------------------------------------------------------------------------- // Init of a rips complex from points // ---------------------------------------------------------------------------- - Rips_complex rips_complex_from_file(points, threshold, euclidean_distance); + Rips_complex rips_complex_from_points(points, threshold, euclidean_distance); Simplex_tree simplex; - if (rips_complex_from_file.create_complex(simplex, 1)) { + if (rips_complex_from_points.create_complex(simplex, 1)) { // ---------------------------------------------------------------------------- // Display information about the one skeleton rips complex // ---------------------------------------------------------------------------- diff --git a/src/Rips_complex/example/example_rips_complex_from_off_file.cpp b/src/Rips_complex/example/example_rips_complex_from_off_file.cpp index 82baa68e..60050cea 100644 --- a/src/Rips_complex/example/example_rips_complex_from_off_file.cpp +++ b/src/Rips_complex/example/example_rips_complex_from_off_file.cpp @@ -25,14 +25,15 @@ int main(int argc, char **argv) { // Type definitions using Point = std::vector; using Simplex_tree = Gudhi::Simplex_tree<>; - using Rips_complex = Gudhi::rips_complex::Rips_complex; + using Filtration_value = Simplex_tree::Filtration_value; + using Rips_complex = Gudhi::rips_complex::Rips_complex; // ---------------------------------------------------------------------------- // Init of a rips complex from an OFF file // ---------------------------------------------------------------------------- Gudhi::Points_off_reader off_reader(off_file_name); Rips_complex rips_complex_from_file(off_reader.get_point_cloud(), threshold, - euclidean_distance); + euclidean_distance); std::streambuf* streambufffer; std::ofstream ouput_file_stream; diff --git a/src/Rips_complex/test/test_rips_complex.cpp b/src/Rips_complex/test/test_rips_complex.cpp index 5f129160..f8be9748 100644 --- a/src/Rips_complex/test/test_rips_complex.cpp +++ b/src/Rips_complex/test/test_rips_complex.cpp @@ -40,6 +40,7 @@ // Type definitions using Point = std::vector; using Simplex_tree = Gudhi::Simplex_tree<>; +using Filtration_value = Simplex_tree::Filtration_value; using Rips_complex = Gudhi::rips_complex::Rips_complex; bool are_almost_the_same(float a, float b) { @@ -58,7 +59,8 @@ BOOST_AUTO_TEST_CASE(RIPS_DOC_OFF_file) { rips_threshold << "==========" << std::endl; Gudhi::Points_off_reader off_reader(off_file_name); - Rips_complex rips_complex_from_file(off_reader.get_point_cloud(), rips_threshold, euclidean_distance); + Rips_complex rips_complex_from_file(off_reader.get_point_cloud(), rips_threshold, + euclidean_distance); const int DIMENSION_1 = 1; Simplex_tree st; @@ -87,10 +89,10 @@ BOOST_AUTO_TEST_CASE(RIPS_DOC_OFF_file) { std::cout << vertex << ","; vp.push_back(off_reader.get_point_cloud().at(vertex)); } - std::cout << ") - distance =" << euclidean_distance(vp.at(0), vp.at(1)) << + std::cout << ") - distance =" << euclidean_distance(vp.at(0), vp.at(1)) << " - filtration =" << st.filtration(f_simplex) << std::endl; BOOST_CHECK(vp.size() == 2); - BOOST_CHECK(are_almost_the_same(st.filtration(f_simplex), euclidean_distance(vp.at(0), vp.at(1)))); + BOOST_CHECK(are_almost_the_same(st.filtration(f_simplex), euclidean_distance(vp.at(0), vp.at(1)))); } } diff --git a/src/Witness_complex/include/gudhi/Landmark_choice_by_furthest_point.h b/src/Witness_complex/include/gudhi/Landmark_choice_by_furthest_point.h index df93155b..bcb89e00 100644 --- a/src/Witness_complex/include/gudhi/Landmark_choice_by_furthest_point.h +++ b/src/Witness_complex/include/gudhi/Landmark_choice_by_furthest_point.h @@ -77,7 +77,7 @@ namespace witness_complex { chosen_landmarks.push_back(curr_max_w); unsigned i = 0; for (auto& p : points) { - double curr_dist = euclidean_distance(p, *(std::begin(points) + chosen_landmarks[current_number_of_landmarks])); + double curr_dist = euclidean_distance(p, *(std::begin(points) + chosen_landmarks[current_number_of_landmarks])); wit_land_dist[i].push_back(curr_dist); knn[i].push_back(current_number_of_landmarks); if (curr_dist < dist_to_L[i]) diff --git a/src/Witness_complex/include/gudhi/Landmark_choice_by_random_point.h b/src/Witness_complex/include/gudhi/Landmark_choice_by_random_point.h index ebf6aad1..b5aab9d5 100644 --- a/src/Witness_complex/include/gudhi/Landmark_choice_by_random_point.h +++ b/src/Witness_complex/include/gudhi/Landmark_choice_by_random_point.h @@ -78,7 +78,7 @@ namespace witness_complex { int landmarks_i = 0; for (landmarks_it = landmarks.begin(), landmarks_i = 0; landmarks_it != landmarks.end(); ++landmarks_it, landmarks_i++) { - dist_i dist = std::make_pair(euclidean_distance(points[points_i], points[*landmarks_it]), landmarks_i); + dist_i dist = std::make_pair(euclidean_distance(points[points_i], points[*landmarks_it]), landmarks_i); l_heap.push(dist); } for (int i = 0; i < dim + 1; i++) { diff --git a/src/common/include/gudhi/distance_functions.h b/src/common/include/gudhi/distance_functions.h index b2726ba8..006df275 100644 --- a/src/common/include/gudhi/distance_functions.h +++ b/src/common/include/gudhi/distance_functions.h @@ -28,13 +28,13 @@ /* Compute the Euclidean distance between two Points given * by a range of coordinates. The points are assumed to have * the same dimension. */ -template< typename Point > -double euclidean_distance(const Point &p1,const Point &p2) { - double dist = 0.; +template< typename Filtration_value, typename Point > +Filtration_value euclidean_distance(const Point &p1,const Point &p2) { + Filtration_value dist = 0.; auto it1 = p1.begin(); auto it2 = p2.begin(); for (; it1 != p1.end(); ++it1, ++it2) { - double tmp = *it1 - *it2; + Filtration_value tmp = (double)(*it1) - (double)(*it2); dist += tmp*tmp; } return std::sqrt(dist); -- cgit v1.2.3