OTB  6.7.0
Orfeo Toolbox
otbSOMModel.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 #ifndef otbSOMModel_h
21 #define otbSOMModel_h
22 
23 #include "otbSOMMap.h"
24 
25 #include "itkEuclideanDistanceMetric.h" // the distance function
26 
29 
32 
33 namespace otb
34 {
35 
41 template <class TInputValue, unsigned int MapDimension>
42 class ITK_EXPORT SOMModel
43  : public MachineLearningModel<
44  itk::VariableLengthVector< TInputValue >,
45  itk::VariableLengthVector< TInputValue > >
46 {
47 public:
48  typedef SOMModel Self;
49  typedef MachineLearningModel<
54 
56  typedef typename Superclass::InputSampleType InputSampleType;
57  typedef typename Superclass::InputListSampleType InputListSampleType;
58  typedef typename InputListSampleType::Pointer ListSamplePointerType;
59  typedef typename Superclass::TargetValueType TargetValueType;
61  typedef typename Superclass::TargetListSampleType TargetListSampleType;
62 
63  // Confidence map related typedefs
64  typedef typename Superclass::ConfidenceValueType ConfidenceValueType;
65  typedef typename Superclass::ConfidenceSampleType ConfidenceSampleType;
66  typedef typename Superclass::ConfidenceListSampleType ConfidenceListSampleType;
67  typedef typename Superclass::ProbaSampleType ProbaSampleType;
68  typedef typename Superclass::ProbaListSampleType ProbaListSampleType;
69  typedef SOMMap<
73  MapDimension> MapType;
74  typedef typename MapType::SizeType SizeType;
76 
79 
80  itkNewMacro(Self);
81  itkTypeMacro(SOMModel, DimensionalityReductionModel);
82 
84  itkSetMacro(NumberOfIterations, unsigned int);
85  itkGetMacro(NumberOfIterations, unsigned int);
86  itkSetMacro(BetaInit, double);
87  itkGetMacro(BetaInit, double);
88  itkSetMacro(WriteMap, bool);
89  itkGetMacro(WriteMap, bool);
90  itkSetMacro(BetaEnd, double);
91  itkGetMacro(BetaEnd, double);
92  itkSetMacro(MinWeight, InputValueType);
93  itkGetMacro(MinWeight, InputValueType);
94  itkSetMacro(MaxWeight, InputValueType);
95  itkGetMacro(MaxWeight, InputValueType);
96  itkSetMacro(MapSize, SizeType);
97  itkGetMacro(MapSize, SizeType);
98  itkSetMacro(NeighborhoodSizeInit, SizeType);
99  itkGetMacro(NeighborhoodSizeInit, SizeType);
100  itkSetMacro(RandomInit, bool);
101  itkGetMacro(RandomInit, bool);
102  itkSetMacro(Seed, unsigned int);
103  itkGetMacro(Seed, unsigned int);
105 
106  bool CanReadFile(const std::string & filename) override;
107  bool CanWriteFile(const std::string & filename) override;
108 
109  void Save(const std::string & filename, const std::string & name="") override;
110  void Load(const std::string & filename, const std::string & name="") override;
111 
112  void Train() override;
113 
114 protected:
115  SOMModel();
116  ~SOMModel() override;
117 
118 private:
120 
121  virtual TargetSampleType DoPredict(
122  const InputSampleType& input,
123  ConfidenceValueType * quality = nullptr,
124  ProbaSampleType * proba = nullptr) const override;
125 
128 
130  unsigned int m_NumberOfIterations;
131 
133  double m_BetaInit;
134 
136  double m_BetaEnd;
137 
140 
143 
146 
149 
151  unsigned int m_Seed;
152 
155 
158 
161 };
162 
163 } // end namespace otb
164 
165 #ifndef OTB_MANUAL_INSTANTIATION
166 #include "otbSOMModel.hxx"
167 #endif
168 
169 #endif
Superclass::ConfidenceValueType ConfidenceValueType
Definition: otbSOMModel.h:64
SOMModel Self
Definition: otbSOMModel.h:48
SOMMap< itk::VariableLengthVector< TInputValue >, itk::Statistics::EuclideanDistanceMetric< itk::VariableLengthVector< TInputValue > >, MapDimension > MapType
Definition: otbSOMModel.h:73
MapType::SpacingType SpacingType
Definition: otbSOMModel.h:75
Superclass::InputValueType InputValueType
Definition: otbSOMModel.h:55
MapType::Pointer m_SOMMap
Definition: otbSOMModel.h:119
MachineLearningModel is the base class for all classifier objects (SVM, KNN, Random Forests...
double m_BetaEnd
Definition: otbSOMModel.h:136
itk::SmartPointer< const Self > ConstPointer
Definition: otbSOMModel.h:53
InputListSampleType::Pointer ListSamplePointerType
Definition: otbSOMModel.h:58
This class represent a Self Organizing Map.
Definition: otbSOMMap.h:54
Superclass::SizeType SizeType
Definition: otbSOMMap.h:81
Functor::CzihoSOMLearningBehaviorFunctor SOMLearningBehaviorFunctorType
Definition: otbSOMModel.h:77
double m_BetaInit
Definition: otbSOMModel.h:133
Superclass::TargetListSampleType TargetListSampleType
Definition: otbSOMModel.h:61
Superclass::InputListSampleType InputListSampleType
Definition: otbSOMModel.h:57
itk::SmartPointer< Self > Pointer
Definition: otbSOMModel.h:52
Superclass::InputSampleType InputSampleType
Definition: otbSOMModel.h:56
Superclass::TargetValueType TargetValueType
Definition: otbSOMModel.h:59
MachineLearningModel< itk::VariableLengthVector< TInputValue >, itk::VariableLengthVector< TInputValue > > Superclass
Definition: otbSOMModel.h:51
MapType::SizeType SizeType
Definition: otbSOMModel.h:74
Functor::CzihoSOMNeighborhoodBehaviorFunctor SOMNeighborhoodBehaviorFunctorType
Definition: otbSOMModel.h:78
Superclass::ProbaSampleType ProbaSampleType
Definition: otbSOMModel.h:67
Superclass::TargetSampleType TargetSampleType
Definition: otbSOMModel.h:60
SizeType m_MapSize
Definition: otbSOMModel.h:127
Superclass::ConfidenceListSampleType ConfidenceListSampleType
Definition: otbSOMModel.h:66
unsigned int m_NumberOfIterations
Definition: otbSOMModel.h:130
SizeType m_NeighborhoodSizeInit
Definition: otbSOMModel.h:139
MLMSampleTraits< TInputValue >::ValueType InputValueType
unsigned int m_Seed
Definition: otbSOMModel.h:151
SOMLearningBehaviorFunctorType m_BetaFunctor
Definition: otbSOMModel.h:154
Superclass::ConfidenceSampleType ConfidenceSampleType
Definition: otbSOMModel.h:65
Superclass::SpacingType SpacingType
Definition: otbSOMMap.h:84
Superclass::ProbaListSampleType ProbaListSampleType
Definition: otbSOMModel.h:68
SOMNeighborhoodBehaviorFunctorType m_NeighborhoodSizeFunctor
Definition: otbSOMModel.h:157
Neighborhood size behavior over SOM training phase.
InputValueType m_MaxWeight
Definition: otbSOMModel.h:145
InputValueType m_MinWeight
Definition: otbSOMModel.h:142
MLMTargetTraits< TTargetValue >::SampleType TargetSampleType