Newer
Older
Cédric Traizet
committed
#ifndef cbTrainPCA_txx
#define cbTrainPCA_txx
#include "otbTrainDimensionalityReductionApplicationBase.h"
Cédric Traizet
committed
namespace otb
{
namespace Wrapper
{
template <class TInputValue, class TOutputValue>
void
TrainDimensionalityReductionApplicationBase<TInputValue,TOutputValue>
Cédric Traizet
committed
::InitPCAParams()
{
AddChoice("algorithm.pca", "Shark PCA");
SetParameterDescription("algorithm.pca",
Cédric Traizet
committed
"This group of parameters allows setting Shark PCA parameters. "
);
//Output Dimension
AddParameter(ParameterType_Int, "algorithm.pca.dim",
Cédric Traizet
committed
"Dimension of the output of the pca transformation");
SetParameterInt("algorithm.pca.dim",10, false);
Cédric Traizet
committed
SetParameterDescription(
Cédric Traizet
committed
"Dimension of the output of the pca transformation.");
}
template <class TInputValue, class TOutputValue>
void TrainDimensionalityReductionApplicationBase<TInputValue,TOutputValue>
Cédric Traizet
committed
::TrainPCA(typename ListSampleType::Pointer trainingListSample,std::string modelPath)
{
typedef otb::PCAModel<InputValueType> PCAModelType;
Cédric Traizet
committed
typename PCAModelType::Pointer dimredTrainer = PCAModelType::New();
dimredTrainer->SetDimension(GetParameterInt("algorithm.pca.dim"));
Cédric Traizet
committed
dimredTrainer->SetInputListSample(trainingListSample);
dimredTrainer->SetWriteEigenvectors(true);
Cédric Traizet
committed
dimredTrainer->Train();
dimredTrainer->Save(modelPath);
}
} //end namespace wrapper
} //end namespace otb
#endif