Debian Codegraph @

src/Persistence_representations/utilities/persistence_landscapes/compute_distance_of_landscapes.cpp

raw symbols SCIP
1 /* This file is part of the Gudhi Library - https://gudhi.inria.fr/ - which is released under MIT.
2 * See file LICENSE or go to https://gudhi.inria.fr/licensing/ for full license details.
3 * Author(s): Pawel Dlotko
4 *
5 * Copyright (C) 2016 Inria
6 *
7 * Modification(s):
8 * - YYYY/MM Author: Description of the modification
9 */
10
11 #include <gudhi/Persistence_landscape.h>cxx . . $ `<file>/src/Persistence_representations/include/gudhi/Persistence_landscape.h`/
12
13 #include <iostream>
14 #include <sstream>
15 #include <limits>
16 #include <vector>
17
18 using Persistence_landscapecxx . . $ Persistence_landscape# = Gudhicxx . . $ Gudhi/::Persistence_representationscxx . . $ Gudhi/Persistence_representations/::Persistence_landscapecxx . . $ Gudhi/Persistence_representations/Persistence_landscape#;
19
20 int maincxx . . $ main(afcd3168fc1188a4).(int argc, char** argv) {
21 stdcxx . . $ std/::clogcxx . . $ std/clog. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "This program computes distance of persistence landscapes stored in files (the files needs to be "
22 <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "created beforehand).\n"
23 <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "The first parameter of a program is an integer p. The program compute L^p distance of the two heat "
24 <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "maps. For L^infty distance choose p = -1. \n"
25 <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "The remaining parameters of this program are names of files with persistence landscapes.\n";
26
27 if (argc < 3) {
28 stdcxx . . $ std/::clogcxx . . $ std/clog. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Wrong number of parameters, the program will now terminate \n";
29 return 1;
30 }
31
32 int pp = atoi(argv[1]);
33 double p = stdcxx . . $ std/::numeric_limitscxx . . $ std/numeric_limits#<double>::maxcxx . . $ std/numeric_limits#max(e4aa362e81f92a46).();
34 if (pp != -1) {
35 p = pp;
36 }
37
38 stdcxx . . $ std/::vectorcxx . . $ std/vector#<const char*> filenamescxx . . $ std/vector#vector(49f6e7a06ebc5aa8).;
39 for (int i = 2; i < argc; ++i) {
40 filenames.push_backcxx . . $ std/vector#push_back(77d9f17553126ecb).(argv[i]);
41 }
42 stdcxx . . $ std/::vectorcxx . . $ std/vector#<Persistence_landscapecxx . . $ Persistence_landscape#> landscaspescxx . . $ std/vector#vector(49f6e7a06ebc5aa8).;
43 landscaspes.reservecxx . . $ std/vector#reserve(2c44cd906ae4e829).(filenames.sizecxx . . $ std/vector#size(c9b1e749b64d5edc).());
44 for (size_t file_no = 0; file_no != filenames.sizecxx . . $ std/vector#size(c9b1e749b64d5edc).(); ++file_no) {
45 Persistence_landscapecxx . . $ Persistence_landscape# lcxx . . $ Gudhi/Persistence_representations/Persistence_landscape#Persistence_landscape(49f6e7a06ebc5aa8).;
46 l.load_landscape_from_filecxx . . $ Gudhi/Persistence_representations/Persistence_landscape#load_landscape_from_file(85c52e162fed56f9).(filenames[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).file_no]);
47 landscaspes.push_backcxx . . $ std/vector#push_back(77d9f17553126ecb).(l);
48 }
49
50 // and now we will compute the scalar product of landscapes.
51
52 // first we prepare an array:
53 stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::vectorcxx . . $ std/vector#<double> > distancecxx . . $ std/vector#vector(83fdeebbe0501a83).(filenames.sizecxx . . $ std/vector#size(c9b1e749b64d5edc).());
54 for (size_t i = 0; i != filenames.sizecxx . . $ std/vector#size(c9b1e749b64d5edc).(); ++i) {
55 stdcxx . . $ std/::vectorcxx . . $ std/vector#<double> vcxx . . $ std/vector#vector(229e4d6bd205de31).(filenames.sizecxx . . $ std/vector#size(c9b1e749b64d5edc).(), 0);
56 distance[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).i] =cxx . . $ std/vector#`operator=`(e6b68e61becad66f). v;
57 }
58
59 // and now we can compute the distances:
60 for (size_t i = 0; i != landscaspes.sizecxx . . $ std/vector#size(c9b1e749b64d5edc).(); ++i) {
61 for (size_t j = i; j != landscaspes.sizecxx . . $ std/vector#size(c9b1e749b64d5edc).(); ++j) {
62 distance[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).i][cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).j] = distance[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).j][cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).i] = compute_distance_of_landscapescxx . . $ Gudhi/Persistence_representations/compute_distance_of_landscapes(88485c2055347dee).(landscaspes[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).i], landscaspes[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).j], p);
63 }
64 }
65
66 // and now output the result to the screen and a file:
67 stdcxx . . $ std/::ofstreamcxx . . $ std/ofstream# outcxx . . $ std/basic_ofstream#basic_ofstream(49f6e7a06ebc5aa8).;
68 out.opencxx . . $ std/basic_ofstream#open(b8cd37071ce335df).("distance.land");
69 for (size_t i = 0; i != distance.sizecxx . . $ std/vector#size(c9b1e749b64d5edc).(); ++i) {
70 for (size_t j = 0; j != distance.sizecxx . . $ std/vector#size(c9b1e749b64d5edc).(); ++j) {
71 stdcxx . . $ std/::clogcxx . . $ std/clog. <<cxx . . $ std/basic_ostream#`operator<<`(968942d578224538). distance[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).i][cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).j] <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " ";
72 out <<cxx . . $ std/basic_ostream#`operator<<`(968942d578224538). distance[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).i][cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).j] <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " ";
73 }
74 stdcxx . . $ std/::clogcxx . . $ std/clog. <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).;
75 out <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).;
76 }
77 out.closecxx . . $ std/basic_ofstream#close(49f6e7a06ebc5aa8).();
78
79 stdcxx . . $ std/::clogcxx . . $ std/clog. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Distance can be found in 'distance.land' file\n";
80 return 0;
81 }