OTB  9.0.0
Orfeo Toolbox
otbSOMModel.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 #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
otb::SOMModel::m_RandomInit
bool m_RandomInit
Definition: otbSOMModel.h:137
otb::SOMModel::Self
SOMModel Self
Definition: otbSOMModel.h:45
otbSOMModel.hxx
otb::MachineLearningModel::TargetListSampleType
itk::Statistics::ListSample< TargetSampleType > TargetListSampleType
Definition: otbMachineLearningModel.h:92
otb::SOMModel::ConfidenceValueType
Superclass::ConfidenceValueType ConfidenceValueType
Definition: otbSOMModel.h:59
otb::SOMModel::m_BetaEnd
double m_BetaEnd
Definition: otbSOMModel.h:125
otbCzihoSOMLearningBehaviorFunctor.h
otb::MachineLearningModel< itk::VariableLengthVector< TInputValue >, itk::VariableLengthVector< TInputValue > >::ProbaListSampleType
itk::Statistics::ListSample< ProbaSampleType > ProbaListSampleType
Definition: otbMachineLearningModel.h:102
otb::SOMMap::SizeType
Superclass::SizeType SizeType
Definition: otbSOMMap.h:79
otb::SOMModel
Definition: otbSOMModel.h:42
otb::MachineLearningModel::InputListSampleType
itk::Statistics::ListSample< InputSampleType > InputListSampleType
Definition: otbMachineLearningModel.h:85
otb::MachineLearningModel::InputValueType
MLMSampleTraits< TInputValue >::ValueType InputValueType
Definition: otbMachineLearningModel.h:83
otb::SOMModel::ProbaListSampleType
Superclass::ProbaListSampleType ProbaListSampleType
Definition: otbSOMModel.h:63
otb::Functor::CzihoSOMLearningBehaviorFunctor
Beta behavior over SOM training phase.
Definition: otbCzihoSOMLearningBehaviorFunctor.h:65
otbSOMMap.h
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otbMachineLearningModelTraits.h
otb::SOMModel::ListSamplePointerType
InputListSampleType::Pointer ListSamplePointerType
Definition: otbSOMModel.h:53
otb::SOMModel::SizeType
MapType::SizeType SizeType
Definition: otbSOMModel.h:66
otb::MachineLearningModel::ConfidenceListSampleType
itk::Statistics::ListSample< ConfidenceSampleType > ConfidenceListSampleType
Definition: otbMachineLearningModel.h:98
otb::SOMModel::SpacingType
MapType::SpacingType SpacingType
Definition: otbSOMModel.h:67
otbCzihoSOMNeighborhoodBehaviorFunctor.h
otb::SOMModel::TargetListSampleType
Superclass::TargetListSampleType TargetListSampleType
Definition: otbSOMModel.h:56
otb::SOMModel::m_BetaFunctor
SOMLearningBehaviorFunctorType m_BetaFunctor
Definition: otbSOMModel.h:143
otb::SOMModel::InputSampleType
Superclass::InputSampleType InputSampleType
Definition: otbSOMModel.h:51
otb::SOMModel::m_WriteMap
bool m_WriteMap
Definition: otbSOMModel.h:149
otb::SOMModel::Superclass
MachineLearningModel< itk::VariableLengthVector< TInputValue >, itk::VariableLengthVector< TInputValue > > Superclass
Definition: otbSOMModel.h:46
otbMachineLearningModel.h
otb::SOMModel::MapType
SOMMap< itk::VariableLengthVector< TInputValue >, itk::Statistics::EuclideanDistanceMetric< itk::VariableLengthVector< TInputValue > >, MapDimension > MapType
Definition: otbSOMModel.h:65
otb::SOMModel::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition: otbSOMModel.h:48
otb::SOMMap::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbSOMMap.h:60
otb::SOMModel::m_MaxWeight
InputValueType m_MaxWeight
Definition: otbSOMModel.h:134
otb::SOMModel::m_NumberOfIterations
unsigned int m_NumberOfIterations
Definition: otbSOMModel.h:119
otb::SOMModel::InputValueType
Superclass::InputValueType InputValueType
Definition: otbSOMModel.h:50
otb::SOMModel::m_BetaInit
double m_BetaInit
Definition: otbSOMModel.h:122
otb::MachineLearningModel< itk::VariableLengthVector< TInputValue >, itk::VariableLengthVector< TInputValue > >::ConfidenceSampleType
MLMTargetTraits< double >::SampleType ConfidenceSampleType
Definition: otbMachineLearningModel.h:97
otb::SOMModel::SOMLearningBehaviorFunctorType
Functor::CzihoSOMLearningBehaviorFunctor SOMLearningBehaviorFunctorType
Definition: otbSOMModel.h:69
otb::SOMMap::SpacingType
Superclass::SpacingType SpacingType
Definition: otbSOMMap.h:82
otb::SOMModel::ProbaSampleType
Superclass::ProbaSampleType ProbaSampleType
Definition: otbSOMModel.h:62
otb::SOMModel::TargetSampleType
Superclass::TargetSampleType TargetSampleType
Definition: otbSOMModel.h:55
otb::SOMModel::ConfidenceListSampleType
Superclass::ConfidenceListSampleType ConfidenceListSampleType
Definition: otbSOMModel.h:61
otb::MachineLearningModel
MachineLearningModel is the base class for all classifier objects (SVM, KNN, Random Forests,...
Definition: otbMachineLearningModel.h:70
otb::SOMModel::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbSOMModel.h:47
otb::MachineLearningModel< itk::VariableLengthVector< TInputValue >, itk::VariableLengthVector< TInputValue > >::TargetValueType
MLMTargetTraits< itk::VariableLengthVector< TInputValue > >::ValueType TargetValueType
Definition: otbMachineLearningModel.h:90
otb::SOMModel::SOMNeighborhoodBehaviorFunctorType
Functor::CzihoSOMNeighborhoodBehaviorFunctor SOMNeighborhoodBehaviorFunctorType
Definition: otbSOMModel.h:70
otb::SOMModel::ConfidenceSampleType
Superclass::ConfidenceSampleType ConfidenceSampleType
Definition: otbSOMModel.h:60
otb::SOMModel::TargetValueType
Superclass::TargetValueType TargetValueType
Definition: otbSOMModel.h:54
otb::SOMModel::m_NeighborhoodSizeFunctor
SOMNeighborhoodBehaviorFunctorType m_NeighborhoodSizeFunctor
Definition: otbSOMModel.h:146
otb::SOMMap
This class represent a Self Organizing Map.
Definition: otbSOMMap.h:53
otb::SOMModel::InputListSampleType
Superclass::InputListSampleType InputListSampleType
Definition: otbSOMModel.h:52
otb::SOMModel::m_Seed
unsigned int m_Seed
Definition: otbSOMModel.h:140
otb::Functor::CzihoSOMNeighborhoodBehaviorFunctor
Neighborhood size behavior over SOM training phase.
Definition: otbCzihoSOMNeighborhoodBehaviorFunctor.h:56
otb::MachineLearningModel::TargetSampleType
MLMTargetTraits< TTargetValue >::SampleType TargetSampleType
Definition: otbMachineLearningModel.h:91
otb::SOMModel::m_MinWeight
InputValueType m_MinWeight
Definition: otbSOMModel.h:131
otb::SOMModel::m_SOMMap
MapType::Pointer m_SOMMap
Definition: otbSOMModel.h:111