diff --git a/sources/core/args.h b/sources/core/args.h index 7bb78c8978c11f6b67a420254c3f17ce4fa200a2..74bc610ee15c2d19cff3599fee0934239a3b9cf0 100644 --- a/sources/core/args.h +++ b/sources/core/args.h @@ -23,7 +23,7 @@ class arguments // Constructor and destructor arguments() { - } ; + } arguments(int argc, char** const argv) { std::string key ; @@ -53,8 +53,10 @@ class arguments } _map.insert(std::pair(key, data)) ; } - } ; - ~arguments() { } ; + } + ~arguments() + { + } //! \brief is the elements in the command line ? bool is_defined(const std::string& key) const @@ -67,7 +69,7 @@ class arguments { return false ; } - } ; + } //! \brief access the element stored value std::string operator[](const std::string& key) const { @@ -80,7 +82,7 @@ class arguments //std::cerr << "Underfined request to key : \"" << key << "\"" << std::endl ; return std::string() ; } - } ; + } //! \brief acces to the float value associated with the parameter //! \a key. //! @@ -113,6 +115,9 @@ class arguments vec get_vec(const std::string& key, int size, float default_value = 0.0f) const { vec res(size); + for(int i=0; i 0) { std::string s = _map.find(key)->second; diff --git a/sources/core/clustering.cpp b/sources/core/clustering.cpp new file mode 100644 index 0000000000000000000000000000000000000000..50f961407f4b2f82607837ecc0cdffbf8c6b356d --- /dev/null +++ b/sources/core/clustering.cpp @@ -0,0 +1,98 @@ +#include "clustering.h" + +#include +#include +#include + +clustering::clustering(const data* d, const arguments& args) +{ + // List of the indices of the clustering + std::vector indices; + + vec findices = args.get_vec("cluster-dim", d->dimX(), -1.0f); + for(int i=0; i= 0 && id < d->dimX()); + } + std::cout << "<> the resulting data will have " << indices.size() << " dimensions" << std::endl; + + // We cannot have null cluster size of full rank. + assert(indices.size() > 0 && indices.size() < d->dimX()); + + // Fit the slice into the domain of definition of the data + int compressed_size = d->dimX()-indices.size(); + vec compressed_vec = args.get_vec("cluster-slice", d->dimX(), std::numeric_limits::max()); + for(int i=0; idimX(); ++i) + { + compressed_vec[i] = std::min(compressed_vec[i], d->max()[i]); + compressed_vec[i] = std::max(compressed_vec[i], d->min()[i]); + } + + // Set the limit of the new domain and dimensions + _nX = indices.size(); + _nY = d->dimY(); + _min = vec(_nX); + _max = vec(_nX); + for(int i=0; i<_nX; ++i) + { + _min[i] = d->min()[indices[i]]; + _max[i] = d->max()[indices[i]]; + } + + for(int i=0; isize(); ++i) + { + vec p = d->get(i); + bool reject = false; + for(int i=0; idimX(); ++i) + { + if(is_in(indices, i) == -1 && p[i] != compressed_vec[i]) + { + reject = true; + } + } + if(reject) + { + continue; + } + + vec e(dimX()+dimY()); + for(int i=0; i<_nX; ++i) + { + e[i] = p[indices[i]]; + } + for(int i=0; i<_nY; ++i) + { + e[_nX + i] = p[d->dimX() + i]; + } + _data.push_back(e); + } + std::cout << "<> clustering left " << _data.size() << " elements" << std::endl; +} + +vec clustering::get(int i) const +{ + return _data[i]; +} + +vec clustering::operator[](int i) const +{ + return _data[i]; +} + +int clustering::size() const +{ + return _data.size(); +} + +vec clustering::min() const +{ + return _min; +} + +vec clustering::max() const +{ + return _max; +} diff --git a/sources/core/clustering.h b/sources/core/clustering.h new file mode 100644 index 0000000000000000000000000000000000000000..1cb493fb8cbb6634d36c0807acc6a1a1b60a624d --- /dev/null +++ b/sources/core/clustering.h @@ -0,0 +1,45 @@ +#pragma once + +#include "data.h" +#include "common.h" + +#include + +class clustering : public data +{ + public: // methods + + //! \brief constructor loading a full dimension data and clustering + //! it into a low dimension one. + clustering(const data* d, const arguments& args); + + //! \brief the clustering class cannot load from a file. It requires + //! a complete object to be created. + virtual void load(const std::string& filename) + { + throw; + } + //! \brief the clustering class cannot load from a file. It requires + //! a complete object to be created. + virtual void load(const std::string& filename, const arguments& args) + { + throw; + } + + //! \brief aces to data in linear order + virtual vec get(int i) const ; + //! \brief aces to data in linear order + virtual vec operator[](int i) const ; + + //! \brief return the size of the data after clusterization + int size() const; + + //! \brief get min input space values + virtual vec min() const ; + //! \brief get max input space values + virtual vec max() const ; + + protected: + std::vector _data; + vec _min, _max; +}; diff --git a/sources/core/common.h b/sources/core/common.h index 6988f23dee1e218d0a14a150919bb795bbb3c161..7ff15c7b9a72284dc1e1f09e222ec6bd3293a942 100644 --- a/sources/core/common.h +++ b/sources/core/common.h @@ -50,7 +50,7 @@ class vec : public std::vector } return *this ; } - + // Mathematical operators // friend vec operator-(const vec& a) @@ -219,11 +219,25 @@ class vec : public std::vector out << "]" ; return out ; - } ; + } } ; +//! \brief locate the first index of value v in vector vec. Complexity in +//! O(n) is the worst case. +template int is_in(std::vector ve, T v) +{ + int res = -1; + for(unsigned int i=0; i> not implemented " << __FILE__ \ << ":" << __LINE__ << std::endl; \ diff --git a/sources/core/core.pro b/sources/core/core.pro index 057a788b457aba3a67af38a0ccbbdcd22a2010d5..7842e2b6f968228865c4284cb33fec957e90aa97 100644 --- a/sources/core/core.pro +++ b/sources/core/core.pro @@ -12,8 +12,10 @@ HEADERS = args.h \ plugins_manager.h \ vertical_segment.h \ rational_function.h \ - params.h + params.h \ + clustering.h SOURCES = plugins_manager.cpp \ vertical_segment.cpp \ - rational_function.cpp + rational_function.cpp \ + clustering.cpp diff --git a/sources/core/plugins_manager.h b/sources/core/plugins_manager.h index 8a8061237af1c03b2eeddd761822c794ed1cbc3d..4b091cdaf01ea41e7a5beb8402a32b670115f75c 100644 --- a/sources/core/plugins_manager.h +++ b/sources/core/plugins_manager.h @@ -7,6 +7,7 @@ #include "data.h" #include "fitter.h" #include "args.h" +#include "clustering.h" #define USING_STATIC @@ -77,6 +78,13 @@ class plugins_manager { std::cout << "<> no change was made to the parametrization" << std::endl; } + + // Check is the data has to be clusterized + if(args.is_defined("cluster-dim")) + { + clustering* cluster = new clustering(d, args); + d = cluster; + } } //! \brief Provide a measure of how much memory there is on the system.