OTB  9.0.0
Orfeo Toolbox
otbDecisionTree.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 otbDecisionTree_h
22 #define otbDecisionTree_h
23 
24 #include <map>
25 #include "itkObjectFactory.h"
26 #include "itkDataObject.h"
27 
28 namespace otb
29 {
30 
60 template <class AttributeValueType, class LabelType>
61 class ITK_EXPORT DecisionTree : public itk::DataObject
62 {
63 public:
65  {
66  MIN,
67  LT = MIN,
68  LE,
69  EQ,
70  GE,
71  GT,
72  MAX = GT
73  };
75  typedef DecisionTree Self;
76  typedef itk::DataObject Superclass;
77  typedef itk::SmartPointer<Self> Pointer;
78  typedef itk::SmartPointer<const Self> ConstPointer;
79 
81  itkNewMacro(Self);
82 
84  itkTypeMacro(DecisionTree, DataObject);
85 
86  typedef typename std::pair<AttributeValueType, DecisionTreeTestType> KeyType;
87  typedef typename std::map<KeyType, Pointer> TreeMapType;
88  typedef typename std::map<KeyType, LabelType> LabelMapType;
89  typedef std::vector<AttributeValueType> ExampleType;
90 
91  itkSetMacro(Attribute, unsigned int);
92  itkGetMacro(Attribute, unsigned int);
93 
95  void AddBranch(AttributeValueType attr, DecisionTreeTestType testType, Pointer branch);
96 
99  void AddBranch(AttributeValueType attr, Pointer branch);
100 
102  void AddBranch(AttributeValueType attr, DecisionTreeTestType testType, LabelType label);
103 
106  void AddBranch(AttributeValueType attr, LabelType label);
107 
108  LabelType Decide(const ExampleType& example);
109 
110 protected:
112  DecisionTree();
113 
115  ~DecisionTree() override;
116 
120  void PrintSelf(std::ostream& os, itk::Indent indent) const override;
121 
122 private:
123  DecisionTree(const Self&) = delete;
124  void operator=(const Self&) = delete;
125 
128 
131 
133  unsigned int m_Attribute;
134 
136  bool m_IsFinal;
137 
138  LabelType m_Label;
139 };
140 } // end namespace otb
141 
142 #ifndef OTB_MANUAL_INSTANTIATION
143 #include "otbDecisionTree.hxx"
144 #endif
145 
146 #endif
otb::CellFusionMode::MIN
@ MIN
Definition: otbMulti3DMapToDEMFilter.h:41
otb::DecisionTree::Self
DecisionTree Self
Definition: otbDecisionTree.h:75
otb::DecisionTree::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition: otbDecisionTree.h:78
otb::DecisionTree::TreeMapType
std::map< KeyType, Pointer > TreeMapType
Definition: otbDecisionTree.h:87
otb::DecisionTree::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbDecisionTree.h:77
otb::DecisionTree::m_LabelMap
LabelMapType m_LabelMap
Definition: otbDecisionTree.h:130
otb::DecisionTree::DecisionTreeTestType
DecisionTreeTestType
Definition: otbDecisionTree.h:64
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::DecisionTree::KeyType
std::pair< AttributeValueType, DecisionTreeTestType > KeyType
Definition: otbDecisionTree.h:84
otb::DecisionTree::m_TreeMap
TreeMapType * m_TreeMap
Definition: otbDecisionTree.h:127
otb::DecisionTree::GE
@ GE
Definition: otbDecisionTree.h:70
otb::DecisionTree::m_Attribute
unsigned int m_Attribute
Definition: otbDecisionTree.h:133
otb::DecisionTree::MIN
@ MIN
Definition: otbDecisionTree.h:66
otb::DecisionTree::m_IsFinal
bool m_IsFinal
Definition: otbDecisionTree.h:136
otb::DecisionTree
Models a decision tree.
Definition: otbDecisionTree.h:61
otb::DecisionTree::LabelMapType
std::map< KeyType, LabelType > LabelMapType
Definition: otbDecisionTree.h:88
otb::DecisionTree::Superclass
itk::DataObject Superclass
Definition: otbDecisionTree.h:76
otb::DecisionTree::EQ
@ EQ
Definition: otbDecisionTree.h:69
otbDecisionTree.hxx
otb::DecisionTree::ExampleType
std::vector< AttributeValueType > ExampleType
Definition: otbDecisionTree.h:89
otb::DecisionTree::LE
@ LE
Definition: otbDecisionTree.h:68
otb::DecisionTree::GT
@ GT
Definition: otbDecisionTree.h:71
otb::DecisionTree::m_Label
LabelType m_Label
Definition: otbDecisionTree.h:138