OTB  6.7.0
Orfeo Toolbox
otbBoostMachineLearningModel.h
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 
21 #ifndef otbBoostMachineLearningModel_h
22 #define otbBoostMachineLearningModel_h
23 
24 #include "otbRequiresOpenCVCheck.h"
25 
26 #include "itkLightObject.h"
27 #include "itkFixedArray.h"
29 
30 #ifdef OTB_OPENCV_3
31 #include "otbOpenCVUtils.h"
32 #else
33 class CvBoost;
34 #endif
35 
36 namespace otb
37 {
38 template <class TInputValue, class TTargetValue>
39 class ITK_EXPORT BoostMachineLearningModel
40  : public MachineLearningModel <TInputValue, TTargetValue>
41 {
42 public:
48 
49  typedef typename Superclass::InputValueType InputValueType;
50  typedef typename Superclass::InputSampleType InputSampleType;
51  typedef typename Superclass::InputListSampleType InputListSampleType;
52  typedef typename Superclass::TargetValueType TargetValueType;
54  typedef typename Superclass::TargetListSampleType TargetListSampleType;
55  typedef typename Superclass::ConfidenceValueType ConfidenceValueType;
56  typedef typename Superclass::ProbaSampleType ProbaSampleType;
58  itkNewMacro(Self);
61 
67  itkGetMacro(BoostType, int);
68  itkSetMacro(BoostType, int);
70 
76  itkGetMacro(SplitCrit, int);
77  itkSetMacro(SplitCrit, int);
79 
84  itkGetMacro(WeakCount, int);
85  itkSetMacro(WeakCount, int);
87 
95  itkGetMacro(WeightTrimRate, double);
96  itkSetMacro(WeightTrimRate, double);
98 
103  itkGetMacro(MaxDepth, int);
104  itkSetMacro(MaxDepth, int);
106 
108  void Train() override;
109 
111  void Save(const std::string & filename, const std::string & name="") override;
112 
114  void Load(const std::string & filename, const std::string & name="") override;
115 
118 
120  bool CanReadFile(const std::string &) override;
121 
123  bool CanWriteFile(const std::string &) override;
125 
126 protected:
129 
131  ~BoostMachineLearningModel() override;
132 
134  TargetSampleType DoPredict(const InputSampleType& input, ConfidenceValueType *quality=nullptr, ProbaSampleType *proba=nullptr) const override;
135 
137  void PrintSelf(std::ostream& os, itk::Indent indent) const override;
138 
139 private:
140  BoostMachineLearningModel(const Self &) = delete;
141  void operator =(const Self&) = delete;
142 
143 #ifdef OTB_OPENCV_3
144  cv::Ptr<cv::ml::Boost> m_BoostModel;
145 #else
146  CvBoost * m_BoostModel;
147 #endif
153 };
154 } // end namespace otb
155 
156 #ifndef OTB_MANUAL_INSTANTIATION
158 #endif
159 
160 #endif
Superclass::TargetListSampleType TargetListSampleType
Superclass::ConfidenceValueType ConfidenceValueType
MachineLearningModel is the base class for all classifier objects (SVM, KNN, Random Forests...
Superclass::InputSampleType InputSampleType
Superclass::InputValueType InputValueType
MachineLearningModel< TInputValue, TTargetValue > Superclass
Superclass::TargetSampleType TargetSampleType
Superclass::InputListSampleType InputListSampleType
itk::SmartPointer< const Self > ConstPointer
Superclass::TargetValueType TargetValueType
Superclass::ProbaSampleType ProbaSampleType
MLMTargetTraits< TTargetValue >::SampleType TargetSampleType