summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUlrich Bauer <mail@ulrich-bauer.org>2016-08-04 11:43:06 +0200
committerUlrich Bauer <mail@ulrich-bauer.org>2016-08-04 12:09:33 +0200
commit467714a91eb10c7a434eb389795b9cc186560b07 (patch)
tree2d9443abc343be162b0ac11af1b0f2a17f44eab5
parentb9094739598846b0e61642351d10deb48bf23dcf (diff)
precompute distance matrix for point cloud input
rename compile options
-rw-r--r--Makefile20
-rw-r--r--README.md9
-rw-r--r--ripser.cpp44
-rw-r--r--ripser.xcodeproj/project.pbxproj5
4 files changed, 55 insertions, 23 deletions
diff --git a/Makefile b/Makefile
index dbe3ed9..3cd0c79 100644
--- a/Makefile
+++ b/Makefile
@@ -1,14 +1,26 @@
build: ripser
-all: ripser ripser-coeff ripser-point-cloud ripser-point-cloud-coeff ripser-dipha ripser-dipha-coeff
+all: ripser ripser-coeff ripser-dist ripser-dist-coeff ripser-upper-dist ripser-upper-dist-coeff ripser-point-cloud ripser-point-cloud-coeff ripser-dipha ripser-dipha-coeff
ripser: ripser.cpp
- c++ -std=c++11 ripser.cpp -o ripser -Ofast -D NDEBUG -D FILE_FORMAT_LOWER_TRIANGULAR_CSV
+ c++ -std=c++11 ripser.cpp -o ripser -Ofast -D NDEBUG -D FILE_FORMAT_LOWER_DISTANCE_MATRIX
ripser-coeff: ripser.cpp
- c++ -std=c++11 ripser.cpp -o ripser-coeff -Ofast -D NDEBUG -D FILE_FORMAT_LOWER_TRIANGULAR_CSV -D USE_COEFFICIENTS
+ c++ -std=c++11 ripser.cpp -o ripser-coeff -Ofast -D NDEBUG -D FILE_FORMAT_LOWER_DISTANCE_MATRIX -D USE_COEFFICIENTS
+
+ripser-dist: ripser.cpp
+ c++ -std=c++11 ripser.cpp -o ripser-dist -Ofast -D NDEBUG -D FILE_FORMAT_DISTANCE_MATRIX
+
+ripser-dist-coeff: ripser.cpp
+ c++ -std=c++11 ripser.cpp -o ripser-dist-coeff -Ofast -D NDEBUG -D FILE_FORMAT_DISTANCE_MATRIX -D USE_COEFFICIENTS
+
+ripser-upper-dist: ripser.cpp
+ c++ -std=c++11 ripser.cpp -o ripser-upper-dist -Ofast -D NDEBUG -D FILE_FORMAT_UPPER_DISTANCE_MATRIX
+
+ripser-upper-dist-coeff: ripser.cpp
+ c++ -std=c++11 ripser.cpp -o ripser-upper-dist-coeff -Ofast -D NDEBUG -D FILE_FORMAT_UPPER_DISTANCE_MATRIX -D USE_COEFFICIENTS
ripser-point-cloud: ripser.cpp
c++ -std=c++11 ripser.cpp -o ripser-point-cloud -Ofast -D NDEBUG -D FILE_FORMAT_POINT_CLOUD
@@ -24,4 +36,4 @@ ripser-dipha-coeff: ripser.cpp
clean:
- rm ripser ripser-coeff ripser-point-cloud ripser-point-cloud-coeff ripser-dipha ripser-dipha-coeff
+ rm ripser ripser-coeff ripser-dist ripser-dist-coeff ripser-upper-dist ripser-upper-dist-coeff ripser-point-cloud ripser-point-cloud-coeff ripser-dipha ripser-dipha-coeff
diff --git a/README.md b/README.md
index 71c82fd..9e96a03 100644
--- a/README.md
+++ b/README.md
@@ -59,18 +59,19 @@ Ripser supports several compile-time options. They are switched on by defining t
Furthermore, one of the following options needs to be chosen to specify the format for the input files:
- - `FILE_FORMAT_LOWER_TRIANGULAR_CSV`: lower triangular distance matrix; a comma (or whitespace, or other non-numerical character) separated list of the distance matrix entries below the diagonal, sorted lexicographically by row index, then column index
- - `FILE_FORMAT_UPPER_TRIANGULAR_CSV`: upper triangular distance matrix; similar to the previous, but for the entries above the diagonal; suitable for output from the MATLAB function `pdist`, saved in a CSV file
+ - `FILE_FORMAT_LOWER_DISTANCE_MATRIX`: lower triangular distance matrix; a comma (or whitespace, or other non-numerical character) separated list of the distance matrix entries below the diagonal, sorted lexicographically by row index, then column index
+ - `FILE_FORMAT_UPPER_DISTANCE_MATRIX`: upper triangular distance matrix; similar to the previous, but for the entries above the diagonal; suitable for output from the MATLAB function `pdist`, saved in a CSV file
+ - `FILE_FORMAT_DISTANCE_MATRIX`: full distance matrix; similar to the above, but for all entries of the distance matrix
- `FILE_FORMAT_DIPHA`: DIPHA distance matrix as described on the [DIPHA] website
- `FILE_FORMAT_POINT_CLOUD`: point cloud; a comma (or whitespace, or other non-numerical character) separated list of coordinates of the points in some Euclidean space, one point per line
For example, to build with support for coefficients:
```sh
-$ c++ -std=c++11 ripser.cpp -o ripser -Ofast -D NDEBUG -D FILE_FORMAT_LOWER_TRIANGULAR_CSV -D USE_COEFFICIENTS
+$ c++ -std=c++11 ripser.cpp -o ripser -Ofast -D NDEBUG -D FILE_FORMAT_LOWER_DISTANCE_MATRIX -D USE_COEFFICIENTS
```
-A Makefile is provided with some variants of the above options. Use `make all` to build them. The default `make` only builds a binary with the option `FILE_FORMAT_LOWER_TRIANGULAR_CSV`.
+A Makefile is provided with some variants of the above options. Use `make all` to build them. The default `make` only builds a binary with the option `FILE_FORMAT_LOWER_DISTANCE_MATRIX`.
The following options are supported at the command line:
diff --git a/ripser.cpp b/ripser.cpp
index b6b7094..964210a 100644
--- a/ripser.cpp
+++ b/ripser.cpp
@@ -21,8 +21,9 @@
//#define INDICATE_PROGRESS
#define PRINT_PERSISTENCE_PAIRS
-//#define FILE_FORMAT_LOWER_TRIANGULAR_CSV
-//#define FILE_FORMAT_UPPER_TRIANGULAR_CSV
+//#define FILE_FORMAT_LOWER_DISTANCE_MATRIX
+//#define FILE_FORMAT_UPPER_DISTANCE_MATRIX
+//#define FILE_FORMAT_DISTANCE_MATRIX
//#define FILE_FORMAT_POINT_CLOUD
//#define FILE_FORMAT_DIPHA
@@ -82,6 +83,13 @@ public:
}
};
+bool is_prime(const coefficient_t n) {
+ if (!(n & 1) || n < 2) return n == 2;
+ for (coefficient_t p = 3, q = n / p, r = n % p; p <= q; p += 2, q = n / p, r = n % p)
+ if (!r) return false;
+ return true;
+}
+
std::vector<coefficient_t> multiplicative_inverse_vector(const coefficient_t m) {
std::vector<coefficient_t> inverse(m);
inverse[1] = 1;
@@ -686,13 +694,6 @@ void compute_pairs(std::vector<diameter_index_t>& columns_to_reduce,
#endif
}
-bool is_prime(const coefficient_t n) {
- if (!(n & 1) || n < 2) return n == 2;
- for (coefficient_t p = 3, q = n / p, r = n % p; p <= q; p += 2, q = n / p, r = n % p)
- if (!r) return false;
- return true;
-}
-
template <typename T> T read(std::ifstream& s) {
T result;
s.read(reinterpret_cast<char*>(&result), sizeof(T));
@@ -796,7 +797,26 @@ int main(int argc, char** argv) {
#endif
-#ifdef FILE_FORMAT_LOWER_TRIANGULAR_CSV
+#ifdef FILE_FORMAT_DISTANCE_MATRIX
+
+ std::vector<value_t> distances;
+
+ std::string line;
+ value_t value;
+ for (int i = 0; std::getline(input_stream, line); ++i) {
+ std::istringstream s(line);
+ for (int j = 0; j < i && s >> value; ++j) distances.push_back(value);
+ }
+
+ compressed_lower_distance_matrix dist(std::move(distances));
+
+ index_t n = dist.size();
+
+ std::cout << "distance matrix with " << n << " points" << std::endl;
+
+#endif
+
+#ifdef FILE_FORMAT_LOWER_DISTANCE_MATRIX
std::vector<value_t> distances;
value_t value;
@@ -813,7 +833,7 @@ int main(int argc, char** argv) {
#endif
-#ifdef FILE_FORMAT_UPPER_TRIANGULAR_CSV
+#ifdef FILE_FORMAT_UPPER_DISTANCE_MATRIX
std::vector<value_t> distances;
value_t value;
@@ -859,10 +879,8 @@ int main(int argc, char** argv) {
#endif
-#ifndef FILE_FORMAT_POINT_CLOUD
auto result = std::minmax_element(dist.distances.begin(), dist.distances.end());
std::cout << "value range: [" << *result.first << "," << *result.second << "]" << std::endl;
-#endif
dim_max = std::min(dim_max, n - 2);
diff --git a/ripser.xcodeproj/project.pbxproj b/ripser.xcodeproj/project.pbxproj
index 52c2d4e..980df17 100644
--- a/ripser.xcodeproj/project.pbxproj
+++ b/ripser.xcodeproj/project.pbxproj
@@ -209,8 +209,9 @@
buildSettings = {
GCC_PREPROCESSOR_DEFINITIONS = (
"$(inherited)",
- _FILE_FORMAT_LOWER_TRIANGULAR_CSV,
- FILE_FORMAT_POINT_CLOUD,
+ FILE_FORMAT_DISTANCE_MATRIX,
+ _FILE_FORMAT_LOWER_DISTANCE_MATRIX,
+ _FILE_FORMAT_POINT_CLOUD,
);
PRODUCT_NAME = "$(TARGET_NAME)";
};