OTB  6.7.0
Orfeo Toolbox
otbSVMMarginSampler.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 otbSVMMarginSampler_h
22 #define otbSVMMarginSampler_h
23 
25 #include "itkVectorImage.h"
26 
27 namespace otb
28 {
29 
37 template< class TSample, class TModel >
38 class ITK_EXPORT SVMMarginSampler :
40 {
41 public:
47 
50  itkNewMacro(Self);
52 
54  typedef typename Superclass::MembershipSampleType OutputType;
55 
57  typedef typename TSample::MeasurementType MeasurementType;
58  typedef typename TSample::MeasurementVectorType MeasurementVectorType;
59  typedef std::pair<unsigned int, double> IndexAndDistanceType;
60  typedef std::vector<IndexAndDistanceType> IndexAndDistanceVectorType;
61  typedef std::vector<unsigned int> IndexVectorType;
62 
63 
64  static bool Compare(const IndexAndDistanceType& l1, const IndexAndDistanceType & l2)
65  {
66  bool resp = l2.second > l1.second;
67  return resp;
68  }
69 
71  typedef TModel SVMModelType;
72  typedef typename SVMModelType::Pointer SVMModelPointer;
73 
74  itkSetMacro(NumberOfCandidates, unsigned int);
75  itkGetMacro(NumberOfCandidates, unsigned int);
76 
78  itkSetObjectMacro(Model, SVMModelType);
79 
81  itkGetObjectMacro(Model, SVMModelType);
82 
84  {
85  return m_MarginSamples;
86  }
87 
88 protected:
90  ~SVMMarginSampler() override {}
91  void PrintSelf(std::ostream& os, itk::Indent indent) const override;
92 
94  void GenerateData() override;
95  virtual void DoMarginSampling();
97 
98 private:
99 
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
117 
118 
Implement one iteration of active learning by margin.
itk::SmartPointer< const Self > ConstPointer
itk::Statistics::SampleClassifierFilter< TSample > Superclass
SVMModelType::Pointer SVMModelPointer
TSample::MeasurementVectorType MeasurementVectorType
std::vector< IndexAndDistanceType > IndexAndDistanceVectorType
TSample::MeasurementType MeasurementType
const IndexVectorType & GetMarginSamples()
static bool Compare(const IndexAndDistanceType &l1, const IndexAndDistanceType &l2)
IndexVectorType m_MarginSamples
std::pair< unsigned int, double > IndexAndDistanceType
Superclass::MembershipSampleType OutputType
itk::SmartPointer< Self > Pointer
std::vector< unsigned int > IndexVectorType