Loading...
Searching...
No Matches
Strong_witness_complex.h
1/* This file is part of the Gudhi Library - https://gudhi.inria.fr/ - which is released under MIT.
2 * See file LICENSE or go to https://gudhi.inria.fr/licensing/ for full license details.
3 * Author(s): Siargey Kachanovich
4 *
5 * Copyright (C) 2015 Inria
6 *
7 * Modification(s):
8 * - YYYY/MM Author: Description of the modification
9 */
10
11#ifndef STRONG_WITNESS_COMPLEX_H_
12#define STRONG_WITNESS_COMPLEX_H_
13
14#include <gudhi/Active_witness/Active_witness.h>
15
16#include <utility>
17#include <vector>
18#include <list>
19#include <limits>
20
21namespace Gudhi {
22
23namespace witness_complex {
24
39template< class Nearest_landmark_table_ >
41 private:
42 typedef typename Nearest_landmark_table_::value_type Nearest_landmark_range;
43 typedef std::size_t Witness_id;
44 typedef std::size_t Landmark_id;
45 typedef std::pair<Landmark_id, double> Id_distance_pair;
47 typedef std::list< ActiveWitness > ActiveWitnessList;
48 typedef std::vector< Landmark_id > typeVectorVertex;
49 typedef std::vector<Nearest_landmark_range> Nearest_landmark_table_internal;
50 typedef Landmark_id Vertex_handle;
51
52 protected:
53 Nearest_landmark_table_internal nearest_landmark_table_;
54
55 public:
57 /* @name Constructor
58 */
59
61
63 }
64
73 Strong_witness_complex(Nearest_landmark_table_ const & nearest_landmark_table)
74 : nearest_landmark_table_(std::begin(nearest_landmark_table), std::end(nearest_landmark_table)) {
75 }
76
86 template < typename SimplicialComplexForWitness >
88 double max_alpha_square,
89 Landmark_id limit_dimension = std::numeric_limits<Landmark_id>::max()) const {
90 Landmark_id complex_dim = 0;
91 if (complex.num_vertices() > 0) {
92 std::cerr << "Strong witness complex cannot create complex - complex is not empty.\n";
93 return false;
94 }
95 if (max_alpha_square < 0) {
96 std::cerr << "Strong witness complex cannot create complex - squared relaxation parameter must be "
97 << "non-negative.\n";
98 return false;
99 }
100 for (auto w : nearest_landmark_table_) {
101 ActiveWitness aw(w);
102 typeVectorVertex simplex;
103 typename ActiveWitness::iterator aw_it = aw.begin();
104 float lim_dist2 = aw.begin()->second + max_alpha_square;
105 while ((Landmark_id)simplex.size() <= limit_dimension && aw_it != aw.end() && aw_it->second < lim_dist2) {
106 simplex.push_back(aw_it->first);
107 complex.insert_simplex_and_subfaces(simplex, aw_it->second - aw.begin()->second);
108 aw_it++;
109 }
110 // continue inserting limD-faces of the following simplices
111 typeVectorVertex& vertices = simplex; // 'simplex' now will be called vertices
112 while (aw_it != aw.end() && aw_it->second < lim_dist2) {
113 typeVectorVertex facet = {};
114 add_all_faces_of_dimension(limit_dimension, vertices, vertices.begin(), aw_it,
115 aw_it->second - aw.begin()->second, facet, complex);
116 vertices.push_back(aw_it->first);
117 aw_it++;
118 }
119 if ((Landmark_id)simplex.size() - 1 > complex_dim)
120 complex_dim = simplex.size() - 1;
121 }
122 return true;
123 }
124
126
127 private:
133 template < typename SimplicialComplexForWitness >
134 void add_all_faces_of_dimension(Landmark_id dim,
135 typeVectorVertex& vertices,
136 typename typeVectorVertex::iterator curr_it,
137 typename ActiveWitness::iterator aw_it,
138 double filtration_value,
139 typeVectorVertex& simplex,
140 SimplicialComplexForWitness& sc) const {
141 if (dim > 0) {
142 while (curr_it != vertices.end()) {
143 simplex.push_back(*curr_it);
144 ++curr_it;
145 add_all_faces_of_dimension(dim-1,
146 vertices,
147 curr_it,
148 aw_it,
149 filtration_value,
150 simplex,
151 sc);
152 simplex.pop_back();
153 add_all_faces_of_dimension(dim,
154 vertices,
155 curr_it,
156 aw_it,
157 filtration_value,
158 simplex,
159 sc);
160 }
161 } else if (dim == 0) {
162 simplex.push_back(aw_it->first);
163 sc.insert_simplex_and_subfaces(simplex, filtration_value);
164 simplex.pop_back();
165 }
166 }
167};
168
169} // namespace witness_complex
170
171} // namespace Gudhi
172
173#endif // STRONG_WITNESS_COMPLEX_H_
Iterator in the nearest landmark list.
Definition: Active_witness_iterator.h:34
Class representing a list of nearest neighbors to a given witness.
Definition: Active_witness.h:27
Constructs strong witness complex for a given table of nearest landmarks with respect to witnesses.
Definition: Strong_witness_complex.h:40
bool create_complex(SimplicialComplexForWitness &complex, double max_alpha_square, Landmark_id limit_dimension=std::numeric_limits< Landmark_id >::max()) const
Outputs the strong witness complex of relaxation 'max_alpha_square' in a simplicial complex data stru...
Definition: Strong_witness_complex.h:87
Strong_witness_complex(Nearest_landmark_table_ const &nearest_landmark_table)
Initializes member variables before constructing simplicial complex.
Definition: Strong_witness_complex.h:73
The concept SimplicialComplexForWitness describes the requirements for a type to implement a simplici...
Definition: SimplicialComplexForWitness.h:22
Insertion_result_type insert_simplex_and_subfaces(Input_vertex_range const &vertex_range, Filtration_value filtration)
Inserts a simplex and all its faces with vertices from a given range 'vertex_range' in the simplicial...