summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Alpha_complex/test/CMakeLists.txt14
-rw-r--r--src/Alpha_complex/test/Weighted_alpha_complex_non_visible_points_unit_test.cpp60
-rw-r--r--src/Alpha_complex/test/Weighted_alpha_complex_unit_test.cpp102
-rw-r--r--src/Alpha_complex/test/Zero_weighted_alpha_complex_unit_test.cpp77
-rw-r--r--src/Tangential_complex/include/gudhi/Tangential_complex.h8
-rw-r--r--src/python/gudhi/representations/vector_methods.py19
-rw-r--r--src/python/gudhi/rips_complex.pyx8
-rwxr-xr-xsrc/python/test/test_representations.py26
8 files changed, 199 insertions, 115 deletions
diff --git a/src/Alpha_complex/test/CMakeLists.txt b/src/Alpha_complex/test/CMakeLists.txt
index db5d840f..0595ca92 100644
--- a/src/Alpha_complex/test/CMakeLists.txt
+++ b/src/Alpha_complex/test/CMakeLists.txt
@@ -59,4 +59,18 @@ if (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 5.1.0)
endif()
gudhi_add_boost_test(Weighted_alpha_complex_test_unit)
+ add_executable ( Weighted_alpha_complex_non_visible_points_test_unit Weighted_alpha_complex_non_visible_points_unit_test.cpp )
+ target_link_libraries(Weighted_alpha_complex_non_visible_points_test_unit ${CGAL_LIBRARY})
+ if (TBB_FOUND)
+ target_link_libraries(Weighted_alpha_complex_non_visible_points_test_unit ${TBB_LIBRARIES})
+ endif()
+ gudhi_add_boost_test(Weighted_alpha_complex_non_visible_points_test_unit)
+
+ add_executable ( Zero_weighted_alpha_complex_test_unit Zero_weighted_alpha_complex_unit_test.cpp )
+ target_link_libraries(Zero_weighted_alpha_complex_test_unit ${CGAL_LIBRARY})
+ if (TBB_FOUND)
+ target_link_libraries(Zero_weighted_alpha_complex_test_unit ${TBB_LIBRARIES})
+ endif()
+ gudhi_add_boost_test(Zero_weighted_alpha_complex_test_unit)
+
endif (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 5.1.0) \ No newline at end of file
diff --git a/src/Alpha_complex/test/Weighted_alpha_complex_non_visible_points_unit_test.cpp b/src/Alpha_complex/test/Weighted_alpha_complex_non_visible_points_unit_test.cpp
new file mode 100644
index 00000000..dd83c1da
--- /dev/null
+++ b/src/Alpha_complex/test/Weighted_alpha_complex_non_visible_points_unit_test.cpp
@@ -0,0 +1,60 @@
+/* This file is part of the Gudhi Library - https://gudhi.inria.fr/ - which is released under MIT.
+ * See file LICENSE or go to https://gudhi.inria.fr/licensing/ for full license details.
+ * Author(s): Vincent Rouvreau
+ *
+ * Copyright (C) 2020 Inria
+ *
+ * Modification(s):
+ * - YYYY/MM Author: Description of the modification
+ */
+
+#define BOOST_TEST_DYN_LINK
+#define BOOST_TEST_MODULE "weighted_alpha_complex_non_visible_points"
+#include <boost/test/unit_test.hpp>
+#include <boost/mpl/list.hpp>
+
+#include <CGAL/Epick_d.h>
+#include <CGAL/Epeck_d.h>
+
+#include <vector>
+
+#include <gudhi/Alpha_complex.h>
+#include <gudhi/Simplex_tree.h>
+
+
+using list_of_1d_kernel_variants = boost::mpl::list<CGAL::Epeck_d< CGAL::Dynamic_dimension_tag >,
+ CGAL::Epeck_d< CGAL::Dimension_tag<1>>,
+ CGAL::Epick_d< CGAL::Dynamic_dimension_tag >,
+ CGAL::Epick_d< CGAL::Dimension_tag<1>>
+ >;
+
+BOOST_AUTO_TEST_CASE_TEMPLATE(Weighted_alpha_complex_non_visible_points, Kernel, list_of_1d_kernel_variants) {
+ // check that for 2 closed weighted 1-d points, one with a high weight to hide the second one with a small weight,
+ // that the point with a small weight has the same high filtration value than the edge formed by the 2 points
+ using Point_d = typename Kernel::Point_d;
+ std::vector<Point_d> points;
+ std::vector<double> p1 {0.};
+ points.emplace_back(p1.begin(), p1.end());
+ // closed enough points
+ std::vector<double> p2 {0.1};
+ points.emplace_back(p2.begin(), p2.end());
+ std::vector<typename Kernel::FT> weights {100., 0.01};
+
+ Gudhi::alpha_complex::Alpha_complex<Kernel, true> alpha_complex(points, weights);
+ Gudhi::Simplex_tree<> stree;
+ BOOST_CHECK(alpha_complex.create_complex(stree));
+
+ std::clog << "Iterator on weighted alpha complex simplices in the filtration order, with [filtration value]:"
+ << std::endl;
+ for (auto f_simplex : stree.filtration_simplex_range()) {
+ std::clog << " ( ";
+ for (auto vertex : stree.simplex_vertex_range(f_simplex)) {
+ std::clog << vertex << " ";
+ }
+ std::clog << ") -> " << "[" << stree.filtration(f_simplex) << "] " << std::endl;
+ }
+
+ BOOST_CHECK(stree.filtration(stree.find({0})) == -100.);
+ BOOST_CHECK(stree.filtration(stree.find({1})) == stree.filtration(stree.find({0, 1})));
+ BOOST_CHECK(stree.filtration(stree.find({1})) > 100000);
+} \ No newline at end of file
diff --git a/src/Alpha_complex/test/Weighted_alpha_complex_unit_test.cpp b/src/Alpha_complex/test/Weighted_alpha_complex_unit_test.cpp
index d267276c..875704ee 100644
--- a/src/Alpha_complex/test/Weighted_alpha_complex_unit_test.cpp
+++ b/src/Alpha_complex/test/Weighted_alpha_complex_unit_test.cpp
@@ -13,10 +13,8 @@
#include <boost/test/unit_test.hpp>
#include <boost/mpl/list.hpp>
-#include <CGAL/Epick_d.h>
#include <CGAL/Epeck_d.h>
-#include <cmath> // float comparison
#include <vector>
#include <random>
#include <array>
@@ -25,69 +23,6 @@
#include <gudhi/Alpha_complex.h>
#include <gudhi/Alpha_complex_3d.h>
#include <gudhi/Simplex_tree.h>
-#include <gudhi/Unitary_tests_utils.h>
-
-using list_of_exact_kernel_variants = boost::mpl::list<CGAL::Epeck_d< CGAL::Dynamic_dimension_tag >,
- CGAL::Epeck_d< CGAL::Dimension_tag<4> >
- > ;
-
-BOOST_AUTO_TEST_CASE_TEMPLATE(Zero_weighted_alpha_complex, Kernel, list_of_exact_kernel_variants) {
- // Check that in exact mode for static dimension 4 the code for dD unweighted and for dD weighted with all weights
- // 0 give exactly the same simplex tree (simplices and filtration values).
-
- // Random points construction
- using Point_d = typename Kernel::Point_d;
- std::vector<Point_d> points;
- std::uniform_real_distribution<double> rd_pts(-10., 10.);
- std::random_device rand_dev;
- std::mt19937 rand_engine(rand_dev());
- for (int idx = 0; idx < 20; idx++) {
- std::vector<double> point {rd_pts(rand_engine), rd_pts(rand_engine), rd_pts(rand_engine), rd_pts(rand_engine)};
- points.emplace_back(point.begin(), point.end());
- }
-
- // Alpha complex from points
- Gudhi::alpha_complex::Alpha_complex<Kernel, false> alpha_complex_from_points(points);
- Gudhi::Simplex_tree<> simplex;
- Gudhi::Simplex_tree<>::Filtration_value infty = std::numeric_limits<Gudhi::Simplex_tree<>::Filtration_value>::infinity();
- BOOST_CHECK(alpha_complex_from_points.create_complex(simplex, infty, true));
- std::clog << "Iterator on alpha complex simplices in the filtration order, with [filtration value]:"
- << std::endl;
- for (auto f_simplex : simplex.filtration_simplex_range()) {
- std::clog << " ( ";
- for (auto vertex : simplex.simplex_vertex_range(f_simplex)) {
- std::clog << vertex << " ";
- }
- std::clog << ") -> " << "[" << simplex.filtration(f_simplex) << "] " << std::endl;
- }
-
- // Alpha complex from zero weighted points
- std::vector<typename Kernel::FT> weights(20, 0.);
- Gudhi::alpha_complex::Alpha_complex<Kernel, true> alpha_complex_from_zero_weighted_points(points, weights);
- Gudhi::Simplex_tree<> zw_simplex;
- BOOST_CHECK(alpha_complex_from_zero_weighted_points.create_complex(zw_simplex, infty, true));
-
- std::clog << "Iterator on zero weighted alpha complex simplices in the filtration order, with [filtration value]:"
- << std::endl;
- for (auto f_simplex : zw_simplex.filtration_simplex_range()) {
- std::clog << " ( ";
- for (auto vertex : zw_simplex.simplex_vertex_range(f_simplex)) {
- std::clog << vertex << " ";
- }
- std::clog << ") -> " << "[" << zw_simplex.filtration(f_simplex) << "] " << std::endl;
- }
-
- BOOST_CHECK(zw_simplex == simplex);
-}
-
-template <typename Point_d>
-bool cgal_3d_point_sort (Point_d a,Point_d b) {
- if (a[0] != b[0])
- return a[0] < b[0];
- if (a[1] != b[1])
- return a[1] < b[1];
- return a[2] < b[2];
-}
BOOST_AUTO_TEST_CASE(Weighted_alpha_complex_3d_comparison) {
// check that for random weighted 3d points in safe mode the 3D and dD codes give the same result with some tolerance
@@ -189,41 +124,4 @@ BOOST_AUTO_TEST_CASE(Weighted_alpha_complex_3d_comparison) {
}
++dD_itr;
}
-}
-
-using list_of_1d_kernel_variants = boost::mpl::list<CGAL::Epeck_d< CGAL::Dynamic_dimension_tag >,
- CGAL::Epeck_d< CGAL::Dimension_tag<1>>,
- CGAL::Epick_d< CGAL::Dynamic_dimension_tag >,
- CGAL::Epick_d< CGAL::Dimension_tag<1>>
- >;
-
-BOOST_AUTO_TEST_CASE_TEMPLATE(Weighted_alpha_complex_non_visible_points, Kernel, list_of_1d_kernel_variants) {
- // check that for 2 closed weighted 1-d points, one with a high weight to hide the second one with a small weight,
- // that the point with a small weight has the same high filtration value than the edge formed by the 2 points
- using Point_d = typename Kernel::Point_d;
- std::vector<Point_d> points;
- std::vector<double> p1 {0.};
- points.emplace_back(p1.begin(), p1.end());
- // closed enough points
- std::vector<double> p2 {0.1};
- points.emplace_back(p2.begin(), p2.end());
- std::vector<typename Kernel::FT> weights {100., 0.01};
-
- Gudhi::alpha_complex::Alpha_complex<Kernel, true> alpha_complex(points, weights);
- Gudhi::Simplex_tree<> stree;
- BOOST_CHECK(alpha_complex.create_complex(stree));
-
- std::clog << "Iterator on weighted alpha complex simplices in the filtration order, with [filtration value]:"
- << std::endl;
- for (auto f_simplex : stree.filtration_simplex_range()) {
- std::clog << " ( ";
- for (auto vertex : stree.simplex_vertex_range(f_simplex)) {
- std::clog << vertex << " ";
- }
- std::clog << ") -> " << "[" << stree.filtration(f_simplex) << "] " << std::endl;
- }
-
- BOOST_CHECK(stree.filtration(stree.find({0})) == -100.);
- BOOST_CHECK(stree.filtration(stree.find({1})) == stree.filtration(stree.find({0, 1})));
- BOOST_CHECK(stree.filtration(stree.find({1})) > 100000);
} \ No newline at end of file
diff --git a/src/Alpha_complex/test/Zero_weighted_alpha_complex_unit_test.cpp b/src/Alpha_complex/test/Zero_weighted_alpha_complex_unit_test.cpp
new file mode 100644
index 00000000..b7df07c7
--- /dev/null
+++ b/src/Alpha_complex/test/Zero_weighted_alpha_complex_unit_test.cpp
@@ -0,0 +1,77 @@
+/* This file is part of the Gudhi Library - https://gudhi.inria.fr/ - which is released under MIT.
+ * See file LICENSE or go to https://gudhi.inria.fr/licensing/ for full license details.
+ * Author(s): Vincent Rouvreau
+ *
+ * Copyright (C) 2020 Inria
+ *
+ * Modification(s):
+ * - YYYY/MM Author: Description of the modification
+ */
+
+#define BOOST_TEST_DYN_LINK
+#define BOOST_TEST_MODULE "zero_weighted_alpha_complex"
+#include <boost/test/unit_test.hpp>
+#include <boost/mpl/list.hpp>
+
+#include <CGAL/Epeck_d.h>
+
+#include <vector>
+#include <random>
+#include <cmath> // for std::fabs
+
+#include <gudhi/Alpha_complex.h>
+#include <gudhi/Simplex_tree.h>
+#include <gudhi/Unitary_tests_utils.h>
+
+using list_of_exact_kernel_variants = boost::mpl::list<CGAL::Epeck_d< CGAL::Dynamic_dimension_tag >,
+ CGAL::Epeck_d< CGAL::Dimension_tag<4> >
+ > ;
+
+BOOST_AUTO_TEST_CASE_TEMPLATE(Zero_weighted_alpha_complex, Kernel, list_of_exact_kernel_variants) {
+ // Check that in exact mode for static dimension 4 the code for dD unweighted and for dD weighted with all weights
+ // 0 give exactly the same simplex tree (simplices and filtration values).
+
+ // Random points construction
+ using Point_d = typename Kernel::Point_d;
+ std::vector<Point_d> points;
+ std::uniform_real_distribution<double> rd_pts(-10., 10.);
+ std::random_device rand_dev;
+ std::mt19937 rand_engine(rand_dev());
+ for (int idx = 0; idx < 20; idx++) {
+ std::vector<double> point {rd_pts(rand_engine), rd_pts(rand_engine), rd_pts(rand_engine), rd_pts(rand_engine)};
+ points.emplace_back(point.begin(), point.end());
+ }
+
+ // Alpha complex from points
+ Gudhi::alpha_complex::Alpha_complex<Kernel, false> alpha_complex_from_points(points);
+ Gudhi::Simplex_tree<> simplex;
+ Gudhi::Simplex_tree<>::Filtration_value infty = std::numeric_limits<Gudhi::Simplex_tree<>::Filtration_value>::infinity();
+ BOOST_CHECK(alpha_complex_from_points.create_complex(simplex, infty, true));
+ std::clog << "Iterator on alpha complex simplices in the filtration order, with [filtration value]:"
+ << std::endl;
+ for (auto f_simplex : simplex.filtration_simplex_range()) {
+ std::clog << " ( ";
+ for (auto vertex : simplex.simplex_vertex_range(f_simplex)) {
+ std::clog << vertex << " ";
+ }
+ std::clog << ") -> " << "[" << simplex.filtration(f_simplex) << "] " << std::endl;
+ }
+
+ // Alpha complex from zero weighted points
+ std::vector<typename Kernel::FT> weights(20, 0.);
+ Gudhi::alpha_complex::Alpha_complex<Kernel, true> alpha_complex_from_zero_weighted_points(points, weights);
+ Gudhi::Simplex_tree<> zw_simplex;
+ BOOST_CHECK(alpha_complex_from_zero_weighted_points.create_complex(zw_simplex, infty, true));
+
+ std::clog << "Iterator on zero weighted alpha complex simplices in the filtration order, with [filtration value]:"
+ << std::endl;
+ for (auto f_simplex : zw_simplex.filtration_simplex_range()) {
+ std::clog << " ( ";
+ for (auto vertex : zw_simplex.simplex_vertex_range(f_simplex)) {
+ std::clog << vertex << " ";
+ }
+ std::clog << ") -> " << "[" << zw_simplex.filtration(f_simplex) << "] " << std::endl;
+ }
+
+ BOOST_CHECK(zw_simplex == simplex);
+} \ No newline at end of file
diff --git a/src/Tangential_complex/include/gudhi/Tangential_complex.h b/src/Tangential_complex/include/gudhi/Tangential_complex.h
index f007bdd5..f3491f91 100644
--- a/src/Tangential_complex/include/gudhi/Tangential_complex.h
+++ b/src/Tangential_complex/include/gudhi/Tangential_complex.h
@@ -954,7 +954,11 @@ class Tangential_complex {
// Triangulation's traits functor & objects
typename Tr_traits::Compute_weight_d point_weight = local_tr_traits.compute_weight_d_object();
+#if CGAL_VERSION_NR < 1050200000
typename Tr_traits::Power_center_d power_center = local_tr_traits.power_center_d_object();
+#else
+ typename Tr_traits::Construct_power_sphere_d power_center = local_tr_traits.construct_power_sphere_d_object();
+#endif
//***************************************************
// Build a minimal triangulation in the tangent space
@@ -1100,7 +1104,11 @@ class Tangential_complex {
std::size_t closest_pt_index = updated_pts_ds.k_nearest_neighbors(center_point, 1, false).begin()->first;
typename K::Construct_weighted_point_d k_constr_wp = m_k.construct_weighted_point_d_object();
+#if CGAL_VERSION_NR < 1050200000
typename K::Power_distance_d k_power_dist = m_k.power_distance_d_object();
+#else
+ typename K::Compute_power_product_d k_power_dist = m_k.compute_power_product_d_object();
+#endif
// Construct a weighted point equivalent to the star sphere
Weighted_point star_sphere = k_constr_wp(compute_perturbed_point(i), m_squared_star_spheres_radii_incl_margin[i]);
diff --git a/src/python/gudhi/representations/vector_methods.py b/src/python/gudhi/representations/vector_methods.py
index cdcb1fde..84bc99a2 100644
--- a/src/python/gudhi/representations/vector_methods.py
+++ b/src/python/gudhi/representations/vector_methods.py
@@ -605,18 +605,19 @@ class Atol(BaseEstimator, TransformerMixin):
>>> b = np.array([[4, 2, 0], [4, 4, 0], [4, 0, 2]])
>>> c = np.array([[3, 2, -1], [1, 2, -1]])
>>> atol_vectoriser = Atol(quantiser=KMeans(n_clusters=2, random_state=202006))
- >>> atol_vectoriser.fit(X=[a, b, c]).centers
- array([[ 2. , 0.66666667, 3.33333333],
- [ 2.6 , 2.8 , -0.4 ]])
+ >>> atol_vectoriser.fit(X=[a, b, c]).centers # doctest: +SKIP
+ >>> # array([[ 2. , 0.66666667, 3.33333333],
+ >>> # [ 2.6 , 2.8 , -0.4 ]])
>>> atol_vectoriser(a)
- array([1.18168665, 0.42375966])
+ >>> # array([1.18168665, 0.42375966]) # doctest: +SKIP
>>> atol_vectoriser(c)
- array([0.02062512, 1.25157463])
- >>> atol_vectoriser.transform(X=[a, b, c])
- array([[1.18168665, 0.42375966],
- [0.29861028, 1.06330156],
- [0.02062512, 1.25157463]])
+ >>> # array([0.02062512, 1.25157463]) # doctest: +SKIP
+ >>> atol_vectoriser.transform(X=[a, b, c]) # doctest: +SKIP
+ >>> # array([[1.18168665, 0.42375966],
+ >>> # [0.29861028, 1.06330156],
+ >>> # [0.02062512, 1.25157463]])
"""
+ # Note the example above must be up to date with the one in tests called test_atol_doc
def __init__(self, quantiser, weighting_method="cloud", contrast="gaussian"):
"""
Constructor for the Atol measure vectorisation class.
diff --git a/src/python/gudhi/rips_complex.pyx b/src/python/gudhi/rips_complex.pyx
index 72e82c79..c3470292 100644
--- a/src/python/gudhi/rips_complex.pyx
+++ b/src/python/gudhi/rips_complex.pyx
@@ -49,13 +49,13 @@ cdef class RipsComplex:
:type max_edge_length: float
:param points: A list of points in d-Dimension.
- :type points: list of list of double
+ :type points: list of list of float
Or
:param distance_matrix: A distance matrix (full square or lower
triangular).
- :type points: list of list of double
+ :type points: list of list of float
And in both cases
@@ -89,10 +89,10 @@ cdef class RipsComplex:
def create_simplex_tree(self, max_dimension=1):
"""
- :param max_dimension: graph expansion for rips until this given maximal
+ :param max_dimension: graph expansion for Rips until this given maximal
dimension.
:type max_dimension: int
- :returns: A simplex tree created from the Delaunay Triangulation.
+ :returns: A simplex tree encoding the Vietoris–Rips filtration.
:rtype: SimplexTree
"""
stree = SimplexTree()
diff --git a/src/python/test/test_representations.py b/src/python/test/test_representations.py
index 43c914f3..cda1a15b 100755
--- a/src/python/test/test_representations.py
+++ b/src/python/test/test_representations.py
@@ -46,6 +46,32 @@ def test_multiple():
assert d1 == pytest.approx(d2, rel=0.02)
+# Test sorted values as points order can be inverted, and sorted test is not documentation-friendly
+# Note the test below must be up to date with the Atol class documentation
+def test_atol_doc():
+ a = np.array([[1, 2, 4], [1, 4, 0], [1, 0, 4]])
+ b = np.array([[4, 2, 0], [4, 4, 0], [4, 0, 2]])
+ c = np.array([[3, 2, -1], [1, 2, -1]])
+
+ atol_vectoriser = Atol(quantiser=KMeans(n_clusters=2, random_state=202006))
+ # Atol will do
+ # X = np.concatenate([a,b,c])
+ # kmeans = KMeans(n_clusters=2, random_state=202006).fit(X)
+ # kmeans.labels_ will be : array([1, 0, 1, 0, 0, 1, 0, 0])
+ first_cluster = np.asarray([a[0], a[2], b[2]])
+ second_cluster = np.asarray([a[1], b[0], b[2], c[0], c[1]])
+
+ # Check the center of the first_cluster and second_cluster are in Atol centers
+ centers = atol_vectoriser.fit(X=[a, b, c]).centers
+ np.isclose(centers, first_cluster.mean(axis=0)).all(1).any()
+ np.isclose(centers, second_cluster.mean(axis=0)).all(1).any()
+
+ vectorization = atol_vectoriser.transform(X=[a, b, c])
+ assert np.allclose(vectorization[0], atol_vectoriser(a))
+ assert np.allclose(vectorization[1], atol_vectoriser(b))
+ assert np.allclose(vectorization[2], atol_vectoriser(c))
+
+
def test_dummy_atol():
a = np.array([[1, 2, 4], [1, 4, 0], [1, 0, 4]])
b = np.array([[4, 2, 0], [4, 4, 0], [4, 0, 2]])