summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorROUVREAU Vincent <vincent.rouvreau@inria.fr>2019-05-28 10:28:12 +0200
committerROUVREAU Vincent <vincent.rouvreau@inria.fr>2019-05-28 10:28:12 +0200
commitc0f2c9489d33abd75924413eb14070f2a2741f33 (patch)
treefd0964613ed00d28dcb57e8ee603ed7839f060ff
parent2bd43179e588e0b653eb4cf47613e49dc3ac20a9 (diff)
parentc91827a7a316df5b236237695e44778e0a79bcf1 (diff)
Merge branch 'master' of github.com:GUDHI/gudhi-devel
-rw-r--r--src/Witness_complex/example/example_nearest_landmark_table.cpp21
-rw-r--r--src/Witness_complex/include/gudhi/Strong_witness_complex.h7
-rw-r--r--src/Witness_complex/include/gudhi/Witness_complex.h11
-rw-r--r--src/cython/cython/strong_witness_complex.pyx12
-rw-r--r--src/cython/cython/witness_complex.pyx12
-rwxr-xr-xsrc/cython/example/witness_complex_from_nearest_landmark_table.py12
6 files changed, 41 insertions, 34 deletions
diff --git a/src/Witness_complex/example/example_nearest_landmark_table.cpp b/src/Witness_complex/example/example_nearest_landmark_table.cpp
index acaf7c54..441900c1 100644
--- a/src/Witness_complex/example/example_nearest_landmark_table.cpp
+++ b/src/Witness_complex/example/example_nearest_landmark_table.cpp
@@ -19,22 +19,19 @@ int main(int argc, char * const argv[]) {
using Persistent_cohomology = Gudhi::persistent_cohomology::Persistent_cohomology<Simplex_tree, Field_Zp>;
Simplex_tree simplex_tree;
- Nearest_landmark_table nlt;
// Example contains 5 witnesses and 5 landmarks
- Nearest_landmark_range w0 = {std::make_pair(0, 0), std::make_pair(1, 1), std::make_pair(2, 2),
- std::make_pair(3, 3), std::make_pair(4, 4)}; nlt.push_back(w0);
- Nearest_landmark_range w1 = {std::make_pair(1, 0), std::make_pair(2, 1), std::make_pair(3, 2),
- std::make_pair(4, 3), std::make_pair(0, 4)}; nlt.push_back(w1);
- Nearest_landmark_range w2 = {std::make_pair(2, 0), std::make_pair(3, 1), std::make_pair(4, 2),
- std::make_pair(0, 3), std::make_pair(1, 4)}; nlt.push_back(w2);
- Nearest_landmark_range w3 = {std::make_pair(3, 0), std::make_pair(4, 1), std::make_pair(0, 2),
- std::make_pair(1, 3), std::make_pair(2, 4)}; nlt.push_back(w3);
- Nearest_landmark_range w4 = {std::make_pair(4, 0), std::make_pair(0, 1), std::make_pair(1, 2),
- std::make_pair(2, 3), std::make_pair(3, 4)}; nlt.push_back(w4);
+ Nearest_landmark_table nlt = {
+ {{0, 0.0}, {1, 0.1}, {2, 0.2}, {3, 0.3}, {4, 0.4}}, // witness 0
+ {{1, 0.0}, {2, 0.1}, {3, 0.2}, {4, 0.3}, {0, 0.4}}, // witness 1
+ {{2, 0.0}, {3, 0.1}, {4, 0.2}, {0, 0.3}, {1, 0.4}}, // witness 2
+ {{3, 0.0}, {4, 0.1}, {0, 0.2}, {1, 0.3}, {2, 0.4}}, // witness 3
+ {{4, 0.0}, {0, 0.1}, {1, 0.2}, {2, 0.3}, {3, 0.4}} // witness 4
+ };
+ /* distance(witness3, landmark3) is 0, distance(witness3, landmark4) is 0.1, etc. */
Witness_complex witness_complex(nlt);
- witness_complex.create_complex(simplex_tree, 4.1);
+ witness_complex.create_complex(simplex_tree, .41);
std::cout << "Number of simplices: " << simplex_tree.num_simplices() << std::endl;
diff --git a/src/Witness_complex/include/gudhi/Strong_witness_complex.h b/src/Witness_complex/include/gudhi/Strong_witness_complex.h
index fd6b3f38..03d6d2e7 100644
--- a/src/Witness_complex/include/gudhi/Strong_witness_complex.h
+++ b/src/Witness_complex/include/gudhi/Strong_witness_complex.h
@@ -40,10 +40,13 @@ namespace witness_complex {
* \brief Constructs strong witness complex for a given table of nearest landmarks with respect to witnesses.
* \ingroup witness_complex
*
- * \tparam Nearest_landmark_table_ needs to be a range of a range of pairs of nearest landmarks and distances.
+ * \tparam Nearest_landmark_table_ needs to be a range (one entry per witness)
+ * of sorted ranges of pairs of nearest landmarks and distances.
* The class Nearest_landmark_table_::value_type must be a copiable range.
* The range of pairs must admit a member type 'iterator'. The dereference type
- * of the pair range iterator needs to be 'std::pair<std::size_t, double>'.
+ * of the pair range iterator needs to be 'std::pair<std::size_t, double>'
+ * where the first element is the index of the landmark, and the second its
+ * (squared) distance to the witness.
*/
template< class Nearest_landmark_table_ >
class Strong_witness_complex {
diff --git a/src/Witness_complex/include/gudhi/Witness_complex.h b/src/Witness_complex/include/gudhi/Witness_complex.h
index 67885258..1f61f8f2 100644
--- a/src/Witness_complex/include/gudhi/Witness_complex.h
+++ b/src/Witness_complex/include/gudhi/Witness_complex.h
@@ -75,10 +75,13 @@ class Witness_complex {
/**
* \brief Initializes member variables before constructing simplicial complex.
* \details Records nearest landmark table.
- * @param[in] nearest_landmark_table needs to be a range of a range of pairs of nearest landmarks and distances.
+ * @param[in] nearest_landmark_table needs to be a range (one entry per witness)
+ * of sorted ranges of pairs of nearest landmarks and distances.
* The class Nearest_landmark_table_::value_type must be a copiable range.
* The range of pairs must admit a member type 'iterator'. The dereference type
- * of the pair range iterator needs to be 'std::pair<std::size_t, double>'.
+ * of the pair range iterator needs to be 'std::pair<std::size_t, double>'
+ * where the first element is the index of the landmark, and the second its
+ * (squared) distance to the witness.
*/
Witness_complex(Nearest_landmark_table_ const & nearest_landmark_table)
@@ -108,8 +111,8 @@ class Witness_complex {
}
ActiveWitnessList active_witnesses;
Landmark_id k = 0; /* current dimension in iterative construction */
- for (auto w : nearest_landmark_table_)
- active_witnesses.push_back(ActiveWitness(w));
+ for (auto&& w : nearest_landmark_table_)
+ active_witnesses.emplace_back(w);
while (!active_witnesses.empty() && k <= limit_dimension) {
typename ActiveWitnessList::iterator aw_it = active_witnesses.begin();
std::vector<Landmark_id> simplex;
diff --git a/src/cython/cython/strong_witness_complex.pyx b/src/cython/cython/strong_witness_complex.pyx
index 74c5cb05..4b7bff34 100644
--- a/src/cython/cython/strong_witness_complex.pyx
+++ b/src/cython/cython/strong_witness_complex.pyx
@@ -47,8 +47,10 @@ cdef class StrongWitnessComplex:
def __init__(self, nearest_landmark_table=None):
"""StrongWitnessComplex constructor.
- :param nearest_landmark_table: A list of nearest landmark.
- :type nearest_landmark_table: list of list of pair of unsigned and double
+ :param nearest_landmark_table: A list of lists of nearest landmarks and their distances.
+ `nearest_landmark_table[w][k]==(l,d)` means that l is the k-th nearest landmark to
+ witness w, and d is the (squared) distance between l and w.
+ :type nearest_landmark_table: list of list of pair of int and float
"""
# The real cython constructor
@@ -65,10 +67,10 @@ cdef class StrongWitnessComplex:
"""
return self.thisptr != NULL
- def create_simplex_tree(self, max_alpha_square, limit_dimension = -1):
+ def create_simplex_tree(self, max_alpha_square = float('inf'), limit_dimension = -1):
"""
- :param max_alpha_square: The maximum alpha square threshold the
- simplices shall not exceed. Default is set to infinity.
+ :param max_alpha_square: The maximum relaxation parameter.
+ Default is set to infinity.
:type max_alpha_square: float
:returns: A simplex tree created from the Delaunay Triangulation.
:rtype: SimplexTree
diff --git a/src/cython/cython/witness_complex.pyx b/src/cython/cython/witness_complex.pyx
index 8591465a..b1cce83f 100644
--- a/src/cython/cython/witness_complex.pyx
+++ b/src/cython/cython/witness_complex.pyx
@@ -47,8 +47,10 @@ cdef class WitnessComplex:
def __init__(self, nearest_landmark_table=None):
"""WitnessComplex constructor.
- :param nearest_landmark_table: A list of nearest landmark.
- :type nearest_landmark_table: list of list of pair of unsigned and double
+ :param nearest_landmark_table: A list of lists of nearest landmarks and their distances.
+ `nearest_landmark_table[w][k]==(l,d)` means that l is the k-th nearest landmark to
+ witness w, and d is the (squared) distance between l and w.
+ :type nearest_landmark_table: list of list of pair of int and float
"""
# The real cython constructor
@@ -65,10 +67,10 @@ cdef class WitnessComplex:
"""
return self.thisptr != NULL
- def create_simplex_tree(self, max_alpha_square, limit_dimension = -1):
+ def create_simplex_tree(self, max_alpha_square = float('inf'), limit_dimension = -1):
"""
- :param max_alpha_square: The maximum alpha square threshold the
- simplices shall not exceed. Default is set to infinity.
+ :param max_alpha_square: The maximum relaxation parameter.
+ Default is set to infinity.
:type max_alpha_square: float
:returns: A simplex tree created from the Delaunay Triangulation.
:rtype: SimplexTree
diff --git a/src/cython/example/witness_complex_from_nearest_landmark_table.py b/src/cython/example/witness_complex_from_nearest_landmark_table.py
index e6b295ee..1b79d9b2 100755
--- a/src/cython/example/witness_complex_from_nearest_landmark_table.py
+++ b/src/cython/example/witness_complex_from_nearest_landmark_table.py
@@ -30,14 +30,14 @@ __license__ = "GPL v3"
print("#####################################################################")
print("WitnessComplex creation from nearest landmark table")
-nearest_landmark_table = [[[0, 0], [1, 1], [2, 2], [3, 3], [4, 4]],
- [[1, 0], [2, 1], [3, 2], [4, 3], [0, 4]],
- [[2, 0], [3, 1], [4, 2], [0, 3], [1, 4]],
- [[3, 0], [4, 1], [0, 2], [1, 3], [2, 4]],
- [[4, 0], [0, 1], [1, 2], [2, 3], [3, 4]]]
+nearest_landmark_table = [[[0, 0.0], [1, 0.1], [2, 0.2], [3, 0.3], [4, 0.4]],
+ [[1, 0.0], [2, 0.1], [3, 0.2], [4, 0.3], [0, 0.4]],
+ [[2, 0.0], [3, 0.1], [4, 0.2], [0, 0.3], [1, 0.4]],
+ [[3, 0.0], [4, 0.1], [0, 0.2], [1, 0.3], [2, 0.4]],
+ [[4, 0.0], [0, 0.1], [1, 0.2], [2, 0.3], [3, 0.4]]]
witness_complex = StrongWitnessComplex(nearest_landmark_table=nearest_landmark_table)
-simplex_tree = witness_complex.create_simplex_tree(max_alpha_square=4.1)
+simplex_tree = witness_complex.create_simplex_tree(max_alpha_square=0.41)
message = "Number of simplices: " + repr(simplex_tree.num_simplices())
print(message)