From 0887295c5873343e7ea8a2c7614d7d809dc061fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Traizet?= <traizetc@cesbio.cnes.fr> Date: Wed, 5 Jul 2017 11:11:09 +0200 Subject: [PATCH] PCA now outputs Eigenvectors and eigenvalues in a txt file --- include/PCAModel.txx | 12 ++++++++++++ include/cbTrainPCA.txx | 1 + 2 files changed, 13 insertions(+) diff --git a/include/PCAModel.txx b/include/PCAModel.txx index ec941e1f28..dab5b6483a 100644 --- a/include/PCAModel.txx +++ b/include/PCAModel.txx @@ -78,6 +78,16 @@ void PCAModel<TInputValue>::Save(const std::string & filename, const std::string boost::archive::polymorphic_text_oarchive oa(ofs); m_encoder.write(oa); ofs.close(); + + if (this->m_WriteEigenvectors == true) // output the map vectors in a txt file + { + std::ofstream otxt(filename+".txt"); + + otxt << m_pca.eigenvectors() << std::endl; + otxt << m_pca.eigenvalues() << std::endl; + + otxt.close(); + } } template <class TInputValue> @@ -109,6 +119,8 @@ void PCAModel<TInputValue>::Load(const std::string & filename, const std::string m_encoder.setStructure(eigenvectors, m_encoder.offset() ); std::cout << m_encoder.matrix() << "end" << std::endl; //this->m_Size = m_NumberOfHiddenNeurons; + + } diff --git a/include/cbTrainPCA.txx b/include/cbTrainPCA.txx index 9c02c566cd..d51926469b 100644 --- a/include/cbTrainPCA.txx +++ b/include/cbTrainPCA.txx @@ -40,6 +40,7 @@ void cbLearningApplicationBaseDR<TInputValue,TOutputValue> typename PCAModelType::Pointer dimredTrainer = PCAModelType::New(); dimredTrainer->SetDimension(GetParameterInt("model.pca.dim")); dimredTrainer->SetInputListSample(trainingListSample); + dimredTrainer->SetWriteEigenvectors(true); dimredTrainer->Train(); dimredTrainer->Save(modelPath); } -- GitLab