Persistence_compute.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): David Salinas
4 *
5 * Copyright (C) 2014 Inria
6 *
7 * Modification(s):
8 * - YYYY/MM Author: Description of the modification
9 */
10
11
12#ifndef UTILS_PERSISTENCE_COMPUTE_H_
13#define UTILS_PERSISTENCE_COMPUTE_H_
14
16#include <gudhi/Simplex_tree.h>
18#include <gudhi/Persistent_cohomology.h>
19#include <gudhi/Rips_complex.h>
20
21#include <vector>
22
23struct Persistence_params {
24 int p;
25 double threshold;
26 int max_dim;
27 double min_pers;
28
29 Persistence_params(int p_, double th_, int max_dim_ = 10, double min_pers_ = 0)
30 : p(p_), threshold(th_), max_dim(max_dim_), min_pers(min_pers_) { }
31};
32
36template<typename SkBlComplex> class Persistence_compute {
37 public:
38 typedef typename SkBlComplex::Vertex_handle Vertex_handle;
39 typedef typename SkBlComplex::Edge_handle Edge_handle;
40
48 Persistence_compute(SkBlComplex& complex, std::ostream& stream, const Persistence_params& params) {
49 // for now everything is copied, todo boost adapt iterators to points of SkBlComplex instead of copying to an
50 // initial vector
51 typedef std::vector<double> Point_t;
52 std::vector< Point_t > points;
53 points.reserve(complex.num_vertices());
54 for (auto v : complex.vertex_range()) {
55 const auto & pt = complex.point(v);
56 Point_t pt_to_add(pt.cartesian_begin(), pt.cartesian_end());
57 points.emplace_back(std::move(pt_to_add));
58 }
59
65
66 Rips_complex rips_complex(points, params.threshold, Euclidean_distance());
67
68 Simplex_tree st;
69 rips_complex.create_complex(st, params.max_dim);
70 Persistent_cohomology pcoh(st);
71 // initializes the coefficient field for homology
72 pcoh.init_coefficients(params.p);
73 // put params.min_pers
74 pcoh.compute_persistent_cohomology(params.min_pers);
75 stream << "persistence: \n";
76 stream << "p dimension birth death: \n";
77 pcoh.output_diagram(stream);
78 }
79};
80
81#endif // UTILS_PERSISTENCE_COMPUTE_H_
Compute the Euclidean distance between two Points given by a range of coordinates....
Definition: distance_functions.h:34
Options::Filtration_value Filtration_value
Type for the value of the filtration function.
Definition: Simplex_tree.h:82
Structure representing the coefficient field .
Definition: Field_Zp.h:27
Computes the persistent cohomology of a filtered complex.
Definition: Persistent_cohomology.h:52
void output_diagram(std::ostream &ostream=std::cout)
Output the persistence diagram in ostream.
Definition: Persistent_cohomology.h:561
void compute_persistent_cohomology(Filtration_value min_interval_length=0)
Compute the persistent homology of the filtered simplicial complex.
Definition: Persistent_cohomology.h:172
void init_coefficients(int charac)
Initializes the coefficient field.
Definition: Persistent_cohomology.h:156
Rips complex data structure.
Definition: Rips_complex.h:45
void create_complex(SimplicialComplexForRips &complex, int dim_max)
Initializes the simplicial complex from the Rips graph and expands it until a given maximal dimension...
Definition: Rips_complex.h:101
Definition: Persistence_compute.h:36
Persistence_compute(SkBlComplex &complex, std::ostream &stream, const Persistence_params &params)
Compute persistence parameters : unsigned dim_max double threshold int p for coefficient Z_p.
Definition: Persistence_compute.h:48
Global distance functions.
Graph simplicial complex methods.
Value type for a filtration function on a cell complex.
Definition: FiltrationValue.h:20
GUDHIdev  Version 3.5.0  - C++ library for Topological Data Analysis (TDA) and Higher Dimensional Geometry Understanding.  - Copyright : MIT Generated on Tue Aug 16 2022 14:01:50 for GUDHIdev by Doxygen 1.9.4