diff options
author | Ulrich Bauer <mail@ulrich-bauer.org> | 2016-08-25 00:23:31 +0200 |
---|---|---|
committer | Ulrich Bauer <mail@ulrich-bauer.org> | 2016-08-25 00:29:08 +0200 |
commit | 48b815399d656ea9988ede177c955000c8a67acf (patch) | |
tree | c8659e0d2a09be0e2b419f98391f3eea489e66f5 /ripser.cpp | |
parent | bedbfdfb53779c85d17324efbb2867d308aa174b (diff) |
cleanup
Diffstat (limited to 'ripser.cpp')
-rw-r--r-- | ripser.cpp | 97 |
1 files changed, 35 insertions, 62 deletions
@@ -33,18 +33,6 @@ #include <sstream> #include <unordered_map> - - -#include "prettyprint.hpp" - - -#ifdef __EMSCRIPTEN__ -#include <emscripten.h> -#include <emscripten/bind.h> - -using namespace emscripten; -#endif - #ifdef USE_GOOGLE_HASHMAP #include <sparsehash/sparse_hash_map> template <class Key, class T> class hash_map : public google::sparse_hash_map<Key, T> { @@ -61,7 +49,6 @@ typedef float value_t; typedef long index_t; typedef long coefficient_t; - class binomial_coeff_table { std::vector<std::vector<index_t>> B; index_t n_max, k_max; @@ -613,7 +600,7 @@ void compute_pairs(std::vector<diameter_index_t>& columns_to_reduce, hash_map<in index_t coface_index = get_index(coface); value_t coface_diameter = simplex_diameter; for (index_t v : vertices) { coface_diameter = std::max(coface_diameter, dist(v, covertex)); } - assert(dim == 0 || comp.diameter(coface_index) == coface_diameter); + assert(comp.diameter(coface_index) == coface_diameter); if (coface_diameter <= threshold) { coefficient_t coface_coefficient = get_coefficient(coface) * get_coefficient(simplex) * factor; @@ -924,70 +911,56 @@ int main(int argc, char** argv) { std::vector<diameter_index_t> columns_to_reduce; - union_find dset(n); - - std::vector<diameter_index_t> edges(binomial_coeff(n, 2)); - - rips_filtration_comparator<decltype(dist)> comp(dist, 1, binomial_coeff); - - assert(dist.distances.size() == binomial_coeff(n, 2)); - - for (index_t index = binomial_coeff(n, 2); index-- > 0;) { - edges[index] = diameter_index_t(comp.diameter(index), index); - } - - std::sort(edges.rbegin(), edges.rend(), comp); - - std::vector<index_t> vertices_of_edge(2); - + { + union_find dset(n); + std::vector<diameter_index_t> edges; + rips_filtration_comparator<decltype(dist)> comp(dist, 1, binomial_coeff); + for (index_t index = binomial_coeff(n, 2); index-- > 0;) { + value_t diameter = comp.diameter(index); + if (diameter <= threshold) edges.push_back(diameter_index_t(diameter, index)); + } + std::sort(edges.rbegin(), edges.rend(), greater_diameter_or_smaller_index<diameter_index_t>()); + #ifdef PRINT_PERSISTENCE_PAIRS - std::cout << "persistence intervals in dim 0:" << std::endl; + std::cout << "persistence intervals in dim 0:" << std::endl; #endif - - for (auto e: edges) { - vertices_of_edge.clear(); - get_simplex_vertices(get_index(e), 1, n, binomial_coeff, std::back_inserter(vertices_of_edge)); - index_t u = dset.find(vertices_of_edge[0]), v = dset.find(vertices_of_edge[1]); - - if ( u != v ) { -// std::cout << "tree edge " << vertices_of_edge[0] << "-" << vertices_of_edge[1] << " " << e << std::endl; + std::vector<index_t> vertices_of_edge(2); + for (auto e: edges) { + vertices_of_edge.clear(); + get_simplex_vertices(get_index(e), 1, n, binomial_coeff, std::back_inserter(vertices_of_edge)); + index_t u = dset.find(vertices_of_edge[0]), v = dset.find(vertices_of_edge[1]); + + if ( u != v ) { #ifdef PRINT_PERSISTENCE_PAIRS -#ifdef INDICATE_PROGRESS - std::cout << "\033[K"; -#endif - std::cout << " [0," << get_diameter(e) << ")" << std::endl; + std::cout << " [0," << get_diameter(e) << ")" << std::endl; #endif - dset.link(u, v); - } else { -// std::cout << "cycle edge " << vertices_of_edge[0] << "-" << vertices_of_edge[1] << " " << e << std::endl; - columns_to_reduce.push_back(e); + dset.link(u, v); + } else + columns_to_reduce.push_back(e); } + std::reverse(columns_to_reduce.begin(), columns_to_reduce.end()); + +#ifdef PRINT_PERSISTENCE_PAIRS + for (index_t i = 0; i < n; ++i) + if (dset.find(i) == i) + std::cout << " [0, )" << std::endl << std::flush; +#endif } - std::sort(columns_to_reduce.begin(), columns_to_reduce.end(), - greater_diameter_or_smaller_index<diameter_index_t>()); - -// std::cout << columns_to_reduce << std::endl; - - - -// columns_to_reduce.clear(); -// for (index_t index = n; index-- > 0;) columns_to_reduce.push_back(diameter_index_t(0, index)); - for (index_t dim = 1; dim <= dim_max; ++dim) { rips_filtration_comparator<decltype(dist)> comp(dist, dim + 1, binomial_coeff); rips_filtration_comparator<decltype(dist)> comp_prev(dist, dim, binomial_coeff); - + hash_map<index_t, index_t> pivot_column_index; pivot_column_index.reserve(columns_to_reduce.size()); - + compute_pairs(columns_to_reduce, pivot_column_index, dist, comp, comp_prev, dim, n, threshold, modulus, - multiplicative_inverse, binomial_coeff); - + multiplicative_inverse, binomial_coeff); + if (dim < dim_max) { assemble_columns_to_reduce(columns_to_reduce, pivot_column_index, comp, dim, n, threshold, binomial_coeff); -// std::cout << columns_to_reduce << std::endl; + // std::cout << columns_to_reduce << std::endl; } } }
\ No newline at end of file |