21 #ifndef otbConfusionMatrixCalculator_hxx
22 #define otbConfusionMatrixCalculator_hxx
28 template <
class TRefListLabel,
class TProdListLabel>
31 m_OverallAccuracy(0.0),
32 m_FalseNegativeValue(0.0),
33 m_TrueNegativeValue(0.0),
34 m_FalsePositiveValue(0.0),
35 m_TruePositiveValue(0.0),
50 template <
class TRefListLabel,
class TProdListLabel>
53 typename RefListLabelType::ConstIterator refIterator = m_ReferenceLabels->Begin();
54 typename ProdListLabelType::ConstIterator prodIterator = m_ProducedLabels->Begin();
57 if ((m_ReferenceLabels->Size() != m_ProducedLabels->Size()) || (m_ReferenceLabels->Size() == 0) || (m_ProducedLabels->Size() == 0))
59 otbMsgDebugMacro(<<
"refLabels size = " << m_ReferenceLabels->Size() <<
" / proLabels size = " << m_ProducedLabels->Size());
60 throw itk::ExceptionObject(__FILE__, __LINE__,
"ListSample size mismatch", ITK_LOCATION);
63 m_NumberOfSamples = m_ReferenceLabels->Size();
67 while (refIterator != m_ReferenceLabels->End())
69 ClassLabelType currentLabel = refIterator.GetMeasurementVector()[0];
70 if (m_MapOfClasses.find(currentLabel) == m_MapOfClasses.end())
72 m_MapOfClasses[currentLabel] = countClasses;
73 m_MapOfIndices[countClasses] = currentLabel;
79 m_NumberOfClasses = countClasses;
83 typename MapOfClassesType::iterator itMapOfClasses;
84 itMapOfClasses = m_MapOfClasses.begin();
86 unsigned int itElt = 0;
87 while (itMapOfClasses != m_MapOfClasses.end())
90 m_MapOfClasses[currentLabel] = itElt;
91 m_MapOfIndices[itElt] = currentLabel;
97 std::vector<long int> samplesPerClass;
99 for (
unsigned int i = 0; i < m_NumberOfClasses; ++i)
100 samplesPerClass.push_back(0);
103 m_ConfusionMatrix.Fill(0);
105 refIterator = m_ReferenceLabels->Begin();
106 prodIterator = m_ProducedLabels->Begin();
108 while (refIterator != m_ReferenceLabels->End())
110 int refLabel = refIterator.GetMeasurementVector()[0];
111 int prodLabel = prodIterator.GetMeasurementVector()[0];
113 int refPos = m_MapOfClasses[refLabel];
114 int prodPos = m_MapOfClasses[prodLabel];
116 ++samplesPerClass[refPos];
117 m_ConfusionMatrix(refPos, prodPos) += 1;
124 m_ConfMatMeasurements->SetConfusionMatrix(m_ConfusionMatrix);
125 m_ConfMatMeasurements->Compute();
127 this->m_TruePositiveValues = m_ConfMatMeasurements->GetTruePositiveValues();
128 this->m_FalseNegativeValues = m_ConfMatMeasurements->GetFalseNegativeValues();
129 this->m_TrueNegativeValues = m_ConfMatMeasurements->GetTrueNegativeValues();
130 this->m_FalsePositiveValues = m_ConfMatMeasurements->GetFalsePositiveValues();
132 this->m_Precisions = m_ConfMatMeasurements->GetPrecisions();
133 this->m_Recalls = m_ConfMatMeasurements->GetRecalls();
134 this->m_FScores = m_ConfMatMeasurements->GetFScores();
137 this->m_TruePositiveValue = m_ConfMatMeasurements->GetTruePositiveValue();
138 this->m_FalseNegativeValue = m_ConfMatMeasurements->GetFalseNegativeValue();
139 this->m_TrueNegativeValue = m_ConfMatMeasurements->GetTrueNegativeValue();
140 this->m_FalsePositiveValue = m_ConfMatMeasurements->GetFalsePositiveValue();
142 this->m_Precision = m_ConfMatMeasurements->GetPrecision();
143 this->m_Recall = m_ConfMatMeasurements->GetRecall();
144 this->m_FScore = m_ConfMatMeasurements->GetFScore();
146 this->m_OverallAccuracy = m_ConfMatMeasurements->GetOverallAccuracy();
147 this->m_KappaIndex = m_ConfMatMeasurements->GetKappaIndex();
150 template <
class TRefListLabel,
class TProdListLabel>
153 os << indent <<
"TODO";