OTB  10.0.0
Orfeo Toolbox
otbSOMModel.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 #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 : public MachineLearningModel<itk::VariableLengthVector<TInputValue>, itk::VariableLengthVector<TInputValue>>
43 {
44 public:
45  typedef SOMModel Self;
46  typedef MachineLearningModel<itk::VariableLengthVector<TInputValue>, itk::VariableLengthVector<TInputValue>> Superclass;
47  typedef itk::SmartPointer<Self> Pointer;
48  typedef itk::SmartPointer<const Self> ConstPointer;
49 
51  typedef typename Superclass::InputSampleType InputSampleType;
53  typedef typename InputListSampleType::Pointer ListSamplePointerType;
57 
58  // Confidence map related typedefs
59  typedef typename Superclass::ConfidenceValueType ConfidenceValueType;
62  typedef typename Superclass::ProbaSampleType ProbaSampleType;
64  typedef SOMMap<itk::VariableLengthVector<TInputValue>, itk::Statistics::EuclideanDistanceMetric<itk::VariableLengthVector<TInputValue>>, MapDimension>
66  typedef typename MapType::SizeType SizeType;
68 
71 
72  itkNewMacro(Self);
73  itkTypeMacro(SOMModel, DimensionalityReductionModel);
74 
76  itkSetMacro(NumberOfIterations, unsigned int);
77  itkGetMacro(NumberOfIterations, unsigned int);
78  itkSetMacro(BetaInit, double);
79  itkGetMacro(BetaInit, double);
80  itkSetMacro(WriteMap, bool);
81  itkGetMacro(WriteMap, bool);
82  itkSetMacro(BetaEnd, double);
83  itkGetMacro(BetaEnd, double);
84  itkSetMacro(MinWeight, InputValueType);
85  itkGetMacro(MinWeight, InputValueType);
86  itkSetMacro(MaxWeight, InputValueType);
87  itkGetMacro(MaxWeight, InputValueType);
88  itkSetMacro(MapSize, SizeType);
89  itkGetMacro(MapSize, SizeType);
90  itkSetMacro(NeighborhoodSizeInit, SizeType);
91  itkGetMacro(NeighborhoodSizeInit, SizeType);
92  itkSetMacro(RandomInit, bool);
93  itkGetMacro(RandomInit, bool);
94  itkSetMacro(Seed, unsigned int);
95  itkGetMacro(Seed, unsigned int);
97 
98  bool CanReadFile(const std::string& filename) override;
99  bool CanWriteFile(const std::string& filename) override;
100 
101  void Save(const std::string& filename, const std::string& name = "") override;
102  void Load(const std::string& filename, const std::string& name = "") override;
103 
104  void Train() override;
105 
106 protected:
107  SOMModel();
108  ~SOMModel() override;
109 
110 private:
112 
113  virtual TargetSampleType DoPredict(const InputSampleType& input, ConfidenceValueType* quality = nullptr, ProbaSampleType* proba = nullptr) const override;
114 
116  SizeType m_MapSize{0,0};
117 
119  unsigned int m_NumberOfIterations;
120 
122  double m_BetaInit;
123 
125  double m_BetaEnd;
126 
128  SizeType m_NeighborhoodSizeInit{0,0};
129 
132 
135 
138 
140  unsigned int m_Seed;
141 
144 
147 
150 };
151 
152 } // end namespace otb
153 
154 #ifndef OTB_MANUAL_INSTANTIATION
155 #include "otbSOMModel.hxx"
156 #endif
157 
158 #endif
Neighborhood size behavior over SOM training phase.
MachineLearningModel is the base class for all classifier objects (SVM, KNN, Random Forests,...
MLMSampleTraits< TInputValue >::ValueType InputValueType
MLMTargetTraits< TTargetValue >::SampleType TargetSampleType
This class represent a Self Organizing Map.
Definition: otbSOMMap.h:54
Superclass::SizeType SizeType
Definition: otbSOMMap.h:79
Superclass::SpacingType SpacingType
Definition: otbSOMMap.h:82
itk::SmartPointer< Self > Pointer
Definition: otbSOMMap.h:60
SOMNeighborhoodBehaviorFunctorType m_NeighborhoodSizeFunctor
Definition: otbSOMModel.h:146
InputListSampleType::Pointer ListSamplePointerType
Definition: otbSOMModel.h:53
Superclass::InputSampleType InputSampleType
Definition: otbSOMModel.h:51
MapType::SizeType SizeType
Definition: otbSOMModel.h:66
Superclass::TargetValueType TargetValueType
Definition: otbSOMModel.h:54
unsigned int m_NumberOfIterations
Definition: otbSOMModel.h:119
unsigned int m_Seed
Definition: otbSOMModel.h:140
Superclass::ConfidenceListSampleType ConfidenceListSampleType
Definition: otbSOMModel.h:61
Superclass::TargetSampleType TargetSampleType
Definition: otbSOMModel.h:55
Superclass::ProbaSampleType ProbaSampleType
Definition: otbSOMModel.h:62
Superclass::ConfidenceValueType ConfidenceValueType
Definition: otbSOMModel.h:59
Functor::CzihoSOMNeighborhoodBehaviorFunctor SOMNeighborhoodBehaviorFunctorType
Definition: otbSOMModel.h:70
MapType::SpacingType SpacingType
Definition: otbSOMModel.h:67
Superclass::ProbaListSampleType ProbaListSampleType
Definition: otbSOMModel.h:63
Superclass::InputValueType InputValueType
Definition: otbSOMModel.h:50
Superclass::InputListSampleType InputListSampleType
Definition: otbSOMModel.h:52
MachineLearningModel< itk::VariableLengthVector< TInputValue >, itk::VariableLengthVector< TInputValue > > Superclass
Definition: otbSOMModel.h:46
itk::SmartPointer< const Self > ConstPointer
Definition: otbSOMModel.h:48
MapType::Pointer m_SOMMap
Definition: otbSOMModel.h:111
Superclass::TargetListSampleType TargetListSampleType
Definition: otbSOMModel.h:56
SOMLearningBehaviorFunctorType m_BetaFunctor
Definition: otbSOMModel.h:143
double m_BetaInit
Definition: otbSOMModel.h:122
Functor::CzihoSOMLearningBehaviorFunctor SOMLearningBehaviorFunctorType
Definition: otbSOMModel.h:69
InputValueType m_MinWeight
Definition: otbSOMModel.h:131
double m_BetaEnd
Definition: otbSOMModel.h:125
SOMMap< itk::VariableLengthVector< TInputValue >, itk::Statistics::EuclideanDistanceMetric< itk::VariableLengthVector< TInputValue > >, MapDimension > MapType
Definition: otbSOMModel.h:65
Superclass::ConfidenceSampleType ConfidenceSampleType
Definition: otbSOMModel.h:60
itk::SmartPointer< Self > Pointer
Definition: otbSOMModel.h:47
SOMModel Self
Definition: otbSOMModel.h:45
InputValueType m_MaxWeight
Definition: otbSOMModel.h:134
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.