OTB  6.7.0
Orfeo Toolbox
otbDimensionalityReductionTrainPCA.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES)
3  *
4  * This file is part of Orfeo Toolbox
5  *
6  * https://www.orfeo-toolbox.org/
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 #ifndef otbDimensionalityReductionTrainPCA_hxx
21 #define otbDimensionalityReductionTrainPCA_hxx
22 
24 #include "otbPCAModel.h"
25 
26 namespace otb
27 {
28 namespace Wrapper
29 {
30 
31 template <class TInputValue, class TOutputValue>
32 void
33 TrainDimensionalityReductionApplicationBase<TInputValue,TOutputValue>
34 ::InitPCAParams()
35 {
36  AddChoice("algorithm.pca", "Shark PCA");
37  SetParameterDescription("algorithm.pca",
38  "This group of parameters allows setting Shark PCA parameters. "
39  );
40 
41  //Output Dimension
42  AddParameter(ParameterType_Int, "algorithm.pca.dim",
43  "Dimension of the output of the pca transformation");
44  SetParameterInt("algorithm.pca.dim",10, false);
45  SetParameterDescription(
46  "algorithm.pca.dim",
47  "Dimension of the output of the pca transformation.");
48 }
49 
50 template <class TInputValue, class TOutputValue>
51 void TrainDimensionalityReductionApplicationBase<TInputValue,TOutputValue>
52 ::TrainPCA(typename ListSampleType::Pointer trainingListSample,std::string modelPath)
53 {
54  typedef otb::PCAModel<InputValueType> PCAModelType;
55  typename PCAModelType::Pointer dimredTrainer = PCAModelType::New();
56  dimredTrainer->SetDimension(GetParameterInt("algorithm.pca.dim"));
57  dimredTrainer->SetInputListSample(trainingListSample);
58  dimredTrainer->SetWriteEigenvectors(true);
59  dimredTrainer->Train();
60  dimredTrainer->Save(modelPath);
61 }
62 
63 } //end namespace wrapper
64 } //end namespace otb
65 
66 #endif