From b6ee08d1c2f56f2701090fa7486a14bca651be78 Mon Sep 17 00:00:00 2001 From: pdlotko Date: Wed, 6 Sep 2017 14:27:54 +0000 Subject: Another time when I hit the problem with compilation, and fail to solve it... git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/persistence_representation_integration@2647 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: e6a0101ab3bd96031dd9fa23e8db629f65820271 --- .../persistence_representations_intervals.pyx | 3 +- .../persistence_representations_landscapes.pyx | 4 +- ...rsistence_representations_landscapes_example.py | 6 +- ...e_representations_landscapes_on_grid_example.py | 110 +++++++++++++++++++++ src/cython/gudhi.pyx.in | 1 + .../test_persistence_representations_landscapes.py | 10 +- ...rsistence_representations_landscapes_on_grid.py | 10 +- 7 files changed, 128 insertions(+), 16 deletions(-) create mode 100755 src/cython/example/persistence_representations_landscapes_on_grid_example.py (limited to 'src') diff --git a/src/cython/cython/persistence_representations_intervals.pyx b/src/cython/cython/persistence_representations_intervals.pyx index 42370870..c1cc347d 100644 --- a/src/cython/cython/persistence_representations_intervals.pyx +++ b/src/cython/cython/persistence_representations_intervals.pyx @@ -259,8 +259,7 @@ cdef class PersistenceIntervals: return self.thisptr.cumulative_characteristic_function_of_diagram(x_min, x_max, number_of_bins) else: if (self.thisptr != NULL) and (x_min is not None) and (x_max is not None): - return - self.thisptr.cumulative_characteristic_function_of_diagram(x_min, x_max, 10) + return self.thisptr.cumulative_characteristic_function_of_diagram(x_min, x_max, 10) def compute_persistent_betti_numbers(self): """ diff --git a/src/cython/cython/persistence_representations_landscapes.pyx b/src/cython/cython/persistence_representations_landscapes.pyx index 9c3c2863..035c7d58 100644 --- a/src/cython/cython/persistence_representations_landscapes.pyx +++ b/src/cython/cython/persistence_representations_landscapes.pyx @@ -133,7 +133,8 @@ cdef class PersistenceLandscapes: self.thisptr = new Persistence_landscape_interface(vector_of_intervals, number_of_levels) else: print("Persistence interals can be constructed from vector of birth-death pairs, vector_of_intervals or a Gudhi-style file.") - + self.thisptr = new Persistence_landscape_interface() + def __dealloc__(self): """ destructor @@ -321,6 +322,7 @@ cdef class PersistenceLandscapes: :param vector of persistence landscapes to average :type vectors of references to persistence landscapes """ + #TODO -- add a check if all objects in the to_average are of the same type. cdef vector[Persistence_landscape_interface*] cpp_list if ( self.thisptr != NULL ) and ( to_average is not None ): for elt in to_average: diff --git a/src/cython/example/persistence_representations_landscapes_example.py b/src/cython/example/persistence_representations_landscapes_example.py index b7e47c0b..94b68225 100755 --- a/src/cython/example/persistence_representations_landscapes_example.py +++ b/src/cython/example/persistence_representations_landscapes_example.py @@ -53,11 +53,11 @@ print "L^1 Norm of l1 : ", l1.compute_norm_of_landscape(1.) print "L^1 Norm of l2 : ", l2.compute_norm_of_landscape(1.) #here is the average of landscapes: -average = gudhi.PersistenceLandscapes -average.compute_average([l1, l2]) +average = gudhi.PersistenceLandscapes() +average.compute_average(to_average=[l1, l2]) #here is the distance of landscapes: -print "Distance : ", l1.distance(l2) +print "Distance : ", l1.distance(average,1) #here is the scalar product of landscapes: print "Scalar product : ", l1.compute_scalar_product(l2) diff --git a/src/cython/example/persistence_representations_landscapes_on_grid_example.py b/src/cython/example/persistence_representations_landscapes_on_grid_example.py new file mode 100755 index 00000000..60b0e873 --- /dev/null +++ b/src/cython/example/persistence_representations_landscapes_on_grid_example.py @@ -0,0 +1,110 @@ +#!/usr/bin/env python + +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 . +""" + +__author__ = "Pawel Dlotko" +__copyright__ = "Copyright (C) 2017 Swansea University" +__license__ = "GPL v3" + +print("#####################################################################") +print("Persistence representations landscapes on a grid example") + +persistence1 = [(1, 2),(6, 8),(0, 4),(3, 8)] +persistence2 = [(2, 9),(1, 6),(3, 5),(6, 10)] + +#create two persistence landscapes based on persistence1 and persistence2: +l1 = PersistenceLandscapeOnGrid(persistence1, 0, 11, 20) +l2 = PersistenceLandscapeOnGrid(persistence2, 0, 11, 20) + +#This is how to compute integral of landscapes: +print "Integral of the first landscape : " , l1.compute_integral_of_landscape() +print "Integral of the second landscape : " , l2.compute_integral_of_landscape() + +#here are the maxima of the functions: +print "Maximum of l1 : " , l1.compute_maximum() +print "Maximum of l2 : " , l2.compute_maximum() + +#here are the norms of landscapes: +print "L^1 Norm of l1 : " , l1.compute_norm_of_landscape(1.) +print "L^1 Norm of l2 : " , l2.compute_norm_of_landscape(1.) + +#here is the average of landscapes: +average = PersistenceLandscapeOnGrid(); +average.compute_average(to_average=[l1, l2]); + + +#here is the distance of landscapes: +print "Distance : " , l1.distance(l2) + +#here is the scalar product of landscapes: +print "Scalar product : " , l1.compute_scalar_product(l2) + + + + + + + + + + + + + + + + + + +persistence1 = [(1,2),(6,8),(0,4),(3,8)] +persistence2 = [(2,9),(1,6),(3,5),(6,10)] + + +#create two persistence landscapes based on persistence1 and persistence2: +l1 = gudhi.PersistenceLandscapes(vector_of_intervals=persistence1, dimension=3) +l2 = gudhi.PersistenceLandscapes(vector_of_intervals=persistence2) + +#This is how to compute integral of landscapes: +print "Integral of the first landscape : ", l1.compute_integral_of_landscape() +print "Integral of the second landscape : ", l2.compute_integral_of_landscape() + +#here are the maxima of the functions: +print "Maximum of l1 : ", l1.compute_maximum() +print "Maximum of l2 : ", l2.compute_maximum() + +#here are the norms of landscapes: +print "L^1 Norm of l1 : ", l1.compute_norm_of_landscape(1.) +print "L^1 Norm of l2 : ", l2.compute_norm_of_landscape(1.) + +#here is the average of landscapes: +average = gudhi.PersistenceLandscapes() +average.compute_average(to_average=[l1, l2]) + +#here is the distance of landscapes: +print "Distance : ", l1.distance(average,1) + +#here is the scalar product of landscapes: +print "Scalar product : ", l1.compute_scalar_product(l2) diff --git a/src/cython/gudhi.pyx.in b/src/cython/gudhi.pyx.in index a6aa21aa..0fa226db 100644 --- a/src/cython/gudhi.pyx.in +++ b/src/cython/gudhi.pyx.in @@ -34,6 +34,7 @@ include "cython/witness_complex.pyx" include "cython/strong_witness_complex.pyx" include "cython/persistence_representations_intervals.pyx" include "cython/persistence_representations_landscapes.pyx" +include "cython/persistence_representations_landscapes_on_grid.pyx" @GUDHI_CYTHON_ALPHA_COMPLEX@ @GUDHI_CYTHON_EUCLIDEAN_WITNESS_COMPLEX@ @GUDHI_CYTHON_SUBSAMPLING@ diff --git a/src/cython/test/test_persistence_representations_landscapes.py b/src/cython/test/test_persistence_representations_landscapes.py index bf099f0f..f5e6f351 100755 --- a/src/cython/test/test_persistence_representations_landscapes.py +++ b/src/cython/test/test_persistence_representations_landscapes.py @@ -31,14 +31,14 @@ epsilon = 0.0000005; def test_check_construction_of_landscape(): p = gudhi.Persistence_landscape("data/file_with_diagram",0) - q = gudhi.Persistence_landscape + q = gudhi.Persistence_landscape() q.load_landscape_from_file("data/file_with_landscape_from_file_with_diagram") assert p == q def test_check_construction_of_landscape_form_gudhi_style_file(): p = gudhi.Persistence_landscape("data/persistence_file_with_four_entries_per_line", 1) - q = gudhi.Persistence_landscape + q = gudhi.Persistence_landscape() q.load_landscape_from_file("data/persistence_file_with_four_entries_per_line_landscape"); assert p == q; @@ -85,7 +85,7 @@ def test_check_computations_of_values_on_different_points(): def test_check_computations_of_maxima_and_norms(): diag = read_persistence_intervals_in_one_dimension_from_file("data/file_with_diagram") p = gudhi.Persistence_landscape(diag) - second = gudhi.Persistence_landscape + second = gudhi.Persistence_landscape() second.load_landscape_from_file("data/file_with_landscape_from_file_with_diagram_1") sum_ = gudhi.Persistence_landscape() sum_ = p + second; @@ -113,9 +113,9 @@ def test_check_computations_of_averages(): p = gudhi.Persistence_landscape(diag) diag2 = read_persistence_intervals_in_one_dimension_from_file("data/file_with_diagram_1") q = gudhi.Persistence_landscape(diag2) - av = gudhi.Persistence_landscape + av = gudhi.Persistence_landscape() av.compute_average({p, q}) - template_average = Persistence_landscape + template_average = Persistence_landscape() template_averagetemplate_average.load_landscape_from_file("data/average") assert template_average == av diff --git a/src/cython/test/test_persistence_representations_landscapes_on_grid.py b/src/cython/test/test_persistence_representations_landscapes_on_grid.py index c03b8312..7a1f2b49 100755 --- a/src/cython/test/test_persistence_representations_landscapes_on_grid.py +++ b/src/cython/test/test_persistence_representations_landscapes_on_grid.py @@ -34,15 +34,15 @@ epsilon = 0.0000005; def test_check_construction_of_landscape: l = gudhi.PersistenceLandscapeOnGrid("data/file_with_diagram_1", 100,sys.maxsize) l.print_to_file("landscape_from_file_with_diagram_1") - g = gudhi.PersistenceLandscapeOnGrid + g = gudhi.PersistenceLandscapeOnGrid() g.load_landscape_from_file("landscape_from_file_with_diagram_1") assert l == g def test_check_construction_of_landscape_using_only_ten_levels: number = 10 - gudhi.PersistenceLandscapeOnGrid l("data/file_with_diagram_1", 100, number) - gudhi.PersistenceLandscapeOnGrid g("data/file_with_diagram_1", 100, sys.maxsize) + l = gudhi.PersistenceLandscapeOnGrid("data/file_with_diagram_1", 100, number) + g = gudhi.PersistenceLandscapeOnGrid("data/file_with_diagram_1", 100, sys.maxsize) for level in range(0,number): v1 = l.vectorize(level) v2 = g.vectorize(level) @@ -98,10 +98,10 @@ def test_check_default_parameters_of_distances: def test_check_computations_of_averages: p = gudhi.PersistenceLandscapeOnGrid("data/file_with_diagram", 0., 1., 100) q = gudhi.PersistenceLandscapeOnGrid("data/file_with_diagram_1", 0., 1., 100) - av = gudhi.PersistenceLandscapeOnGrid + av = gudhi.PersistenceLandscapeOnGrid() av.compute_average({&p, &q) - template_average = gudhi.PersistenceLandscapeOnGrid + template_average = gudhi.PersistenceLandscapeOnGrid() template_average.load_landscape_from_file("data/average_on_a_grid") assert template_average == av -- cgit v1.2.3