summaryrefslogtreecommitdiff
path: root/src/python
diff options
context:
space:
mode:
authorMathieuCarriere <mathieu.carriere3@gmail.com>2020-03-23 21:22:16 -0400
committerMathieuCarriere <mathieu.carriere3@gmail.com>2020-03-23 21:22:16 -0400
commitbc223c3cc7cb9e9c0bb3573af720fce9c5380b94 (patch)
treef52f422105e609d0eb43d29cd0a942c9db52bf71 /src/python
parent1e0e378ab442672ef569e93c4114b0e99ea70f6e (diff)
new fixes
Diffstat (limited to 'src/python')
-rw-r--r--src/python/gudhi/simplex_tree.pxd2
-rw-r--r--src/python/gudhi/simplex_tree.pyx21
-rw-r--r--src/python/include/Simplex_tree_interface.h34
-rwxr-xr-xsrc/python/test/test_simplex_tree.py7
4 files changed, 29 insertions, 35 deletions
diff --git a/src/python/gudhi/simplex_tree.pxd b/src/python/gudhi/simplex_tree.pxd
index b6284af4..595f22bb 100644
--- a/src/python/gudhi/simplex_tree.pxd
+++ b/src/python/gudhi/simplex_tree.pxd
@@ -58,7 +58,7 @@ cdef extern from "Simplex_tree_interface.h" namespace "Gudhi":
bool prune_above_filtration(double filtration)
bool make_filtration_non_decreasing()
void compute_extended_filtration()
- vector[vector[pair[int, pair[double, double]]]] compute_extended_persistence_subdiagrams(vector[pair[int, pair[double, double]]] dgm)
+ vector[vector[pair[int, pair[double, double]]]] compute_extended_persistence_subdiagrams(vector[pair[int, pair[double, double]]] dgm, double min_persistence)
# Iterators over Simplex tree
pair[vector[int], double] get_simplex_and_filtration(Simplex_tree_simplex_handle f_simplex)
Simplex_tree_simplices_iterator get_simplices_iterator_begin()
diff --git a/src/python/gudhi/simplex_tree.pyx b/src/python/gudhi/simplex_tree.pyx
index 5b850462..bcb1578d 100644
--- a/src/python/gudhi/simplex_tree.pyx
+++ b/src/python/gudhi/simplex_tree.pyx
@@ -411,7 +411,7 @@ cdef class SimplexTree:
.. note::
Note that this code creates an extra vertex internally, so you should make sure that
- the Simplex_tree does not contain a vertex with the largest Vertex_handle.
+ the Simplex_tree does not contain a vertex with the largest possible value (i.e., 4294967295).
"""
return self.get_ptr().compute_extended_filtration()
@@ -422,18 +422,16 @@ cdef class SimplexTree:
:param homology_coeff_field: The homology coefficient field. Must be a
prime number. Default value is 11.
:type homology_coeff_field: int.
- :param min_persistence: The minimum persistence value to take into
+ :param min_persistence: The minimum persistence value (i.e., the absolute value of the difference between the persistence diagram point coordinates) to take into
account (strictly greater than min_persistence). Default value is
0.0.
Sets min_persistence to -1.0 to see all values.
:type min_persistence: float.
- :returns: A vector of four persistence diagrams. The first one is Ordinary, the second one is Relative, the third one is Extended+ and the fourth one is Extended-. See section 2.2 in https://link.springer.com/article/10.1007/s10208-017-9370-z for a description of these subtypes.
+ :returns: A list of four persistence diagrams in the format described in :func:`persistence()<gudhi.SimplexTree.persistence>`. The first one is Ordinary, the second one is Relative, the third one is Extended+ and the fourth one is Extended-. See section 2.2 in https://link.springer.com/article/10.1007/s10208-017-9370-z for a description of these subtypes.
.. note::
- This function should be called only if :func:`extend_filtration()<gudhi.SimplexTree.extend_filtration>`,
- :func:`initialize_filtration()<gudhi.SimplexTree.initialize_filtration>`,
- and (optionally) :func:`persistence()<gudhi.SimplexTree.persistence>` have been called first!
+ This function should be called only if :func:`extend_filtration()<gudhi.SimplexTree.extend_filtration>` has been called first!
.. note::
@@ -442,14 +440,11 @@ cdef class SimplexTree:
performed on these values during the computation of extended persistence.
"""
cdef vector[pair[int, pair[double, double]]] persistence_result
- if self.pcohptr == NULL:
- self.pcohptr = new Simplex_tree_persistence_interface(self.get_ptr(), False)
- if self.pcohptr != NULL:
- self.pcohptr.get_persistence(homology_coeff_field, min_persistence)
if self.pcohptr != NULL:
- pairs = self.pcohptr.persistence_pairs()
- persistence_result = [(len(splx1)-1, [self.filtration(splx1), self.filtration(splx2)]) for [splx1, splx2] in pairs]
- return self.get_ptr().compute_extended_persistence_subdiagrams(persistence_result)
+ del self.pcohptr
+ self.pcohptr = new Simplex_tree_persistence_interface(self.get_ptr(), False)
+ persistence_result = self.pcohptr.get_persistence(homology_coeff_field, -1.)
+ return self.get_ptr().compute_extended_persistence_subdiagrams(persistence_result, min_persistence)
def persistence(self, homology_coeff_field=11, min_persistence=0, persistence_dim_max = False):
diff --git a/src/python/include/Simplex_tree_interface.h b/src/python/include/Simplex_tree_interface.h
index a6b1a06e..1a18aed6 100644
--- a/src/python/include/Simplex_tree_interface.h
+++ b/src/python/include/Simplex_tree_interface.h
@@ -38,7 +38,6 @@ class Simplex_tree_interface : public Simplex_tree<SimplexTreeOptions> {
using Skeleton_simplex_iterator = typename Base::Skeleton_simplex_iterator;
using Complex_simplex_iterator = typename Base::Complex_simplex_iterator;
using Extended_filtration_data = typename Base::Extended_filtration_data;
- using Extended_simplex_type = typename Base::Extended_simplex_type;
public:
@@ -124,31 +123,34 @@ class Simplex_tree_interface : public Simplex_tree<SimplexTreeOptions> {
void compute_extended_filtration() {
this->efd = this->extend_filtration();
+ this->initialize_filtration();
return;
}
- std::vector<std::vector<std::pair<int, std::pair<Filtration_value, Filtration_value>>>> compute_extended_persistence_subdiagrams(const std::vector<std::pair<int, std::pair<Filtration_value, Filtration_value>>>& dgm){
+ std::vector<std::vector<std::pair<int, std::pair<Filtration_value, Filtration_value>>>> compute_extended_persistence_subdiagrams(const std::vector<std::pair<int, std::pair<Filtration_value, Filtration_value>>>& dgm, Filtration_value min_persistence){
std::vector<std::vector<std::pair<int, std::pair<Filtration_value, Filtration_value>>>> new_dgm(4);
for (unsigned int i = 0; i < dgm.size(); i++){
std::pair<Filtration_value, Extended_simplex_type> px = this->decode_extended_filtration(dgm[i].second.first, this->efd);
std::pair<Filtration_value, Extended_simplex_type> py = this->decode_extended_filtration(dgm[i].second.second, this->efd);
std::pair<int, std::pair<Filtration_value, Filtration_value>> pd_point = std::make_pair(dgm[i].first, std::make_pair(px.first, py.first));
- //Ordinary
- if (px.second == Base::UP && py.second == Base::UP){
- new_dgm[0].push_back(pd_point);
- }
- // Relative
- else if (px.second == Base::DOWN && py.second == Base::DOWN){
- new_dgm[1].push_back(pd_point);
- }
- else{
- // Extended+
- if (px.first < py.first){
- new_dgm[2].push_back(pd_point);
+ if(std::abs(px.first - py.first) > min_persistence){
+ //Ordinary
+ if (px.second == Extended_simplex_type::UP && py.second == Extended_simplex_type::UP){
+ new_dgm[0].push_back(pd_point);
+ }
+ // Relative
+ else if (px.second == Extended_simplex_type::DOWN && py.second == Extended_simplex_type::DOWN){
+ new_dgm[1].push_back(pd_point);
}
- //Extended-
else{
- new_dgm[3].push_back(pd_point);
+ // Extended+
+ if (px.first < py.first){
+ new_dgm[2].push_back(pd_point);
+ }
+ //Extended-
+ else{
+ new_dgm[3].push_back(pd_point);
+ }
}
}
}
diff --git a/src/python/test/test_simplex_tree.py b/src/python/test/test_simplex_tree.py
index 20f6aabf..70b26e97 100755
--- a/src/python/test/test_simplex_tree.py
+++ b/src/python/test/test_simplex_tree.py
@@ -291,10 +291,8 @@ def test_extend_filtration():
([5], 6.0)
]
-
st.extend_filtration()
- st.initialize_filtration()
-
+
assert list(st.get_filtration()) == [
([6], -3.0),
([0], -2.0),
@@ -323,7 +321,7 @@ def test_extend_filtration():
([0, 3, 6], 2.0)
]
- dgms = st.extended_persistence()
+ dgms = st.extended_persistence(min_persistence=-1.)
assert dgms[0][0][1][0] == pytest.approx(2.)
assert dgms[0][0][1][1] == pytest.approx(3.)
@@ -334,7 +332,6 @@ def test_extend_filtration():
assert dgms[3][0][1][0] == pytest.approx(6.)
assert dgms[3][0][1][1] == pytest.approx(1.)
-
def test_simplices_iterator():
st = SimplexTree()