Commit 0887295c authored by Cédric Traizet's avatar Cédric Traizet
Browse files

PCA now outputs Eigenvectors and eigenvalues in a txt file

No related merge requests found
Showing with 13 additions and 0 deletions
+13 -0
...@@ -78,6 +78,16 @@ void PCAModel<TInputValue>::Save(const std::string & filename, const std::string ...@@ -78,6 +78,16 @@ void PCAModel<TInputValue>::Save(const std::string & filename, const std::string
boost::archive::polymorphic_text_oarchive oa(ofs); boost::archive::polymorphic_text_oarchive oa(ofs);
m_encoder.write(oa); m_encoder.write(oa);
ofs.close(); 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> template <class TInputValue>
...@@ -109,6 +119,8 @@ void PCAModel<TInputValue>::Load(const std::string & filename, const std::string ...@@ -109,6 +119,8 @@ void PCAModel<TInputValue>::Load(const std::string & filename, const std::string
m_encoder.setStructure(eigenvectors, m_encoder.offset() ); m_encoder.setStructure(eigenvectors, m_encoder.offset() );
std::cout << m_encoder.matrix() << "end" << std::endl; std::cout << m_encoder.matrix() << "end" << std::endl;
//this->m_Size = m_NumberOfHiddenNeurons; //this->m_Size = m_NumberOfHiddenNeurons;
} }
......
...@@ -40,6 +40,7 @@ void cbLearningApplicationBaseDR<TInputValue,TOutputValue> ...@@ -40,6 +40,7 @@ void cbLearningApplicationBaseDR<TInputValue,TOutputValue>
typename PCAModelType::Pointer dimredTrainer = PCAModelType::New(); typename PCAModelType::Pointer dimredTrainer = PCAModelType::New();
dimredTrainer->SetDimension(GetParameterInt("model.pca.dim")); dimredTrainer->SetDimension(GetParameterInt("model.pca.dim"));
dimredTrainer->SetInputListSample(trainingListSample); dimredTrainer->SetInputListSample(trainingListSample);
dimredTrainer->SetWriteEigenvectors(true);
dimredTrainer->Train(); dimredTrainer->Train();
dimredTrainer->Save(modelPath); dimredTrainer->Save(modelPath);
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment