OTB  9.0.0
Orfeo Toolbox
otbSVMMarginSampler.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 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 
80  itkGetObjectMacro(Model, SVMModelType);
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
otb::SVMMarginSampler::~SVMMarginSampler
~SVMMarginSampler() override
Definition: otbSVMMarginSampler.h:89
otb::SVMMarginSampler::MeasurementVectorType
TSample::MeasurementVectorType MeasurementVectorType
Definition: otbSVMMarginSampler.h:57
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::SVMMarginSampler::IndexVectorType
std::vector< unsigned int > IndexVectorType
Definition: otbSVMMarginSampler.h:60
otb::SVMMarginSampler::m_NumberOfCandidates
unsigned int m_NumberOfCandidates
Definition: otbSVMMarginSampler.h:102
otb::SVMMarginSampler::SVMModelType
TModel SVMModelType
Definition: otbSVMMarginSampler.h:70
otb::SVMMarginSampler::m_Model
SVMModelPointer m_Model
Definition: otbSVMMarginSampler.h:100
otb::SVMMarginSampler::IndexAndDistanceVectorType
std::vector< IndexAndDistanceType > IndexAndDistanceVectorType
Definition: otbSVMMarginSampler.h:59
otb::SVMMarginSampler::GetMarginSamples
const IndexVectorType & GetMarginSamples()
Definition: otbSVMMarginSampler.h:82
otbSVMMarginSampler.hxx
otb::SVMMarginSampler::MeasurementType
TSample::MeasurementType MeasurementType
Definition: otbSVMMarginSampler.h:56
otb::SVMMarginSampler::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition: otbSVMMarginSampler.h:45
otb::SVMMarginSampler::Compare
static bool Compare(const IndexAndDistanceType &l1, const IndexAndDistanceType &l2)
Definition: otbSVMMarginSampler.h:63
otb::SVMMarginSampler::Superclass
itk::Statistics::SampleClassifierFilter< TSample > Superclass
Definition: otbSVMMarginSampler.h:43
otb::SVMMarginSampler::Self
SVMMarginSampler Self
Definition: otbSVMMarginSampler.h:42
otb::SVMMarginSampler
Implement one iteration of active learning by margin.
Definition: otbSVMMarginSampler.h:38
otb::SVMMarginSampler::IndexAndDistanceType
std::pair< unsigned int, double > IndexAndDistanceType
Definition: otbSVMMarginSampler.h:58
otb::SVMMarginSampler::m_MarginSamples
IndexVectorType m_MarginSamples
Definition: otbSVMMarginSampler.h:104
otb::SVMMarginSampler::OutputType
Superclass::MembershipSampleType OutputType
Definition: otbSVMMarginSampler.h:49
otb::SVMMarginSampler::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbSVMMarginSampler.h:44
otb::SVMMarginSampler::SVMModelPointer
SVMModelType::Pointer SVMModelPointer
Definition: otbSVMMarginSampler.h:71