23 #ifndef SPARSE_RIPS_COMPLEX_H_ 24 #define SPARSE_RIPS_COMPLEX_H_ 26 #include <gudhi/Debug_utils.h> 27 #include <gudhi/graph_simplicial_complex.h> 28 #include <gudhi/choose_n_farthest_points.h> 30 #include <boost/graph/adjacency_list.hpp> 31 #include <boost/range/metafunctions.hpp> 37 namespace rips_complex {
54 template <
typename Filtration_value>
58 typedef typename boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS,
59 boost::property<vertex_filtration_t, Filtration_value>,
60 boost::property<edge_filtration_t, Filtration_value>>
63 typedef int Vertex_handle;
73 template <
typename RandomAccessPo
intRange,
typename Distance>
75 GUDHI_CHECK(epsilon > 0,
"epsilon must be positive");
76 std::vector<Vertex_handle> sorted_points;
77 std::vector<Filtration_value> params;
78 auto dist_fun = [&](Vertex_handle i, Vertex_handle j) {
return distance(points[i], points[j]); };
79 Ker<decltype(dist_fun)> kernel(dist_fun);
81 std::back_inserter(sorted_points), std::back_inserter(params));
82 compute_sparse_graph(sorted_points, params, dist_fun, epsilon);
93 template <
typename DistanceMatrix>
96 [&](Vertex_handle i, Vertex_handle j) {
return distance_matrix[j][i]; }, epsilon) {}
108 template <
typename SimplicialComplexForRips>
111 std::invalid_argument(
"Sparse_rips_complex::create_complex - simplicial complex is not empty"));
119 template <
class Distance>
121 typedef std::size_t Point_d;
122 Ker(Distance& d) : dist(d) {}
124 typedef Distance Squared_distance_d;
125 Squared_distance_d& squared_distance_d_object()
const {
return dist; }
130 template <
typename Po
intRange,
typename ParamRange,
typename Distance>
131 void compute_sparse_graph(
const PointRange& points,
const ParamRange& params, Distance& dist,
double epsilon) {
132 const int n = boost::size(points);
134 new (&graph_) Graph(n);
136 typename boost::graph_traits<Graph>::vertex_iterator v_i, v_e;
137 for (std::tie(v_i, v_e) = vertices(graph_); v_i != v_e; ++v_i) {
140 put(vertex_filtration_t(), graph_, v, 0);
146 for (
int i = 0; i < n; ++i)
147 for (
int j = i + 1; j < n; ++j) {
148 auto&& pi = points[i];
149 auto&& pj = points[j];
150 auto d = dist(pi, pj);
153 GUDHI_CHECK(lj <= li,
"Bad furthest point sorting");
157 if (d * epsilon <= 2 * lj)
159 else if (d * epsilon <= li + lj && (epsilon >= 1 || d * epsilon <= lj * (1 + 1 / (1 - epsilon))))
160 alpha = (d - lj / epsilon) * 2;
164 add_edge(pi, pj, alpha, graph_);
175 #endif // SPARSE_RIPS_COMPLEX_H_ void choose_n_farthest_points(Kernel const &k, Point_range const &input_pts, std::size_t final_size, std::size_t starting_point, PointOutputIterator output_it, DistanceOutputIterator dist_it={})
Subsample by a greedy strategy of iteratively adding the farthest point from the current chosen point...
Definition: choose_n_farthest_points.h:78
void expansion(int max_dim)
Expands the simplicial complex containing only its one skeleton until a given maximal dimension as ex...
void insert_graph(const OneSkeletonGraph &skel_graph)
Inserts a given Gudhi::rips_complex::Rips_complex::OneSkeletonGraph in the simplicial complex...
The concept SimplicialComplexForRips describes the requirements for a type to implement a simplicial ...
Definition: SimplicialComplexForRips.h:33
Definition: SimplicialComplexForAlpha.h:26
Value type for a filtration function on a cell complex.
Definition: FiltrationValue.h:32
std::size_t num_vertices()
Returns the number of vertices in the simplicial complex.
Sparse_rips_complex(const RandomAccessPointRange &points, Distance distance, double epsilon)
Sparse_rips_complex constructor from a list of points.
Definition: Sparse_rips_complex.h:74
Sparse_rips_complex(const DistanceMatrix &distance_matrix, double epsilon)
Sparse_rips_complex constructor from a distance matrix.
Definition: Sparse_rips_complex.h:94
Sparse Rips complex data structure.
Definition: Sparse_rips_complex.h:55
void create_complex(SimplicialComplexForRips &complex, int dim_max)
Fills the simplicial complex with the sparse Rips graph and expands it with all the cliques...
Definition: Sparse_rips_complex.h:109