Skip to content

Commit

Permalink
removal of 'erase_birth_history'
Browse files Browse the repository at this point in the history
  • Loading branch information
hschreiber committed Oct 21, 2024
1 parent 5db9b3a commit 915b5ea
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 37 deletions.
15 changes: 4 additions & 11 deletions src/Zigzag_persistence/include/gudhi/filtered_zigzag_persistence.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,9 @@ namespace zigzag_persistence {
*
* @brief Default options for @ref Filtered_zigzag_persistence_with_storage and @ref Filtered_zigzag_persistence.
*/
struct Default_filtered_zigzag_options {
using Internal_key = int; /**< Cell ID used internally, must be signed. */
struct Default_filtered_zigzag_options : Default_zigzag_options {
using Cell_key = int; /**< Cell ID used in the given boundaries. */
using Filtration_value = double; /**< Filtration value type. */
using Dimension = int; /**< Dimension value type. */
/**
* @brief Column type use by the internal matrix.
*/
static const Gudhi::persistence_matrix::Column_types column_type =
Gudhi::persistence_matrix::Column_types::NAIVE_VECTOR;
};

/**
Expand Down Expand Up @@ -302,7 +295,7 @@ class Filtered_zigzag_persistence_with_storage

private:
std::unordered_map<Cell_key, Internal_key> handleToKey_; /**< Map from input keys to internal keys. */
Dimension dimMax_; /**< Maximal dimension of a bar to record. */
Dimension dimMax_; /**< Maximal dimension of a bar to record. */
std::vector<Index_interval> persistenceDiagram_; /**< Stores current closed persistence intervals. */
Internal_key numArrow_; /**< Current arrow number. */
Filtration_value previousFiltrationValue_; /**< Filtration value of the previous arrow. */
Expand All @@ -312,7 +305,7 @@ class Filtered_zigzag_persistence_with_storage
* i is the smallest cell index whose cell has filtration value f.
*/
std::vector<std::pair<Internal_key, Filtration_value> > filtrationValues_;
Zigzag_persistence<FilteredZigzagOptions, false> pers_; /**< Class computing the pairs. */
Zigzag_persistence<FilteredZigzagOptions> pers_; /**< Class computing the pairs. */

/**
* @brief Stores the filtration value if the value is new. Assumes that the given value is either greater (or equal)
Expand Down Expand Up @@ -578,7 +571,7 @@ class Filtered_zigzag_persistence {
Dictionary<Cell_key, Internal_key> handleToKey_; /**< Map from input keys to internal keys. */
Internal_key numArrow_; /**< Current arrow number. */
Dictionary<Internal_key, Filtration_value> keyToFiltrationValue_; /**< Cell Key to filtration value map. */
Zigzag_persistence<FilteredZigzagOptions, true> pers_; /**< Class computing the pairs. */
Zigzag_persistence<FilteredZigzagOptions> pers_; /**< Class computing the pairs. */
}; // end class Filtered_zigzag_persistence

} // namespace zigzag_persistence
Expand Down
33 changes: 8 additions & 25 deletions src/Zigzag_persistence/include/gudhi/zigzag_persistence.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,11 @@ struct Default_zigzag_options {
* @brief Column type use by the internal matrix.
*/
static const Gudhi::persistence_matrix::Column_types column_type =
Gudhi::persistence_matrix::Column_types::NAIVE_VECTOR; //TODO: redo benchmark with oscillating rips
Gudhi::persistence_matrix::Column_types::NAIVE_VECTOR;
};

// TODO: add the possibility of something else than Z2. Which means that the possibility of vineyards without Z2
// also needs to be implemented. The theory needs to be done first.
// TODO: erase_birth_history will be moved to the options if it is proven to be useful. In the meantime
// it stays here undocumented to ease benchmarks.
/**
* @class Zigzag_persistence zigzag_persistence.h gudhi/zigzag_persistence.h
* @brief Class computing the zigzag persistent homology of a zigzag sequence. Algorithm based on \cite zigzag.
Expand Down Expand Up @@ -146,7 +144,7 @@ struct Default_zigzag_options {
*
* @tparam ZigzagOptions Structure following the @ref ZigzagOptions concept. Default value: @ref Default_zigzag_options.
*/
template <class ZigzagOptions = Default_zigzag_options, bool erase_birth_history = true>
template <class ZigzagOptions = Default_zigzag_options>
class Zigzag_persistence
{
public:
Expand Down Expand Up @@ -324,19 +322,8 @@ class Zigzag_persistence
template <typename F>
void get_current_infinite_intervals(F&& stream_infinite_interval) {
for (auto& p : births_) {
if constexpr (erase_birth_history) {
auto& col = matrix_.get_column(p.first);
stream_infinite_interval(col.get_dimension(), p.second);
} else {
try {
auto& col = matrix_.get_column(p.first);
if (!col.is_paired()) {
stream_infinite_interval(col.get_dimension(), p.second);
}
} catch (const std::out_of_range&) {
continue;
}
}
auto& col = matrix_.get_column(p.first);
stream_infinite_interval(col.get_dimension(), p.second);
}
}

Expand Down Expand Up @@ -438,10 +425,8 @@ class Zigzag_persistence
} // birth not available anymore, do not
} // modify *chain_f_it.

if constexpr (erase_birth_history) {
birthOrdering_.remove_birth(maxb);
births_.erase(chainFp);
}
birthOrdering_.remove_birth(maxb);
births_.erase(chainFp);

// Update persistence diagram with left interval [fil(b_max) ; fil(m))
stream_interval_(dim - 1, maxb, numArrow_);
Expand Down Expand Up @@ -477,10 +462,8 @@ class Zigzag_persistence
if (!col.is_paired()) { // in F
auto it = births_.find(currCol);
stream_interval_(col.get_dimension(), it->second, numArrow_);
if constexpr (erase_birth_history) {
birthOrdering_.remove_birth(it->second);
births_.erase(it);
}
birthOrdering_.remove_birth(it->second);
births_.erase(it);
} else { // in H -> paired with c_g, that now belongs to F now
// maintain the <=b order
birthOrdering_.add_birth_backward(numArrow_);
Expand Down
1 change: 0 additions & 1 deletion src/Zigzag_persistence/test/test_zigzag_persistence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include <gudhi/zigzag_persistence.h>

using ZP = Gudhi::zigzag_persistence::Zigzag_persistence<>;
// using ZP = Gudhi::zigzag_persistence::Zigzag_persistence<Gudhi::zigzag_persistence::Default_zigzag_options, false>;

struct Interval {
Interval() {}
Expand Down

0 comments on commit 915b5ea

Please sign in to comment.