diff --git a/include/PCAModel.txx b/include/PCAModel.txx index ec941e1f2802578781ccf5fb206a9a5d48e89a3b..dab5b6483a010da8f5498316e7a1f326db83cc32 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 9c02c566cd83f49c4d011050140acaca3e10cee2..d51926469b1eadea2f01edc6faacc617e6c41770 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); }