Loading...
Searching...
No Matches
example_zigzag_filtration_as_input_loop.cpp
/* This file is part of the Gudhi Library - https://gudhi.inria.fr/ - which is released under MIT.
* See file LICENSE or go to https://gudhi.inria.fr/licensing/ for full license details.
* Author(s): Hannah Schreiber
*
* Copyright (C) 2023 Inria
*
* Modification(s):
* - YYYY/MM Author: Description of the modification
*/
#include <iostream>
#include <vector>
#include <gudhi/filtered_zigzag_persistence.h>
using ZP = Gudhi::zigzag_persistence::Filtered_zigzag_persistence_with_storage<>;
using Cell_handle = ZP::Cell_key;
using Filtration_value = ZP::Filtration_value;
using Interval_filtration = ZP::Filtration_value_interval;
void print_barcode(ZP& zp) {
std::cout << std::endl << "Current barcode:" << std::endl;
for (Interval_filtration& bar : zp.get_persistence_diagram(0, true)) {
//stream out content of bar
std::cout << bar << std::endl;
//to access the content of the bar, it can either be used as a struct:
// bar.birth
// bar.death
// bar.dim
//or as a tuple
// std::get<0>(bar) <- birth
// std::get<1>(bar) <- death
// std::get<2>(bar) <- dim
}
}
void print_indices(ZP& zp) {
std::cout << std::endl << "Current pairs:" << std::endl;
for (auto& bar : zp.get_index_persistence_diagram()) {
//stream out content of bar
std::cout << bar << std::endl;
//to access the content of the bar, it can either be used as a struct:
// bar.birth
// bar.death
// bar.dim
//or as a tuple:
// std::get<0>(bar) <- birth
// std::get<1>(bar) <- death
// std::get<2>(bar) <- dim
}
}
std::vector<std::vector<Cell_handle> > get_boundaries() {
return {{},
{},
{},
{0, 1},
{0, 2},
{},
{1, 2},
{},
{5, 7},
{},
{3, 4, 6},
{7, 9},
{5, 9},
{8, 11, 12},
{10}, // remove
{13}, // remove
{1, 7},
{3, 4, 6},
{2, 7},
{8, 11, 12},
{0, 7},
{4, 18, 20},
{6, 16, 18},
{3, 16, 20},
{19}, // remove
{8}, // remove
{12}, // remove
{17, 21, 22, 23},
{27}}; // remove
}
std::vector<Filtration_value> get_filtration_values() {
return {0, 0, 0,
1, 1, 1,
2, 2, 2,
3, 3, 3, 3,
4,
5,
6, 6, 6,
7, 7, 7, 7, 7, 7,
8,
9, 9, 9,
10};
}
std::vector<bool> get_directions() {
return {true, true, true, true, true, true, true, true, true, true, true, true, true, true,
false, false,
true, true, true, true, true, true, true, true,
false, false, false,
true,
false};
}
std::vector<unsigned int> get_batch_sizes() {
return {14, 2, 8, 3, 1, 1};
}
int main(int argc, char* const argv[]) {
std::clog << "********** Example **********" << std::endl;
ZP zp;
std::vector<std::vector<Cell_handle> > simplices = get_boundaries();
std::vector<Filtration_value> fils = get_filtration_values();
std::vector<bool> dirs = get_directions();
for (unsigned int i = 0; i < simplices.size(); ++i) {
if (i > 0 && dirs[i] != dirs[i - 1]) {
print_barcode(zp);
print_indices(zp);
}
if (dirs[i]) {
int dim = simplices[i].size() == 0 ? 0 : simplices[i].size() - 1;
zp.insert_cell(i, simplices[i], dim, fils[i]);
} else {
auto id = simplices[i][0];
zp.remove_cell(id, fils[i]);
}
}
print_barcode(zp);
print_indices(zp);
return 0;
}
Gudhi::zigzag_persistence::Filtered_zigzag_persistence_with_storage
Class computing the zigzag persistent homology of a zigzag filtration. Algorithm based on zigzag....
Definition filtered_zigzag_persistence.h:121
Gudhi::zigzag_persistence::Filtered_zigzag_persistence_with_storage::remove_cell
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
Gudhi::zigzag_persistence::Filtered_zigzag_persistence_with_storage::Filtration_value
typename Options::Filtration_value Filtration_value
Definition filtered_zigzag_persistence.h:126
Gudhi::zigzag_persistence::Filtered_zigzag_persistence_with_storage::Filtration_value_interval
Gudhi::persistence_matrix::Persistence_interval< Dimension, Filtration_value > Filtration_value_interval
Persistence filtration interval type.
Definition filtered_zigzag_persistence.h:136
Gudhi::zigzag_persistence::Filtered_zigzag_persistence_with_storage::get_persistence_diagram
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
Gudhi::zigzag_persistence::Filtered_zigzag_persistence_with_storage::Cell_key
typename Options::Cell_key Cell_key
Definition filtered_zigzag_persistence.h:125
Gudhi::zigzag_persistence::Filtered_zigzag_persistence_with_storage::get_index_persistence_diagram
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
Gudhi::zigzag_persistence::Filtered_zigzag_persistence_with_storage::insert_cell
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
filtered_zigzag_persistence.h
Contains the implementation of the Gudhi::zigzag_persistence::Default_filtered_zigzag_options structu...