21 #ifndef otbDecisionTree_hxx
22 #define otbDecisionTree_hxx
26 #include "itkNumericTraits.h"
33 template <
class AttributeValueType,
class LabelType>
38 m_Label =
static_cast<LabelType
>(0);
44 template <
class AttributeValueType,
class LabelType>
50 template <
class AttributeValueType,
class LabelType>
55 (*m_TreeMap)[key] = branch;
58 template <
class AttributeValueType,
class LabelType>
63 (*m_TreeMap)[key] = branch;
66 template <
class AttributeValueType,
class LabelType>
71 m_LabelMap[key] = label;
74 template <
class AttributeValueType,
class LabelType>
79 m_LabelMap[key] = label;
82 template <
class AttributeValueType,
class LabelType>
85 AttributeValueType attrValue = example[m_Attribute];
87 otbMsgDevMacro(<<
"Trying to match attribute " << m_Attribute <<
" with value " << attrValue);
92 typename LabelMapType::const_iterator lmIt = m_LabelMap.begin();
93 while (lmIt != m_LabelMap.end())
97 AttributeValueType theValue = theKey.first;
101 if (attrValue < theValue)
105 if (attrValue <= theValue)
109 if (attrValue == theValue)
113 if (attrValue >= theValue)
117 if (attrValue > theValue)
125 itkGenericExceptionMacro(<<
"Example could not be handled by decision tree.");
132 std::vector<KeyType> candidateKeys;
134 typename TreeMapType::const_iterator tmIt = m_TreeMap->begin();
135 while (tmIt != m_TreeMap->end())
139 AttributeValueType theValue = theKey.first;
143 if (attrValue < theValue)
145 candidateKeys.push_back(theKey);
150 if (attrValue <= theValue)
152 candidateKeys.push_back(theKey);
157 if (attrValue == theValue)
159 candidateKeys.push_back(theKey);
164 if (attrValue >= theValue)
166 candidateKeys.push_back(theKey);
171 if (attrValue > theValue)
173 candidateKeys.push_back(theKey);
185 itkGenericExceptionMacro(<<
"Example could not be handled by decision tree.");
190 typename std::vector<KeyType>::const_iterator ckIt = candidateKeys.begin();
191 while (ckIt != candidateKeys.end())
194 Pointer child = (*m_TreeMap)[(*ckIt)];
195 return child->Decide(example);
201 return static_cast<LabelType
>(0);
208 template <
class AttributeValueType,
class LabelType>
211 Superclass::PrintSelf(os, indent);