summaryrefslogtreecommitdiff
path: root/src/Kernels/example/kernel_basic_example.cpp
blob: 7ecbe401ebcc088aebfdfcdc22277b40256d75b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*    This file is part of the Gudhi Library. The Gudhi library
 *    (Geometric Understanding in Higher Dimensions) is a generic C++
 *    library for computational topology.
 *
 *    Authors:       Mathieu Carrière
 *
 *    Copyright (C) 2017  INRIA
 *
 *    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/>.
 */

#include <gudhi/kernel.h>
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>


void usage(int nbArgs, char *const progName) {
  std::cerr << "Error: Number of arguments (" << nbArgs << ") is not correct\n";
  std::cerr << "Usage: " << progName << " PD1 PD2 \n";
  std::cerr << "       i.e.: " << progName << " ../../../../data/persistence_diagram/PD1.pers ../../../../data/persistence_diagram/PD2.pers \n";
  exit(-1);  // ----- >>
}

int main(int argc, char **argv) {

  if (argc != 3) usage(argc, argv[0]);

  double sigma = 2; double tau = 5;

  std::string PDname1(argv[1]); std::string PDname2(argv[2]);
  std::vector< std::pair<double, double> > v1, v2; std::string line; double b,d;

  std::ifstream input1(PDname1);
  while(std::getline(input1,line)){
    std::stringstream stream(line); stream >> b; stream >> d; v1.push_back(std::pair<double,double>(b,d));
  }

  std::ifstream input2(PDname2);
  while(std::getline(input2,line)){
    std::stringstream stream(line); stream >> b; stream >> d; v2.push_back(std::pair<double,double>(b,d));
  }

  std::cout << "SWK exact = "    << Gudhi::kernel::sliced_wasserstein_kernel                             (v1,v2,sigma,-1)                                    << std::endl;
  std::cout << "SWK approx = "   << Gudhi::kernel::sliced_wasserstein_kernel                             (v1,v2,sigma)                                       << std::endl;
  std::cout << "PSSK exact = "   << Gudhi::kernel::persistence_scale_space_kernel                        (v1,v2,sigma,-1)                                    << std::endl;
  std::cout << "PSSK approx = "  << Gudhi::kernel::persistence_scale_space_kernel                        (v1,v2,sigma)                                       << std::endl;
  std::cout << "LPWGK exact = "  << Gudhi::kernel::linear_persistence_weighted_gaussian_kernel           (v1,v2,sigma,Gudhi::kernel::arctan_weight,-1)       << std::endl;
  std::cout << "LPWGK approx = " << Gudhi::kernel::linear_persistence_weighted_gaussian_kernel           (v1,v2,sigma,Gudhi::kernel::arctan_weight)          << std::endl;
  std::cout << "GPWGK exact = "  << Gudhi::kernel::gaussian_persistence_weighted_gaussian_kernel         (v1,v2,sigma,tau,Gudhi::kernel::arctan_weight,-1)   << std::endl;
  std::cout << "GPWGK approx = " << Gudhi::kernel::gaussian_persistence_weighted_gaussian_kernel         (v1,v2,sigma,tau,Gudhi::kernel::arctan_weight)      << std::endl;

}