22#ifndef FILTERED_ZIGZAG_PERSISTENCE_H_
23#define FILTERED_ZIGZAG_PERSISTENCE_H_
27#include <unordered_map>
31#include <gudhi/Debug_utils.h>
36namespace zigzag_persistence {
119template <
class FilteredZigzagOptions = Default_filtered_zigzag_options>
153 : dimMax_(ignoreCyclesAboveDim),
154 persistenceDiagram_(),
159 if (dimMax_ == -1 || (dimMax_ != -1 && dim < dimMax_)) {
160 persistenceDiagram_.emplace_back(birth, death, dim);
163 preallocationSize) {}
179 template <
class BoundaryRange = std::initializer_list<Cell_key> >
181 const BoundaryRange& boundary,
185 if (dimMax_ != -1 && dimension > dimMax_) {
191 _store_filtration_value(filtrationValue);
193 [[maybe_unused]]
auto res = handleToKey_.try_emplace(cellID, numArrow_);
195 GUDHI_CHECK(res.second,
"Zigzag_persistence::insert_cell - cell already in the complex");
198 std::vector<Internal_key> translatedBoundary;
199 translatedBoundary.reserve(dimension * 2);
200 for (
auto b : boundary) {
201 translatedBoundary.push_back(handleToKey_.at(b));
203 std::sort(translatedBoundary.begin(), translatedBoundary.end());
205 pers_.insert_cell(translatedBoundary, dimension);
222 auto it = handleToKey_.find(cellID);
224 if (it == handleToKey_.end()) {
230 _store_filtration_value(filtrationValue);
232 pers_.remove_cell(it->second);
233 handleToKey_.erase(it);
246 pers_.apply_identity();
269 std::lower_bound(filtrationValues_.begin(),
270 filtrationValues_.end(),
272 [](std::pair<Internal_key, Filtration_value> p,
Internal_key k) { return p.first < k; });
273 if (itBirth == filtrationValues_.end() || itBirth->first > idx) {
276 return itBirth->second;
287 bool includeInfiniteBars =
true) {
288 std::vector<Filtration_value_interval> diag = _get_persistence_diagram(shortestInterval);
290 if (includeInfiniteBars) {
291 _retrieve_infinite_bars(diag);
298 std::unordered_map<Cell_key, Internal_key> handleToKey_;
300 std::vector<Index_interval> persistenceDiagram_;
308 std::vector<std::pair<Internal_key, Filtration_value> > filtrationValues_;
318 if (filtrationValue != previousFiltrationValue_)
321 previousFiltrationValue_ = filtrationValue;
322 filtrationValues_.emplace_back(numArrow_, previousFiltrationValue_);
332 std::vector<Filtration_value_interval> _get_persistence_diagram(
Filtration_value shortestInterval) {
333 std::vector<Filtration_value_interval> diag;
334 diag.reserve(persistenceDiagram_.size());
341 for (
auto bar : persistenceDiagram_) {
345 std::swap(birth, death);
348 if (death - birth > shortestInterval) {
349 diag.emplace_back(birth, death, bar.dim);
361 void _retrieve_infinite_bars(std::vector<Filtration_value_interval>& diag) {
362 auto stream_infinite_interval = [&](Dimension dim,
Internal_key birthIndex) {
363 if (dimMax_ == -1 || (dimMax_ != -1 && dim < dimMax_))
441template <
class FilteredZigzagOptions = Default_filtered_zigzag_options>
467 template <
typename F>
469 : handleToKey_(preallocationSize),
471 keyToFiltrationValue_(preallocationSize),
473 [&, stream_interval =
std::forward<F>(stream_interval)](
Dimension dim,
476 auto itB = keyToFiltrationValue_.find(birth);
477 auto itD = keyToFiltrationValue_.find(death);
478 if (itB->second != itD->second) stream_interval(dim, itB->second, itD->second);
479 keyToFiltrationValue_.erase(itB);
480 keyToFiltrationValue_.erase(itD);
482 preallocationSize) {}
497 template <
class BoundaryRange = std::initializer_list<Cell_key> >
499 const BoundaryRange& boundary,
505 [[maybe_unused]]
auto res = handleToKey_.try_emplace(cellID, numArrow_);
507 GUDHI_CHECK(res.second,
"Zigzag_persistence::insert_cell - cell already in the complex");
509 keyToFiltrationValue_.try_emplace(numArrow_, filtrationValue);
512 std::vector<Internal_key> translatedBoundary;
513 translatedBoundary.reserve(dimension * 2);
514 for (
auto b : boundary) {
515 translatedBoundary.push_back(handleToKey_.at(b));
517 std::sort(translatedBoundary.begin(), translatedBoundary.end());
535 auto it = handleToKey_.find(cellID);
536 GUDHI_CHECK(it != handleToKey_.end(),
"Zigzag_persistence::remove_cell - cell not in the complex");
538 keyToFiltrationValue_.try_emplace(numArrow_, filtrationValue);
541 handleToKey_.erase(it);
564 template <
typename F>
567 [&](
Dimension dim,
Internal_key birth) { stream_infinite_interval(dim, keyToFiltrationValue_.at(birth)); });
571 template <
typename key_type,
typename value_type>
572 using Dictionary = std::unordered_map<key_type, value_type>;
574 Dictionary<Cell_key, Internal_key> handleToKey_;
576 Dictionary<Internal_key, Filtration_value> keyToFiltrationValue_;
Class computing the zigzag persistent homology of a zigzag filtration. Algorithm based on ....
Definition: filtered_zigzag_persistence.h:121
Internal_key remove_cell(Cell_key cellID, Filtration_value filtrationValue)
Updates the zigzag persistence diagram after the removal of the given cell if the cell was contained ...
Definition: filtered_zigzag_persistence.h:221
typename Options::Internal_key Internal_key
Definition: filtered_zigzag_persistence.h:124
Filtered_zigzag_persistence_with_storage(unsigned int preallocationSize=0, int ignoreCyclesAboveDim=-1)
Constructor.
Definition: filtered_zigzag_persistence.h:152
typename Options::Filtration_value Filtration_value
Definition: filtered_zigzag_persistence.h:126
Internal_key apply_identity()
To use when a cell is neither inserted nor removed, but the filtration moves along the identity opera...
Definition: filtered_zigzag_persistence.h:244
std::vector< Filtration_value_interval > get_persistence_diagram(Filtration_value shortestInterval=0., bool includeInfiniteBars=true)
Returns the current persistence diagram.
Definition: filtered_zigzag_persistence.h:286
typename Options::Dimension Dimension
Definition: filtered_zigzag_persistence.h:127
typename Options::Cell_key Cell_key
Definition: filtered_zigzag_persistence.h:125
const std::vector< Index_interval > & get_index_persistence_diagram() const
Returns the "index persistence diagram" of the current filtration, that is, the pairs of atomic arrow...
Definition: filtered_zigzag_persistence.h:257
Internal_key insert_cell(Cell_key cellID, const BoundaryRange &boundary, Dimension dimension, Filtration_value filtrationValue)
Updates the zigzag persistence diagram after the insertion of the given cell.
Definition: filtered_zigzag_persistence.h:180
Filtration_value get_filtration_value_from_index(Internal_key idx)
Returns the filtration value associated to the index returned by get_index_persistence_diagram.
Definition: filtered_zigzag_persistence.h:266
Class computing the zigzag persistent homology of a zigzag filtration. Algorithm based on .
Definition: filtered_zigzag_persistence.h:442
void get_current_infinite_intervals(F &&stream_infinite_interval)
Outputs through the given callback method all current infinite bars.
Definition: filtered_zigzag_persistence.h:565
typename Options::Cell_key Cell_key
Definition: filtered_zigzag_persistence.h:446
typename Options::Filtration_value Filtration_value
Definition: filtered_zigzag_persistence.h:447
Internal_key remove_cell(Cell_key cellID, Filtration_value filtrationValue)
Updates the zigzag persistence diagram after the removal of the given cell. preallocationSize.
Definition: filtered_zigzag_persistence.h:532
typename Options::Dimension Dimension
Definition: filtered_zigzag_persistence.h:448
typename Options::Internal_key Internal_key
Definition: filtered_zigzag_persistence.h:445
Filtered_zigzag_persistence(F &&stream_interval, unsigned int preallocationSize=0)
Constructor.
Definition: filtered_zigzag_persistence.h:468
Internal_key insert_cell(Cell_key cellID, const BoundaryRange &boundary, Dimension dimension, Filtration_value filtrationValue)
Updates the zigzag persistence diagram after the insertion of the given cell.
Definition: filtered_zigzag_persistence.h:498
Internal_key apply_identity()
To use when a cell is neither inserted nor removed, but the filtration moves along the identity opera...
Definition: filtered_zigzag_persistence.h:551
Class computing the zigzag persistent homology of a zigzag sequence. Algorithm based on .
Definition: zigzag_persistence.h:149
Index remove_cell(Index arrowNumber)
Updates the zigzag persistence diagram after the removal of the given cell.
Definition: zigzag_persistence.h:300
Index insert_cell(const BoundaryRange &boundary, Dimension dimension)
Updates the zigzag persistence diagram after the insertion of the given cell.
Definition: zigzag_persistence.h:288
Index apply_identity()
To use when a cell is neither inserted nor removed, but the filtration moves along the identity opera...
Definition: zigzag_persistence.h:312
void get_current_infinite_intervals(F &&stream_infinite_interval)
Outputs through the given callback method all birth indices which are currently not paired with a dea...
Definition: zigzag_persistence.h:323
Gudhi namespace.
Definition: SimplicialComplexForAlpha.h:14
Contains Gudhi::persistence_matrix::Persistence_interval class.
Value type for a filtration function on a cell complex.
Definition: FiltrationValue.h:20
Type for an interval in a persistent diagram or barcode. Stores the birth, death and dimension of the...
Definition: persistence_interval.h:40
static constexpr Event_value inf
Stores the infinity value for birth and death events. Its value depends on the template parameter Eve...
Definition: persistence_interval.h:50
Default options for Filtered_zigzag_persistence_with_storage and Filtered_zigzag_persistence.
Definition: filtered_zigzag_persistence.h:43
int Cell_key
Definition: filtered_zigzag_persistence.h:44
double Filtration_value
Definition: filtered_zigzag_persistence.h:45
Default options for Zigzag_persistence.
Definition: zigzag_persistence.h:64
List of options used for the filtered zigzag persistence computation.
Definition: ZigzagOptions.h:27
unspecified Dimension
Type for the dimension values.
Definition: ZigzagOptions.h:47
unspecified Filtration_value
Type for filtration values.
Definition: ZigzagOptions.h:42
unspecified Internal_key
Numerical type for the cell IDs used internally and other indexations. It must be signed.
Definition: ZigzagOptions.h:31
unspecified Cell_key
Type for the cell IDs used at insertion and in the boundaries given as argument. Has to be usable as ...
Definition: ZigzagOptions.h:37
Contains the implementation of the Gudhi::zigzag_persistence::Zigzag_persistence class.