OTB  10.0.0
Orfeo Toolbox
otbTrainVectorBase.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2024 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 otbTrainVectorBase_h
21 #define otbTrainVectorBase_h
22 
24 #include "otbWrapperApplication.h"
26 
28 #include "otbOGRFeatureWrapper.h"
30 
31 #include "itkVariableLengthVector.h"
33 
34 #include "itkListSample.h"
36 
37 #include <algorithm>
38 #include <locale>
39 #include <string>
40 
41 namespace otb
42 {
43 namespace Wrapper
44 {
45 
46 template <class TInputValue, class TOutputValue>
47 class TrainVectorBase : public LearningApplicationBase<TInputValue, TOutputValue>
48 {
49 public:
53  typedef itk::SmartPointer<Self> Pointer;
54  typedef itk::SmartPointer<const Self> ConstPointer;
55 
57  itkTypeMacro(Self, Superclass);
58 
62 
63  typedef double ValueType;
64  typedef itk::VariableLengthVector<ValueType> MeasurementType;
65 
67 
69 
70 protected:
73  {
74  public:
77  };
78 
81  {
82  public:
83  typename ListSampleType::Pointer listSample;
84  typename TargetListSampleType::Pointer labeledListSample;
86  {
87  listSample = ListSampleType::New();
88  labeledListSample = TargetListSampleType::New();
89  }
90  };
92 
98  {
99  public:
100 
102  std::vector<int> m_SelectedIdx;
103 
105  std::vector<int> m_SelectedCFieldIdx;
106 
108  std::string m_SelectedCFieldName;
109 
111  std::vector<std::string> m_SelectedNames;
112  unsigned int m_NbFeatures;
113 
114  void SetFieldNames(std::vector<std::string> fieldNames, std::vector<int> selectedIdx)
115  {
116  m_SelectedIdx = selectedIdx;
117  m_NbFeatures = static_cast<unsigned int>(selectedIdx.size());
118  m_SelectedNames = std::vector<std::string>(m_NbFeatures);
119  for (unsigned int i = 0; i < m_NbFeatures; ++i)
120  {
121  m_SelectedNames[i] = fieldNames[selectedIdx[i]];
122  }
123  }
124  void SetClassFieldNames(std::vector<std::string> cFieldNames, std::vector<int> selectedCFieldIdx)
125  {
126  m_SelectedCFieldIdx = selectedCFieldIdx;
127  // Handle only one class field name, if several are provided only the first one is used.
128  if (selectedCFieldIdx.empty())
129  m_SelectedCFieldName.clear();
130  else
131  m_SelectedCFieldName = cFieldNames[selectedCFieldIdx.front()];
132  }
133  };
134 
135 
136 protected:
142  virtual void ExtractAllSamples(const ShiftScaleParameters& measurement);
143 
150  virtual SamplesWithLabel ExtractTrainingSamplesWithLabel(const ShiftScaleParameters& measurement);
151 
158  virtual SamplesWithLabel ExtractClassificationSamplesWithLabel(const ShiftScaleParameters& measurement);
159 
160 
169  SamplesWithLabel ExtractSamplesWithLabel(std::string parameterName, std::string parameterLayer, const ShiftScaleParameters& measurement);
170 
171 
177  ShiftScaleParameters GetStatistics(unsigned int nbFeatures);
178 
181  typename TargetListSampleType::Pointer m_PredictedList;
183 
184  void DoInit() override;
185  void DoUpdateParameters() override;
186  void DoExecute() override;
187 };
188 }
189 }
190 
191 #ifndef OTB_MANUAL_INSTANTIATION
192 #include "otbTrainVectorBase.hxx"
193 #endif
194 
195 #endif
Read a xml file where are stored several statistics.
This class generate a shifted and scaled version of the input sample list.
This class represent an application TODO.
LearningApplicationBase is the base class for application that use machine learning model.
ModelType::TargetListSampleType TargetListSampleType
ModelType::InputListSampleType ListSampleType
void SetFieldNames(std::vector< std::string > fieldNames, std::vector< int > selectedIdx)
void SetClassFieldNames(std::vector< std::string > cFieldNames, std::vector< int > selectedCFieldIdx)
LearningApplicationBase< TInputValue, TOutputValue > Superclass
otb::Statistics::ShiftScaleSampleListFilter< ListSampleType, ListSampleType > ShiftScaleFilterType
virtual void ExtractAllSamples(const ShiftScaleParameters &measurement)
otb::StatisticsXMLFileReader< SampleType > StatisticsReader
virtual SamplesWithLabel ExtractClassificationSamplesWithLabel(const ShiftScaleParameters &measurement)
SamplesWithLabel m_ClassificationSamplesWithLabel
itk::VariableLengthVector< ValueType > MeasurementType
TargetListSampleType::Pointer m_PredictedList
itk::SmartPointer< const Self > ConstPointer
Superclass::SampleType SampleType
SamplesWithLabel m_TrainingSamplesWithLabel
itk::SmartPointer< Self > Pointer
Superclass::ListSampleType ListSampleType
SamplesWithLabel ExtractSamplesWithLabel(std::string parameterName, std::string parameterLayer, const ShiftScaleParameters &measurement)
ShiftScaleParameters GetStatistics(unsigned int nbFeatures)
Superclass::TargetListSampleType TargetListSampleType
virtual SamplesWithLabel ExtractTrainingSamplesWithLabel(const ShiftScaleParameters &measurement)
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.