Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simplex tree update #29

Merged
merged 2 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 51 additions & 1 deletion multipers/gudhi/gudhi/Multi_critical_filtration.h
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,57 @@ class Multi_critical_filtration {
return stream;
}

public:
friend bool unify_lifetimes(Multi_critical_filtration& f1, const Multi_critical_filtration& f2){
bool modified = false;
for (const Generator& g : f2.multi_filtration_){
modified |= f1.add_generator(g);
}
return modified;
}

friend bool intersect_lifetimes(Multi_critical_filtration& f1, const Multi_critical_filtration& f2){
if (f1.is_nan() || f2.is_nan()) return false;

if constexpr (co){
if (f1.is_plus_inf()){
if (f2.is_plus_inf()) return false;
f1 = f2;
return true;
}
if (f1.is_minus_inf()){
return false;
}
} else {
if (f1.is_minus_inf()){
if (f2.is_minus_inf()) return false;
f1 = f2;
return true;
}
if (f1.is_plus_inf()){
return false;
}
}

Multi_critical_filtration res(1, -_get_default_value());
// TODO: see if the order can be used to avoid n^2 complexity and
// perhaps even to replace add_generator by add_guaranteed_generator
for (const Generator& of1 : f1.multi_filtration_){
for (const Generator& of2 : f2.multi_filtration_){
// TODO: avoid one go-through by constructing nf directly as the max/min
Generator nf = of1;
if constexpr (co){
nf.pull_to_greatest_common_lower_bound(of2);
} else {
nf.push_to_least_common_upper_bound(of2);
}
res.add_generator(nf);
}
}
swap(f1, res);

return f1 != res;
}

/**
* @brief Indicates if the class manages multi-critical filtration values.
*/
Expand Down
48 changes: 37 additions & 11 deletions multipers/gudhi/gudhi/One_critical_filtration.h
Original file line number Diff line number Diff line change
Expand Up @@ -958,19 +958,27 @@ class One_critical_filtration : public std::vector<T> {
* cones: \f$ \mathrm{this} = \min \{ y \in \mathbb R^n : y \ge this \} \cap \{ y \in \mathbb R^n : y \ge x \} \f$.
*
* @param x The target filtration value towards which to push.
* @return True if and only if the value of this actually changed.
*/
void push_to_least_common_upper_bound(const One_critical_filtration &x) {
if (this->is_plus_inf() || this->is_nan() || x.is_nan() || x.is_minus_inf()) return;
bool push_to_least_common_upper_bound(const One_critical_filtration &x) {
if (this->is_plus_inf() || this->is_nan() || x.is_nan() || x.is_minus_inf()) return false;
if (x.is_plus_inf() || this->is_minus_inf()) {
*this = x;
return;
if (!x.is_minus_inf() && !this->is_plus_inf()) {
*this = x;
return true;
}
return false;
}

GUDHI_CHECK(this->num_parameters() == x.num_parameters(),
"A filtration value cannot be pushed to another one with different numbers of parameters.");

for (std::size_t i = 0; i < x.num_parameters(); i++)
bool modified = false;
for (std::size_t i = 0; i < x.num_parameters(); i++) {
modified |= Base::operator[](i) < x[i];
Base::operator[](i) = Base::operator[](i) > x[i] ? Base::operator[](i) : x[i];
}
return modified;
}

/**
Expand All @@ -981,19 +989,27 @@ class One_critical_filtration : public std::vector<T> {
* cones: \f$ \mathrm{this} = \min \{ y \in \mathbb R^n : y \le this \} \cap \{ y \in \mathbb R^n : y \le x \} \f$.
*
* @param x The target filtration value towards which to pull.
* @return True if and only if the value of this actually changed.
*/
void pull_to_greatest_common_lower_bound(const One_critical_filtration &x) {
if (x.is_plus_inf() || this->is_nan() || x.is_nan() || this->is_minus_inf()) return;
bool pull_to_greatest_common_lower_bound(const One_critical_filtration &x) {
if (x.is_plus_inf() || this->is_nan() || x.is_nan() || this->is_minus_inf()) return false;
if (this->is_plus_inf() || x.is_minus_inf()) {
*this = x;
return;
if (!x.is_plus_inf() && !this->is_minus_inf()) {
*this = x;
return true;
}
return false;
}

GUDHI_CHECK(this->num_parameters() == x.num_parameters(),
"A filtration value cannot be pulled to another one with different numbers of parameters.");

for (std::size_t i = 0u; i < x.num_parameters(); i++)
bool modified = false;
for (std::size_t i = 0; i < x.num_parameters(); i++) {
modified |= Base::operator[](i) > x[i];
Base::operator[](i) = Base::operator[](i) > x[i] ? x[i] : Base::operator[](i);
}
return modified;
}

/**
Expand Down Expand Up @@ -1169,7 +1185,17 @@ class One_critical_filtration : public std::vector<T> {
return stream;
}

public:
friend bool unify_lifetimes(One_critical_filtration& f1, const One_critical_filtration& f2){
//WARNING: costly check
GUDHI_CHECK(f1 <= f2 || f2 <= f1, "When 1-critical, two non-comparable filtration values cannot be unified.");

return f1.pull_to_greatest_common_lower_bound(f2);
}

friend bool intersect_lifetimes(One_critical_filtration& f1, const One_critical_filtration& f2){
return f1.push_to_least_common_upper_bound(f2);
}

/**
* @brief Infinity value of an entry of the filtration value.
*/
Expand Down
Loading
Loading