From: Grenier Thomas Date: Sun, 10 Dec 2017 12:49:29 +0000 (+0100) Subject: base of v2.0 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=2c235d4243c9fc08c6ba76efdf1944a23e586985;p=STMS.git base of v2.0 --- diff --git a/Src/STMS_generateClosestMap.cxx b/Src/STMS_generateClosestMap.cxx new file mode 100644 index 0000000..a8b8eef --- /dev/null +++ b/Src/STMS_generateClosestMap.cxx @@ -0,0 +1,122 @@ +#include +#include +#include +#include +#include +#include + +#include + +typedef std::vector< float > TimeSerieType; +typedef std::pair< unsigned int , float> DistanceIndexType; + +#pragma omp declare simd +float distsq(float x, float y) +{ + return (x-y) * (x-y); +} + +#pragma omp declare simd +bool DistancePairComp (const DistanceIndexType &x, const DistanceIndexType &y) +{ + return x.second < y.second; +} + +float EuclidianDistanceTimeSerie( const TimeSerieType &a, const TimeSerieType &b) +{ + float dist = 0; + unsigned int n = a.size(); + #pragma omp parallel for simd reduction(+:dist) schedule(simd:static, 5) + for (unsigned int i=0; i ClassSeries; +std::vector< unsigned int > ClassLabels; +std::vector< unsigned int > ClassEffectif; + +unsigned int K = 5; +unsigned int N = 2; +std::cout << "argv[1] : csv filemane " << std::endl; +std::cout << "argv[2] : K the number of neigboors" << std::endl; +std::cout << "argv[3] : N the minimum effectif of classes "<< std::endl; + +/////////////////////////////////////////////////////////////// +/// \brief reading csv file +/////////////////////////////////////////////////////////////// +std::ifstream ifs; +ifs.open (argv[1], std::ifstream::in); +std::cout << "argv[1] : csv filemane = " << argv[1] << std::endl; + + +std::string ID_str, Effectif_str, Value_str; + +std::string::size_type sz = 0; // use to identify the endline +while( ifs.good() ) +{ + if(sz == 0) std::getline(ifs, ID_str, ','); +// std::cout << ID_str << " " ; + ClassLabels.push_back( std::stof(ID_str) ); + + std::getline(ifs, Effectif_str, ','); + // std::cout << Effectif_str << " " ; + ClassEffectif.push_back( std::stof(Effectif_str) ); + + TimeSerieType tmpSerie; + int a; + do + { + std::getline(ifs, Value_str, ','); +// std::cout << Value_str << " " ; + a= Value_str.find('\n'); + tmpSerie.push_back( std::stof(Value_str, &sz) ); + } while( a == -1 ); +// std::cout << std::endl; + ClassSeries.push_back( tmpSerie ); + ID_str = Value_str.substr(sz+1); // " 2\n12" -> "12" +} +ifs.close(); +/////////////////////////////////////////////////////////////// + + +std::cout << " starting analysis " << std::endl; +/////////////////////////////////////////////////////////////// +/// \brief compute k nearest neigboor of each entry (effectif > N) +/////////////////////////////////////////////////////////////// +for(unsigned int i=0; i N ) // if class's cardinal is > to N + { + std::vector< DistanceIndexType > DistanceToSeries(ClassSeries.size()) ; // we will use the current sample to validate (so sizes are the same) + unsigned int n= ClassSeries.size(); + #pragma omp parallel for shared(DistanceToSeries) + for(unsigned int j=0; j