summaryrefslogtreecommitdiff
path: root/src/Gudhi_stat/example
diff options
context:
space:
mode:
authorpdlotko <pdlotko@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2016-10-11 10:38:55 +0000
committerpdlotko <pdlotko@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2016-10-11 10:38:55 +0000
commit6775c536373f8288021cb20854cd06d40edf8f82 (patch)
tree278fb5b2087e844d31669e24bd8b11261e5e8d23 /src/Gudhi_stat/example
parent7a6ebbd6c26306bca806bbc8c08f74a13c63fca6 (diff)
adding better examples in /example folder.
git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/gudhi_stat@1691 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 78b3c03fdc58cebe5bfae75bf624ab982702d7dc
Diffstat (limited to 'src/Gudhi_stat/example')
-rw-r--r--src/Gudhi_stat/example/persistence_heat_maps.cpp78
-rw-r--r--src/Gudhi_stat/example/persistence_landscape.cpp72
-rw-r--r--src/Gudhi_stat/example/persistence_landscape_on_grid.cpp67
-rw-r--r--src/Gudhi_stat/example/vector_representation.cpp56
4 files changed, 233 insertions, 40 deletions
diff --git a/src/Gudhi_stat/example/persistence_heat_maps.cpp b/src/Gudhi_stat/example/persistence_heat_maps.cpp
index e336ab44..7f5580da 100644
--- a/src/Gudhi_stat/example/persistence_heat_maps.cpp
+++ b/src/Gudhi_stat/example/persistence_heat_maps.cpp
@@ -27,6 +27,7 @@
#include <gudhi/concretizations/Persistence_heat_maps.h>
#include <iostream>
+#include <vector>
@@ -40,13 +41,62 @@ using namespace std;
int main( int argc , char** argv )
-{
- //if ( argc != 2 )
- //{
- // cout << "To run this program, please provide the name of a file with persistence diagram \n";
- // return 1;
- //}
+{
+ //create two simple vectors with birth--death pairs:
+
+ std::vector< std::pair< double , double > > persistence1;
+ std::vector< std::pair< double , double > > persistence2;
+
+ persistence1.push_back( std::make_pair(1,2) );
+ persistence1.push_back( std::make_pair(6,8) );
+ persistence1.push_back( std::make_pair(0,4) );
+ persistence1.push_back( std::make_pair(3,8) );
+
+ persistence2.push_back( std::make_pair(2,9) );
+ persistence2.push_back( std::make_pair(1,6) );
+ persistence2.push_back( std::make_pair(3,5) );
+ persistence2.push_back( std::make_pair(6,10) );
+
+ //over here we define a function we sill put on a top on every birth--death pair in the persistence interval. It can be anything. Over here we will use standarg Gaussian
+ std::vector< std::vector<double> > filter = create_Gaussian_filter(5,1);
+
+ //creating two heat maps.
+ Persistence_heat_maps hm1( persistence1 , filter , constant_function, false , 20 , 0 , 11 );
+ Persistence_heat_maps hm2( persistence2 , filter , constant_function, false , 20 , 0 , 11 );
+
+ std::vector<Persistence_heat_maps*> vector_of_maps;
+ vector_of_maps.push_back( &hm1 );
+ vector_of_maps.push_back( &hm2 );
+
+ //compute median/mean of a vector of heat maps:
+ Persistence_heat_maps mean;
+ mean.compute_mean( vector_of_maps );
+ Persistence_heat_maps median;
+ median.compute_median( vector_of_maps );
+
+ //to compute L^1 disance between hm1 and hm2:
+ std::cout << "The L^1 distance is : " << hm1.distance( (Abs_Topological_data_with_distances*)(&hm2) , 1 ) << std::endl;
+
+ //to average of hm1 and hm2:
+ std::vector< Abs_Topological_data_with_averages* > to_average;
+ to_average.push_back( (Abs_Topological_data_with_averages*)(&hm1) );
+ to_average.push_back( (Abs_Topological_data_with_averages*)(&hm2) );
+ Persistence_heat_maps av;
+ av.compute_average( to_average );
+ //to compute scalar product of hm1 and hm2:
+ std::cout << "Scalar product is : " << hm1.compute_scalar_product( (Abs_Topological_data_with_scalar_product*)(&hm2) ) << std::endl;
+
+ return 0;
+}
+
+
+
+
+
+
+
+//Below I am storing the code used to generate tests for that functionality.
/*
std::vector< std::pair< double,double > > intervals;
intervals.push_back( std::make_pair(0.5,0.5) );
@@ -166,7 +216,7 @@ int main( int argc , char** argv )
*/
-
+/*
std::vector< std::vector<double> > filter = create_Gaussian_filter(30,1);
Persistence_heat_maps p( "file_with_diagram" , filter , constant_function, false , 1000 , 0 , 1 );
Persistence_heat_maps q( "file_with_diagram_1" , filter , constant_function, false , 1000 , 0 , 1 );
@@ -181,16 +231,4 @@ int main( int argc , char** argv )
percentage_of_active.print_to_file( "template_percentage_of_active_of_heat_maps" );
//percentage_of_active.plot( "template_percentage_of_active_of_heat_maps" );
-
-
-
-
- return 0;
-}
-
-
-
-
-
-
-
+*/
diff --git a/src/Gudhi_stat/example/persistence_landscape.cpp b/src/Gudhi_stat/example/persistence_landscape.cpp
index 3204148b..f5110153 100644
--- a/src/Gudhi_stat/example/persistence_landscape.cpp
+++ b/src/Gudhi_stat/example/persistence_landscape.cpp
@@ -34,9 +34,70 @@ using namespace Gudhi::Gudhi_stat;
int main( int argc , char** argv )
-{
-
- if ( argc != 2 )
+{
+ //create two simple vectors with birth--death pairs:
+
+ std::vector< std::pair< double , double > > persistence1;
+ std::vector< std::pair< double , double > > persistence2;
+
+ persistence1.push_back( std::make_pair(1,2) );
+ persistence1.push_back( std::make_pair(6,8) );
+ persistence1.push_back( std::make_pair(0,4) );
+ persistence1.push_back( std::make_pair(3,8) );
+
+ persistence2.push_back( std::make_pair(2,9) );
+ persistence2.push_back( std::make_pair(1,6) );
+ persistence2.push_back( std::make_pair(3,5) );
+ persistence2.push_back( std::make_pair(6,10) );
+
+ //create two persistence landscapes based on persistence1 and persistence2:
+ Persistence_landscape l1( persistence1 );
+ Persistence_landscape l2( persistence2 );
+
+ //This is how to compute integral of landscapes:
+ std::cout << "Integral of the first landscape : " << l1.compute_integral_of_landscape() << endl;
+ std::cout << "Integral of the second landscape : " << l2.compute_integral_of_landscape() << endl;
+
+ //And here how to write landscapes to stream:
+ std::cout << "l1 : " << l1 << std::endl;
+ std::cout << "l2 : " << l2 << std::endl;
+
+ //Arythmetic operations on landscapes:
+ Persistence_landscape sum = l1+l2;
+ std::cout << "sum : " << sum << std::endl;
+
+ //here are the maxima of the functions:
+ std::cout << "Maximum of l1 : " << l1.compute_maximum() << std::endl;
+ std::cout << "Maximum of l2 : " << l2.compute_maximum() << std::endl;
+
+ //here are the norms of landscapes:
+ std::cout << "L^1 Norm of l1 : " << l1.compute_norm_of_landscape( 1. ) << std::endl;
+ std::cout << "L^1 Norm of l2 : " << l2.compute_norm_of_landscape( 1. ) << std::endl;
+
+ //here is the average of landscapes:
+ Persistence_landscape average;
+ std::vector< Abs_Topological_data_with_averages* > to_average;
+ to_average.push_back( (Abs_Topological_data_with_averages*)(&l1) );
+ to_average.push_back( (Abs_Topological_data_with_averages*)(&l2) );
+ average.compute_average( to_average );
+ std::cout << "average : " << average << std::endl;
+
+ //here is the distance of landscapes:
+ std::cout << "Distance : " << l1.distance( (Abs_Topological_data_with_distances*)(&l2) ) << std::endl;
+
+ //here is the scalar product of landscapes:
+ std::cout << "Scalar product : " << l1.compute_scalar_product( (Abs_Topological_data_with_scalar_product*)(&l2) ) << std::endl;
+
+ //here is how to create a file which is suitable for vizualization via gnuplot:
+ average.plot( "average_landscape" );
+
+ return 0;
+}
+
+
+//Below I am storing the code used to generate tests for that functionality.
+/*
+if ( argc != 2 )
{
std::cerr << "To run this program, please provide a name of a file with persistence landscape \n";
//return 1;
@@ -161,7 +222,4 @@ int main( int argc , char** argv )
Persistence_landscape q( "../test/data/file_with_diagram_1" );
cout << "Scalar product : " << p.compute_scalar_product( &q ) << endl;
}
-
-
- return 0;
-}
+*/
diff --git a/src/Gudhi_stat/example/persistence_landscape_on_grid.cpp b/src/Gudhi_stat/example/persistence_landscape_on_grid.cpp
index e1a0ba5d..ddda78d2 100644
--- a/src/Gudhi_stat/example/persistence_landscape_on_grid.cpp
+++ b/src/Gudhi_stat/example/persistence_landscape_on_grid.cpp
@@ -35,7 +35,65 @@ using namespace Gudhi::Gudhi_stat;
int main( int argc , char** argv )
{
- /*
+ //create two simple vectors with birth--death pairs:
+
+ std::vector< std::pair< double , double > > persistence1;
+ std::vector< std::pair< double , double > > persistence2;
+
+ persistence1.push_back( std::make_pair(1,2) );
+ persistence1.push_back( std::make_pair(6,8) );
+ persistence1.push_back( std::make_pair(0,4) );
+ persistence1.push_back( std::make_pair(3,8) );
+
+ persistence2.push_back( std::make_pair(2,9) );
+ persistence2.push_back( std::make_pair(1,6) );
+ persistence2.push_back( std::make_pair(3,5) );
+ persistence2.push_back( std::make_pair(6,10) );
+
+ //create two persistence landscapes based on persistence1 and persistence2:
+ Persistence_landscape_on_grid l1( persistence1 , 0 , 11 , 20 );
+ Persistence_landscape_on_grid l2( persistence2 , 0 , 11 , 20 );
+
+ //This is how to compute integral of landscapes:
+ std::cout << "Integral of the first landscape : " << l1.compute_integral_of_landscape() << endl;
+ std::cout << "Integral of the second landscape : " << l2.compute_integral_of_landscape() << endl;
+
+ //And here how to write landscapes to stream:
+ std::cout << "l1 : " << l1 << std::endl;
+ std::cout << "l2 : " << l2 << std::endl;
+
+ //here are the maxima of the functions:
+ std::cout << "Maximum of l1 : " << l1.compute_maximum() << std::endl;
+ std::cout << "Maximum of l2 : " << l2.compute_maximum() << std::endl;
+
+ //here are the norms of landscapes:
+ std::cout << "L^1 Norm of l1 : " << l1.compute_norm_of_landscape( 1. ) << std::endl;
+ std::cout << "L^1 Norm of l2 : " << l2.compute_norm_of_landscape( 1. ) << std::endl;
+
+ //here is the average of landscapes:
+ Persistence_landscape_on_grid average;
+ std::vector< Abs_Topological_data_with_averages* > to_average;
+ to_average.push_back( (Abs_Topological_data_with_averages*)(&l1) );
+ to_average.push_back( (Abs_Topological_data_with_averages*)(&l2) );
+ average.compute_average( to_average );
+ std::cout << "average : " << average << std::endl;
+
+ //here is the distance of landscapes:
+ std::cout << "Distance : " << l1.distance( (Abs_Topological_data_with_distances*)(&l2) ) << std::endl;
+
+ //here is the scalar product of landscapes:
+ std::cout << "Scalar product : " << l1.compute_scalar_product( (Abs_Topological_data_with_scalar_product*)(&l2) ) << std::endl;
+
+ //here is how to create a file which is suitable for vizualization via gnuplot:
+ average.plot( "average_landscape" );
+
+
+ return 0;
+}
+
+
+//Below I am storing the code used to generate tests for that functionality.
+/*
Persistence_landscape_on_grid l( "file_with_diagram_1" , 100 );
l.print_to_file( "landscape_from_file_with_diagram_1" );
@@ -132,7 +190,7 @@ int main( int argc , char** argv )
cerr << p.distance( &q , -1 ) << endl;
*/
-
+/*
Persistence_landscape_on_grid p( "file_with_diagram", 0,1,10000 );
Persistence_landscape_on_grid q( "file_with_diagram_1", 0,1,10000 );
@@ -141,7 +199,4 @@ int main( int argc , char** argv )
//Persistence_landscape_on_grid p( aa, 0,1,10 );
//Persistence_landscape_on_grid q( aa, 0,1,10 );
cerr << p.compute_scalar_product( &q ) << endl;
-
-
- return 0;
-}
+*/
diff --git a/src/Gudhi_stat/example/vector_representation.cpp b/src/Gudhi_stat/example/vector_representation.cpp
index 0581baf4..773c60fa 100644
--- a/src/Gudhi_stat/example/vector_representation.cpp
+++ b/src/Gudhi_stat/example/vector_representation.cpp
@@ -37,13 +37,58 @@ using namespace Gudhi::Gudhi_stat;
using namespace std;
-double epsilon = 0.000005;
-
int main( int argc , char** argv )
{
- if ( argc < 2 )
+ //create two simple vectors with birth--death pairs:
+
+ std::vector< std::pair< double , double > > persistence1;
+ std::vector< std::pair< double , double > > persistence2;
+
+ persistence1.push_back( std::make_pair(1,2) );
+ persistence1.push_back( std::make_pair(6,8) );
+ persistence1.push_back( std::make_pair(0,4) );
+ persistence1.push_back( std::make_pair(3,8) );
+
+ persistence2.push_back( std::make_pair(2,9) );
+ persistence2.push_back( std::make_pair(1,6) );
+ persistence2.push_back( std::make_pair(3,5) );
+ persistence2.push_back( std::make_pair(6,10) );
+
+ //create two persistence vectors based on persistence1 and persistence2:
+ Vector_distances_in_diagram<euclidean_distance<double> > v1 = Vector_distances_in_diagram<euclidean_distance<double> >( persistence1 , std::numeric_limits<size_t>::max() );
+ Vector_distances_in_diagram<euclidean_distance<double> > v2 = Vector_distances_in_diagram<euclidean_distance<double> >( persistence2 , std::numeric_limits<size_t>::max() );
+
+ //writing to a stream:
+ std::cout << "v1 : " << v1 << std::endl;
+ std::cout << "v2 : " << v2 << std::endl;
+
+ //averages:
+ Vector_distances_in_diagram<euclidean_distance<double> > average;
+ std::vector< Abs_Topological_data_with_averages* > to_average;
+ to_average.push_back( (Abs_Topological_data_with_averages*)(&v1) );
+ to_average.push_back( (Abs_Topological_data_with_averages*)(&v2) );
+ average.compute_average( to_average );
+ std::cout << "Average : " << average << std::endl;
+
+ //computations of distances:
+ std::cout << "l^1 distance : " << v1.distance( (Abs_Topological_data_with_distances*)(&v2) ) << std::endl;
+
+ //computations of scalar product:
+ std::cout << "Scalar product of l1 and l2 : " << v1.compute_scalar_product( (Abs_Topological_data_with_scalar_product*)(&v2) ) << std::endl;
+
+ //create a file with a gnuplot script:
+ v1.plot( "plot_of_vector_representation" );
+
+ return 0;
+}
+
+
+
+
+/*
+ if ( argc < 2 )
{
cout << "To run this program, please provide the name of a file with persistence diagram. If you provide two files, we will do distance, scalar produc and average computations \n";
return 1;
@@ -71,7 +116,4 @@ int main( int argc , char** argv )
cout << "Here is an average : " << average << endl;
}
- return 0;
-}
-
-
+*/