11 #ifndef WITNESS_COMPLEX_H_
12 #define WITNESS_COMPLEX_H_
14 #include <gudhi/Active_witness/Active_witness.h>
15 #include <gudhi/Witness_complex/all_faces_in.h>
24 namespace witness_complex {
37 template<
class Nearest_landmark_table_ >
40 typedef typename Nearest_landmark_table_::value_type Nearest_landmark_range;
41 typedef std::size_t Witness_id;
42 typedef std::size_t Landmark_id;
43 typedef std::pair<Landmark_id, double> Id_distance_pair;
45 typedef std::list< ActiveWitness > ActiveWitnessList;
46 typedef std::vector< Landmark_id > typeVectorVertex;
47 typedef std::vector<Nearest_landmark_range> Nearest_landmark_table_internal;
48 typedef Landmark_id Vertex_handle;
51 Nearest_landmark_table_internal nearest_landmark_table_;
76 : nearest_landmark_table_(std::begin(nearest_landmark_table), std::end(nearest_landmark_table)) {
88 template <
typename SimplicialComplexForWitness >
90 double max_alpha_square,
91 std::size_t limit_dimension = std::numeric_limits<std::size_t>::max())
const {
93 std::cerr <<
"Witness complex cannot create complex - complex is not empty.\n";
96 if (max_alpha_square < 0) {
97 std::cerr <<
"Witness complex cannot create complex - squared relaxation parameter must be non-negative.\n";
100 ActiveWitnessList active_witnesses;
102 for (
auto&& w : nearest_landmark_table_)
103 active_witnesses.emplace_back(w);
104 while (!active_witnesses.empty() && k <= limit_dimension) {
105 typename ActiveWitnessList::iterator aw_it = active_witnesses.begin();
106 std::vector<Landmark_id> simplex;
107 simplex.reserve(k+1);
108 while (aw_it != active_witnesses.end()) {
109 bool ok = add_all_faces_of_dimension(k,
111 std::numeric_limits<double>::infinity(),
116 assert(simplex.empty());
118 active_witnesses.erase(aw_it++);
135 template <
typename SimplicialComplexForWitness >
136 bool add_all_faces_of_dimension(
int dim,
138 double norelax_dist2,
139 typename ActiveWitness::iterator curr_l,
140 std::vector<Landmark_id>& simplex,
142 typename ActiveWitness::iterator end)
const {
145 bool will_be_active =
false;
146 typename ActiveWitness::iterator l_it = curr_l;
148 for (; l_it != end && l_it->second - alpha2 <= norelax_dist2; ++l_it) {
149 simplex.push_back(l_it->first);
151 typename ActiveWitness::iterator next_it = l_it;
152 will_be_active = add_all_faces_of_dimension(dim-1,
158 end) || will_be_active;
160 assert(!simplex.empty());
163 if (l_it->second <= norelax_dist2)
164 norelax_dist2 = l_it->second;
166 }
else if (dim == 0) {
167 for (; l_it != end && l_it->second - alpha2 <= norelax_dist2; ++l_it) {
168 simplex.push_back(l_it->first);
169 double filtration_value = 0;
171 if (l_it->second > norelax_dist2)
172 filtration_value = l_it->second - norelax_dist2;
173 if (all_faces_in(simplex, &filtration_value, sc)) {
174 will_be_active =
true;
177 assert(!simplex.empty());
180 if (l_it->second < norelax_dist2)
181 norelax_dist2 = l_it->second;
184 return will_be_active;
Class representing a list of nearest neighbors to a given witness.
Definition: Active_witness.h:27
Constructs (weak) witness complex for a given table of nearest landmarks with respect to witnesses.
Definition: Witness_complex.h:38
bool create_complex(SimplicialComplexForWitness &complex, double max_alpha_square, std::size_t limit_dimension=std::numeric_limits< std::size_t >::max()) const
Outputs the (weak) witness complex of relaxation 'max_alpha_square' in a simplicial complex data stru...
Definition: Witness_complex.h:89
Witness_complex(Nearest_landmark_table_ const &nearest_landmark_table)
Initializes member variables before constructing simplicial complex.
Definition: Witness_complex.h:75
Gudhi namespace.
Definition: SimplicialComplexForAlpha.h:14
The concept SimplicialComplexForWitness describes the requirements for a type to implement a simplici...
Definition: SimplicialComplexForWitness.h:22
std::size_t num_vertices()
Insertion_result_type insert_simplex(Input_vertex_range const &vertex_range, Filtration_value filtration)
Inserts a simplex with vertices from a given range 'vertex_range' in the simplicial complex....
Simplex_handle find(Input_vertex_range const &vertex_range)
Finds a simplex with vertices given by a range.
Simplex_handle null_simplex()
Returns a Simplex_hanlde that is different from all simplex handles of the simplices.