OTB  9.0.0
Orfeo Toolbox
otbBoostMachineLearningModel.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2022 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 
21 #ifndef otbBoostMachineLearningModel_h
22 #define otbBoostMachineLearningModel_h
23 
24 #include "otbRequiresOpenCVCheck.h"
25 
26 #include "itkLightObject.h"
27 #include "itkFixedArray.h"
29 
30 #include "otbOpenCVUtils.h"
31 
32 namespace otb
33 {
34 template <class TInputValue, class TTargetValue>
35 class ITK_EXPORT BoostMachineLearningModel : public MachineLearningModel<TInputValue, TTargetValue>
36 {
37 public:
41  typedef itk::SmartPointer<Self> Pointer;
42  typedef itk::SmartPointer<const Self> ConstPointer;
43 
45  typedef typename Superclass::InputSampleType InputSampleType;
50  typedef typename Superclass::ConfidenceValueType ConfidenceValueType;
51  typedef typename Superclass::ProbaSampleType ProbaSampleType;
53  itkNewMacro(Self);
56 
62  itkGetMacro(BoostType, int);
63  itkSetMacro(BoostType, int);
65 
70  itkGetMacro(WeakCount, int);
71  itkSetMacro(WeakCount, int);
73 
81  itkGetMacro(WeightTrimRate, double);
82  itkSetMacro(WeightTrimRate, double);
84 
89  itkGetMacro(MaxDepth, int);
90  itkSetMacro(MaxDepth, int);
92 
94  void Train() override;
95 
97  void Save(const std::string& filename, const std::string& name = "") override;
98 
100  void Load(const std::string& filename, const std::string& name = "") override;
101 
104 
106  bool CanReadFile(const std::string&) override;
107 
109  bool CanWriteFile(const std::string&) override;
111 
112 protected:
115 
117  ~BoostMachineLearningModel() override = default;
118 
120  TargetSampleType DoPredict(const InputSampleType& input, ConfidenceValueType* quality = nullptr, ProbaSampleType* proba = nullptr) const override;
121 
123  void PrintSelf(std::ostream& os, itk::Indent indent) const override;
124 
125 private:
126  BoostMachineLearningModel(const Self&) = delete;
127  void operator=(const Self&) = delete;
128 
129  cv::Ptr<cv::ml::Boost> m_BoostModel;
130 
135 };
136 } // end namespace otb
137 
138 #ifndef OTB_MANUAL_INSTANTIATION
140 #endif
141 
142 #endif
otb::MachineLearningModel< TInputValue, TTargetValue >::TargetListSampleType
itk::Statistics::ListSample< TargetSampleType > TargetListSampleType
Definition: otbMachineLearningModel.h:92
otb::BoostMachineLearningModel::m_WeakCount
int m_WeakCount
Definition: otbBoostMachineLearningModel.h:132
otb::BoostMachineLearningModel::ConfidenceValueType
Superclass::ConfidenceValueType ConfidenceValueType
Definition: otbBoostMachineLearningModel.h:50
otb::BoostMachineLearningModel::m_WeightTrimRate
double m_WeightTrimRate
Definition: otbBoostMachineLearningModel.h:133
otb::MachineLearningModel< TInputValue, TTargetValue >::InputListSampleType
itk::Statistics::ListSample< InputSampleType > InputListSampleType
Definition: otbMachineLearningModel.h:85
otb::MachineLearningModel< TInputValue, TTargetValue >::InputValueType
MLMSampleTraits< TInputValue >::ValueType InputValueType
Definition: otbMachineLearningModel.h:83
otb::BoostMachineLearningModel
Definition: otbBoostMachineLearningModel.h:35
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::BoostMachineLearningModel::InputListSampleType
Superclass::InputListSampleType InputListSampleType
Definition: otbBoostMachineLearningModel.h:46
otb::BoostMachineLearningModel::InputValueType
Superclass::InputValueType InputValueType
Definition: otbBoostMachineLearningModel.h:44
otb::BoostMachineLearningModel::Self
BoostMachineLearningModel Self
Definition: otbBoostMachineLearningModel.h:39
otb::BoostMachineLearningModel::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition: otbBoostMachineLearningModel.h:42
otbMachineLearningModel.h
otb::BoostMachineLearningModel::InputSampleType
Superclass::InputSampleType InputSampleType
Definition: otbBoostMachineLearningModel.h:45
otb::BoostMachineLearningModel::TargetValueType
Superclass::TargetValueType TargetValueType
Definition: otbBoostMachineLearningModel.h:47
otb::BoostMachineLearningModel::m_BoostType
int m_BoostType
Definition: otbBoostMachineLearningModel.h:131
otb::BoostMachineLearningModel::Superclass
MachineLearningModel< TInputValue, TTargetValue > Superclass
Definition: otbBoostMachineLearningModel.h:40
otb::MachineLearningModel
MachineLearningModel is the base class for all classifier objects (SVM, KNN, Random Forests,...
Definition: otbMachineLearningModel.h:70
otb::BoostMachineLearningModel::TargetListSampleType
Superclass::TargetListSampleType TargetListSampleType
Definition: otbBoostMachineLearningModel.h:49
otb::BoostMachineLearningModel::m_BoostModel
cv::Ptr< cv::ml::Boost > m_BoostModel
Definition: otbBoostMachineLearningModel.h:129
otbOpenCVUtils.h
otb::MachineLearningModel< TInputValue, TTargetValue >::TargetValueType
MLMTargetTraits< TTargetValue >::ValueType TargetValueType
Definition: otbMachineLearningModel.h:90
otb::BoostMachineLearningModel::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbBoostMachineLearningModel.h:41
otb::BoostMachineLearningModel::m_MaxDepth
int m_MaxDepth
Definition: otbBoostMachineLearningModel.h:134
otb::BoostMachineLearningModel::ProbaSampleType
Superclass::ProbaSampleType ProbaSampleType
Definition: otbBoostMachineLearningModel.h:51
otbRequiresOpenCVCheck.h
otbBoostMachineLearningModel.hxx
otb::BoostMachineLearningModel::TargetSampleType
Superclass::TargetSampleType TargetSampleType
Definition: otbBoostMachineLearningModel.h:48
otb::MachineLearningModel::TargetSampleType
MLMTargetTraits< TTargetValue >::SampleType TargetSampleType
Definition: otbMachineLearningModel.h:91