diff --git a/include/SOMModel.h b/include/SOMModel.h index a5752ac5c9c5797a865980bea98a71f2842bdc16..c9553cd9c37e76d2a9c271c72c12caa4b0bd60b3 100644 --- a/include/SOMModel.h +++ b/include/SOMModel.h @@ -60,6 +60,8 @@ public: itkGetMacro(NumberOfIterations, unsigned int); itkSetMacro(BetaInit, double); itkGetMacro(BetaInit, double); + itkSetMacro(WriteMap, bool); + itkGetMacro(WriteMap, bool); itkSetMacro(BetaEnd, double); itkGetMacro(BetaEnd, double); itkSetMacro(MinWeight, InputValueType); @@ -121,7 +123,8 @@ private: SOMLearningBehaviorFunctorType m_BetaFunctor; /** Behavior of the Neighborhood extent */ SOMNeighborhoodBehaviorFunctorType m_NeighborhoodSizeFunctor; - + /** Write the SOM Map vectors in a txt file */ + bool m_WriteMap; }; diff --git a/include/SOMModel.txx b/include/SOMModel.txx index b0b2229ac75600ae0ac4661fb016183a4b7c616e..6195b9f96189f1a781a6db581da79aa131f502e0 100644 --- a/include/SOMModel.txx +++ b/include/SOMModel.txx @@ -112,6 +112,24 @@ void SOMModel<TInputValue, MapDimension>::Save(const std::string & filename, con ++inputIterator; } ofs.close(); + + if (this->m_WriteMap == true) // output the map vectors in a txt file + { + std::ofstream otxt(filename+".txt"); + inputIterator.GoToBegin(); + while(!inputIterator.IsAtEnd()) + { + InputSampleType vect = inputIterator.Get(); + for (size_t i=0;i<vect.GetNumberOfElements();i++) + { + + otxt << vect[i] << " "; + } + otxt << std::endl; + ++inputIterator; + } + otxt.close(); + } } template <class TInputValue, unsigned int MapDimension> diff --git a/include/cbTrainSOM.txx b/include/cbTrainSOM.txx index 538ccea03c4d6895b0b12bff9fda3edc596b8f10..fa9137b30957065a7d68198f57b247617b7130b6 100644 --- a/include/cbTrainSOM.txx +++ b/include/cbTrainSOM.txx @@ -120,6 +120,7 @@ void cbLearningApplicationBaseDR<TInputValue,TOutputValue> std::cout << dim << std::endl; dimredTrainer->SetNumberOfIterations(GetParameterInt("model.som.ni")); dimredTrainer->SetBetaInit(GetParameterFloat("model.som.bi")); + dimredTrainer->SetWriteMap(true); dimredTrainer->SetBetaEnd(GetParameterFloat("model.som.bf")); dimredTrainer->SetMaxWeight(GetParameterFloat("model.som.iv")); typename TemplateEstimatorType::SizeType size;