OTB  10.0.0
Orfeo Toolbox
otbSVMMarginSampler.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 
21 #ifndef otbSVMMarginSampler_h
22 #define otbSVMMarginSampler_h
23 
24 #include "itkSampleClassifierFilter.h"
25 #include "itkVectorImage.h"
26 
27 namespace otb
28 {
29 
37 template <class TSample, class TModel>
38 class ITK_EXPORT SVMMarginSampler : public itk::Statistics::SampleClassifierFilter<TSample>
39 {
40 public:
43  typedef itk::Statistics::SampleClassifierFilter<TSample> Superclass;
44  typedef itk::SmartPointer<Self> Pointer;
45  typedef itk::SmartPointer<const Self> ConstPointer;
46 
48  itkTypeMacro(SVMMarginSampler, itk::Statistics::SampleClassifierFilter);
49  itkNewMacro(Self);
51 
53  typedef typename Superclass::MembershipSampleType OutputType;
54 
56  typedef typename TSample::MeasurementType MeasurementType;
57  typedef typename TSample::MeasurementVectorType MeasurementVectorType;
58  typedef std::pair<unsigned int, double> IndexAndDistanceType;
59  typedef std::vector<IndexAndDistanceType> IndexAndDistanceVectorType;
60  typedef std::vector<unsigned int> IndexVectorType;
61 
62 
63  static bool Compare(const IndexAndDistanceType& l1, const IndexAndDistanceType& l2)
64  {
65  bool resp = l2.second > l1.second;
66  return resp;
67  }
68 
70  typedef TModel SVMModelType;
71  typedef typename SVMModelType::Pointer SVMModelPointer;
72 
73  itkSetMacro(NumberOfCandidates, unsigned int);
74  itkGetMacro(NumberOfCandidates, unsigned int);
75 
77  itkSetObjectMacro(Model, SVMModelType);
78 
81 
83  {
84  return m_MarginSamples;
85  }
86 
87 protected:
89  ~SVMMarginSampler() override
90  {
91  }
92  void PrintSelf(std::ostream& os, itk::Indent indent) const override;
93 
95  void GenerateData() override;
96  virtual void DoMarginSampling();
98 
99 private:
101 
102  unsigned int m_NumberOfCandidates;
103 
105 
106 }; // end of class
107 
108 
109 } // end of namespace otb
110 
111 
112 #ifndef OTB_MANUAL_INSTANTIATION
113 #include "otbSVMMarginSampler.hxx"
114 #endif
115 
116 #endif
Implement one iteration of active learning by margin.
itk::SmartPointer< Self > Pointer
std::vector< IndexAndDistanceType > IndexAndDistanceVectorType
itk::SmartPointer< const Self > ConstPointer
IndexVectorType m_MarginSamples
TSample::MeasurementVectorType MeasurementVectorType
const IndexVectorType & GetMarginSamples()
itkGetObjectMacro(Model, SVMModelType)
Superclass::MembershipSampleType OutputType
TSample::MeasurementType MeasurementType
std::pair< unsigned int, double > IndexAndDistanceType
std::vector< unsigned int > IndexVectorType
static bool Compare(const IndexAndDistanceType &l1, const IndexAndDistanceType &l2)
SVMModelType::Pointer SVMModelPointer
itk::Statistics::SampleClassifierFilter< TSample > Superclass
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.