From dd56587db3c4f63719cacd4f6dd34412d4115719 Mon Sep 17 00:00:00 2001 From: pdlotko Date: Mon, 27 Mar 2017 19:48:49 +0000 Subject: adding persistence_representations subfolder (at the moment with all the junk). git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/gudhi_stat@2256 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: fdf52ca688d992655ff139f42e316d5b7b3f8a12 --- .../one_d_gaussians_kernel.h | 82 ++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 src/Gudhi_stat/include/gudhi/persistence_representations/one_d_gaussians_kernel.h (limited to 'src/Gudhi_stat/include/gudhi/persistence_representations/one_d_gaussians_kernel.h') diff --git a/src/Gudhi_stat/include/gudhi/persistence_representations/one_d_gaussians_kernel.h b/src/Gudhi_stat/include/gudhi/persistence_representations/one_d_gaussians_kernel.h new file mode 100644 index 00000000..671e7ad1 --- /dev/null +++ b/src/Gudhi_stat/include/gudhi/persistence_representations/one_d_gaussians_kernel.h @@ -0,0 +1,82 @@ +#pragma once + +#include + +#include "kernel.h" +#include "one_d_gaussians.h" + + +template +class one_d_gaussians_kernel : public Persistence_kernel +{ +public: + one_d_gaussians_kernel( std::vector< Persistence_intervals >& intervals_ , size_t number_of_points , double min_ = -1 , double max_ = -1 , size_t range = -1 ); + one_d_gaussians_kernel( char* filename , size_t number_of_points , double min_ = -1 , double max_ = -1 , size_t range = -1 ); + + double compute_scalar_product( size_t number_of_first_barcode , size_t number_of_second_barcode ); +private: + std::vector< one_d_gaussians > gaussians; + void construct( std::vector< Persistence_intervals >& intervals , size_t number_of_points , double min_ = -1 , double max_ = -1 , size_t range = -1 ); +}; + + +template +void one_d_gaussians_kernel::construct( std::vector< Persistence_intervals >& intervals_ , size_t number_of_points , double min_ , double max_ , size_t range ) +{ + for ( size_t nr = 0 ; nr != intervals_.size() ; ++nr ) + { + std::vector< Persistence_intervals > aa; + aa.push_back( intervals_[nr] ); + cerr << "intervals_[nr].size() : " << intervals_[nr].size() << endl; + cerr << "A \n"; + this->gaussians.push_back( one_d_gaussians( aa , number_of_points , min_ , max_ , range ) ); + cerr << "B \n"; + } +} + +template +one_d_gaussians_kernel::one_d_gaussians_kernel( std::vector< Persistence_intervals >& intervals , size_t number_of_points , double min_ , double max_ , size_t range ):Persistence_kernel(intervals.size()) +{ + this->construct( intervals , number_of_points , min_ , max_ , range ); +} + +template +one_d_gaussians_kernel::one_d_gaussians_kernel( char* filename , size_t number_of_points , double min_ , double max_ , size_t range ) +{ + std::vector names = readFileNames( filename ); + std::vector< Persistence_intervals > intervals; + for ( size_t file_no = 0 ; file_no != names.size() ; ++file_no ) + { + cout << "Reading file : " << names[file_no] << endl; + Persistence_intervals interval( (char*)names[file_no].c_str() ); + intervals.push_back( interval ); + } + + //in this case, if min_ and max_ are not specified by the user, we should compute it, so that they are the same for all the considered cases: + if ( min_ == max_ == -1 ) + { + min_ = INT_MAX; + max_ = INT_MIN; + //in this case, the values of min_ and max_ are not specified by the user, and we should specify them here. + for ( size_t diagNo = 0 ; diagNo != intervals.size() ; ++diagNo ) + { + std::pair mM = intervals[diagNo].min_max(); + if ( min_ > mM.first )min_ = mM.first; + if ( max_ < mM.second )max_ = mM.second; + } + } + this->construct( intervals , number_of_points , min_ , max_ , range ); + this->number_of_intervals = names.size(); +} + +template +double one_d_gaussians_kernel::compute_scalar_product( size_t number_of_first_barcode , size_t number_of_second_barcode ) +{ + double result = 0; + for ( size_t i = 0 ; i != this->gaussians[number_of_first_barcode].size() ; ++i ) + { + result += this->gaussians[number_of_first_barcode][i] * this->gaussians[number_of_second_barcode][i]; + } + //cerr << "Scalar product : " << result << endl; getchar(); + return result; +} -- cgit v1.2.3