X-Git-Url: https://git.sthu.org/?p=libstick.git;a=blobdiff_plain;f=include%2Flibstick%2Fpersistence.h;h=72b07b813944d758fe4927484d4fb03f96651926;hp=481d6480d2dd50821d82845672fdf0dd45873673;hb=7857e2e4890104e2f7e5a91f1ace889a3f072f08;hpb=dc2f0350ffdb47296a5094caa6184b1541e384ab diff --git a/include/libstick/persistence.h b/include/libstick/persistence.h index 481d648..72b07b8 100644 --- a/include/libstick/persistence.h +++ b/include/libstick/persistence.h @@ -35,6 +35,34 @@ class persistence { * zero, the cycle never dies. Otherwise, 'death' is always larger * than 'birth'. */ IT death; + + + /** Get the value of the birth index w.r.t. to a simplicial order o + * and a simplicial function f. Requires that o and f are defined + * on the same simplicial complex. */ + template + VT get_birth_value(const simplex_order &o, const simplicial_function &f) const { + assert(&f.get_complex() == &o.get_complex()); + return f.get_value(o.order_to_complex(birth)); + } + + /** Get the value of the death index w.r.t. to a simplicial order o + * and a simplicial function f. Requires that o and f are defined + * on the same simplicial complex. */ + template + VT get_death_value(const simplex_order &o, const simplicial_function &f) const { + assert(&f.get_complex() == &o.get_complex()); + return f.get_value(o.order_to_complex(death)); + } + + /** Get the persistence of this point w.r.t. to a simplicial order + * o and a simplicial function f. Requires that o and f are defined + * on the same simplicial complex. */ + template + VT get_persistence(const simplex_order &o, const simplicial_function &f) const { + assert(&f.get_complex() == &o.get_complex()); + return get_death_value(o, f) - get_birth_value(o, f); + } }; /** Save the births and deaths of simplices of a fixed dimension, say p. */ @@ -302,12 +330,8 @@ class persistence { if (death > 0) { os << birth << "\033[1;31m -> " << death << "\033[0;m"; - if (f != NULL) { - const IT birth_idx = order.order_to_complex(birth); - const IT death_idx = order.order_to_complex(death); - const VT pers = f->get_value(death_idx) - f->get_value(birth_idx); - os << " \tpers: " << pers; - } + if (f != NULL) + os << " \tpers: " << dia.births[i].get_persistence(get_order(), *f); } else { os << "\033[1;32m" << birth << "\033[0;m"; if (f != NULL)