From 1a728400187d89db914e865a979c85c7260b0b02 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Mon, 21 Nov 2016 16:24:15 +0000 Subject: Add distance matrix rips construction (doc, code, test) git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/distance_matrix_in_rips_module@1766 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 6b9bdecbaf0aca12facb023e66bdea71e8e8cd38 --- src/common/doc/main_page.h | 3 +- src/common/include/gudhi/distance_functions.h | 11 +-- .../include/gudhi/graph_simplicial_complex.h | 2 +- src/common/include/gudhi/reader_utils.h | 84 +++++++++++----------- src/common/test/test_distance_matrix_reader.cpp | 16 ++--- 5 files changed, 62 insertions(+), 54 deletions(-) (limited to 'src/common') diff --git a/src/common/doc/main_page.h b/src/common/doc/main_page.h index 85310f66..85ae8679 100644 --- a/src/common/doc/main_page.h +++ b/src/common/doc/main_page.h @@ -60,7 +60,7 @@ @@ -68,6 +68,7 @@ Rips_complex is a simplicial complex constructed from a one skeleton graph.
The filtration value of each edge is computed from a user-given distance function and is inserted until a user-given threshold value.
+ This complex can be built from a point cloud and a distance function, or from a distance matrix.
User manual: \ref rips_complex - Reference manual: Gudhi::rips_complex::Rips_complex diff --git a/src/common/include/gudhi/distance_functions.h b/src/common/include/gudhi/distance_functions.h index 006df275..ed2c1f5d 100644 --- a/src/common/include/gudhi/distance_functions.h +++ b/src/common/include/gudhi/distance_functions.h @@ -4,7 +4,7 @@ * * Author(s): Clément Maria * - * Copyright (C) 2014 INRIA Sophia Antipolis-Méditerranée (France) + * Copyright (C) 2014 INRIA * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -25,9 +25,12 @@ #include // for std::sqrt -/* Compute the Euclidean distance between two Points given - * by a range of coordinates. The points are assumed to have - * the same dimension. */ +/** @file + * @brief Global distance functions + */ + +/** @brief Compute the Euclidean distance between two Points given by a range of coordinates. The points are assumed to + * have the same dimension. */ template< typename Filtration_value, typename Point > Filtration_value euclidean_distance(const Point &p1,const Point &p2) { Filtration_value dist = 0.; diff --git a/src/common/include/gudhi/graph_simplicial_complex.h b/src/common/include/gudhi/graph_simplicial_complex.h index 9dbcd891..5fe7c826 100644 --- a/src/common/include/gudhi/graph_simplicial_complex.h +++ b/src/common/include/gudhi/graph_simplicial_complex.h @@ -4,7 +4,7 @@ * * Author(s): Clément Maria * - * Copyright (C) 2014 INRIA Sophia Antipolis-Méditerranée (France) + * Copyright (C) 2014 INRIA * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/common/include/gudhi/reader_utils.h b/src/common/include/gudhi/reader_utils.h index 40d566d8..3799e583 100644 --- a/src/common/include/gudhi/reader_utils.h +++ b/src/common/include/gudhi/reader_utils.h @@ -34,14 +34,20 @@ #include #include +// Keep this file tag for Doxygen to parse the code, otherwise, functions are not documented. +// It is required for global functions and variables. + +/** @file + * @brief This file includes common file reader for GUDHI + */ + /** - * \brief Read a set of points to turn it - * into a vector< vector > by filling points + * @brief Read a set of points to turn it into a vector< vector > by filling points. * - * File format: 1 point per line - * X11 X12 ... X1d - * X21 X22 ... X2d - * etc + * File format: 1 point per line
+ * X11 X12 ... X1d
+ * X21 X22 ... X2d
+ * etc
*/ inline void read_points(std::string file_name, std::vector< std::vector< double > > & points) { std::ifstream in_file(file_name.c_str(), std::ios::in); @@ -66,12 +72,12 @@ inline void read_points(std::string file_name, std::vector< std::vector< double } /** - * \brief Read a graph from a file. + * @brief Read a graph from a file. * - * File format: 1 simplex per line - * Dim1 X11 X12 ... X1d Fil1 - * Dim2 X21 X22 ... X2d Fil2 - * etc + * File format: 1 simplex per line
+ * Dim1 X11 X12 ... X1d Fil1
+ * Dim2 X21 X22 ... X2d Fil2
+ * etc
* * The vertices must be labeled from 0 to n-1. * Every simplex must appear exactly once. @@ -141,12 +147,12 @@ inline Graph_t read_graph(std::string file_name) { } /** - * \brief Read a face from a file. + * @brief Read a face from a file. * - * File format: 1 simplex per line - * Dim1 X11 X12 ... X1d Fil1 - * Dim2 X21 X22 ... X2d Fil2 - * etc + * File format: 1 simplex per line
+ * Dim1 X11 X12 ... X1d Fil1
+ * Dim2 X21 X22 ... X2d Fil2
+ * etc
* * The vertices must be labeled from 0 to n-1. * Every simplex must appear exactly once. @@ -167,18 +173,16 @@ bool read_simplex(std::istream & in_, std::vector< Vertex_handle > & simplex, Fi } /** - * \brief Read a hasse simplex from a file. + * @brief Read a hasse simplex from a file. * - * File format: 1 simplex per line - * Dim1 k11 k12 ... k1Dim1 Fil1 - * Dim2 k21 k22 ... k2Dim2 Fil2 - * etc + * File format: 1 simplex per line
+ * Dim1 k11 k12 ... k1Dim1 Fil1
+ * Dim2 k21 k22 ... k2Dim2 Fil2
+ * etc
* - * The key of a simplex is its position in the filtration order - * and also the number of its row in the file. - * Dimi ki1 ki2 ... kiDimi Fili means that the ith simplex in the - * filtration has dimension Dimi, filtration value fil1 and simplices with - * key ki1 ... kiDimi in its boundary.*/ + * The key of a simplex is its position in the filtration order and also the number of its row in the file. + * Dimi ki1 ki2 ... kiDimi Fili means that the ith simplex in the filtration has dimension Dimi, filtration value + * fil1 and simplices with key ki1 ... kiDimi in its boundary.*/ template< typename Simplex_key, typename Filtration_value > bool read_hasse_simplex(std::istream & in_, std::vector< Simplex_key > & boundary, Filtration_value & fil) { int dim; @@ -197,27 +201,27 @@ bool read_hasse_simplex(std::istream & in_, std::vector< Simplex_key > & boundar } /** - * \brief Read a lower triangular distance matrix from a csv file. We assume that the .csv store the whole + * @brief Read a lower triangular distance matrix from a csv file. We assume that the .csv store the whole * (square) matrix. * - * \author Pawel Dlotko + * @author Pawel Dlotko * - * Square matrix file format: - * 0;D12;...;D1j - * D21;0;...;D2j - * ... - * Dj1;Dj2;...;0 + * Square matrix file format:
+ * 0;D12;...;D1j
+ * D21;0;...;D2j
+ * ...
+ * Dj1;Dj2;...;0
* - * lower matrix file format: - * 0 - * D21; - * D31;D32; - * ... - * Dj1;Dj2;...;Dj(j-1); + * lower matrix file format:
+ * 0
+ * D21;
+ * D31;D32;
+ * ...
+ * Dj1;Dj2;...;Dj(j-1);
* **/ template< typename Filtration_value > -std::vector< std::vector< Filtration_value > > read_lower_triangular_matrix_from_csv_file(std::string filename, +std::vector< std::vector< Filtration_value > > read_lower_triangular_matrix_from_csv_file(const std::string& filename, const char separator=';') { bool dbg = false; if (dbg) { diff --git a/src/common/test/test_distance_matrix_reader.cpp b/src/common/test/test_distance_matrix_reader.cpp index 7eb7e846..a4c46bb1 100644 --- a/src/common/test/test_distance_matrix_reader.cpp +++ b/src/common/test/test_distance_matrix_reader.cpp @@ -47,21 +47,21 @@ BOOST_AUTO_TEST_CASE( lower_triangular_distance_matrix ) std::cout << "from_lower_triangular size = " << from_lower_triangular.size() << std::endl; BOOST_CHECK(from_lower_triangular.size() == 5); - for (int i = 0; i < from_lower_triangular.size(); i++) { + for (std::size_t i = 0; i < from_lower_triangular.size(); i++) { std::cout << "from_lower_triangular[" << i << "] size = " << from_lower_triangular[i].size() << std::endl; BOOST_CHECK(from_lower_triangular[i].size() == i); } std::vector expected = {1}; - BOOST_CHECK(from_lower_triangular[0] == expected); + BOOST_CHECK(from_lower_triangular[1] == expected); expected = {2,3}; - BOOST_CHECK(from_lower_triangular[0] == expected); + BOOST_CHECK(from_lower_triangular[2] == expected); expected = {4,5,6}; - BOOST_CHECK(from_lower_triangular[0] == expected); + BOOST_CHECK(from_lower_triangular[3] == expected); expected = {7,8,9,10}; - BOOST_CHECK(from_lower_triangular[0] == expected); + BOOST_CHECK(from_lower_triangular[4] == expected); } @@ -78,8 +78,8 @@ BOOST_AUTO_TEST_CASE( full_square_distance_matrix ) } std::cout << "from_full_square size = " << from_full_square.size() << std::endl; BOOST_CHECK(from_full_square.size() == 5); - for (int i = 0; i < from_lower_triangular.size(); i++) { - std::cout << "from_lower_triangular[" << i << "] size = " << from_lower_triangular[i].size() << std::endl; - BOOST_CHECK(from_lower_triangular[i].size() == i); + for (std::size_t i = 0; i < from_full_square.size(); i++) { + std::cout << "from_full_square[" << i << "] size = " << from_full_square[i].size() << std::endl; + BOOST_CHECK(from_full_square[i].size() == i); } } -- cgit v1.2.3
- Author: Clément Maria
+ Author: Clément Maria, Pawel Dlotko, Vincent Rouvreau
Introduced in: GUDHI 1.4.0
Copyright: GPL v3