summaryrefslogtreecommitdiff
path: root/src/cython
diff options
context:
space:
mode:
authorpdlotko <pdlotko@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2017-08-22 19:38:57 +0000
committerpdlotko <pdlotko@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2017-08-22 19:38:57 +0000
commitd7797ccdc896a06977155b16df327eb6c379907a (patch)
treeca7a9f273a7d2709894d3754e2b36f9c9f639216 /src/cython
parentc415445c6a30cfdc7abc63dba23e4eb5e7ff98da (diff)
First almost working version.
git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/persistence_representation_integration@2619 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 6f677549e1889ffe29125d2550b2a4a57099b3f5
Diffstat (limited to 'src/cython')
-rw-r--r--src/cython/cython/persistence_representations_intervals.pyx11
-rwxr-xr-xsrc/cython/example/persistence_representations_diagrams_example.py83
-rw-r--r--src/cython/include/persistence_representations_intervals.h5
-rwxr-xr-xsrc/cython/test/test_persistence_representations_diagrams.py87
4 files changed, 121 insertions, 65 deletions
diff --git a/src/cython/cython/persistence_representations_intervals.pyx b/src/cython/cython/persistence_representations_intervals.pyx
index 29027801..887010e5 100644
--- a/src/cython/cython/persistence_representations_intervals.pyx
+++ b/src/cython/cython/persistence_representations_intervals.pyx
@@ -91,11 +91,14 @@ cdef class PersistenceIntervals:
# The real cython constructor
- def __cinit__(self, vector_of_intervals=None, dimension = None, file_with_intervals=''):
+ def __cinit__(self, vector_of_intervals=None, dimension = None, file_with_intervals=''):
if (vector_of_intervals is None) and (file_with_intervals is not ''):
- self.thisptr = new Persistence_intervals_interface(file_with_intervals, dimension)
- elif (file_with_intervals is not '') and (vector_of_intervals is not None):
- if os.path.isfile(file_with_intervals):
+ if ( dimension is not None ):
+ self.thisptr = new Persistence_intervals_interface(file_with_intervals, dimension)
+ else:
+ self.thisptr = new Persistence_intervals_interface(file_with_intervals)
+ elif (file_with_intervals is '') and (vector_of_intervals is not None):
+ if os.path.isfile(file_with_intervals):
self.thisptr = new Persistence_intervals_interface(str.encode(file_with_intervals))
else:
print("file " + file_with_intervals + " not found.")
diff --git a/src/cython/example/persistence_representations_diagrams_example.py b/src/cython/example/persistence_representations_diagrams_example.py
index 62dc84d7..bcf17f5a 100755
--- a/src/cython/example/persistence_representations_diagrams_example.py
+++ b/src/cython/example/persistence_representations_diagrams_example.py
@@ -33,15 +33,6 @@ print("#####################################################################")
print("Persistence representations diagrams example")
-
-
-
-
-
-
-
-
-
parser = argparse.ArgumentParser(description='Statistics od persistence diagrams from file ',
epilog='Example: '
'example/persistence_representations_diagrams_example.py '
@@ -53,55 +44,27 @@ args = parser.parse_args()
print "Here are the parameters of the program: ",args.file," , " ,args.dimension
-
-p = gudhi.PersistenceIntervals(args.file,args.dimension);
+p = gudhi.PersistenceDiagrams(None,args.dimension,args.file);
min_max_ = p.get_x_range();
-print( "Birth-death range : ", min_max_)
-"""
-std::vector<double> dominant_ten_intervals_length = p.length_of_dominant_intervals(10);
-std::cout << "Length of ten dominant intervals : " << std::endl;
-for (size_t i = 0; i != dominant_ten_intervals_length.size(); ++i) {
-std::cout << dominant_ten_intervals_length[i] << std::endl;
-}
-
-std::vector<std::pair<double, double> > ten_dominant_intervals = p.dominant_intervals(10);
-std::cout << "Here are the dominant intervals : " << std::endl;
-for (size_t i = 0; i != ten_dominant_intervals.size(); ++i) {
-std::cout << "( " << ten_dominant_intervals[i].first << "," << ten_dominant_intervals[i].second << std::endl;
-}
-
-std::vector<size_t> histogram = p.histogram_of_lengths(10);
-std::cout << "Here is the histogram of barcode's length : " << std::endl;
-for (size_t i = 0; i != histogram.size(); ++i) {
-std::cout << histogram[i] << " ";
-}
-std::cout << std::endl;
-
-std::vector<size_t> cumulative_histogram = p.cumulative_histogram_of_lengths(10);
-std::cout << "Cumulative histogram : " << std::endl;
-for (size_t i = 0; i != cumulative_histogram.size(); ++i) {
-std::cout << cumulative_histogram[i] << " ";
-}
-std::cout << std::endl;
-
-std::vector<double> char_funct_diag = p.characteristic_function_of_diagram(min_max_.first, min_max_.second);
-std::cout << "Characteristic function of diagram : " << std::endl;
-for (size_t i = 0; i != char_funct_diag.size(); ++i) {
-std::cout << char_funct_diag[i] << " ";
-}
-std::cout << std::endl;
-
-std::vector<double> cumul_char_funct_diag =
- p.cumulative_characteristic_function_of_diagram(min_max_.first, min_max_.second);
-std::cout << "Cumulative characteristic function of diagram : " << std::endl;
-for (size_t i = 0; i != cumul_char_funct_diag.size(); ++i) {
-std::cout << cumul_char_funct_diag[i] << " ";
-}
-std::cout << std::endl;
-
-std::cout << "Persistence Betti numbers \n";
-std::vector<std::pair<double, size_t> > pbns = p.compute_persistent_betti_numbers();
-for (size_t i = 0; i != pbns.size(); ++i) {
-std::cout << pbns[i].first << " " << pbns[i].second << std::endl;
-}
-"""
+print "Birth-death range : ", min_max_
+
+dominant_ten_intervals_length = p.length_of_dominant_intervals(10)
+print "Length of ten dominant intervals : ", dominant_ten_intervals_length
+
+ten_dominant_intervals = p.dominant_intervals(10);
+print "Here are the dominant intervals : " , ten_dominant_intervals
+
+histogram = p.histogram_of_lengths(10);
+print "Here is the histogram of barcode's length : ", histogram
+
+cumulative_histogram = p.cumulative_histogram_of_lengths(10)
+print "Cumulative histogram : " ,cumulative_histogram
+
+char_funct_diag = p.characteristic_function_of_diagram(min_max_[0], min_max_[1],None)
+print "Characteristic function of diagram : ",char_funct_diag
+
+cumul_char_funct_diag = p.cumulative_characteristic_function_of_diagram(min_max_[0], min_max_[1],None)
+print "Cumulative characteristic function of diagram : ",cumul_char_funct_diag
+
+pbns = p.compute_persistent_betti_numbers()
+print "Persistence Betti numbers ", pbns
diff --git a/src/cython/include/persistence_representations_intervals.h b/src/cython/include/persistence_representations_intervals.h
index eb440f1a..a4ad0e0f 100644
--- a/src/cython/include/persistence_representations_intervals.h
+++ b/src/cython/include/persistence_representations_intervals.h
@@ -43,6 +43,7 @@ class Persistence_intervals_interface : public Persistence_intervals
public:
Persistence_intervals_interface(const char* filename, unsigned dimension = std::numeric_limits<unsigned>::max())
: Persistence_intervals(filename, dimension) {
+ std::cout << "CONTSTRUCTOR \n";
}
Persistence_intervals_interface(const std::vector<std::pair<double, double> >& intervals)
@@ -51,7 +52,9 @@ class Persistence_intervals_interface : public Persistence_intervals
std::pair<double, double> get_x_range_interface() const
{
- return this->get_x_range();
+ std::pair<double, double> range = this->get_x_range();
+ std::cout << std::endl << std::endl << range.first << " " << range.second << std::endl << std::endl <<std::endl;
+ return range;
}
std::pair<double, double> get_y_range_interface() const
diff --git a/src/cython/test/test_persistence_representations_diagrams.py b/src/cython/test/test_persistence_representations_diagrams.py
new file mode 100755
index 00000000..5be95a68
--- /dev/null
+++ b/src/cython/test/test_persistence_representations_diagrams.py
@@ -0,0 +1,87 @@
+import gudhi
+
+"""This file is part of the Gudhi Library. The Gudhi library
+ (Geometric Understanding in Higher Dimensions) is a generic C++
+ library for computational topology.
+
+ Author(s): Pawel Dlotko
+
+ Copyright (C) 2017 Swansea University
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+"""
+
+__author__ = "Pawel Dlotko"
+__copyright__ = "Copyright (C) 2017 Swansea University"
+__license__ = "GPL v3"
+
+epsilon = 0.0000005;
+
+def test_check_min_max_function():
+ p = gudhi.PersistenceDiagrams(None,None,"data/file_with_diagram")
+ min_max_ = p.get_x_range()
+ assert fabs(min_max_[0] - 0.0290362) <= epsilon
+ assert fabs(min_max_[1] - 0.994537) <= epsilon
+
+def test_check_length_of_dominant_intervals():
+ p = gudhi.PersistenceDiagrams(None,None,"data/file_with_diagram")
+ dominant_ten_intervals_length = p.length_of_dominant_intervals(10)
+ dominant_intervals_length_ = [0.862625,0.800893,0.762061,0.756501,0.729367,0.718177,0.708395,0.702844,0.700468,0.622177]
+ assert dominant_ten_intervals_length == dominant_intervals_length_
+
+
+def check_dominant_intervals():
+ p = gudhi.PersistenceDiagrams(None,None,"data/file_with_diagram");
+ ten_dominant_intervals = p.dominant_intervals(10);
+ templ = [ (0.114718, 0.977343) , (0.133638, 0.93453) , (0.104599, 0.866659) , (0.149798, 0.906299), (0.247352, 0.976719) , (0.192675, 0.910852) , (0.191836, 0.900231) , (0.284998, 0.987842) , (0.294069, 0.994537), (0.267421, 0.889597)]
+ assert fabs(ten_dominant_intervals - templ) <= epsilon
+
+
+def check_histogram_of_lengths():
+ p = gudhi.PersistenceDiagrams(None,None,"data/file_with_diagram")
+ histogram = p.histogram_of_lengths(10);
+ template_histogram = [10,5,3,4,4,3,6,1,7,1,1]
+ assert fabs(histogram - template_histogram) <= epsilon
+
+
+def check_cumulative_histograms_of_lengths():
+ p = gudhi.PersistenceDiagrams(None,None,"data/file_with_diagram")
+ cumulative_histogram = p.cumulative_histogram_of_lengths(10)
+ template_cumulative_histogram = [10,15,18,22,26,29,35,36,43,44,45]
+ assert fabs(cumulative_histogram - template_cumulative_histogram) <= epsilon
+
+
+def check_characteristic_function_of_diagram():
+ p = gudhi.PersistenceDiagrams(None,None,"data/file_with_diagram")
+ min_max_ = p.get_x_range();
+ char_funct_diag = p.characteristic_function_of_diagram(min_max_[0], min_max_[1]);
+ template_char_funct_diag = [0.370665,0.84058,1.24649,1.3664,1.34032,1.31904,1.14076,0.991259,0.800714,0.0676303]
+ assert fabs(char_funct_diag - template_char_funct_diag) <= 0.0001
+
+
+def check_cumulative_characteristic_function_of_diagram():
+ p = gudhi.PersistenceDiagrams(None,None,"data/file_with_diagram")
+ min_max_ = p.get_x_range()
+ cumul_char_funct_diag = p.cumulative_characteristic_function_of_diagram(min_max_.first, min_max_.second,None);
+ template_char_funct_diag_cumul = [0.370665,1.21125,2.45774,3.82414,5.16446,6.4835,7.62426,8.61552,9.41623,9.48386]
+ assert fabs(cumul_char_funct_diag - template_char_funct_diag_cumul) <= 0.0001
+
+
+def check_compute_persistent_betti_numbers():
+ p = gudhi.PersistenceDiagrams(None,None,"data/file_with_diagram")
+ pbns = [(0.0290362, 1),(0.0307676, 2),(0.0366312, 3),(0.0544614, 4),(0.0920033, 5),(0.104599, 6),(0.114718, 7),(0.117379, 8),(0.123493, 9),(0.133638, 10)(0.137798, 9),(0.149798, 10),(0.155421, 11),(0.158443, 12)(0.176956, 13),(0.183234, 12),(0.191069, 13),(0.191333, 14),(0.191836, 15),(0.192675, 16),(0.208564, 17),(0.218425, 18),(0.219902, 17),(0.23233, 16),(0.234558, 17),(0.237166, 16),(0.247352, 17),(0.267421, 18),(0.268093, 19),(0.278734, 18),(0.284722, 19),(0.284998, 20),(0.294069, 21),(0.306293, 22),(0.322361, 21),(0.323152, 22),(0.371021, 23),(0.372395, 24),(0.387744, 25),(0.435537, 26),(0.462911, 25),(0.483569, 26),(0.489209, 25),(0.517115, 24),(0.522197, 23),(0.532665, 22),(0.545262, 23),(0.587227, 22),(0.593036, 23),(0.602647, 24),(0.605044, 25),(0.621962, 24),(0.629449, 23),(0.636719, 22),(0.64957, 21),(0.650781, 22),(0.654951, 23),(0.683489, 24),(0.687172, 23),(0.69703, 22),(0.701174, 21),(0.717623, 22),(0.722023, 21),(0.722298, 20),(0.725347, 19),(0.73071, 18),(0.758355, 17),(0.770913, 18),(0.790833, 17),(0.821211, 16),(0.849305, 17),(0.853669, 16),(0.866659, 15),(0.872896, 16),(0.889597, 15),(0.900231, 14),(0.903847, 13),(0.906299, 12),(0.910852, 11),(0.93453, 10),(0.944757, 9),(0.947812, 8),(0.959154, 7),(0.975654, 6),(0.976719, 5),(0.977343, 4),(0.980129, 3),(0.987842, 2),(0.990127, 1),(0.994537, 0)]
+ pbns_new = p.compute_persistent_betti_numbers();
+ assert fabs(pbns - pbns_new) <= epsilon
+
+