summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpdlotko <pdlotko@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2017-09-05 05:56:25 +0000
committerpdlotko <pdlotko@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2017-09-05 05:56:25 +0000
commit9b61e1e8fef5e596abe2775203650715534e8a97 (patch)
tree2b6ea202c472543e6132a7bc24c9e44f314b5355
parent214610a9ac8eff11d6a075a3f54e1d040679b57d (diff)
Some further progress on persistence representation's cytonization.
git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/persistence_representation_integration@2643 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 84b4ea7319daf120a82894d80d386f92ec4c91d0
-rw-r--r--src/Persistence_representations/include/gudhi/Persistence_landscape.h54
-rw-r--r--src/cython/cython/persistence_representations_landscapes.pyx53
-rwxr-xr-xsrc/cython/example/persistence_representations_diagrams_example.py2
-rwxr-xr-xsrc/cython/example/persistence_representations_landscapes_example.py77
-rw-r--r--src/cython/include/Persistence_landscape_interface.h25
-rwxr-xr-xsrc/cython/test/test_persistence_representations_intervals.py12
-rwxr-xr-xsrc/cython/test/test_persistence_representations_landscapes.py139
7 files changed, 332 insertions, 30 deletions
diff --git a/src/Persistence_representations/include/gudhi/Persistence_landscape.h b/src/Persistence_representations/include/gudhi/Persistence_landscape.h
index 63e45bc9..5c300112 100644
--- a/src/Persistence_representations/include/gudhi/Persistence_landscape.h
+++ b/src/Persistence_representations/include/gudhi/Persistence_landscape.h
@@ -285,6 +285,8 @@ class Persistence_landscape {
*distance, we need to take its absolute value. This is the purpose of this procedure.
**/
Persistence_landscape abs();
+
+ Persistence_landscape* new_abs();
/**
* Computes the number of landscape functions.
@@ -855,6 +857,58 @@ Persistence_landscape Persistence_landscape::abs() {
return result;
}
+
+Persistence_landscape* Persistence_landscape::new_abs()
+{
+ Persistence_landscape* result = new Persistence_landscape(*this);
+ for (size_t level = 0; level != this->land.size(); ++level)
+ {
+ if (AbsDbg)
+ {
+ std::cout << "level: " << level << std::endl;
+ }
+ std::vector<std::pair<double, double> > lambda_n;
+ lambda_n.push_back(std::make_pair(-std::numeric_limits<int>::max(), 0));
+ for (size_t i = 1; i != this->land[level].size(); ++i)
+ {
+ if (AbsDbg)
+ {
+ std::cout << "this->land[" << level << "][" << i << "] : " << this->land[level][i].first << " "
+ << this->land[level][i].second << std::endl;
+ }
+ // if a line segment between this->land[level][i-1] and this->land[level][i] crosses the x-axis, then we have to
+ // add one landscape point t o result
+ if ((this->land[level][i - 1].second) * (this->land[level][i].second) < 0) {
+ double zero =
+ find_zero_of_a_line_segment_between_those_two_points(this->land[level][i - 1], this->land[level][i]);
+
+ lambda_n.push_back(std::make_pair(zero, 0));
+ lambda_n.push_back(std::make_pair(this->land[level][i].first, fabs(this->land[level][i].second)));
+ if (AbsDbg)
+ {
+ std::cout << "Adding pair : (" << zero << ",0)" << std::endl;
+ std::cout << "In the same step adding pair : (" << this->land[level][i].first << ","
+ << fabs(this->land[level][i].second) << ") " << std::endl;
+ std::cin.ignore();
+ }
+ }
+ else
+ {
+ lambda_n.push_back(std::make_pair(this->land[level][i].first, fabs(this->land[level][i].second)));
+ if (AbsDbg)
+ {
+ std::cout << "Adding pair : (" << this->land[level][i].first << "," << fabs(this->land[level][i].second)
+ << ") " << std::endl;
+ std::cin.ignore();
+ }
+ }
+ }
+ result->land.push_back(lambda_n);
+ }
+ return result;
+}
+
+
Persistence_landscape Persistence_landscape::multiply_lanscape_by_real_number_not_overwrite(double x) const {
std::vector<std::vector<std::pair<double, double> > > result(this->land.size());
for (size_t dim = 0; dim != this->land.size(); ++dim) {
diff --git a/src/cython/cython/persistence_representations_landscapes.pyx b/src/cython/cython/persistence_representations_landscapes.pyx
index a978574a..464f538b 100644
--- a/src/cython/cython/persistence_representations_landscapes.pyx
+++ b/src/cython/cython/persistence_representations_landscapes.pyx
@@ -2,6 +2,7 @@ from cython cimport numeric
from libcpp.vector cimport vector
from libcpp.utility cimport pair
from libcpp cimport bool
+from cython.operator cimport dereference as deref
import os
import sys
@@ -47,14 +48,15 @@ cdef extern from "Persistence_landscape_interface.h" namespace "Gudhi::Persisten
double compute_maximum()const
double compute_minimum()const
double compute_norm_of_landscape(double)
- Persistence_landscape_interface abs()
+ Persistence_landscape_interface* new_abs_interface()
size_t size()const
- double find_max_(unsigned)const
+ double find_max(unsigned)const
double project_to_R(int)const
size_t number_of_projections_to_R()const
vector[double] vectorize(int)const
- size_t number_of_vectorize_function()const
+ size_t number_of_vectorize_functions()const
void compute_average(const vector[Persistence_landscape_interface*]&)
+ void new_compute_average(const vector[Persistence_landscape_interface*]&)
double distance(const Persistence_landscape_interface&, double)
double compute_scalar_product(const Persistence_landscape_interface&)const
pair[double, double] get_y_range(size_t)const
@@ -62,17 +64,16 @@ cdef extern from "Persistence_landscape_interface.h" namespace "Gudhi::Persisten
-
#convention for python class is PersistenceIntervals instead of Persistence_intervals
#for methods it is def num_simplices(self).
cdef class PersistenceLandscapes:
- cdef Persistence_landscape_interface * thisptr
+ cdef Persistence_landscape_interface* thisptr
#Can we have only one constructor, or can we have more
- def __init__(self, vector_of_intervals=None, dimension = None, file_with_intervals=''):
+ def __init__(self):
"""
This is a class implementing persistence landscapes data structures.
For theoretical description, please consult <i>Statistical topological
@@ -92,6 +93,7 @@ cdef class PersistenceLandscapes:
considered the same. If the scale in your persistence diagrams is
comparable to this value, please rescale them before use this code.
"""
+
def __cinit__(self, vector_of_intervals=None, dimension=None, file_with_intervals='',number_of_levels=sys.maxint):
@@ -100,7 +102,7 @@ cdef class PersistenceLandscapes:
It either take text file and a positive integer, or a vector
of pairs. The last optional parameter is the nunmer of levels of
the landscapes to be generated. If not set, all the levels will
- be generated. In case of file, each line of the input file is
+ be generated. In case of file, each line of the input file is,
supposed to contain two numbers of a type double
(or convertible to double) representing the birth and the death
of the persistence interval. If the pairs are not sorted so that
@@ -226,7 +228,7 @@ cdef class PersistenceLandscapes:
:param i
"""
if ( self.thisptr != NULL ) and ( i is not None ):
- return self.thisptr.compute_norm_of_landscape(i)
+ return self.thisptr.compute_norm_of_landscape(i)
def abs( self ):
"""
@@ -240,7 +242,10 @@ cdef class PersistenceLandscapes:
this procedure.
"""
if ( self.thisptr != NULL ):
- return self.thisptr.abs()
+ abs_ = PersistenceLandscapes()
+ abs_.thisptr = self.thisptr.new_abs_interface()
+ return abs_
+
def size( self ):
"""
@@ -249,14 +254,14 @@ cdef class PersistenceLandscapes:
if ( self.thisptr != NULL ):
return self.thisptr.size()
- def find_max_(self, lambda_):
+ def find_max(self, lambda_):
"""
Compute maximal value of lambda-level landscape.
:param level of landscape
:type nonnegative integer
"""
if ( self.thisptr != NULL ) and ( lambda_ is not None ):
- return self.thisptr.find_max_(lambda_)
+ return self.thisptr.find_max(lambda_)
def project_to_R(self, number_of_function):
"""
@@ -294,7 +299,7 @@ cdef class PersistenceLandscapes:
if ( self.thisptr != NULL ) and ( number_of_function is not None ):
return self.thisptr.vectorize(number_of_function)
- def number_of_vectorize_function(self):
+ def number_of_vectorize_functions(self):
"""
The number of projections to R is defined to the number of nonzero
landscape functions. I-th projection is an
@@ -306,21 +311,25 @@ cdef class PersistenceLandscapes:
will be most likely changed in the next versions
"""
if ( self.thisptr != NULL ):
- return self.thisptr.number_of_vectorize_function()
+ return self.thisptr.number_of_vectorize_functions()
- def compute_average(self,to_average):
+ def compute_average( self,to_average=[] ):
"""
A function to compute averaged persistence landscape, based on vector
of persistence landscapes.
This function is required by Topological_data_with_averages concept.
:param vector of persistence landscapes to average
:type vectors of references to persistence landscapes
- """
- if ( self.thisptr != NULL ) and ( to_average is not None ):
- return self.thisptr.compute_average(to_average)
+ """
+ cdef vector[Persistence_landscape_interface*] cpp_list
+ if ( self.thisptr != NULL ) and ( to_average is not None ):
+ for elt in to_average:
+ cpp_list.push_back((<PersistenceLandscapes>elt).thisptr)
+ self.thisptr.new_compute_average( cpp_list )
+
- def distance(self, second, power):
+ def distance(self, PersistenceLandscapes second, power):
"""
A function to compute distance between persistence landscape.
The parameter of this function is a Persistence_landscape.
@@ -330,9 +339,9 @@ cdef class PersistenceLandscapes:
:type PersistenceLandscape
"""
if ( self.thisptr != NULL ) and ( second is not None ) and ( power is not None ):
- return self.thisptr.distance(second, power)
+ return self.thisptr.distance( deref(second.thisptr), power)
- def compute_scalar_product(self, second):
+ def compute_scalar_product(self, PersistenceLandscapes second):
"""
A function to compute scalar product of persistence landscapes.
The parameter of this function is a Persistence_landscape.
@@ -341,7 +350,7 @@ cdef class PersistenceLandscapes:
:type PersistenceLandscape
"""
if ( self.thisptr != NULL ) and ( second is not None ):
- return self.thisptr.compute_scalar_product(second)
+ return self.thisptr.compute_scalar_product( deref(second.thisptr) )
def get_y_range(self, level):
"""
@@ -352,6 +361,6 @@ cdef class PersistenceLandscapes:
:param The level of lrandscape
:type nonnegative integer
"""
- if ( self.thisptr != NULL ) and ( second is not None ):
+ if ( self.thisptr != NULL ):
return self.thisptr.get_y_range(level)
diff --git a/src/cython/example/persistence_representations_diagrams_example.py b/src/cython/example/persistence_representations_diagrams_example.py
index 04651ba5..bd7452a0 100755
--- a/src/cython/example/persistence_representations_diagrams_example.py
+++ b/src/cython/example/persistence_representations_diagrams_example.py
@@ -33,7 +33,7 @@ print("#####################################################################")
print("Persistence representations diagrams example")
-parser = argparse.ArgumentParser(description='Statistics od persistence diagrams from file ',
+parser = argparse.ArgumentParser(description='Statistics of persistence diagrams from file ',
epilog='Example: '
'example/persistence_representations_diagrams_example.py '
'-f file_with_diagram -d 1')
diff --git a/src/cython/example/persistence_representations_landscapes_example.py b/src/cython/example/persistence_representations_landscapes_example.py
new file mode 100755
index 00000000..d2b7b393
--- /dev/null
+++ b/src/cython/example/persistence_representations_landscapes_example.py
@@ -0,0 +1,77 @@
+#!/usr/bin/env python
+
+import gudhi
+from libcpp.vector cimport vector
+from libcpp.utility cimport pair
+
+
+"""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"
+
+print("#####################################################################")
+print("Persistence representations landscapes example")
+
+persistence1 = vector[pair[double, double]]
+persistence2 = vector[pair[double, double]]
+
+persistence1.push_back(make_pair(1, 2))
+persistence1.push_back(make_pair(6, 8))
+persistence1.push_back(make_pair(0, 4))
+persistence1.push_back(make_pair(3, 8))
+
+persistence2.push_back(make_pair(2, 9))
+persistence2.push_back(make_pair(1, 6))
+persistence2.push_back(make_pair(3, 5))
+persistence2.push_back(make_pair(6, 10))
+
+#create two persistence landscapes based on persistence1 and persistence2:
+l1 = gudhi.Persistence_landscape(persistence1)
+l2 = gudhi.Persistence_landscape(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()
+
+#Arithmetic operations on landscapes:
+sum_ = l1 + l2;
+
+#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 = Persistence_landscape
+average.compute_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)
diff --git a/src/cython/include/Persistence_landscape_interface.h b/src/cython/include/Persistence_landscape_interface.h
index acf9aec4..e18a678e 100644
--- a/src/cython/include/Persistence_landscape_interface.h
+++ b/src/cython/include/Persistence_landscape_interface.h
@@ -36,8 +36,29 @@ class Persistence_landscape_interface : public Persistence_landscape
Persistence_landscape_interface(const std::vector<std::pair<double, double> >& p, size_t number_of_levels = std::numeric_limits<size_t>::max() ):Persistence_landscape(p,number_of_levels){}
-
Persistence_landscape_interface(const char* filename, size_t dimension = std::numeric_limits<unsigned>::max() , size_t number_of_levels = std::numeric_limits<size_t>::max() ):Persistence_landscape(filename,dimension,number_of_levels){}
+
+ Persistence_landscape_interface* copy()
+ {
+ Persistence_landscape_interface* copy = new Persistence_landscape_interface(*this);
+ return copy;
+ }
+
+ Persistence_landscape_interface* new_abs_interface()
+ {
+ return (Persistence_landscape_interface*)this->new_abs();
+ }
+
+ void new_compute_average(const std::vector<Persistence_landscape_interface*>& to_average)
+ {
+ std::vector<Persistence_landscape*> to_average_new;
+ to_average_new.reserve( to_average.size() );
+ for ( size_t i = 0 ; i != to_average.size() ; ++i )
+ {
+ to_average_new.push_back( (Persistence_landscape*)to_average[i] );
+ }
+ this->compute_average(to_average_new);
+ }
/*
void load_landscape_from_file_interface(const char* filename)
@@ -88,6 +109,7 @@ class Persistence_landscape_interface : public Persistence_landscape
}
+
double compute_norm_of_landscape_interface(double i)
{
return this->compute_norm_of_landscape(i);
@@ -161,6 +183,7 @@ class Persistence_landscape_interface : public Persistence_landscape
return this->get_y_range( level );
}
*/
+};
} // namespace Persistence_representations
} // namespace Gudhi
diff --git a/src/cython/test/test_persistence_representations_intervals.py b/src/cython/test/test_persistence_representations_intervals.py
index 794cf49d..a8f3686e 100755
--- a/src/cython/test/test_persistence_representations_intervals.py
+++ b/src/cython/test/test_persistence_representations_intervals.py
@@ -41,28 +41,28 @@ def test_check_length_of_dominant_intervals():
assert dominant_ten_intervals_length == dominant_intervals_length_
-def check_dominant_intervals():
+def test_check_dominant_intervals():
p = gudhi.PersistenceIntervals(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():
+def test_check_histogram_of_lengths():
p = gudhi.PersistenceIntervals(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():
+def test_check_cumulative_histograms_of_lengths():
p = gudhi.PersistenceIntervals(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():
+def test_check_characteristic_function_of_diagram():
p = gudhi.PersistenceIntervals(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]);
@@ -70,7 +70,7 @@ def check_characteristic_function_of_diagram():
assert fabs(char_funct_diag - template_char_funct_diag) <= 0.0001
-def check_cumulative_characteristic_function_of_diagram():
+def test_check_cumulative_characteristic_function_of_diagram():
p = gudhi.PersistenceIntervals(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);
@@ -78,7 +78,7 @@ def check_cumulative_characteristic_function_of_diagram():
assert fabs(cumul_char_funct_diag - template_char_funct_diag_cumul) <= 0.0001
-def check_compute_persistent_betti_numbers():
+def test_check_compute_persistent_betti_numbers():
p = gudhi.PersistenceIntervals(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();
diff --git a/src/cython/test/test_persistence_representations_landscapes.py b/src/cython/test/test_persistence_representations_landscapes.py
new file mode 100755
index 00000000..bf099f0f
--- /dev/null
+++ b/src/cython/test/test_persistence_representations_landscapes.py
@@ -0,0 +1,139 @@
+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_construction_of_landscape():
+ p = gudhi.Persistence_landscape("data/file_with_diagram",0)
+ 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.load_landscape_from_file("data/persistence_file_with_four_entries_per_line_landscape");
+ assert p == q;
+
+def test_check_computations_of_integrals():
+ p = gudhi.Persistence_landscape("data/file_with_diagram",0)
+ integral = p.compute_integral_of_landscape()
+ assert fabs(integral - 2.34992) <= 0.00001
+
+
+def test_check_computations_of_integrals_for_each_level_separatelly():
+ diag = read_persistence_intervals_in_one_dimension_from_file("data/file_with_diagram");
+ p = gudhi.Persistence_landscape(diag)
+ integrals_for_different_levels = [0.216432,0.204763,0.188793,0.178856,0.163142,0.155015,0.143046,0.133765,0.123531,0.117393,0.111269,0.104283,0.0941308,0.0811208,0.0679001,0.0580801,0.0489647,0.0407936,0.0342599,0.02896,0.0239881,0.0171792,0.0071511,0.00462067,0.00229033,0.000195296]
+ for lv in range(0, len(integrals_for_different_levels)):
+ integral = p.compute_integral_of_a_level_of_a_landscape(lv);
+ assert fabs(integral - integrals_fir_different_levels[lv]) <= 0.00001
+
+def test_check_computations_of_integrals_of_powers_of_landscape():
+ diag = read_persistence_intervals_in_one_dimension_from_file("data/file_with_diagram")
+ p = gudhi.Persistence_landscape(diag)
+ integrals_fir_different_powers = [17.1692,2.34992,0.49857,0.126405,0.0355235]
+ for power in range(0,5):
+ integral = p.compute_integral_of_landscape(power)
+ assert fabs(integral - integrals_fir_different_powers[power]) <= 0.00005
+
+
+def test_check_computations_of_values_on_different_points():
+ diag = read_persistence_intervals_in_one_dimension_from_file("data/file_with_diagram")
+ p = gudhi.Persistence_landscape(diag);
+ assert fabs(p.compute_value_at_a_given_point(1, 0.0)) <= 0.00001
+ assert fabs(p.compute_value_at_a_given_point(1, 0.1) - 0.0692324) <= 0.00001
+ assert fabs(p.compute_value_at_a_given_point(1, 0.2) - 0.163369) <= 0.00001
+ assert fabs(p.compute_value_at_a_given_point(1, 0.3) - 0.217115) <= 0.00001
+ assert fabs(p.compute_value_at_a_given_point(2, 0.0)) <= 0.00001
+ assert fabs(p.compute_value_at_a_given_point(2, 0.1) - 0.0633688) <= 0.00001
+ assert fabs(p.compute_value_at_a_given_point(2, 0.2) - 0.122361) <= 0.00001
+ assert fabs(p.compute_value_at_a_given_point(2, 0.3) - 0.195401) <= 0.00001
+ assert fabs(p.compute_value_at_a_given_point(3, 0.0)) <= 0.00001
+ assert fabs(p.compute_value_at_a_given_point(3, 0.1) - 0.0455386) <= 0.00001
+ assert fabs(p.compute_value_at_a_given_point(3, 0.2) - 0.0954012) <= 0.00001
+ assert fabs(p.compute_value_at_a_given_point(3, 0.3) - 0.185282) <= 0.00001
+
+
+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.load_landscape_from_file("data/file_with_landscape_from_file_with_diagram_1")
+ sum_ = gudhi.Persistence_landscape()
+ sum_ = p + second;
+ assert fabs(p.compute_maximum() - 0.431313) <= 0.00001
+ assert fabs(p.compute_norm_of_landscape(1) - 2.34992) <= 0.00001
+ assert fabs(p.compute_norm_of_landscape(2) - 0.706095) <= 0.00001
+ assert fabs(p.compute_norm_of_landscape(3) - 0.501867) <= 0.00001
+ assert fabs(compute_distance_of_landscapes(p, sum_, 1) - 27.9323) <= 0.00005
+ assert fabs(compute_distance_of_landscapes(p, sum_, 2) - 2.35199) <= 0.00001
+
+
+
+def test_check_default_parameters_of_distances():
+ diag = read_persistence_intervals_in_one_dimension_from_file("data/file_with_diagram")
+ p = gudhi.Persistence_landscape(diag)
+ diag1 = read_persistence_intervals_in_one_dimension_from_file("data/file_with_diagram_1")
+ q = gudhi.Persistence_landscape(diag1)
+ dist_numeric_limit_max = p.distance(q, sys.float_info.max);
+ dist_infinity = p.distance(q, sys.float_info.max);
+ assert dist_numeric_limit_max == dist_infinity
+
+
+def test_check_computations_of_averages():
+ diag = read_persistence_intervals_in_one_dimension_from_file("data/file_with_diagram")
+ 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.compute_average({p, q})
+ template_average = Persistence_landscape
+ template_averagetemplate_average.load_landscape_from_file("data/average")
+ assert template_average == av
+
+
+def test_check_computations_of_distances():
+ diag = read_persistence_intervals_in_one_dimension_from_file("data/file_with_diagram")
+ p = gudhi.Persistence_landscape(diag)
+ diag2 = read_persistence_intervals_in_one_dimension_from_file("data/file_with_diagram_1")
+ q = Persistence_landscape(diag2)
+ assert fabs(p.distance(q) - 25.5824) <= 0.00005
+ assert fabs(p.distance(q, 2) - 2.12636) <= 0.00001
+ assert fabs(p.distance(q, sys.float_info.max) - 0.359068) <= 0.00001
+
+
+def test_check_computations_of_scalar_product():
+ diag = read_persistence_intervals_in_one_dimension_from_file("data/file_with_diagram")
+ p = gudhi.Persistence_landscape(diag)
+ diag2 = read_persistence_intervals_in_one_dimension_from_file("data/file_with_diagram_1")
+ q = Persistence_landscape(diag2)
+ assert fabs(p.compute_scalar_product(q) - 0.754498) <= 0.00001
+