From b18d93a8b78d96ac192f0de87c5466d9a9296030 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Traizet?= <cedric.traizet@c-s.fr> Date: Wed, 17 Apr 2019 17:26:30 +0200 Subject: [PATCH] ENH: remove normalization from Shark Kmeans machine learning model --- .../otbSharkKMeansMachineLearningModel.h | 8 ------- .../otbSharkKMeansMachineLearningModel.hxx | 21 +------------------ 2 files changed, 1 insertion(+), 28 deletions(-) diff --git a/Modules/Learning/Unsupervised/include/otbSharkKMeansMachineLearningModel.h b/Modules/Learning/Unsupervised/include/otbSharkKMeansMachineLearningModel.h index 700a58eacd..d42e748194 100644 --- a/Modules/Learning/Unsupervised/include/otbSharkKMeansMachineLearningModel.h +++ b/Modules/Learning/Unsupervised/include/otbSharkKMeansMachineLearningModel.h @@ -125,10 +125,6 @@ public: /** Set the number of class for the kMeans algorithm.*/ itkSetMacro( K, unsigned ); - /** If true, normalized input data sample list */ - itkGetMacro( Normalized, bool ); - itkSetMacro( Normalized, bool ); - /** Initialize the centroids for the kmeans algorithm */ void SetCentroidsFromData(const shark::Data<shark::RealVector> & data) { @@ -150,9 +146,6 @@ protected: virtual void DoPredictBatch(const InputListSampleType *, const unsigned int &startIndex, const unsigned int &size, TargetListSampleType *, ConfidenceListSampleType * = nullptr, ProbaListSampleType * = nullptr) const override; - template<typename DataType> - DataType NormalizeData(const DataType &data) const; - template<typename DataType> shark::Normalizer<> TrainNormalizer(const DataType &data) const; @@ -164,7 +157,6 @@ private: void operator=(const Self &) = delete; // Parameters set by the user - bool m_Normalized; unsigned int m_K; unsigned int m_MaximumNumberOfIterations; bool m_CanRead; diff --git a/Modules/Learning/Unsupervised/include/otbSharkKMeansMachineLearningModel.hxx b/Modules/Learning/Unsupervised/include/otbSharkKMeansMachineLearningModel.hxx index 1d27ce519c..ff95c9501a 100644 --- a/Modules/Learning/Unsupervised/include/otbSharkKMeansMachineLearningModel.hxx +++ b/Modules/Learning/Unsupervised/include/otbSharkKMeansMachineLearningModel.hxx @@ -52,7 +52,7 @@ namespace otb template<class TInputValue, class TOutputValue> SharkKMeansMachineLearningModel<TInputValue, TOutputValue> ::SharkKMeansMachineLearningModel() : - m_Normalized( false ), m_K(2), m_MaximumNumberOfIterations( 10 ) + m_K(2), m_MaximumNumberOfIterations( 10 ) { // Default set HardClusteringModel this->m_ConfidenceIndex = true; @@ -77,30 +77,11 @@ SharkKMeansMachineLearningModel<TInputValue, TOutputValue> otb::Shark::ListSampleToSharkVector( this->GetInputListSample(), vector_data ); shark::Data<shark::RealVector> data = shark::createDataFromRange( vector_data ); - // Normalized input value if necessary - if( m_Normalized ) - { - auto normalizer = TrainNormalizer(data); - data = normalizer(data); - } - // Use a Hard Clustering Model for classification shark::kMeans( data, m_K, m_Centroids, m_MaximumNumberOfIterations ); m_ClusteringModel = boost::make_shared<ClusteringModelType>( &m_Centroids ); } -template<class TInputValue, class TOutputValue> -template<typename DataType> -DataType -SharkKMeansMachineLearningModel<TInputValue, TOutputValue> -::NormalizeData(const DataType &data) const -{ - shark::Normalizer<> normalizer; - shark::NormalizeComponentsUnitVariance<> normalizingTrainer( true );//zero mean - normalizingTrainer.train( normalizer, data ); - return normalizer( data ); -} - template<class TInputValue, class TOutputValue> template<typename DataType> shark::Normalizer<> -- GitLab